-
-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #230 from agektmr/dev
Return `AuthenticationExtensionsAuthenticatorOutputs` as part of registration and authentication
- Loading branch information
Showing
8 changed files
with
165 additions
and
6 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
22 changes: 22 additions & 0 deletions
22
packages/server/src/helpers/decodeAuthenticatorExtensions.test.ts
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { decodeAuthenticatorExtensions } from "./decodeAuthenticatorExtensions"; | ||
|
||
test('should decode authenticator extensions', () => { | ||
const extensions = decodeAuthenticatorExtensions(Buffer.from( | ||
'A16F6465766963655075626C69634B6579A56364706B584DA5010203262001215820991A' + | ||
'ABED9DE4271A9EDEAD8806F9DC96D6DCCD0C476253A5510489EC8379BE5B225820A0973C' + | ||
'FDEDBB79E27FEF4EE7481673FB3312504DDCA5434CFD23431D6AD29EDA63736967584730' + | ||
'45022100EFB38074BD15B8C82CF09F87FBC6FB3C7169EA4F1806B7E90937374302345B7A' + | ||
'02202B7113040731A0E727D338D48542863CE65880AA79E5EA740AC8CCD94347988E656E' + | ||
'6F6E6365406573636F706541006661616775696450000000000000000000000000000000' + | ||
'00', 'hex' | ||
)); | ||
expect(extensions).toMatchObject({ | ||
"devicePublicKey": { | ||
"dpk": Buffer.from('A5010203262001215820991AABED9DE4271A9EDEAD8806F9DC96D6DCCD0C476253A5510489EC8379BE5B225820A0973CFDEDBB79E27FEF4EE7481673FB3312504DDCA5434CFD23431D6AD29EDA', 'hex'), | ||
"sig": Buffer.from('3045022100EFB38074BD15B8C82CF09F87FBC6FB3C7169EA4F1806B7E90937374302345B7A02202B7113040731A0E727D338D48542863CE65880AA79E5EA740AC8CCD94347988E', 'hex'), | ||
"nonce": Buffer.from('', 'hex'), | ||
"scope": Buffer.from('00', 'hex'), | ||
"aaguid": Buffer.from('00000000000000000000000000000000', 'hex') | ||
} | ||
}) | ||
}); |
37 changes: 37 additions & 0 deletions
37
packages/server/src/helpers/decodeAuthenticatorExtensions.ts
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import cbor from 'cbor'; | ||
|
||
/** | ||
* Convert authenticator extension data buffer to a proper object | ||
* | ||
* @param extensionData Authenticator Extension Data buffer | ||
*/ | ||
export function decodeAuthenticatorExtensions( | ||
extensionData: Buffer | ||
): AuthenticationExtensionsAuthenticatorOutputs | undefined { | ||
let toCBOR: AuthenticationExtensionsAuthenticatorOutputs | undefined; | ||
try { | ||
toCBOR = cbor.decodeAllSync(extensionData)[0]; | ||
} catch (err) { | ||
const _err = err as Error; | ||
throw new Error(`Error decoding authenticator extensions: ${_err.message}`); | ||
} | ||
return toCBOR; | ||
} | ||
|
||
export type AuthenticationExtensionsAuthenticatorOutputs = { | ||
devicePublicKey?: DevicePublicKeyAuthenticatorOutput; | ||
uvm?: UVMAuthenticatorOutput; | ||
} | ||
|
||
export type DevicePublicKeyAuthenticatorOutput = { | ||
dpk?: Buffer; | ||
scp?: Buffer; | ||
sig?: string; | ||
aaguid?: Buffer; | ||
} | ||
|
||
// TODO: Need to verify this format | ||
// https://w3c.github.io/webauthn/#sctn-uvm-extension. | ||
export type UVMAuthenticatorOutput = { | ||
uvm?: Buffer[] | ||
} |
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
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