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:
4NK Dev 2025-09-30 13:46:02 +00:00
parent 82981febd7
commit f14057a623
5 changed files with 30 additions and 20 deletions

View File

@ -22,12 +22,12 @@ async function debugTest() {
// 2. Test direct de getRoutes()
console.log('\n🛣 Test direct de getRoutes()...');
const routes = await client.getRoutes();
console.log(`\n📋 Résultats:`);
console.log(` Total des routes: ${routes.total_routes}`);
console.log(` Utilisateur: ${routes.user_id}`);
console.log(` Timestamp: ${routes.timestamp}`);
console.log('\n📝 Routes disponibles:');
routes.routes.forEach((route, index) => {
console.log(` ${index + 1}. ${route.method} ${route.path}`);

View File

@ -9,6 +9,7 @@
"version": "1.0.0",
"license": "MIT",
"dependencies": {
"@noble/ciphers": "^2.0.1",
"dotenv": "^17.2.3",
"node-fetch": "^3.3.2"
},
@ -1153,6 +1154,18 @@
"@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": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",

View File

@ -43,6 +43,7 @@
"typescript": "^5.3.0"
},
"dependencies": {
"@noble/ciphers": "^2.0.1",
"dotenv": "^17.2.3",
"node-fetch": "^3.3.2"
},

View File

@ -1,7 +1,7 @@
import fetch from 'node-fetch';
import https from 'https';
import dotenv from 'dotenv';
import { createDecipheriv } from 'crypto';
const { chacha20poly1305 } = require('@noble/ciphers/chacha.js');
import fs from 'fs';
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
try {
// Convertir la clé base64 en Buffer
// Convertir la clé base64 en Uint8Array
const key = Buffer.from(keyToUse, 'base64');
// Déchiffrement ChaCha20-Poly1305
const decipher = createDecipheriv('chacha20-poly1305', key, nonce);
// Déchiffrer le contenu
let decrypted = decipher.update(ciphertext);
decrypted = Buffer.concat([decrypted, decipher.final()]);
// Déchiffrement ChaCha20-Poly1305 avec @noble/ciphers
const cipher = chacha20poly1305(key, nonce);
const decrypted = cipher.decrypt(ciphertext);
// Déchiffrement réussi, mettre à jour la clé pour la prochaine requête
if (nextKey) {
@ -556,7 +553,7 @@ export class SecureVaultClient {
}
// Retourner le contenu déchiffré
return decrypted.toString('utf-8');
return Buffer.from(decrypted).toString('utf-8');
} catch (decryptError) {
// 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é...`);
try {
const nextKeyBuffer = Buffer.from(nextKey, 'base64');
const decipherNext = createDecipheriv('chacha20-poly1305', nextKeyBuffer, nonce);
let decryptedNext = decipherNext.update(ciphertext);
decryptedNext = Buffer.concat([decryptedNext, decipherNext.final()]);
const cipherNext = chacha20poly1305(nextKeyBuffer, nonce);
const decryptedNext = cipherNext.decrypt(ciphertext);
console.log(`✅ Déchiffrement réussi avec la prochaine clé !`);
// Déchiffrement réussi avec la prochaine clé, mettre à jour
this.updateNextKey(nextKey);
return decryptedNext.toString('utf-8');
return Buffer.from(decryptedNext).toString('utf-8');
} catch (nextDecryptError) {
console.warn(`⚠️ Déchiffrement avec la prochaine clé échoué: ${nextDecryptError instanceof Error ? nextDecryptError.message : 'Erreur inconnue'}`);
}

View File

@ -29,13 +29,13 @@ async function testRoutes() {
// 3. Test de la nouvelle méthode getRoutes()
console.log('\n🛣 Récupération des routes disponibles...');
const routes = await client.getRoutes();
console.log(`\n📋 Résultats:`);
console.log(` Total des routes: ${routes.total_routes}`);
console.log(` Utilisateur: ${routes.user_id}`);
console.log(` Timestamp: ${routes.timestamp}`);
console.log(` Type d'authentification: ${routes.authentication.type}`);
console.log('\n📝 Routes disponibles:');
routes.routes.forEach((route, index) => {
console.log(`\n ${index + 1}. ${route.method} ${route.path}`);
@ -43,14 +43,14 @@ async function testRoutes() {
console.log(` Authentification: ${route.authentication}`);
console.log(` Headers requis: ${route.headers_required.join(', ')}`);
console.log(` Type de réponse: ${route.response_type}`);
if (route.parameters) {
console.log(` Paramètres:`);
Object.entries(route.parameters).forEach(([key, value]) => {
console.log(` - ${key}: ${value}`);
});
}
if (route.examples && route.examples.length > 0) {
console.log(` Exemples:`);
route.examples.forEach(example => {