Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/conformance-attestation-roots.md
Original file line number Diff line number Diff line change
@@ -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.
11 changes: 7 additions & 4 deletions docs/fido-conformance.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 21 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
48 changes: 37 additions & 11 deletions src/services/conformanceMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<ArrayBuffer>[] {
const unique = new Set<string>();

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(',')
Expand Down
84 changes: 84 additions & 0 deletions tests/fixtures/attestation/android-key.statement.json
Original file line number Diff line number Diff line change
@@ -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": [
"MIIDFTCCArygAwIBAgIJAPYG0nMp5fspMAoGCCqGSM49BAMCMIHcMT0wOwYDVQQDDDRGQUtFIEFuZHJva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id": "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
}
}
25 changes: 21 additions & 4 deletions tests/unit/services/attestationFormats.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] });
}
});
});

Expand Down
32 changes: 30 additions & 2 deletions tests/unit/services/conformanceMetadata.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down