diff --git a/src/services/credentials/webauthn.service.ts b/src/services/credentials/webauthn.service.ts index 44a7b05..e6a3de0 100644 --- a/src/services/credentials/webauthn.service.ts +++ b/src/services/credentials/webauthn.service.ts @@ -248,8 +248,11 @@ export class WebAuthnService { * Sauvegarde la clé PBKDF2 chiffrée dans IndexedDB * NE PAS stocker credentialId avec la clé chiffrée */ - private async savePBKDF2Key(encryptedKey: string, _credentialId: string, securityMode: SecurityMode): Promise { + private async savePBKDF2Key(encryptedKey: string, credentialId: string, securityMode: SecurityMode): Promise { try { + // TEST: Log credentialId used for encryption + console.log('🔐 TEST: credentialId used for encryption:', credentialId); + const db = await this.openDatabase(); console.log(`🔍 Available stores in ${DATABASE_CONFIG.name}:`, Array.from(db.objectStoreNames)); const transaction = db.transaction([DATABASE_CONFIG.stores.pbkdf2keys.name], 'readwrite'); @@ -302,7 +305,23 @@ export class WebAuthnService { // Récupérer le credentialId dynamiquement via WebAuthn // IMPORTANT: Cela nécessite une interaction utilisateur (authentification biométrique) console.log('🔐 Requesting WebAuthn authentication to retrieve credential...'); - const credentialId = await this.getCurrentCredentialId(); + + // TEST: Try to get credentialId from sessionStorage first + const storedCredentialId = sessionStorage.getItem('webauthn_credential_id'); + let credentialId: string | null = null; + + if (storedCredentialId) { + console.log('🔐 Using credentialId from sessionStorage:', storedCredentialId); + credentialId = storedCredentialId; + } else { + // Fallback to WebAuthn + credentialId = await this.getCurrentCredentialId(); + if (credentialId) { + console.log('🔐 Storing credentialId in sessionStorage for testing'); + sessionStorage.setItem('webauthn_credential_id', credentialId); + } + } + if (!credentialId) { console.log('🔍 WebAuthn authentication required but not available'); console.log('ℹ️ For proton-pass or os mode, user interaction is required to decrypt the key');