Skip to content

Commit

Permalink
Merge pull request #171 from screwdriver-cd/embiggen-token-hash
Browse files Browse the repository at this point in the history
fix(tokens): increase hash size to 512 bits
  • Loading branch information
r3rastogi authored Aug 17, 2017
2 parents 8c5eb54 + ddb9ca3 commit baee5e4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions models/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

const Joi = require('joi');
const mutate = require('../lib/mutate');
// Token length, measured in bits
const TOKEN_LENGTH = 256;
// Calculate the character length of the base64 string representing TOKEN_LENGTH bits
// Token hash length, measured in bits
const HASH_LENGTH = 512;
// Calculate the character length of the base64 string representing HASH_LENGTH bits
// Each base64 character represents 6 bits of data
const HASH_LENGTH = Math.ceil(TOKEN_LENGTH / 6);
const HASH_BASE64_LENGTH = Math.ceil(HASH_LENGTH / 6);

const MODEL = {
id: Joi
Expand All @@ -18,7 +18,7 @@ const MODEL = {
.string()
// Using https://www.npmjs.com/package/base64url
.regex(/[a-zA-Z0-9_-]+/)
.length(HASH_LENGTH)
.length(HASH_BASE64_LENGTH)
.description('Hashed token value'),

userId: Joi
Expand Down
2 changes: 1 addition & 1 deletion test/data/token.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Base Token Example
userId: 1234
hash: 'aHashedTokenValueMustBe43CharactersLong_-_-'
hash: 'aHashedTokenValueMustBe86CharactersLong_______________________________________________'
id: 1111
name: 'Auth token'
description: 'A token for authentication'
Expand Down

0 comments on commit baee5e4

Please sign in to comment.