Skip to content

Commit b4c9ece

Browse files
authored
code tests for extensions
- extension tests (with and without AT-Flag) - fixed missing Uint8Array for extension processing
1 parent 3b255a8 commit b4c9ece

File tree

5 files changed

+279
-1
lines changed

5 files changed

+279
-1
lines changed

lib/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ async function parseAuthenticatorData(authnrDataArrayBuffer) {
344344
}
345345

346346
if (extensions) {
347-
const cborObjects = tools.cbor.decodeMultiple(authnrDataBuf.buffer.slice(offset, authnrDataBuf.buffer.byteLength));
347+
const cborObjects = tools.cbor.decodeMultiple(new Uint8Array(authnrDataBuf.buffer.slice(offset, authnrDataBuf.buffer.byteLength)));
348348

349349
// skip publicKey if present
350350
if (attestation) {

rollup.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ const tests = [
2828
"test/parseClientData.test.js",
2929
"test/parseExpectations.test.js",
3030
"test/parseNoneAttestationData.test.js",
31+
"test/parseNoneAttestationDataExtensions.test.js",
3132
"test/parsePackedAttestationData.test.js",
3233
"test/parsePackedSelfAttestationData.test.js",
3334
"test/parseTpmAttestationData.test.js",
3435
"test/parseU2fAttestationData.test.js",
36+
"test/parseJustExtensions.test.js",
3537
"test/parseAppleAttestationData.test.js",
3638
"test/response.test.js",
3739
"test/toolbox.test.js",

test/helpers/fido2-helpers.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@ const challengeResponseAttestationNoneMsgB64Url = {
186186
},
187187
};
188188

189+
const challengeResponseNoneAttestationDataExtensionsMsgB64Url = {
190+
response: {
191+
attestationObject:
192+
"o2NmbXRkbm9uZWdhdHRTdG10oGhhdXRoRGF0YVkBNkmWDeWIDoxodDQXD2R2YFuP5K65ooYyx5lc87qDHZdjwQAAAAAAAAAAAAAAAAAAAAAAAAAAAKIACKLdXqwahqjNbtNs1piUlonluvxOsF9Feeh9k7qXay5zdrm239cW4WQUD_l5ptTzRLU9bSbghnv0FLaRA7tly7La9_QRKDXwZMsbWajlhKQh2ovYnjh6C37qtyPs151ITDFr-67FRgG0c2dJCoOa2hQB8z0tJYuXrkGMpVk0ZSn1qjfeYxJ1V9BDRsfN7r0lVC8sF_w5OJlSomw64qampRylAQIDJiABIVgguxHN3W6ehp0VWXKaMNie1J82MVJCFZYScau74o17cx8iWCDb1jkTLi7lYZZbgwUwpqAk8QmIiPMTVQUVkhGEyGrKw7kAAWtjcmVkUHJvdGVjdAE",
193+
},
194+
};
195+
196+
const challengeResponseJustExtensionsMsgB64Url = {
197+
response: {
198+
attestationObject:
199+
"o2NmbXRkbm9uZWdhdHRTdG10oGhhdXRoRGF0YVkANUmWDeWIDoxodDQXD2R2YFuP5K65ooYyx5lc87qDHZdjgQAAAAC5AAFrY3JlZFByb3RlY3QB",
200+
},
201+
};
202+
189203
const getOptionsRequest = {
190204
username: "bubba",
191205
displayName: "Bubba Smith",
@@ -484,6 +498,26 @@ const makeCredentialAttestationSafetyNetResponse = {
484498
},
485499
};
486500

501+
const makeNoneAttestationDataExtensionsResponse = {
502+
response: {
503+
attestationObject: base64.toArrayBuffer(
504+
challengeResponseNoneAttestationDataExtensionsMsgB64Url.response
505+
.attestationObject,
506+
true,
507+
),
508+
},
509+
};
510+
511+
const makeJustExtensionsResponse = {
512+
response: {
513+
attestationObject: base64.toArrayBuffer(
514+
challengeResponseJustExtensionsMsgB64Url.response
515+
.attestationObject,
516+
true,
517+
),
518+
},
519+
};
520+
487521
const assertionResponse = {
488522
id: assertionResponseMsgB64Url.id,
489523
rawId: base64.toArrayBuffer(assertionResponseMsgB64Url.rawId, true),
@@ -549,6 +583,8 @@ const lib = {
549583
makeCredentialAttestationPackedResponseWindowsHello,
550584
makeCredentialAttestationTpmResponse,
551585
makeCredentialAttestationSafetyNetResponse,
586+
makeNoneAttestationDataExtensionsResponse,
587+
makeJustExtensionsResponse,
552588
assertionResponse,
553589
assertionResponseWindowsHello,
554590
assnPublicKey,

test/parseJustExtensions.test.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Testing lib
2+
import * as chai from "chai";
3+
import * as chaiAsPromised from "chai-as-promised";
4+
5+
// Helpers
6+
import * as h from "./helpers/fido2-helpers.js";
7+
8+
// Test subject
9+
import { arrayBufferEquals, noneAttestation, parseAttestationObject, parseAuthnrAttestationResponse } from "../lib/main.js";
10+
chai.use(chaiAsPromised.default);
11+
const { assert } = chai;
12+
13+
const parser = {
14+
parseAuthnrAttestationResponse,
15+
parseAttestationObject,
16+
};
17+
18+
const runs = [
19+
{ functionName: "parseAuthnrAttestationResponse" },
20+
{ functionName: "parseAttestationObject" },
21+
];
22+
23+
runs.forEach(function(run) {
24+
describe(run.functionName + " (without + extensions)", function() {
25+
it("parser is object", function() {
26+
assert.equal(typeof parser, "object");
27+
});
28+
29+
it("correctly parses extension data", async function() {
30+
const ret = run.functionName == "parseAuthnrAttestationResponse"
31+
? await parser[run.functionName](
32+
h.lib.makeJustExtensionsResponse,
33+
)
34+
: await parser[run.functionName](
35+
h.lib.makeJustExtensionsResponse.response
36+
.attestationObject,
37+
);
38+
39+
assert.instanceOf(ret, Map);
40+
assert.strictEqual(ret.size, 7);
41+
assert.isDefined(ret.get("webAuthnExtensions"));
42+
const fmt = ret.get("fmt");
43+
assert.strictEqual(fmt, "none");
44+
// got the right authData CBOR
45+
const rawAuthnrData = ret.get("rawAuthnrData");
46+
assert.instanceOf(rawAuthnrData, ArrayBuffer);
47+
const expectedRawAuthnrData = new Uint8Array([
48+
0x49, 0x96, 0x0D, 0xE5, 0x88, 0x0E, 0x8C, 0x68, 0x74, 0x34, 0x17, 0x0F, 0x64, 0x76, 0x60, 0x5B,
49+
0x8F, 0xE4, 0xAE, 0xB9, 0xA2, 0x86, 0x32, 0xC7, 0x99, 0x5C, 0xF3, 0xBA, 0x83, 0x1D, 0x97, 0x63,
50+
0x81, 0x00, 0x00, 0x00, 0x00, 0xb9, 0x00, 0x01, 0x6b, 0x63, 0x72, 0x65, 0x64, 0x50, 0x72, 0x6f,
51+
0x74, 0x65, 0x63, 0x74, 0x01,
52+
]).buffer;
53+
assert(arrayBufferEquals(rawAuthnrData, expectedRawAuthnrData), "authData contains right bytes");
54+
const rpIdHash = ret.get("rpIdHash");
55+
const expectedRpIdHash = new Uint8Array([
56+
0x49, 0x96, 0x0D, 0xE5, 0x88, 0x0E, 0x8C, 0x68, 0x74, 0x34, 0x17, 0x0F, 0x64, 0x76, 0x60, 0x5B,
57+
0x8F, 0xE4, 0xAE, 0xB9, 0xA2, 0x86, 0x32, 0xC7, 0x99, 0x5C, 0xF3, 0xBA, 0x83, 0x1D, 0x97, 0x63,
58+
]).buffer;
59+
assert(arrayBufferEquals(rpIdHash, expectedRpIdHash), "correct rpIdHash");
60+
// flags
61+
const flags = ret.get("flags");
62+
assert.instanceOf(flags, Set);
63+
assert.strictEqual(flags.size, 2);
64+
assert.isTrue(flags.has("UP"));
65+
assert.isTrue(flags.has("ED"));
66+
// counter
67+
assert.strictEqual(ret.get("counter"), 0);
68+
assert.isNumber(ret.get("counter"));
69+
});
70+
});
71+
});
72+
73+
describe("parseFn (none)", function() {
74+
it("throws if attStmn has fields", function() {
75+
const attStmt = { test: 1 };
76+
assert.throws(
77+
() => {
78+
noneAttestation.parseFn(attStmt);
79+
},
80+
Error, "'none' attestation format: attStmt had fields",
81+
);
82+
});
83+
});
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
// Testing lib
2+
import * as chai from "chai";
3+
import * as chaiAsPromised from "chai-as-promised";
4+
5+
// Helpers
6+
import * as h from "./helpers/fido2-helpers.js";
7+
8+
// Test subject
9+
import { arrayBufferEquals, noneAttestation, parseAttestationObject, parseAuthnrAttestationResponse } from "../lib/main.js";
10+
chai.use(chaiAsPromised.default);
11+
const { assert } = chai;
12+
13+
const parser = {
14+
parseAuthnrAttestationResponse,
15+
parseAttestationObject,
16+
};
17+
18+
const runs = [
19+
{ functionName: "parseAuthnrAttestationResponse" },
20+
{ functionName: "parseAttestationObject" },
21+
];
22+
23+
runs.forEach(function(run) {
24+
describe(run.functionName + " (none + extensions)", function() {
25+
it("parser is object", function() {
26+
assert.equal(typeof parser, "object");
27+
});
28+
29+
it("correctly parses extension data", async function() {
30+
const ret = run.functionName == "parseAuthnrAttestationResponse"
31+
? await parser[run.functionName](
32+
h.lib.makeNoneAttestationDataExtensionsResponse,
33+
)
34+
: await parser[run.functionName](
35+
h.lib.makeNoneAttestationDataExtensionsResponse.response
36+
.attestationObject,
37+
);
38+
39+
assert.instanceOf(ret, Map);
40+
assert.strictEqual(ret.size, 13);
41+
assert.isDefined(ret.get("webAuthnExtensions"));
42+
const fmt = ret.get("fmt");
43+
assert.strictEqual(fmt, "none");
44+
// got the right authData CBOR
45+
const rawAuthnrData = ret.get("rawAuthnrData");
46+
assert.instanceOf(rawAuthnrData, ArrayBuffer);
47+
const expectedRawAuthnrData = new Uint8Array([
48+
0x49, 0x96, 0x0D, 0xE5, 0x88, 0x0E, 0x8C, 0x68, 0x74, 0x34, 0x17, 0x0F, 0x64, 0x76, 0x60, 0x5B,
49+
0x8F, 0xE4, 0xAE, 0xB9, 0xA2, 0x86, 0x32, 0xC7, 0x99, 0x5C, 0xF3, 0xBA, 0x83, 0x1D, 0x97, 0x63,
50+
0xC1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
51+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x00, 0x08, 0xA2, 0xDD, 0x5E, 0xAC, 0x1A, 0x86, 0xA8,
52+
0xCD, 0x6E, 0xD3, 0x6C, 0xD6, 0x98, 0x94, 0x96, 0x89, 0xE5, 0xBA, 0xFC, 0x4E, 0xB0, 0x5F, 0x45,
53+
0x79, 0xE8, 0x7D, 0x93, 0xBA, 0x97, 0x6B, 0x2E, 0x73, 0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 0xE5, 0x61, 0x96, 0x5B,
65+
0x83, 0x05, 0x30, 0xA6, 0xA0, 0x24, 0xF1, 0x09, 0x88, 0x88, 0xF3, 0x13, 0x55, 0x05, 0x15, 0x92,
66+
0x11, 0x84, 0xC8, 0x6A, 0xCA, 0xC3, 0xb9, 0x00, 0x01, 0x6b, 0x63, 0x72, 0x65, 0x64, 0x50, 0x72,
67+
0x6f, 0x74, 0x65, 0x63, 0x74, 0x01,
68+
]).buffer;
69+
assert(arrayBufferEquals(rawAuthnrData, expectedRawAuthnrData), "authData contains right bytes");
70+
const rpIdHash = ret.get("rpIdHash");
71+
const expectedRpIdHash = new Uint8Array([
72+
0x49, 0x96, 0x0D, 0xE5, 0x88, 0x0E, 0x8C, 0x68, 0x74, 0x34, 0x17, 0x0F, 0x64, 0x76, 0x60, 0x5B,
73+
0x8F, 0xE4, 0xAE, 0xB9, 0xA2, 0x86, 0x32, 0xC7, 0x99, 0x5C, 0xF3, 0xBA, 0x83, 0x1D, 0x97, 0x63,
74+
]).buffer;
75+
assert(arrayBufferEquals(rpIdHash, expectedRpIdHash), "correct rpIdHash");
76+
// flags
77+
const flags = ret.get("flags");
78+
assert.instanceOf(flags, Set);
79+
assert.strictEqual(flags.size, 3);
80+
assert.isTrue(flags.has("UP"));
81+
assert.isTrue(flags.has("ED"));
82+
assert.isTrue(flags.has("AT"));
83+
// counter
84+
assert.strictEqual(ret.get("counter"), 0);
85+
assert.isNumber(ret.get("counter"));
86+
// aaguid
87+
const aaguid = ret.get("aaguid");
88+
assert.instanceOf(aaguid, ArrayBuffer);
89+
let expectedAaguid = new Uint8Array([
90+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
91+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
92+
]).buffer;
93+
assert(arrayBufferEquals(aaguid, expectedAaguid), "correct aaguid");
94+
// credIdLen
95+
assert.strictEqual(ret.get("credIdLen"), 162);
96+
// credId
97+
const credId = ret.get("credId");
98+
assert.instanceOf(credId, ArrayBuffer);
99+
const expectedCredId = new Uint8Array([
100+
0x00, 0x08, 0xA2, 0xDD, 0x5E, 0xAC, 0x1A, 0x86, 0xA8, 0xCD, 0x6E, 0xD3, 0x6C, 0xD6, 0x98, 0x94,
101+
0x96, 0x89, 0xE5, 0xBA, 0xFC, 0x4E, 0xB0, 0x5F, 0x45, 0x79, 0xE8, 0x7D, 0x93, 0xBA, 0x97, 0x6B,
102+
0x2E, 0x73, 0x76, 0xB9, 0xB6, 0xDF, 0xD7, 0x16, 0xE1, 0x64, 0x14, 0x0F, 0xF9, 0x79, 0xA6, 0xD4,
103+
0xF3, 0x44, 0xB5, 0x3D, 0x6D, 0x26, 0xE0, 0x86, 0x7B, 0xF4, 0x14, 0xB6, 0x91, 0x03, 0xBB, 0x65,
104+
0xCB, 0xB2, 0xDA, 0xF7, 0xF4, 0x11, 0x28, 0x35, 0xF0, 0x64, 0xCB, 0x1B, 0x59, 0xA8, 0xE5, 0x84,
105+
0xA4, 0x21, 0xDA, 0x8B, 0xD8, 0x9E, 0x38, 0x7A, 0x0B, 0x7E, 0xEA, 0xB7, 0x23, 0xEC, 0xD7, 0x9D,
106+
0x48, 0x4C, 0x31, 0x6B, 0xFB, 0xAE, 0xC5, 0x46, 0x01, 0xB4, 0x73, 0x67, 0x49, 0x0A, 0x83, 0x9A,
107+
0xDA, 0x14, 0x01, 0xF3, 0x3D, 0x2D, 0x25, 0x8B, 0x97, 0xAE, 0x41, 0x8C, 0xA5, 0x59, 0x34, 0x65,
108+
0x29, 0xF5, 0xAA, 0x37, 0xDE, 0x63, 0x12, 0x75, 0x57, 0xD0, 0x43, 0x46, 0xC7, 0xCD, 0xEE, 0xBD,
109+
0x25, 0x54, 0x2F, 0x2C, 0x17, 0xFC, 0x39, 0x38, 0x99, 0x52, 0xA2, 0x6C, 0x3A, 0xE2, 0xA6, 0xA6,
110+
0xA5, 0x1C,
111+
]).buffer;
112+
assert(arrayBufferEquals(credId, expectedCredId), "correct credId");
113+
// credentialPublicKeyCose
114+
const credentialPublicKeyCose = ret.get("credentialPublicKeyCose");
115+
assert.instanceOf(credentialPublicKeyCose, ArrayBuffer);
116+
const expectedCredentialPublicKeyCose = new Uint8Array([
117+
0xA5, 0x01, 0x02, 0x03, 0x26, 0x20, 0x01, 0x21, 0x58, 0x20, 0xBB, 0x11, 0xCD, 0xDD, 0x6E, 0x9E,
118+
0x86, 0x9D, 0x15, 0x59, 0x72, 0x9A, 0x30, 0xD8, 0x9E, 0xD4, 0x9F, 0x36, 0x31, 0x52, 0x42, 0x15,
119+
0x96, 0x12, 0x71, 0xAB, 0xBB, 0xE2, 0x8D, 0x7B, 0x73, 0x1F, 0x22, 0x58, 0x20, 0xDB, 0xD6, 0x39,
120+
0x13, 0x2E, 0x2E, 0xE5, 0x61, 0x96, 0x5B, 0x83, 0x05, 0x30, 0xA6, 0xA0, 0x24, 0xF1, 0x09, 0x88,
121+
0x88, 0xF3, 0x13, 0x55, 0x05, 0x15, 0x92, 0x11, 0x84, 0xC8, 0x6A, 0xCA, 0xC3,
122+
// TODO: does not only contain the COSE if the buffer contains extensions
123+
0xb9, 0x00, 0x01, 0x6b, 0x63, 0x72, 0x65, 0x64, 0x50, 0x72, 0x6f, 0x74, 0x65, 0x63, 0x74, 0x01,
124+
]).buffer;
125+
assert(arrayBufferEquals(credentialPublicKeyCose, expectedCredentialPublicKeyCose), "correct credentialPublicKeyCose");
126+
// credentialPublicKeyJwk
127+
const credentialPublicKeyJwk = ret.get("credentialPublicKeyJwk");
128+
assert.isObject(credentialPublicKeyJwk);
129+
assert.strictEqual(Object.keys(credentialPublicKeyJwk).length, 5);
130+
assert.strictEqual(credentialPublicKeyJwk.kty, "EC");
131+
assert.strictEqual(credentialPublicKeyJwk.crv, "P-256");
132+
assert.strictEqual(credentialPublicKeyJwk.alg, "ES256");
133+
assert.strictEqual(credentialPublicKeyJwk.x, "uxHN3W6ehp0VWXKaMNie1J82MVJCFZYScau74o17cx8");
134+
assert.strictEqual(credentialPublicKeyJwk.y, "29Y5Ey4u5WGWW4MFMKagJPEJiIjzE1UFFZIRhMhqysM");
135+
// credentialPublicKeyPem
136+
const credentialPublicKeyPem = ret.get("credentialPublicKeyPem");
137+
assert.isString(credentialPublicKeyPem);
138+
const expectedPem = "-----BEGIN PUBLIC KEY-----\n" +
139+
"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEuxHN3W6ehp0VWXKaMNie1J82MVJC\n" +
140+
"FZYScau74o17cx/b1jkTLi7lYZZbgwUwpqAk8QmIiPMTVQUVkhGEyGrKww==\n" +
141+
"-----END PUBLIC KEY-----\n";
142+
assert.strictEqual(credentialPublicKeyPem, expectedPem);
143+
});
144+
});
145+
});
146+
147+
describe("parseFn (none)", function() {
148+
it("throws if attStmn has fields", function() {
149+
const attStmt = { test: 1 };
150+
assert.throws(
151+
() => {
152+
noneAttestation.parseFn(attStmt);
153+
},
154+
Error, "'none' attestation format: attStmt had fields",
155+
);
156+
});
157+
});

0 commit comments

Comments
 (0)