Skip to content
This repository was archived by the owner on Jul 25, 2021. It is now read-only.

Commit 102fc81

Browse files
committed
Clean up get credential
1 parent 147081a commit 102fc81

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/webauthn_authenticator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class Authenticator {
5050
let isRecovery: [boolean, string] = [false, ""];
5151
let credentialOptions: PublicKeyCredentialSource[] = [];
5252
if (allowCredentialDescriptorList) {
53+
// Simplified credential lookup
5354
for (let i = 0; i < allowCredentialDescriptorList.length; i++) {
5455
const rawCredId = allowCredentialDescriptorList[i].id as ArrayBuffer;
5556
const credId = byteArrayToBase64(new Uint8Array(rawCredId), true);
@@ -59,6 +60,7 @@ export class Authenticator {
5960
}
6061
}
6162
} else {
63+
// If no credentials were supplied, load all credentials associated to the RPID
6264
credentialOptions = credentialOptions.concat(await CredentialsMap.load(rpId));
6365
}
6466
if (credentialOptions.length == 0) {
@@ -75,6 +77,7 @@ export class Authenticator {
7577
}
7678
}
7779
if (!isRecovery[0]) {
80+
// No recovery and no associated credential found
7881
throw new Error(`Container does not manage any related credentials`);
7982
}
8083
}
@@ -84,7 +87,6 @@ export class Authenticator {
8487
credSource = credentialOptions[0];
8588
}
8689

87-
8890
const userConsent = await userConsentCallback;
8991
if (!userConsent) {
9092
throw new Error(`no user consent`);
@@ -93,15 +95,13 @@ export class Authenticator {
9395
// Step 8
9496
let processedExtensions = undefined;
9597
if (extensions) {
96-
log.debug(extensions);
9798
if (extensions.has(PSK_EXTENSION_IDENTIFIER)) {
9899
log.debug('Get: PSK requested');
99100
if (!isRecovery[0]) {
100101
throw new Error('PSK extension requested, but no matching recovery key available');
101102
}
102103
const rawPskInput = base64ToByteArray(extensions.get(PSK_EXTENSION_IDENTIFIER), true);
103104
const pskInput = await CBOR.decode(new Buffer(rawPskInput));
104-
log.debug('Get: PSK input', pskInput);
105105
const [newCredId, pskOutput] = await PSK.authenticatorGetCredentialExtensionOutput(isRecovery[1], pskInput.hash, rpId);
106106
processedExtensions = new Map([[PSK_EXTENSION_IDENTIFIER, pskOutput]]);
107107
credSource = await CredentialsMap.lookup(rpId, newCredId);

src/webauthn_client.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,18 @@ export async function createPublicKeyCredential(origin: string, options: Credent
113113
}
114114

115115
export async function getPublicKeyCredential(origin: string, options: CredentialRequestOptions, sameOriginWithAncestors: boolean, userConsentCallback: Promise<boolean>) {
116+
// Step 1
117+
if (!options.publicKey) {
118+
throw new Error('options missing');
119+
}
120+
116121
// Step 2
117122
if (!sameOriginWithAncestors) {
118123
throw new Error(`sameOriginWithAncestors has to be true`);
119124
}
120125

126+
// No timeout
127+
121128
// Step 7
122129
const rpID = options.publicKey.rpId || getDomainFromOrigin(origin);
123130

@@ -136,6 +143,8 @@ export async function getPublicKeyCredential(origin: string, options: Credential
136143
const authenticatorExtensionInput = new Uint8Array(CBOR.encodeCanonical({hash: customClientDataHash}));
137144
authenticatorExtensions = new Map([[PSK_EXTENSION_IDENTIFIER, byteArrayToBase64(authenticatorExtensionInput, true)]]);
138145
// clientExtensions = {[PSK_EXTENSION_IDENTIFIER]: {clientDataJSON: customClientDataJSON}}; // ToDo Add to response
146+
} else {
147+
log.warn('PSK client extension processing failed. Wrong input.');
139148
}
140149
}
141150
}
@@ -147,21 +156,29 @@ export async function getPublicKeyCredential(origin: string, options: Credential
147156
const clientDataHashDigest = await window.crypto.subtle.digest('SHA-256', new TextEncoder().encode(JSON.stringify(clientDataJSON)));
148157
const clientDataHash = new Uint8Array(clientDataHashDigest);
149158

150-
// Step 18: Simplified, just for 1 authenticator
159+
// Handle only 1 authenticator
160+
// Step 18
161+
if (options.publicKey.userVerification && (options.publicKey.userVerification === 'required')) {
162+
throw new Error(`cKey does not support user verification`);
163+
}
164+
151165
const userVerification = options.publicKey.userVerification === "required";
152166
const userPresence = !userVerification;
167+
168+
const allowCredentialDescriptorList = options.publicKey.allowCredentials; // No filtering
169+
153170
const assertionCreationData = await Authenticator.authenticatorGetAssertion(userConsentCallback,
154171
rpID,
155172
clientDataHash,
156173
userPresence,
157174
userVerification,
158-
options.publicKey.allowCredentials,
175+
allowCredentialDescriptorList,
159176
authenticatorExtensions);
160177

161178
log.debug('Received assertion response');
162179

163180
return {
164-
getClientExtensionResults: () => ({}),
181+
getClientExtensionResults: () => (clientExtensions), // ToDo Add client extension output
165182
id: assertionCreationData.credentialId,
166183
rawId: base64ToByteArray(assertionCreationData.credentialId, true),
167184
response: {

0 commit comments

Comments
 (0)