diff --git a/.changeset/conformance-attestation-roots.md b/.changeset/conformance-attestation-roots.md new file mode 100644 index 00000000..2b60286b --- /dev/null +++ b/.changeset/conformance-attestation-roots.md @@ -0,0 +1,5 @@ +--- +'seamless-auth-api': patch +--- + +Conformance mode no longer empties the Apple, Android Key and SafetyNet attestation roots. It installs the attestation roots carried by the loaded conformance statements instead, and keeps the vendor roots when none are loaded. An empty root list made Apple and SafetyNet skip certificate path validation, and `@simplewebauthn/server` 14.1.0 now refuses Android Key attestations outright when it is empty. Production deployments are unaffected: this code runs only in conformance mode. diff --git a/docs/fido-conformance.md b/docs/fido-conformance.md index c3246969..51b3893a 100644 --- a/docs/fido-conformance.md +++ b/docs/fido-conformance.md @@ -139,10 +139,13 @@ conformance authenticator is refused as unlisted, every registration fails, and tests that fail are the ones that depend on a registration having succeeded rather than the metadata tests themselves. -Conformance mode also clears the preset Apple, Android Key and SafetyNet root -certificates. The tools sign those statements with their own test roots, so -validating against the real vendor roots cannot succeed; cleared, the roots carried -in the metadata statement are used instead. +Conformance mode also replaces the preset Apple, Android Key and SafetyNet root +certificates with the attestation roots carried by the loaded statements. The tools +sign those statements with their own test roots, so validating against the real +vendor roots cannot succeed. The roots are replaced rather than emptied: an empty +list would make Apple and SafetyNet skip certificate path validation entirely. If no +statement carries an attestation root, the vendor roots stay in place and the log +says so; the tools' Apple, Android Key and SafetyNet statements are then refused. Conformance mode also brings the metadata service up regardless of whether this deployment requests attestation, because the conformance surface honours the diff --git a/package-lock.json b/package-lock.json index 190c5c41..91c5a94b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,17 +14,17 @@ "@seamless-auth/messaging-aws": "^0.3.1", "@seamless-auth/messaging-twilio": "^0.3.1", "@seamless-auth/types": "^0.41.0", - "@simplewebauthn/server": "^14.0.3", + "@simplewebauthn/server": "^14.1.0", "base64url": "^3.0.1", - "bcrypt-ts": "^9.0.2", + "bcrypt-ts": "^9.0.3", "cors": "^2.8.5", "express": "^5.3.0", - "express-rate-limit": "^8.7.2", + "express-rate-limit": "^8.7.5", "express-slow-down": "^3.1.1", "helmet": "^8.3.0", - "jose": "^6.2.14", + "jose": "^6.2.18", "jsonwebtoken": "^9.0.2", - "libphonenumber-js": "^1.13.15", + "libphonenumber-js": "^1.13.17", "pg": "^8.23.1", "pg-hstore": "^2.3.4", "sequelize": "^6.37.3", @@ -2988,9 +2988,9 @@ } }, "node_modules/@simplewebauthn/server": { - "version": "14.0.3", - "resolved": "https://registry.npmjs.org/@simplewebauthn/server/-/server-14.0.3.tgz", - "integrity": "sha512-D39/0fiDiYmGV+nraY9s63D1Ho2AX/waMLy22/9gUadTUuvbAnstfb4bpbHYbwZuV5ZLDYN1SmzDKuiHzKAA4Q==", + "version": "14.1.0", + "resolved": "https://registry.npmjs.org/@simplewebauthn/server/-/server-14.1.0.tgz", + "integrity": "sha512-HPRRBR4Vzr45+RVvbmf6JuCfGdYYcSs4Pnnnp9YSY2IABa4JKnG+wxybczoB7rmdLCOMS/mbBa2ZL/Bcz58UlA==", "license": "MIT", "dependencies": { "@hexagon/base64": "^1.1.27", @@ -3005,7 +3005,7 @@ "reflect-metadata": "^0.2.2" }, "engines": { - "node": ">=20.0.0" + "node": ">=22.0.0" } }, "node_modules/@smithy/config-resolver": { @@ -4398,9 +4398,9 @@ } }, "node_modules/bcrypt-ts": { - "version": "9.0.2", - "resolved": "https://registry.npmjs.org/bcrypt-ts/-/bcrypt-ts-9.0.2.tgz", - "integrity": "sha512-esaMayGbxzD3bOpy7f00pa5wA15wqhP15RbDYGzh/xGbZRNr05G9HdNiqK4ywzrVdzO8rv+Z4l6m01/9pv1FRA==", + "version": "9.0.3", + "resolved": "https://registry.npmjs.org/bcrypt-ts/-/bcrypt-ts-9.0.3.tgz", + "integrity": "sha512-7N21c3DP+jqYUlxhrx5b4GMzZaLw5kmokizcXny2PIDRxETkll7HNDo36mI2xClsxYdpX+eP77pEDPXYDNNQLw==", "license": "MIT", "engines": { "node": ">=22" @@ -5653,9 +5653,9 @@ } }, "node_modules/express-rate-limit": { - "version": "8.7.2", - "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-8.7.2.tgz", - "integrity": "sha512-U1ScocxDD9WI09LaBVypvNkOtNR5yWAmZLkuKJdAzIchA4YKFYF6GT5IKER7epG58oXtjvGlV0/6ii0F83EyZg==", + "version": "8.7.5", + "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-8.7.5.tgz", + "integrity": "sha512-wi+v38cx2EqD0JnhE/e74o5tFqKWUOAPFJIgyEiqJ8v2MNpoOAA3kI2hXYOI+YM+HE5yqbdAlVxm2GqOIeYOgA==", "license": "MIT", "dependencies": { "debug": "^4.4.3", @@ -6553,9 +6553,9 @@ "license": "MIT" }, "node_modules/jose": { - "version": "6.2.14", - "resolved": "https://registry.npmjs.org/jose/-/jose-6.2.14.tgz", - "integrity": "sha512-3JasLuki1NRLQvY4wCoC37KZk4qxoBx2k2aFqLxT84IezqW0bkJKnNtxnZj/Fu1xsQivoc/lytxaRHJoGLjJ1A==", + "version": "6.2.18", + "resolved": "https://registry.npmjs.org/jose/-/jose-6.2.18.tgz", + "integrity": "sha512-doV4thUwgkrycJH4yLeqwTGIIZphHl+pk7CPReuMIhYhncmgzdko85MaCG4YQFTxqMFr1/oEH32tZuKKovcDEg==", "license": "MIT", "funding": { "url": "https://github.com/sponsors/panva" @@ -6753,9 +6753,9 @@ } }, "node_modules/libphonenumber-js": { - "version": "1.13.15", - "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.13.15.tgz", - "integrity": "sha512-AHdhEQeDFEJ4GKDAQ9AwxChy+v2kUILUB3TGQRpkXMkWePjXTU/WQEzWVQoIx/Gz8fE73Wr5SEuZCy2vk8jrMQ==", + "version": "1.13.17", + "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.13.17.tgz", + "integrity": "sha512-V92dxRHhYTsHF5B6IjR8rtKW6qL7xKuERPFFqZt7XQl8A+NikbwEzjhxGpM+R6JnWjaL7/wokWSdTG/eyYAscQ==", "license": "MIT" }, "node_modules/lightningcss": { diff --git a/package.json b/package.json index da57a23c..45bb1f98 100644 --- a/package.json +++ b/package.json @@ -53,17 +53,17 @@ "@seamless-auth/messaging-aws": "^0.3.1", "@seamless-auth/messaging-twilio": "^0.3.1", "@seamless-auth/types": "^0.41.0", - "@simplewebauthn/server": "^14.0.3", + "@simplewebauthn/server": "^14.1.0", "base64url": "^3.0.1", - "bcrypt-ts": "^9.0.2", + "bcrypt-ts": "^9.0.3", "cors": "^2.8.5", "express": "^5.3.0", - "express-rate-limit": "^8.7.2", + "express-rate-limit": "^8.7.5", "express-slow-down": "^3.1.1", "helmet": "^8.3.0", - "jose": "^6.2.14", + "jose": "^6.2.18", "jsonwebtoken": "^9.0.2", - "libphonenumber-js": "^1.13.15", + "libphonenumber-js": "^1.13.17", "pg": "^8.23.1", "pg-hstore": "^2.3.4", "sequelize": "^6.37.3", diff --git a/src/services/conformanceMetadata.ts b/src/services/conformanceMetadata.ts index afa54662..3fc67294 100644 --- a/src/services/conformanceMetadata.ts +++ b/src/services/conformanceMetadata.ts @@ -14,12 +14,13 @@ import getLogger from '../utils/logger.js'; const logger = getLogger('conformanceMetadata'); /** - * Attestation formats whose preset root certificates have to be cleared. + * Attestation formats whose preset roots are swapped for the conformance roots. * * The tools sign their Apple, Android Key and SafetyNet statements with their - * own test roots, so validating those against the real vendor roots fails every - * one of those tests. Cleared, the library falls back to the roots carried in - * the metadata statement, which is what a run supplies. + * own test roots, so the real vendor roots fail every one of those tests. The + * roots are replaced, never emptied: an empty list makes the library skip + * certificate path validation for Apple and SafetyNet altogether, and Android + * Key refuses every statement-less attestation. */ const VENDOR_ROOT_IDENTIFIERS = ['apple', 'android-key', 'android-safetynet'] as const; @@ -61,22 +62,47 @@ export function applyConformanceMetadataOverrides(): ConformanceMetadataOverride logger.info('Conformance MDS root certificate installed, replacing the FIDO production root.'); } - for (const identifier of VENDOR_ROOT_IDENTIFIERS) { - SettingsService.setRootCertificates({ identifier, certificates: [] }); - } - logger.info( - 'Vendor attestation roots cleared, so conformance statements supply the trust anchor.', - ); - const statements = readStatements(process.env.FIDO_CONFORMANCE_METADATA_DIR); if (statements.length > 0) { overrides.statements = statements; logger.info(`Loaded ${statements.length} local conformance metadata statements.`); } + const attestationRoots = collectAttestationRoots(statements); + if (attestationRoots.length > 0) { + for (const identifier of VENDOR_ROOT_IDENTIFIERS) { + SettingsService.setRootCertificates({ identifier, certificates: attestationRoots }); + } + logger.info( + `Vendor attestation roots replaced with ${attestationRoots.length} roots from the conformance statements.`, + ); + } else { + logger.warn( + "No conformance statement carries an attestation root, so the vendor attestation roots stay in place and the tools' Apple, Android Key and SafetyNet statements will be refused.", + ); + } + return overrides; } +function collectAttestationRoots(statements: MetadataStatement[]): Uint8Array[] { + const unique = new Set(); + + for (const statement of statements) { + const roots: unknown = statement.attestationRootCertificates; + if (!Array.isArray(roots)) { + continue; + } + for (const root of roots) { + if (typeof root === 'string' && root.length > 0) { + unique.add(root); + } + } + } + + return [...unique].map((root) => Uint8Array.from(Buffer.from(root, 'base64'))); +} + function splitList(value: string | undefined): string[] { return (value ?? '') .split(',') diff --git a/tests/fixtures/attestation/android-key.statement.json b/tests/fixtures/attestation/android-key.statement.json new file mode 100644 index 00000000..33bb3beb --- /dev/null +++ b/tests/fixtures/attestation/android-key.statement.json @@ -0,0 +1,84 @@ +{ + "description": "Virtual Secp256R1 FIDO2 Conformance Testing CTAP2 Authenticator with Android Key Attestation", + "aaguid": "550e4b54-aa47-409f-9a95-1ab76c130131", + "protocolFamily": "fido2", + "authenticatorVersion": 2, + "upv": [ + { + "major": 1, + "minor": 0 + } + ], + "authenticationAlgorithms": ["secp256r1_ecdsa_sha256_raw"], + "publicKeyAlgAndEncodings": ["cose"], + "attestationTypes": ["basic_full"], + "schema": 3, + "userVerificationDetails": [ + [ + { + "userVerificationMethod": "none" + } + ], + [ + { + "userVerificationMethod": "presence_internal" + } + ], + [ + { + "userVerificationMethod": "passcode_external", + "caDesc": { + "base": 10, + "minLength": 4 + } + } + ], + [ + { + "userVerificationMethod": "passcode_external", + "caDesc": { + "base": 10, + "minLength": 4 + } + }, + { + "userVerificationMethod": "presence_internal" + } + ] + ], + "keyProtection": ["hardware", "secure_element"], + "matcherProtection": ["on_chip"], + "attachmentHint": ["internal"], + "tcDisplay": [], + "attestationRootCertificates": [ + "MIIDFTCCArygAwIBAgIJAPYG0nMp5fspMAoGCCqGSM49BAMCMIHcMT0wOwYDVQQDDDRGQUtFIEFuZHJvaWQgS2V5c3RvcmUgU29mdHdhcmUgQXR0ZXN0YXRpb24gUm9vdCBGQUtFMTEwLwYJKoZIhvcNAQkBFiJjb25mb3JtYW5jZS10b29sc0BmaWRvYWxsaWFuY2Uub3JnMRYwFAYDVQQKDA1GSURPIEFsbGlhbmNlMSIwIAYDVQQLDBlBdXRoZW50aWNhdG9yIEF0dGVzdGF0aW9uMQswCQYDVQQGEwJVUzELMAkGA1UECAwCTVkxEjAQBgNVBAcMCVdha2VmaWVsZDAgFw0xOTA0MjUwNTQ5MzJaGA8yMDc0MDEyNjA1NDkzMlowgdwxPTA7BgNVBAMMNEZBS0UgQW5kcm9pZCBLZXlzdG9yZSBTb2Z0d2FyZSBBdHRlc3RhdGlvbiBSb290IEZBS0UxMTAvBgkqhkiG9w0BCQEWImNvbmZvcm1hbmNlLXRvb2xzQGZpZG9hbGxpYW5jZS5vcmcxFjAUBgNVBAoMDUZJRE8gQWxsaWFuY2UxIjAgBgNVBAsMGUF1dGhlbnRpY2F0b3IgQXR0ZXN0YXRpb24xCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJNWTESMBAGA1UEBwwJV2FrZWZpZWxkMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEaH+BmKuo1XRtjS3UJVLrjh0bNl/lLhU7VX89N8+kuI8rnZCfXVD5k3qpOFSY6oTtrcZ1aQRSyR4sZ8EC6Hoi7aNjMGEwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAoQwHQYDVR0OBBYEFFKaGzLgVqrNUQ/vX4A3BovykSMdMB8GA1UdIwQYMBaAFFKaGzLgVqrNUQ/vX4A3BovykSMdMAoGCCqGSM49BAMCA0cAMEQCIAfWMAOOjxO6noErB+wtRBmrDruNIApw70G7kBhliXLkAiBM8sYUVClPsJkCUHI5Wix3ybY31L5J51VS+f1gACNn+Q==" + ], + "authenticatorGetInfo": { + "versions": ["U2F_V2", "FIDO_2_0"], + "extensions": ["credProtect", "hmac-secret"], + "aaguid": "550e4b54aa47409f9a951ab76c130131", + "options": { + "plat": false, + "rk": true, + "clientPin": true, + "up": true, + "uv": true, + "uvToken": false, + "config": false + }, + "maxMsgSize": 1200, + "pinUvAuthProtocols": [1], + "maxCredentialCountInList": 16, + "maxCredentialIdLength": 128, + "transports": ["usb", "nfc"], + "algorithms": [ + { + "type": "public-key", + "alg": -7 + } + ], + "maxAuthenticatorConfigLength": 1024, + "defaultCredProtect": 2, + "firmwareVersion": 5 + } +} diff --git a/tests/unit/services/attestationFormats.spec.ts b/tests/unit/services/attestationFormats.spec.ts index 92d6ea37..3283bd4d 100644 --- a/tests/unit/services/attestationFormats.spec.ts +++ b/tests/unit/services/attestationFormats.spec.ts @@ -167,13 +167,30 @@ describe('attestation formats, against statements captured from the FIDO conform await expect(verify(load('android-key'))).rejects.toThrow(/root certificate/i); }); - it('verifies once the preset roots are cleared, which is what conformance mode does', async () => { + it('is refused once the roots are emptied, rather than trusting the chain it carries', async () => { SettingsService.setRootCertificates({ identifier: 'android-key', certificates: [] }); - const result = await verify(load('android-key')); + await expect(verify(load('android-key'))).rejects.toThrow(/No root certificates/i); + }); - expect(result.verified).toBe(true); - expect(result.registrationInfo?.fmt).toBe('android-key'); + it('verifies against its conformance metadata statement, which is how a run supplies the root', async () => { + SettingsService.setRootCertificates({ + identifier: 'android-key', + certificates: productionRoots, + }); + const statement = JSON.parse( + fs.readFileSync(path.join(FIXTURE_DIR, 'android-key.statement.json'), 'utf8'), + ); + await MetadataService.initialize({ mdsServers: [], statements: [statement] }); + + try { + const result = await verify(load('android-key')); + + expect(result.verified).toBe(true); + expect(result.registrationInfo?.fmt).toBe('android-key'); + } finally { + await MetadataService.initialize({ mdsServers: [], statements: [] }); + } }); }); diff --git a/tests/unit/services/conformanceMetadata.spec.ts b/tests/unit/services/conformanceMetadata.spec.ts index 4fe180df..cddcc04c 100644 --- a/tests/unit/services/conformanceMetadata.spec.ts +++ b/tests/unit/services/conformanceMetadata.spec.ts @@ -94,19 +94,47 @@ describe('applyConformanceMetadataOverrides', () => { expect(statements.map((statement: any) => statement.aaguid).sort()).toEqual(['deep', 'top']); }); - it('clears the vendor attestation roots so statements supply the trust anchor', () => { + it('replaces the vendor attestation roots with the roots the statements carry', () => { + const one = Buffer.from('conformance root one').toString('base64'); + const two = Buffer.from('conformance root two').toString('base64'); + fs.writeFileSync( + path.join(tmpDir, 'a.json'), + JSON.stringify({ aaguid: 'a', attestationRootCertificates: [one, two] }), + ); + fs.writeFileSync( + path.join(tmpDir, 'b.json'), + JSON.stringify({ aaguid: 'b', attestationRootCertificates: [one, ''] }), + ); + fs.writeFileSync(path.join(tmpDir, 'c.json'), JSON.stringify({ aaguid: 'c' })); + process.env.FIDO_CONFORMANCE_METADATA_DIR = tmpDir; + const spy = vi .spyOn(SettingsService, 'setRootCertificates') .mockImplementation(() => undefined); applyConformanceMetadataOverrides(); + const expected = [one, two].map((root) => Uint8Array.from(Buffer.from(root, 'base64'))); for (const identifier of ['apple', 'android-key', 'android-safetynet']) { - expect(spy).toHaveBeenCalledWith({ identifier, certificates: [] }); + expect(spy).toHaveBeenCalledWith({ identifier, certificates: expected }); } spy.mockRestore(); }); + it('never empties the vendor attestation roots when no statement carries one', () => { + fs.writeFileSync(path.join(tmpDir, 'bare.json'), JSON.stringify({ aaguid: 'bare' })); + process.env.FIDO_CONFORMANCE_METADATA_DIR = tmpDir; + + const spy = vi + .spyOn(SettingsService, 'setRootCertificates') + .mockImplementation(() => undefined); + + applyConformanceMetadataOverrides(); + + expect(spy).not.toHaveBeenCalled(); + spy.mockRestore(); + }); + it('skips a statement file that parses to something that is not an object', () => { fs.writeFileSync(path.join(tmpDir, 'scalar.json'), '"just a string"'); process.env.FIDO_CONFORMANCE_METADATA_DIR = tmpDir;