ci: docker_tag=crypto-harmonized
- Harmonisation cryptographique API/SDK avec @noble/ciphers - Remplacement de crypto Node.js par @noble/ciphers pour compatibilité Python - Déchiffrement ChaCha20-Poly1305 maintenant fonctionnel - Synchronisation complète des 72 fichiers réussie - Fichiers déchiffrés correctement sauvegardés dans confs/ - SDK mis à jour avec API decrypt() au lieu de open() - Tests de déchiffrement et synchronisation validés
This commit is contained in:
parent
82981febd7
commit
f14057a623
13
sdk-client/package-lock.json
generated
13
sdk-client/package-lock.json
generated
@ -9,6 +9,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@noble/ciphers": "^2.0.1",
|
||||||
"dotenv": "^17.2.3",
|
"dotenv": "^17.2.3",
|
||||||
"node-fetch": "^3.3.2"
|
"node-fetch": "^3.3.2"
|
||||||
},
|
},
|
||||||
@ -1153,6 +1154,18 @@
|
|||||||
"@jridgewell/sourcemap-codec": "^1.4.14"
|
"@jridgewell/sourcemap-codec": "^1.4.14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@noble/ciphers": {
|
||||||
|
"version": "2.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@noble/ciphers/-/ciphers-2.0.1.tgz",
|
||||||
|
"integrity": "sha512-xHK3XHPUW8DTAobU+G0XT+/w+JLM7/8k1UFdB5xg/zTFPnFCobhftzw8wl4Lw2aq/Rvir5pxfZV5fEazmeCJ2g==",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 20.19.0"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://paulmillr.com/funding/"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@nodelib/fs.scandir": {
|
"node_modules/@nodelib/fs.scandir": {
|
||||||
"version": "2.1.5",
|
"version": "2.1.5",
|
||||||
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
"typescript": "^5.3.0"
|
"typescript": "^5.3.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@noble/ciphers": "^2.0.1",
|
||||||
"dotenv": "^17.2.3",
|
"dotenv": "^17.2.3",
|
||||||
"node-fetch": "^3.3.2"
|
"node-fetch": "^3.3.2"
|
||||||
},
|
},
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import https from 'https';
|
import https from 'https';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
import { createDecipheriv } from 'crypto';
|
const { chacha20poly1305 } = require('@noble/ciphers/chacha.js');
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
@ -540,15 +540,12 @@ export class SecureVaultClient {
|
|||||||
// Ne pas mettre à jour la clé immédiatement, attendre un déchiffrement réussi
|
// Ne pas mettre à jour la clé immédiatement, attendre un déchiffrement réussi
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Convertir la clé base64 en Buffer
|
// Convertir la clé base64 en Uint8Array
|
||||||
const key = Buffer.from(keyToUse, 'base64');
|
const key = Buffer.from(keyToUse, 'base64');
|
||||||
|
|
||||||
// Déchiffrement ChaCha20-Poly1305
|
// Déchiffrement ChaCha20-Poly1305 avec @noble/ciphers
|
||||||
const decipher = createDecipheriv('chacha20-poly1305', key, nonce);
|
const cipher = chacha20poly1305(key, nonce);
|
||||||
|
const decrypted = cipher.decrypt(ciphertext);
|
||||||
// Déchiffrer le contenu
|
|
||||||
let decrypted = decipher.update(ciphertext);
|
|
||||||
decrypted = Buffer.concat([decrypted, decipher.final()]);
|
|
||||||
|
|
||||||
// Déchiffrement réussi, mettre à jour la clé pour la prochaine requête
|
// Déchiffrement réussi, mettre à jour la clé pour la prochaine requête
|
||||||
if (nextKey) {
|
if (nextKey) {
|
||||||
@ -556,7 +553,7 @@ export class SecureVaultClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Retourner le contenu déchiffré
|
// Retourner le contenu déchiffré
|
||||||
return decrypted.toString('utf-8');
|
return Buffer.from(decrypted).toString('utf-8');
|
||||||
|
|
||||||
} catch (decryptError) {
|
} catch (decryptError) {
|
||||||
// Si le déchiffrement échoue, essayer avec la prochaine clé si elle est différente
|
// Si le déchiffrement échoue, essayer avec la prochaine clé si elle est différente
|
||||||
@ -564,15 +561,14 @@ export class SecureVaultClient {
|
|||||||
console.log(`🔄 Tentative de déchiffrement avec la prochaine clé...`);
|
console.log(`🔄 Tentative de déchiffrement avec la prochaine clé...`);
|
||||||
try {
|
try {
|
||||||
const nextKeyBuffer = Buffer.from(nextKey, 'base64');
|
const nextKeyBuffer = Buffer.from(nextKey, 'base64');
|
||||||
const decipherNext = createDecipheriv('chacha20-poly1305', nextKeyBuffer, nonce);
|
const cipherNext = chacha20poly1305(nextKeyBuffer, nonce);
|
||||||
let decryptedNext = decipherNext.update(ciphertext);
|
const decryptedNext = cipherNext.decrypt(ciphertext);
|
||||||
decryptedNext = Buffer.concat([decryptedNext, decipherNext.final()]);
|
|
||||||
|
|
||||||
console.log(`✅ Déchiffrement réussi avec la prochaine clé !`);
|
console.log(`✅ Déchiffrement réussi avec la prochaine clé !`);
|
||||||
// Déchiffrement réussi avec la prochaine clé, mettre à jour
|
// Déchiffrement réussi avec la prochaine clé, mettre à jour
|
||||||
this.updateNextKey(nextKey);
|
this.updateNextKey(nextKey);
|
||||||
|
|
||||||
return decryptedNext.toString('utf-8');
|
return Buffer.from(decryptedNext).toString('utf-8');
|
||||||
} catch (nextDecryptError) {
|
} catch (nextDecryptError) {
|
||||||
console.warn(`⚠️ Déchiffrement avec la prochaine clé échoué: ${nextDecryptError instanceof Error ? nextDecryptError.message : 'Erreur inconnue'}`);
|
console.warn(`⚠️ Déchiffrement avec la prochaine clé échoué: ${nextDecryptError instanceof Error ? nextDecryptError.message : 'Erreur inconnue'}`);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user