From 1683e99a6e6a33bd6737240ca6bbc8a9d64b798b Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Fri, 5 Jun 2020 17:54:47 -0700 Subject: Replace asciiToBinary with more base64url usage --- packages/server/src/helpers/decodeClientDataJSON.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/server/src/helpers/decodeClientDataJSON.ts') diff --git a/packages/server/src/helpers/decodeClientDataJSON.ts b/packages/server/src/helpers/decodeClientDataJSON.ts index c0ebb2b..93c6b10 100644 --- a/packages/server/src/helpers/decodeClientDataJSON.ts +++ b/packages/server/src/helpers/decodeClientDataJSON.ts @@ -1,10 +1,10 @@ -import asciiToBinary from './asciiToBinary'; +import base64url from 'base64url'; /** * Decode an authenticator's base64-encoded clientDataJSON to JSON */ export default function decodeClientDataJSON(data: string): ClientDataJSON { - const toString = asciiToBinary(data); + const toString = base64url.decode(data); const clientData: ClientDataJSON = JSON.parse(toString); // `challenge` will be Base64-encoded here. Decode it for easier comparisons with what is provided -- cgit v1.2.3 From 506d1a5beb91ad5e65b30e10cb056d74bc49298c Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Fri, 5 Jun 2020 17:55:58 -0700 Subject: Replace “base64” with “base64url” in some comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/server/src/helpers/decodeAttestationObject.test.ts | 4 ++-- packages/server/src/helpers/decodeClientDataJSON.test.ts | 2 +- packages/server/src/helpers/decodeClientDataJSON.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'packages/server/src/helpers/decodeClientDataJSON.ts') diff --git a/packages/server/src/helpers/decodeAttestationObject.test.ts b/packages/server/src/helpers/decodeAttestationObject.test.ts index e8eb364..2f88f2a 100644 --- a/packages/server/src/helpers/decodeAttestationObject.test.ts +++ b/packages/server/src/helpers/decodeAttestationObject.test.ts @@ -1,6 +1,6 @@ import decodeAttestationObject from './decodeAttestationObject'; -test('should decode base64-encoded indirect attestationObject', () => { +test('should decode base64url-encoded indirect attestationObject', () => { const decoded = decodeAttestationObject( 'o2NmbXRkbm9uZWdhdHRTdG10oGhhdXRoRGF0YVjEAbElFazplpnc037DORGDZNjDq86cN9vm6' + '+APoAM20wtBAAAAAAAAAAAAAAAAAAAAAAAAAAAAQKmPuEwByQJ3e89TccUSrCGDkNWquhevjLLn/' + @@ -13,7 +13,7 @@ test('should decode base64-encoded indirect attestationObject', () => { expect(decoded.authData).toBeDefined(); }); -test('should decode base64-encoded direct attestationObject', () => { +test('should decode base64url-encoded direct attestationObject', () => { const decoded = decodeAttestationObject( 'o2NmbXRoZmlkby11MmZnYXR0U3RtdKJjc2lnWEgwRgIhAK40WxA0t7py7AjEXvwGwTlmqlvrOk' + 's5g9lf+9zXzRiVAiEA3bv60xyXveKDOusYzniD7CDSostCet9PYK7FLdnTdZNjeDVjgVkCwTCCAr0wggGloAMCAQICBCrn' + diff --git a/packages/server/src/helpers/decodeClientDataJSON.test.ts b/packages/server/src/helpers/decodeClientDataJSON.test.ts index 7674ec5..b1a7940 100644 --- a/packages/server/src/helpers/decodeClientDataJSON.test.ts +++ b/packages/server/src/helpers/decodeClientDataJSON.test.ts @@ -1,6 +1,6 @@ import decodeClientDataJSON from './decodeClientDataJSON'; -test('should convert base64-encoded attestation clientDataJSON to JSON', () => { +test('should convert base64url-encoded attestation clientDataJSON to JSON', () => { expect( decodeClientDataJSON( 'eyJjaGFsbGVuZ2UiOiJVMmQ0TjNZME0wOU1jbGRQYjFSNVpFeG5UbG95IiwiY2xpZW50RXh0ZW5zaW9ucyI6e30' + diff --git a/packages/server/src/helpers/decodeClientDataJSON.ts b/packages/server/src/helpers/decodeClientDataJSON.ts index 93c6b10..7c09b0d 100644 --- a/packages/server/src/helpers/decodeClientDataJSON.ts +++ b/packages/server/src/helpers/decodeClientDataJSON.ts @@ -1,13 +1,13 @@ import base64url from 'base64url'; /** - * Decode an authenticator's base64-encoded clientDataJSON to JSON + * Decode an authenticator's base64url-encoded clientDataJSON to JSON */ export default function decodeClientDataJSON(data: string): ClientDataJSON { const toString = base64url.decode(data); const clientData: ClientDataJSON = JSON.parse(toString); - // `challenge` will be Base64-encoded here. Decode it for easier comparisons with what is provided + // `challenge` will be Base64URL-encoded here. Decode it for easier comparisons with what is provided // as the expected value clientData.challenge = Buffer.from(clientData.challenge, 'base64').toString('ascii'); -- cgit v1.2.3 From 328dc36408c2d3d1eac4829bd4cee6a6b573af99 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Fri, 5 Jun 2020 17:56:47 -0700 Subject: Use base64url to decode clientDataJSON --- packages/server/src/helpers/decodeClientDataJSON.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/server/src/helpers/decodeClientDataJSON.ts') diff --git a/packages/server/src/helpers/decodeClientDataJSON.ts b/packages/server/src/helpers/decodeClientDataJSON.ts index 7c09b0d..52bbf4c 100644 --- a/packages/server/src/helpers/decodeClientDataJSON.ts +++ b/packages/server/src/helpers/decodeClientDataJSON.ts @@ -7,9 +7,9 @@ export default function decodeClientDataJSON(data: string): ClientDataJSON { const toString = base64url.decode(data); const clientData: ClientDataJSON = JSON.parse(toString); - // `challenge` will be Base64URL-encoded here. Decode it for easier comparisons with what is provided - // as the expected value - clientData.challenge = Buffer.from(clientData.challenge, 'base64').toString('ascii'); + // `challenge` will be Base64URL-encoded here. Decode it for easier comparisons with what is + // provided as the expected value + clientData.challenge = base64url.decode(clientData.challenge); return clientData; } -- cgit v1.2.3