diff options
author | Matthew Miller <matthew@millerti.me> | 2022-11-11 19:47:25 -0800 |
---|---|---|
committer | Matthew Miller <matthew@millerti.me> | 2022-11-11 19:47:25 -0800 |
commit | 790dd59591dd6cba154ff34bbb6496d91f3be14a (patch) | |
tree | b4195ba4713cbc25f051ab65487d3cafa783dc71 /packages/server/src/authentication/verifyAuthenticationResponse.ts | |
parent | a42cd6ab88bc3081e86a10d920c5a3949ee48f95 (diff) |
Refactor RP ID hash matching
Diffstat (limited to 'packages/server/src/authentication/verifyAuthenticationResponse.ts')
-rw-r--r-- | packages/server/src/authentication/verifyAuthenticationResponse.ts | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/packages/server/src/authentication/verifyAuthenticationResponse.ts b/packages/server/src/authentication/verifyAuthenticationResponse.ts index 100cb4c..4d58078 100644 --- a/packages/server/src/authentication/verifyAuthenticationResponse.ts +++ b/packages/server/src/authentication/verifyAuthenticationResponse.ts @@ -12,6 +12,7 @@ import { parseAuthenticatorData } from '../helpers/parseAuthenticatorData'; import { isBase64URLString } from '../helpers/isBase64URLString'; import { parseBackupFlags } from '../helpers/parseBackupFlags'; import { AuthenticationExtensionsAuthenticatorOutputs } from '../helpers/decodeAuthenticatorExtensions'; +import { matchExpectedRPID } from '../helpers/matchExpectedRPID'; import * as uint8Array from '../helpers/uint8Array'; import * as base64url from '../helpers/base64url'; @@ -148,23 +149,15 @@ export async function verifyAuthenticationResponse( const { rpIdHash, flags, counter, extensionsData } = parsedAuthData; // Make sure the response's RP ID is ours + let expectedRPIDs: string[] = []; if (typeof expectedRPID === 'string') { - const expectedRPIDHash = toHash(uint8Array.fromASCIIString(expectedRPID)); - if (!uint8Array.areEqual(rpIdHash, expectedRPIDHash)) { - throw new Error(`Unexpected RP ID hash`); - } + expectedRPIDs = [expectedRPID]; } else { - // Go through each expected RP ID and try to find one that matches - const foundMatch = expectedRPID.some(expected => { - const expectedRPIDHash = toHash(uint8Array.fromASCIIString(expected)); - return uint8Array.areEqual(rpIdHash, expectedRPIDHash); - }); - - if (!foundMatch) { - throw new Error(`Unexpected RP ID hash`); - } + expectedRPIDs = expectedRPID; } + await matchExpectedRPID(rpIdHash, expectedRPIDs); + if (advancedFIDOConfig !== undefined) { const { userVerification: fidoUserVerification } = advancedFIDOConfig; |