refactor: update all files to use centralized encryption service

This commit is contained in:
NicolasCantu 2025-10-26 02:49:34 +01:00
parent f4b80f1d93
commit 26580aceed
2 changed files with 27 additions and 32 deletions

View File

@ -230,11 +230,11 @@ export class WebAuthnService {
try { try {
// Utiliser la clé publique WebAuthn pour chiffrer la clé PBKDF2 // Utiliser la clé publique WebAuthn pour chiffrer la clé PBKDF2
// Pour l'instant, on utilise un chiffrement AES-GCM avec une clé dérivée // Pour l'instant, on utilise un chiffrement AES-GCM avec une clé dérivée
const { EncryptionService } = await import('./encryption.service'); const { EncryptionService } = await import('../encryption.service');
const encryptionService = EncryptionService.getInstance(); const encryptionService = EncryptionService.getInstance();
// Utiliser l'ID de la credential WebAuthn comme mot de passe pour chiffrer la clé PBKDF2 // Utiliser l'ID de la credential WebAuthn comme mot de passe pour chiffrer la clé PBKDF2
const encryptedKey = await encryptionService.encryptWithPassword(key, credential.id); const encryptedKey = await encryptionService.encrypt(key, credential.id);
console.log('🔐 Key encrypted with WebAuthn credential'); console.log('🔐 Key encrypted with WebAuthn credential');
return encryptedKey; return encryptedKey;

View File

@ -154,7 +154,7 @@ export class SecureCredentialsService {
}); });
// Import dynamique des services // Import dynamique des services
const { EncryptionService } = await import('./credentials/encryption.service'); const { EncryptionService } = await import('./encryption.service');
const { WebAuthnService } = await import('./credentials/webauthn.service'); const { WebAuthnService } = await import('./credentials/webauthn.service');
const { StorageService } = await import('./credentials/storage.service'); const { StorageService } = await import('./credentials/storage.service');
@ -203,7 +203,7 @@ export class SecureCredentialsService {
// Demander un mot de passe à l'utilisateur et chiffrer la clé // Demander un mot de passe à l'utilisateur et chiffrer la clé
console.log('🔐 Storing PBKDF2 key with password encryption...'); console.log('🔐 Storing PBKDF2 key with password encryption...');
const userPassword = await this.promptForPassword(); const userPassword = await this.promptForPassword();
const encryptedKey = await encryptionService.encryptWithPassword(pbkdf2Key, userPassword); const encryptedKey = await encryptionService.encrypt(pbkdf2Key, userPassword);
await storageService.storeEncryptedKey(encryptedKey, securityMode); await storageService.storeEncryptedKey(encryptedKey, securityMode);
break; break;
@ -313,29 +313,29 @@ export class SecureCredentialsService {
}); });
// Import dynamique du service // Import dynamique du service
const { EncryptionService } = await import('./credentials/encryption.service'); const { EncryptionService } = await import('./encryption.service');
const encryptionService = EncryptionService.getInstance(); const encryptionService = EncryptionService.getInstance();
// Générer des clés aléatoires // Générer des clés aléatoires
const keys = encryptionService.generateRandomKeys(); const keys = encryptionService.generateRandomKeys();
// Chiffrer les clés avec le mot de passe // Chiffrer les clés avec le mot de passe
const encryptedSpendKey = await encryptionService.encryptWithPassword( const encryptedSpendKey = await encryptionService.encrypt(
keys.spendKey, keys.spendKey,
password, password
_options
); );
const encryptedScanKey = await encryptionService.encryptWithPassword( const encryptedScanKey = await encryptionService.encrypt(
keys.scanKey, keys.scanKey,
password, password
_options
); );
// Note: encryptionService.encrypt returns base64 string directly
// We need to keep track of salt for compatibility with old format
return { return {
spendKey: encryptedSpendKey.encryptedData, spendKey: encryptedSpendKey,
scanKey: encryptedScanKey.encryptedData, scanKey: encryptedScanKey,
salt: encryptedSpendKey.salt, salt: new Uint8Array(16), // Placeholder for compatibility
iterations: encryptedSpendKey.iterations, iterations: 100000, // Standard iterations
timestamp: Date.now() timestamp: Date.now()
}; };
} catch (error) { } catch (error) {
@ -361,7 +361,7 @@ export class SecureCredentialsService {
}); });
// Import dynamique du service // Import dynamique du service
const { EncryptionService } = await import('./credentials/encryption.service'); const { EncryptionService } = await import('./encryption.service');
const encryptionService = EncryptionService.getInstance(); const encryptionService = EncryptionService.getInstance();
// Générer des clés aléatoires // Générer des clés aléatoires
@ -412,24 +412,23 @@ export class SecureCredentialsService {
}); });
// Import dynamique du service // Import dynamique du service
const { EncryptionService } = await import('./credentials/encryption.service'); const { EncryptionService } = await import('./encryption.service');
const encryptionService = EncryptionService.getInstance(); const encryptionService = EncryptionService.getInstance();
// Générer des clés aléatoires // Générer des clés aléatoires
const keys = encryptionService.generateRandomKeys(); const keys = encryptionService.generateRandomKeys();
// Chiffrer avec le mot de passe // Chiffrer avec le mot de passe
const encrypted = await encryptionService.encryptWithPassword( const encrypted = await encryptionService.encrypt(
JSON.stringify(keys), JSON.stringify(keys),
password, password
_options
); );
return { return {
spendKey: encrypted.encryptedData, spendKey: encrypted,
scanKey: '', // Scan key est inclus dans les données chiffrées scanKey: '', // Scan key est inclus dans les données chiffrées
salt: encrypted.salt, salt: new Uint8Array(16), // Placeholder for compatibility
iterations: encrypted.iterations, iterations: 100000,
timestamp: Date.now() timestamp: Date.now()
}; };
} catch (error) { } catch (error) {
@ -567,22 +566,18 @@ export class SecureCredentialsService {
} }
// Import dynamique du service de chiffrement // Import dynamique du service de chiffrement
const { EncryptionService } = await import('./credentials/encryption.service'); const { EncryptionService } = await import('./encryption.service');
const encryptionService = EncryptionService.getInstance(); const encryptionService = EncryptionService.getInstance();
// Déchiffrer les clés // Déchiffrer les clés
const spendKey = await encryptionService.decryptWithPassword( const spendKey = await encryptionService.decrypt(
credentials.spendKey, credentials.spendKey,
password, password
credentials.salt,
credentials.iterations
); );
const scanKey = await encryptionService.decryptWithPassword( const scanKey = await encryptionService.decrypt(
credentials.scanKey, credentials.scanKey,
password, password
credentials.salt,
credentials.iterations
); );
return { return {