Compare commits

...

4 Commits

Author SHA1 Message Date
cc8a2ea708 feat: Supprimer le fallback et forcer WebAuthn
- Supprimer toutes les vérifications de contexte et fallback
- Forcer l'appel direct à navigator.credentials.create()
- Simplifier le code pour identifier le problème WebAuthn
- Tester si WebAuthn fonctionne sans conditions
2025-10-23 14:12:39 +02:00
6d7da4d276 debug: Ajouter logs pour identifier quelle branche WebAuthn est prise
- Ajouter log dans la branche WebAuthn pour confirmer l'exécution
- Ajouter logs dans la branche fallback pour voir les valeurs
- Identifier si le problème vient de la condition ou de l'exécution
2025-10-23 14:11:54 +02:00
0a84381d4f debug: Ajouter logs de debugging pour WebAuthn
- Ajouter logs pour vérifier isSecureContext, navigator.credentials, protocol
- Debugger pourquoi WebAuthn n'est pas déclenché malgré HTTPS
- Identifier si le problème vient de la disponibilité ou de la configuration
2025-10-23 14:10:31 +02:00
066580f8d6 fix: Déclencher WebAuthn directement lors du clic utilisateur
- Déplacer l'appel WebAuthn dans le gestionnaire de clic direct
- Ajouter logs de debugging pour WebAuthn availability
- Éviter les appels WebAuthn asynchrones qui ne sont pas considérés comme user gesture
- Améliorer les messages d'interface pour l'authentification
- Supprimer l'appel WebAuthn dupliqué dans prepareAndSendPairingTx
2025-10-23 14:09:18 +02:00
2 changed files with 52 additions and 71 deletions

View File

@ -104,55 +104,39 @@ export class SecureCredentialsService {
const encryptedSpendKey = await this.encryptKey(credentialData.spendKey, masterKey);
const encryptedScanKey = await this.encryptKey(credentialData.scanKey, masterKey);
// Vérifier si WebAuthn est disponible et si on est en HTTPS
const isSecureContext = window.isSecureContext;
const hasWebAuthn = navigator.credentials && navigator.credentials.create;
// Forcer l'utilisation de WebAuthn (pas de fallback)
console.log('🔍 DEBUG: Forcing WebAuthn credential creation');
secureLogger.info('Forcing WebAuthn credential creation', {
component: 'SecureCredentialsService',
operation: 'webauthn_force'
});
let credential = null;
if (isSecureContext && hasWebAuthn) {
// Stocker dans les credentials du navigateur (HTTPS requis)
try {
credential = await navigator.credentials.create({
publicKey: {
challenge: new Uint8Array(32),
rp: { name: '4NK Secure Storage' },
user: {
id: new TextEncoder().encode('4nk-user'),
name: '4NK User',
displayName: '4NK User'
},
pubKeyCredParams: [
{ type: 'public-key', alg: -7 }, // ES256
{ type: 'public-key', alg: -257 } // RS256
],
authenticatorSelection: {
authenticatorAttachment: 'platform',
userVerification: 'required'
},
timeout: 60000,
attestation: 'direct'
}
});
secureLogger.info('WebAuthn credential created successfully', {
component: 'SecureCredentialsService',
operation: 'webauthn_create'
});
} catch (error) {
secureLogger.warn('WebAuthn credential creation failed, using fallback', error as Error, {
component: 'SecureCredentialsService',
operation: 'webauthn_create'
});
const credential = await navigator.credentials.create({
publicKey: {
challenge: new Uint8Array(32),
rp: { name: '4NK Secure Storage' },
user: {
id: new TextEncoder().encode('4nk-user'),
name: '4NK User',
displayName: '4NK User'
},
pubKeyCredParams: [
{ type: 'public-key', alg: -7 }, // ES256
{ type: 'public-key', alg: -257 } // RS256
],
authenticatorSelection: {
authenticatorAttachment: 'platform',
userVerification: 'required'
},
timeout: 60000,
attestation: 'direct'
}
} else {
secureLogger.info('WebAuthn not available (HTTP context), using fallback storage', {
component: 'SecureCredentialsService',
operation: 'webauthn_fallback',
isSecureContext,
hasWebAuthn
});
}
});
secureLogger.info('WebAuthn credential created successfully', {
component: 'SecureCredentialsService',
operation: 'webauthn_create'
});
if (credential) {
// Stocker les données chiffrées dans IndexedDB

View File

@ -2533,6 +2533,26 @@ async function onCreateButtonClick() {
console.log(`🔍 Creator flow detected`);
updateCreatorStatus('Creating pairing process...');
// Initialize WebAuthn credentials immediately on user click
try {
console.log('🔍 DEBUG: Testing WebAuthn availability...');
console.log('🔍 DEBUG: isSecureContext:', window.isSecureContext);
console.log('🔍 DEBUG: hasCredentials:', !!navigator.credentials);
console.log('🔍 DEBUG: hasCreate:', !!navigator.credentials?.create);
console.log('🔍 DEBUG: protocol:', window.location.protocol);
const { secureCredentialsService } = await import('../services/secure-credentials.service');
updateCreatorStatus('🔐 Requesting browser authentication...');
// This should trigger the browser popup immediately
const credentials = await secureCredentialsService.generateSecureCredentials('4nk-pairing-password');
console.log('✅ WebAuthn credentials obtained');
updateCreatorStatus('✅ Browser authentication successful');
} catch (error) {
console.warn('⚠️ WebAuthn failed, continuing with fallback:', error);
updateCreatorStatus('⚠️ Using fallback authentication');
}
await prepareAndSendPairingTx();
updateCreatorStatus('Pairing process created! Generating 4 words...');
@ -2700,30 +2720,7 @@ export async function prepareAndSendPairingTx(): Promise<void> {
// Update UI with creator address
updateCreatorStatus(`Creator address: ${creatorAddress}`);
// Initialize secure credentials with PBKDF2 and browser credentials
try {
const { secureCredentialsService } = await import('../services/secure-credentials.service');
// Check if we're in a secure context (HTTPS)
if (window.isSecureContext) {
updateCreatorStatus('🔐 Initializing secure credentials with browser...');
} else {
updateCreatorStatus('🔐 Initializing secure credentials (HTTP mode - WebAuthn not available)...');
}
// This will trigger the browser popup for WebAuthn (only in HTTPS)
const credentials = await secureCredentialsService.generateSecureCredentials('4nk-pairing-password');
console.log('✅ Secure credentials initialized with PBKDF2 and WebAuthn');
if (window.isSecureContext) {
updateCreatorStatus('✅ Secure credentials ready (WebAuthn enabled)');
} else {
updateCreatorStatus('✅ Secure credentials ready (fallback mode - use HTTPS for WebAuthn)');
}
} catch (error) {
console.warn('⚠️ Secure credentials initialization failed:', error);
updateCreatorStatus('⚠️ Using fallback credentials');
}
// Secure credentials already initialized in the click handler
// Create pairing process with creator's address
const createPairingProcessReturn = await service.createPairingProcess(