/
parsePackedSelfAttestationData.test.js
182 lines (155 loc) · 7.4 KB
/
parsePackedSelfAttestationData.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Testing lib
import * as chai from "chai";
import * as chaiAsPromised from "chai-as-promised";
// Helpers
import { arrayBufferEquals, tools } from "../lib/main.js";
// Test subject
import { parseAttestationObject, parseAuthnrAttestationResponse } from "../lib/main.js";
import { packedSelfAttestationResponse } from "./fixtures/packedSelfAttestationData.js";
chai.use(chaiAsPromised.default);
const { assert } = chai;
const parser = {
parseAuthnrAttestationResponse,
parseAttestationObject,
};
const runs = [
{ functionName: "parseAuthnrAttestationResponse" },
{ functionName: "parseAttestationObject" },
];
const parsedPackedSelfAttestationResponse = {
...packedSelfAttestationResponse,
id: tools.base64.toArrayBuffer(packedSelfAttestationResponse.id),
rawId: tools.base64.toArrayBuffer(packedSelfAttestationResponse.rawId),
response: {
attestationObject: tools.base64.toArrayBuffer(
packedSelfAttestationResponse.response.attestationObject,
),
clientDataJSON: tools.base64.toArrayBuffer(
packedSelfAttestationResponse.response.clientDataJSON,
),
},
};
runs.forEach(function(run) {
describe(run.functionName + " (packed self-assigned)", async function() {
it("parser is object", function() {
assert.equal(typeof parser, "object");
});
const ret = run.functionName == "parseAuthnrAttestationResponse"
? await parser[run.functionName](
parsedPackedSelfAttestationResponse,
)
: await parser[run.functionName](
parsedPackedSelfAttestationResponse.response.attestationObject,
);
it("parser returns Map with correct size", function() {
assert.instanceOf(ret, Map);
assert.strictEqual(ret.size, 15);
});
it("is 'packed' fmt", function() {
assert.strictEqual(ret.get("fmt"), "packed");
});
it("has correct alg", function() {
const alg = ret.get("alg");
assert.isObject(alg);
assert.strictEqual(Object.keys(alg).length, 2);
assert.strictEqual(alg.algName, "ECDSA_w_SHA256");
assert.strictEqual(alg.hashAlg, "SHA-256");
});
it("does not have x5c", function() {
const x5c = ret.get("x5c");
assert.isUndefined(x5c);
});
it("does not have attCert", function() {
const attCert = ret.get("attCert");
assert.isUndefined(attCert);
});
it("has sig", function() {
const sig = ret.get("sig");
assert.instanceOf(sig, ArrayBuffer);
let expectedSig = new Uint8Array([
0x30, 0x45, 0x02, 0x21, 0x00, 0x9b, 0x71, 0x6a, 0x01, 0xb0, 0x51, 0x26, 0x01, 0xc8, 0xb0, 0x07,
0x7a, 0xb7, 0x0f, 0xe4, 0x16, 0xfd, 0x7d, 0x24, 0x02, 0x18, 0xa3, 0x99, 0xbc, 0x9b, 0x80, 0x01,
0xe3, 0x07, 0xdd, 0xfb, 0x4a, 0x02, 0x20, 0x0b, 0xa5, 0x88, 0x9f, 0xfe, 0xec, 0x5f, 0xbc, 0x12,
0x08, 0x94, 0x5f, 0x60, 0x67, 0x67, 0x18, 0x18, 0x51, 0x5b, 0xba, 0x7b, 0x02, 0x7d, 0xea, 0xb6,
0xd4, 0x71, 0xe3, 0x3f, 0x07, 0x1a, 0xd8,
]).buffer;
assert.isTrue(arrayBufferEquals(sig, expectedSig), "sig has correct value");
});
it("has correct raw authnrData", function() {
const rawAuthnrData = ret.get("rawAuthnrData");
assert.instanceOf(rawAuthnrData, ArrayBuffer);
assert.strictEqual(rawAuthnrData.byteLength, 283);
let expectedRawAuthnrData = new Uint8Array([
0x49, 0x96, 0x0D, 0xE5, 0x88, 0x0E, 0x8C, 0x68, 0x74, 0x34, 0x17, 0x0F, 0x64, 0x76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, 0x51, 0x1D, 0x20, 0x85, 0x44, 0x92, 0xA1, 0x42, 0x0B, 0x43, 0xA5, 0x01,
0x02, 0x03, 0x26, 0x20, 0x01, 0x21, 0x58, 0x20, 0xB9, 0xB7, 0xD9, 0x2A, 0x9B, 0x86, 0x36, 0xED,
0x25, 0xBB, 0x3B, 0xFE, 0x9B, 0x28, 0x16, 0x54, 0x87, 0xD4, 0xEA, 0x28, 0x13, 0x63, 0xE3, 0x88,
0x4E, 0x1E, 0xE3, 0x49, 0x7D, 0xC4, 0x2F, 0xE7, 0x22, 0x58, 0x20, 0x9C, 0x17, 0xF0, 0xD6, 0xCC,
0x1F, 0xAB, 0x6F, 0xA2, 0x00, 0x89, 0x23, 0x65, 0x12, 0x34, 0x15, 0xEF, 0x64, 0x1C, 0xA6, 0x95,
0xF6, 0x98, 0x3, 0xFA, 0xDA, 0xAD, 0x7A, 0xA8, 0xF0, 0x1C, 0x97,
]).buffer;
assert.isTrue(arrayBufferEquals(rawAuthnrData, expectedRawAuthnrData), "rawAuthnrData has correct value");
});
it("has correct rpIdHash", function() {
const rpIdHash = ret.get("rpIdHash");
assert.instanceOf(rpIdHash, ArrayBuffer);
assert.strictEqual(rpIdHash.byteLength, 32);
let expectedRpIdHash = new Uint8Array([
0x49, 0x96, 0x0D, 0xE5, 0x88, 0x0E, 0x8C, 0x68, 0x74, 0x34, 0x17, 0x0F, 0x64, 0x76, 0x60, 0x5B,
0x8F, 0xE4, 0xAE, 0xB9, 0xA2, 0x86, 0x32, 0xC7, 0x99, 0x5C, 0xF3, 0xBA, 0x83, 0x1D, 0x97, 0x63,
]).buffer;
assert.isTrue(arrayBufferEquals(rpIdHash, expectedRpIdHash), "rpIdHash has correct value");
});
it("has correct flags", function() {
const flags = ret.get("flags");
assert.instanceOf(flags, Set);
assert.strictEqual(flags.size, 3);
assert.isTrue(flags.has("AT"));
assert.isTrue(flags.has("UP"));
assert.isTrue(flags.has("UV"));
});
it("has correct counter", function() {
const counter = ret.get("counter");
assert.isNumber(counter);
assert.strictEqual(counter, 1643037430);
});
it("has correct aaguid", function() {
const aaguid = ret.get("aaguid");
assert.instanceOf(aaguid, ArrayBuffer);
assert.strictEqual(aaguid.byteLength, 16);
let expectedAaguid = new Uint8Array([
0xAD, 0xCE, 0x00, 0x02, 0x35, 0xBC, 0xC6, 0x0A, 0x64, 0x8B, 0x0B, 0x25, 0xF1, 0xF0, 0x55, 0x03,
]).buffer;
assert.isTrue(arrayBufferEquals(aaguid, expectedAaguid), "aaguid has correct value");
});
it("has correct credIdLen", function() {
const credIdLen = ret.get("credIdLen");
assert.isNumber(credIdLen);
assert.strictEqual(credIdLen, 151);
});
it("has correct credentialPublicKeyCose", function() {
const credentialPublicKeyCose = ret.get("credentialPublicKeyCose");
assert.instanceOf(credentialPublicKeyCose, ArrayBuffer);
assert.strictEqual(credentialPublicKeyCose.byteLength, 77);
let expectedCredentialPublicKeyCose = new Uint8Array([
0xA5, 0x01, 0x02, 0x03, 0x26, 0x20, 0x01, 0x21, 0x58, 0x20, 0xB9, 0xB7, 0xD9, 0x2A, 0x9B, 0x86,
0x36, 0xED, 0x25, 0xBB, 0x3B, 0xFE, 0x9B, 0x28, 0x16, 0x54, 0x87, 0xD4, 0xEA, 0x28, 0x13, 0x63,
0xE3, 0x88, 0x4E, 0x1E, 0xE3, 0x49, 0x7D, 0xC4, 0x2F, 0xE7, 0x22, 0x58, 0x20, 0x9C, 0x17, 0xF0,
0xD6, 0xCC, 0x1F, 0xAB, 0x6F, 0xA2, 0x00, 0x89, 0x23, 0x65, 0x12, 0x34, 0x15, 0xEF, 0x64, 0x1C,
0xA6, 0x95, 0xF6, 0x98, 0x03, 0xFA, 0xDA, 0xAD, 0x7A, 0xA8, 0xF0, 0x1C, 0x97,
]).buffer;
assert.isTrue(arrayBufferEquals(credentialPublicKeyCose, expectedCredentialPublicKeyCose), "credentialPublicKeyCose has correct value");
});
});
});