|
| 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, 0x76, 0xB9, 0xB6, 0xDF, 0xD7, 0x16, 0xE1, |
| 54 | + 0x64, 0x14, 0x0F, 0xF9, 0x79, 0xA6, 0xD4, 0xF3, 0x44, 0xB5, 0x3D, 0x6D, 0x26, 0xE0, 0x86, 0x7B, |
| 55 | + 0xF4, 0x14, 0xB6, 0x91, 0x03, 0xBB, 0x65, 0xCB, 0xB2, 0xDA, 0xF7, 0xF4, 0x11, 0x28, 0x35, 0xF0, |
| 56 | + 0x64, 0xCB, 0x1B, 0x59, 0xA8, 0xE5, 0x84, 0xA4, 0x21, 0xDA, 0x8B, 0xD8, 0x9E, 0x38, 0x7A, 0x0B, |
| 57 | + 0x7E, 0xEA, 0xB7, 0x23, 0xEC, 0xD7, 0x9D, 0x48, 0x4C, 0x31, 0x6B, 0xFB, 0xAE, 0xC5, 0x46, 0x01, |
| 58 | + 0xB4, 0x73, 0x67, 0x49, 0x0A, 0x83, 0x9A, 0xDA, 0x14, 0x01, 0xF3, 0x3D, 0x2D, 0x25, 0x8B, 0x97, |
| 59 | + 0xAE, 0x41, 0x8C, 0xA5, 0x59, 0x34, 0x65, 0x29, 0xF5, 0xAA, 0x37, 0xDE, 0x63, 0x12, 0x75, 0x57, |
| 60 | + 0xD0, 0x43, 0x46, 0xC7, 0xCD, 0xEE, 0xBD, 0x25, 0x54, 0x2F, 0x2C, 0x17, 0xFC, 0x39, 0x38, 0x99, |
| 61 | + 0x52, 0xA2, 0x6C, 0x3A, 0xE2, 0xA6, 0xA6, 0xA5, 0x1C, 0xA5, 0x01, 0x02, 0x03, 0x26, 0x20, 0x01, |
| 62 | + 0x21, 0x58, 0x20, 0xBB, 0x11, 0xCD, 0xDD, 0x6E, 0x9E, 0x86, 0x9D, 0x15, 0x59, 0x72, 0x9A, 0x30, |
| 63 | + 0xD8, 0x9E, 0xD4, 0x9F, 0x36, 0x31, 0x52, 0x42, 0x15, 0x96, 0x12, 0x71, 0xAB, 0xBB, 0xE2, 0x8D, |
| 64 | + 0x7B, 0x73, 0x1F, 0x22, 0x58, 0x20, 0xDB, 0xD6, 0x39, 0x13, 0x2E, 0x2E, 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