hadv / hadv/ethaura

Add device attestation for enhanced passkey security

Open
#88 0 comments 0 reactions 0 assignees View on GitHub
⚿ passkey ⛨ security enhancement
Dominant language
JavaScript
Stars
2
Forks
0
PR merge metrics
No merged PRs in 30d

Description

## Overview

Implement WebAuthn device attestation to verify the authenticity and security properties of passkey authenticators during device registration. This enhancement will strengthen the security model by ensuring only trusted hardware authenticators can be registered.

## Background

Currently, EthAura uses `attestation: 'direct'` in the WebAuthn credential creation options (see `PasskeySettings.jsx` and `PasskeyManager.jsx`), but the attestation object is only used to extract the public key coordinates. The attestation signature and certificate chain are not verified.

**Current implementation:**
```javascript
attestation: 'direct', // Get attestation to extract public key
```

The `parsePublicKey()` function in `frontend/src/utils/webauthn.js` extracts the public key from the attestation object but does not verify:
- Attestation signature validity
- Attestation certificate chain
- Authenticator AAGUID (Authenticator Attestation GUID)
- Authenticator security properties

## Security Benefits

Device attestation provides:

1. **Authenticator Verification**: Cryptographically verify that the passkey was created by a genuine hardware authenticator (Secure Enclave, TPM, etc.)
2. **Security Level Assurance**: Confirm the authenticator meets minimum security standards (FIDO2 certified, hardware-backed, etc.)
3. **Attack Prevention**: Prevent registration of software-emulated authenticators or compromised devices
4. **Compliance**: Meet regulatory requirements for high-security applications
5. **Audit Trail**: Track which authenticator models are being used across the platform

## Technical Implementation

### 1. Frontend Changes

**File: `frontend/src/utils/webauthn.js`**

Add new function to verify attestation:

```javascript
/**
* Verify WebAuthn attestation object
* @param {ArrayBuffer} attestationObject - The attestation object from credential creation
* @param {ArrayBuffer} clientDataJSON - The client data JSON
* @returns {Object} Attestation verification result with authenticator info
*/
export async function verifyAttestation(attestationObject, clientDataJSON) {
// 1. Decode CBOR attestation object
// 2. Extract attestation statement (attStmt)
// 3. Extract authenticator data (authData)
// 4. Verify attestation signature based on format (packed, fido-u2f, etc.)
// 5. Verify certificate chain against FIDO MDS (Metadata Service)
// 6. Extract AAGUID and lookup authenticator metadata
// 7. Return verification result with security properties
}
```

**File: `frontend/src/components/PasskeySettings.jsx` and `PasskeyManager.jsx`**

Update credential creation to verify attestation:

```javascript
const credential = await navigator.credentials.create(createCredentialOptions)

// Verify attestation before accepting the credential
const attestationResult = await verifyAttestation(
credential.response.attestationObject,
credential.response.clientDataJSON
)

if (!attestationResult.verified) {
throw new Error(`Attestation verification failed: ${attestationResult.reason}`)
}

// Check security requirements
if (!attestationResult.isHardwareBacked) {
throw new Error('Only hardware-backed authenticators are allowed')
}

if (!attestationResult.isFIDO2Certified) {
console.warn('Authenticator is not FIDO2 certified')
}
```

### 2. Backend Changes

**File: `backend/database.js`**

Extend `passkey_devices` table schema:

```sql
ALTER TABLE passkey_devices ADD COLUMN aaguid TEXT;
ALTER TABLE passkey_devices ADD COLUMN authenticator_name TEXT;
ALTER TABLE passkey_devices ADD COLUMN is_hardware_backed BOOLEAN DEFAULT 1;
ALTER TABLE passkey_devices ADD COLUMN is_fido2_certified BOOLEAN DEFAULT 0;
ALTER TABLE passkey_devices ADD COLUMN attestation_format TEXT; -- 'packed', 'fido-u2f', 'none', etc.
```

**File: `backend/server.js`**

Update device registration endpoint to store attestation metadata:

```javascript
app.post('/api/devices', async (req, res) => {
const {
accountAddress,
credentialId,
publicKey,
attestationMetadata // NEW: AAGUID, authenticator name, security properties
} = req.body

// Validate attestation metadata
if (!attestationMetadata.isHardwareBacked) {
return res.status(400).json({
error: 'Only hardware-backed authenticators are allowed'
})
}

// Store device with attestation metadata
// ...
})
```

### 3. Smart Contract Considerations

The smart contract (`P256Account.sol`) already uses Solady's WebAuthn library which validates authenticator flags during signature verification:

```solidity
bool webAuthnValid = WebAuthn.verify(
challenge,
true, // requireUserVerification - enforce UV flag for security
auth,
_qx,
_qy
);
```

However, attestation verification happens **only during registration** (off-chain), not during transaction signing. The contract should remain unchanged as it already enforces:
- User Present (UP) flag
- User Verified (UV) flag
- Valid P-256 signature

## Implementation Phases

### Phase 1: Basic Attestation Verification (MVP)
- [ ] Implement `verifyAttestation()` function in `webauthn.js`
- [ ] Support "packed" and "none" attestation formats
- [ ] Extract AAGUID from attestation object
- [ ] Update database schema to store AAGUID
- [ ] Update device registration to verify and store attestation metadata

### Phase 2: FIDO MDS Integration
- [ ] Integrate with FIDO Alliance Metadata Service (MDS)
- [ ] Lookup authenticator metadata by AAGUID
- [ ] Verify certificate chain against FIDO root certificates
- [ ] Display authenticator name/model in device management UI
- [ ] Add security badges ("FIDO2 Certified", "Hardware-Backed", etc.)

### Phase 3: Policy Enforcement
- [ ] Add admin configuration for attestation requirements
- [ ] Enforce minimum security level (e.g., require FIDO2 certification)
- [ ] Add allowlist/blocklist for specific authenticator models
- [ ] Implement attestation verification in backend API
- [ ] Add audit logging for attestation failures

### Phase 4: Advanced Features
- [ ] Support additional attestation formats ("fido-u2f", "android-key", "apple", etc.)
- [ ] Implement attestation certificate revocation checking
- [ ] Add authenticator metadata to device management UI
- [ ] Generate security reports based on authenticator usage
- [ ] Add migration path for existing devices without attestation

## Security Considerations

1. **Attestation Format Support**: Start with "packed" format (most common for platform authenticators) and "none" (for privacy-focused users)
2. **Privacy**: Attestation can reveal device model/manufacturer. Consider offering "none" attestation as an option for privacy-conscious users
3. **Certificate Validation**: Verify the entire certificate chain up to a trusted FIDO root certificate
4. **AAGUID Lookup**: Use FIDO MDS to get authenticator metadata, but cache results to avoid rate limiting
5. **Backward Compatibility**: Existing devices registered without attestation should continue to work
6. **Revocation**: Monitor FIDO MDS for authenticator revocations and notify users if their device is compromised

## Testing Requirements

- [ ] Test with macOS Touch ID (Secure Enclave)
- [ ] Test with Windows Hello (TPM)
- [ ] Test with iOS Face ID/Touch ID
- [ ] Test with Android biometric authenticators
- [ ] Test with hardware security keys (YubiKey, etc.)
- [ ] Test attestation verification with valid certificates
- [ ] Test attestation verification with invalid/expired certificates
- [ ] Test with "none" attestation format
- [ ] Test backward compatibility with existing devices

## Resources

- [FIDO Alliance Attestation White Paper (2024)](https://fidoalliance.org/wp-content/uploads/2024/06/EDWG_Attestation-White-Paper_2024-1.pdf)
- [WebAuthn Attestation Specification](https://www.w3.org/TR/webauthn-2/#sctn-attestation)
- [FIDO Metadata Service](https://fidoalliance.org/metadata/)
- [Solady WebAuthn Library](https://github.com/Vectorized/solady/blob/main/src/utils/WebAuthn.sol) (already integrated)

## Related

- PR #87: Multi-Device Passkey Management with Timelock Handling
- `frontend/src/utils/webauthn.js`: Current WebAuthn implementation
- `frontend/src/components/PasskeySettings.jsx`: Passkey registration UI
- `src/P256Account.sol`: Smart contract with WebAuthn signature verification
- `docs/SOLADY_WEBAUTHN_SIGNATURE_FORMAT.md`: Current signature format documentation

## Success Criteria

- ✅ All new passkey registrations verify attestation
- ✅ AAGUID and authenticator metadata stored in database
- ✅ Device management UI displays authenticator model/name
- ✅ Only hardware-backed authenticators can be registered (configurable)
- ✅ Existing devices continue to work without re-registration
- ✅ Comprehensive test coverage across different authenticator types
- ✅ Documentation updated with attestation verification details

---

**Priority**: Medium
**Complexity**: High
**Estimated Effort**: 2-3 weeks
**Dependencies**: None (builds on existing WebAuthn implementation)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.