diff options
Diffstat (limited to 'packages/server/src/helpers')
7 files changed, 28 insertions, 27 deletions
diff --git a/packages/server/src/helpers/asciiToBinary.ts b/packages/server/src/helpers/asciiToBinary.ts deleted file mode 100644 index beb6f1d..0000000 --- a/packages/server/src/helpers/asciiToBinary.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Decode a base64-encoded string to a binary string - * - * @param input Base64-encoded string - */ -export default function asciiToBinary(input: string): string { - return Buffer.from(input, 'base64').toString('binary'); -} 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/decodeAttestationObject.ts b/packages/server/src/helpers/decodeAttestationObject.ts index 2eb9997..e5accdd 100644 --- a/packages/server/src/helpers/decodeAttestationObject.ts +++ b/packages/server/src/helpers/decodeAttestationObject.ts @@ -23,10 +23,12 @@ export enum ATTESTATION_FORMATS { export type AttestationObject = { fmt: ATTESTATION_FORMATS; - attStmt: { - sig?: Buffer; - x5c?: Buffer[]; - response?: Buffer; - }; + attStmt: AttestationStatement; authData: Buffer; }; + +export type AttestationStatement = { + sig?: Buffer; + x5c?: Buffer[]; + response?: Buffer; +}; 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 c0ebb2b..52bbf4c 100644 --- a/packages/server/src/helpers/decodeClientDataJSON.ts +++ b/packages/server/src/helpers/decodeClientDataJSON.ts @@ -1,15 +1,15 @@ -import asciiToBinary from './asciiToBinary'; +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 = 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 - // 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; } diff --git a/packages/server/src/helpers/decodeCredentialPublicKey.ts b/packages/server/src/helpers/decodeCredentialPublicKey.ts new file mode 100644 index 0000000..a856a72 --- /dev/null +++ b/packages/server/src/helpers/decodeCredentialPublicKey.ts @@ -0,0 +1,7 @@ +import cbor from 'cbor'; + +import { COSEPublicKey } from './convertCOSEtoPKCS'; + +export default function decodeCredentialPublicKey(publicKey: Buffer): COSEPublicKey { + return cbor.decodeFirstSync(publicKey); +} diff --git a/packages/server/src/helpers/parseAuthenticatorData.ts b/packages/server/src/helpers/parseAuthenticatorData.ts index 3177dd5..e177002 100644 --- a/packages/server/src/helpers/parseAuthenticatorData.ts +++ b/packages/server/src/helpers/parseAuthenticatorData.ts @@ -27,7 +27,7 @@ export default function parseAuthenticatorData(authData: Buffer): ParsedAuthenti let aaguid: Buffer | undefined = undefined; let credentialID: Buffer | undefined = undefined; - let COSEPublicKey: Buffer | undefined = undefined; + let credentialPublicKey: Buffer | undefined = undefined; if (flags.at) { aaguid = intBuffer.slice(0, 16); @@ -41,7 +41,7 @@ export default function parseAuthenticatorData(authData: Buffer): ParsedAuthenti credentialID = intBuffer.slice(0, credIDLen); intBuffer = intBuffer.slice(credIDLen); - COSEPublicKey = intBuffer; + credentialPublicKey = intBuffer; } return { @@ -52,11 +52,11 @@ export default function parseAuthenticatorData(authData: Buffer): ParsedAuthenti counterBuf, aaguid, credentialID, - COSEPublicKey, + credentialPublicKey, }; } -type ParsedAuthenticatorData = { +export type ParsedAuthenticatorData = { rpIdHash: Buffer; flagsBuf: Buffer; flags: { @@ -70,5 +70,5 @@ type ParsedAuthenticatorData = { counterBuf: Buffer; aaguid?: Buffer; credentialID?: Buffer; - COSEPublicKey?: Buffer; + credentialPublicKey?: Buffer; }; |