-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: the bytes of the output of the hash function must be base64url-e…
…ncoded. (#57) Signed-off-by: JOYE LIN <[email protected]> Co-authored-by: Lukas.J.Han <[email protected]>
- Loading branch information
Showing
5 changed files
with
108 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { Base64Url } from './base64url'; | ||
import { generateSalt, digest } from './crypto'; | ||
import { generateSalt, digest , hexToB64Url} from './crypto'; | ||
import { Hasher, SaltGenerator } from './type'; | ||
|
||
export const createDecoy = async ( | ||
hasher: Hasher = digest, | ||
saltGenerator: SaltGenerator = generateSalt, | ||
): Promise<string> => { | ||
const salt = saltGenerator(16); | ||
const digest = await hasher(salt); | ||
const decoy = Base64Url.encode(digest); | ||
const decoyHexString = await hasher(salt); | ||
const decoy = hexToB64Url(decoyHexString) | ||
return decoy; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,25 @@ | ||
import { createDecoy } from '../decoy'; | ||
import { Base64Url } from '../base64url'; | ||
import { digest } from '../crypto'; | ||
|
||
describe('Decoy', () => { | ||
test('decoy', async () => { | ||
const decoyValue = await createDecoy(); | ||
expect(decoyValue.length).toBe(86); | ||
// base64url-encoded sha256 is a 43-octet URL safe string. | ||
expect(decoyValue.length).toBe(43); | ||
}); | ||
|
||
// ref https://datatracker.ietf.org/doc/draft-ietf-oauth-selective-disclosure-jwt/07/ | ||
// *Claim email*: | ||
// * SHA-256 Hash: JzYjH4svliH0R3PyEMfeZu6Jt69u5qehZo7F7EPYlSE | ||
// * Disclosure: WyI2SWo3dE0tYTVpVlBHYm9TNXRtdlZBIiwgImVtYWlsIiwgImpvaG5kb2VAZXhhbXBsZS5jb20iXQ | ||
// * Contents: ["6Ij7tM-a5iVPGboS5tmvVA", "email", "[email protected]"] | ||
test('apply hasher and saltGenerator', async () => { | ||
const decoyValue = await createDecoy( | ||
async (data) => data, | ||
() => 'salt', | ||
digest, | ||
() => Base64Url.encode('["6Ij7tM-a5iVPGboS5tmvVA", "email", "[email protected]"]'), | ||
); | ||
expect(decoyValue).toBe('c2FsdA'); | ||
expect(decoyValue).toBe('JzYjH4svliH0R3PyEMfeZu6Jt69u5qehZo7F7EPYlSE'); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters