crypto-inventory 0.3.0: glob imports resolved, libcrux and spqr, libsignal KEM key pairs; control-plane: a key agreement or client-side TLS called by the application itself is not routed to the TLS gateway (planner 35/35, B1 negative control 4/4)

This commit is contained in:
Aere Network committed 2026-10-18 05:59:35 +03:00
1 parent f2f6217b4c
commit f971fa9e28
11 files changed
+161 -30

No files matched your search

+67 -20
View File
@@ -60,6 +60,11 @@ const CRATE = {
pqcrypto_hqc: { ofera: 'HQC', grupuri: ['HQC'] },
pqcrypto_classicmceliece: { ofera: 'Classic McEliece (NIST round 4, not standardized)', grupuri: ['UNKNOWN'] },
oqs: { ofera: 'liboqs: post-quantum KEMs and signatures', grupuri: ['MLKEM', 'MLDSA', 'FALCON', 'PREPQ', 'HQC', 'UNKNOWN'] },
libcrux_ml_kem: { ofera: 'ML-KEM (libcrux, formally verified; used under libsignal)', grupuri: ['MLKEM'] },
libcrux_ml_dsa: { ofera: 'ML-DSA (libcrux)', grupuri: ['MLDSA'] },
libcrux_sha3: { ofera: 'SHA3 and SHAKE (libcrux)', grupuri: ['HASH'] },
libcrux_kem: { ofera: 'KEMs (libcrux: ML-KEM, X25519, hybrids)', grupuri: ['MLKEM', 'XDH', 'HYBRID-KEX'] },
spqr: { ofera: "Signal's post-quantum ratchet (SPQR, ML-KEM based)", grupuri: ['MLKEM'] },
libsignal_protocol: { ofera: 'Signal sessions: Curve25519 identity and prekeys, Kyber prekeys (PQXDH), Double Ratchet', grupuri: ['XDH', 'PREPQ', 'MLKEM', 'LIB-MULTI'] },
ring: { ofera: 'ring: AES-GCM, ChaCha20-Poly1305, SHA-2, HMAC, HKDF, PBKDF2, Ed25519, ECDSA P-256/P-384, RSA, X25519, ECDH', grupuri: ['HASH', 'MAC', 'KDF', 'CIPHER', 'EDDSA', 'ECDSA', 'RSA', 'XDH', 'ECDH'] },
openssl: { ofera: 'OpenSSL bindings', grupuri: ['HASH', 'CIPHER', 'RSA', 'EC', 'ECDSA', 'EDDSA', 'XDH', 'TLS'] },
@@ -90,6 +95,7 @@ for (const [crate, tipuri] of Object.entries({
x25519_dalek: ['StaticSecret', 'EphemeralSecret', 'ReusableSecret'],
curve25519_dalek: ['RistrettoPoint', 'EdwardsPoint', 'MontgomeryPoint'],
ml_kem: ['MlKem512', 'MlKem768', 'MlKem1024'], ml_dsa: ['MlDsa44', 'MlDsa65', 'MlDsa87'],
libcrux_ml_kem: ['MlKem512KeyPair', 'MlKem768KeyPair', 'MlKem1024KeyPair', 'MlKem512PublicKey', 'MlKem768PublicKey', 'MlKem1024PublicKey', 'MlKem512PrivateKey', 'MlKem768PrivateKey', 'MlKem1024PrivateKey', 'MlKem512Ciphertext', 'MlKem768Ciphertext', 'MlKem1024Ciphertext'],
libsignal_protocol: ['PreKeyBundle', 'IdentityKeyPair', 'SignalProtocolAddress', 'KyberPreKeyRecord'],
arti_client: ['TorClient'],
})) for (const t of tipuri) UNIC[t] = crate;
@@ -184,36 +190,46 @@ export function detecteazaRust(ctx) {
ctx.adauga(pos, api, fel, curat, { bucata });
};
// o cale scrisa in cod (prefixul `a::b::`) sau un nume de tip -> calea completa prin `use`
const rezolvaCale = (prefix, tip) => {
// o cale scrisa in cod (prefixul `a::b::`) sau un nume de tip -> caile posibile, in ordine: prin `use`, prin numele unic al
// tipului, apoi prin fiecare crate adus cu `use crate::*` (un import glob nu spune ce nume aduce; se incearca si se accepta
// primul care are un inteles acolo). Un prefix din propriul crate (crate::, self::, super::) nu se incearca nicaieri.
const caiPentru = (seg) => {
const r = [];
if (CRATE[seg[0]]) r.push(seg);
for (const g of globuri) if (CRATE[g]) r.push([g, ...seg]);
return r;
};
const candidati = (prefix, tip) => {
const seg = prefix ? prefix.split('::').filter(Boolean) : [];
if (seg.length) {
if (RADACINI_PROPRII.has(seg[0])) return null;
if (RADACINI_PROPRII.has(seg[0])) return [];
const u = locale.get(seg[0]);
const cale = u ? [...u.cale, ...seg.slice(1)] : seg;
return CRATE[cale[0]] ? { crate: cale[0], cale: [...cale, tip] } : null;
if (u) return CRATE[u.crate] ? [{ crate: u.crate, cale: [...u.cale, ...seg.slice(1), tip] }] : [];
return caiPentru(seg).map((c) => ({ crate: c[0], cale: [...c, tip] }));
}
const u = locale.get(tip);
if (u) return CRATE[u.crate] ? { crate: u.crate, cale: u.cale } : null;
if (UNIC[tip]) return { crate: UNIC[tip], cale: [UNIC[tip], tip] };
return null;
if (u) return CRATE[u.crate] ? [{ crate: u.crate, cale: u.cale }] : [];
if (UNIC[tip]) return [{ crate: UNIC[tip], cale: [UNIC[tip], tip] }];
return [...globuri].filter((g) => CRATE[g]).map((g) => ({ crate: g, cale: [g, tip] }));
};
const rezolvaCale = (prefix, tip) => candidati(prefix, tip)[0] || null;
// 1. apelurile statice Tip::metoda, cu sau fara turbofish (Hmac::<Sha256>::new_from_slice)
const RE_STATIC = /(?<![\w:])((?:[A-Za-z_]\w*::)*)([A-Z]\w*)\s*(?:::\s*<([^;{}()=]*?)>)?\s*::\s*([a-z_]\w*)\b/g;
for (const m of ctx.potriviri(RE_STATIC)) {
const [intreg, prefix, tip, generic, metoda] = m;
const r = rezolvaCale(prefix, tip);
const cand = candidati(prefix, tip);
let r = null; let activ = null;
for (const c of cand) { const a = activStatic(c, metoda, generic, ctx, m); if (a) { r = c; activ = a; break; } }
if (!r) {
if (!prefix && /^(SigningKey|VerifyingKey|KeyPair|Keypair|SecretKey|PublicKey|Signature)$/.test(tip) && CTOR.test(metoda) && !locale.has(tip) && !proprii.has(tip)) {
if (!cand.length && !prefix && /^(SigningKey|VerifyingKey|KeyPair|Keypair|SecretKey|PublicKey|Signature)$/.test(tip) && CTOR.test(metoda) && !locale.has(tip) && !proprii.has(tip)) {
// nume ambiguu, fara `use` care sa spuna crate-ul: nu se ghiceste
const tipuriLocale = new RegExp(`\\b(struct|enum|type|trait)\\s+${tip}\\b`).test(ctx.code);
if (!tipuriLocale) ctx.adauga(m.index, `${tip}::${metoda}`, 'call', { grup: 'UNKNOWN', nume: `${tip} (crate not resolved)`, motiv: `${tip}::${metoda} with no \`use\` in this file naming its crate: it may be Ed25519 (ed25519-dalek), ML-DSA (ml-dsa), SLH-DSA (slh-dsa), ECDSA (p256, k256) or RSA (rsa).` }, { bucata: intreg });
}
continue;
}
const activ = activStatic(r, metoda, generic, ctx, m);
if (activ) adauga(r.crate, m.index, `${prefix}${tip}::${metoda}`, 'call', activ, intreg + (activ.bucataExtra || ''));
adauga(r.crate, m.index, `${prefix}${tip}::${metoda}`, 'call', activ, intreg + (activ.bucataExtra || ''));
}
// 2. aliasuri de tip cu parametru generic: type HmacSha256 = Hmac<Sha256>; type Kdf = Hkdf<Sha512>;
@@ -230,11 +246,13 @@ export function detecteazaRust(ctx) {
// rustls::crypto::ring::default_provider(), libsignal_protocol::process_prekey_bundle(...)
for (const m of ctx.potriviri(/(?<![\w:.])((?:[a-z_]\w*::)+)([a-z_]\w*)\s*(?:::\s*<([^;{}()=]*?)>)?\s*\(/g)) {
const seg = m[1].split('::').filter(Boolean);
if (RADACINI_PROPRII.has(seg[0])) continue;
const u = locale.get(seg[0]);
const cale = u ? [...u.cale, ...seg.slice(1), m[2]] : [...seg, m[2]];
if (RADACINI_PROPRII.has(cale[0]) || !CRATE[cale[0]]) continue;
const activ = activFunctie(cale, m[3], ctx, m);
if (activ) adauga(cale[0], m.index, cale.join('::'), 'call', activ, m[0].trim() + (activ.bucataExtra || ''));
const cai = u ? (CRATE[u.crate] ? [[...u.cale, ...seg.slice(1), m[2]]] : []) : caiPentru(seg).map((c) => [...c, m[2]]);
for (const cale of cai) {
const activ = activFunctie(cale, m[3], ctx, m);
if (activ) { adauga(cale[0], m.index, cale.join('::'), 'call', activ, m[0].trim() + (activ.bucataExtra || '')); break; }
}
}
// functii importate direct: use pbkdf2::pbkdf2_hmac; use blake3::hash; use libsignal_protocol::process_prekey_bundle;
for (const [local, u] of locale) {
@@ -251,10 +269,11 @@ export function detecteazaRust(ctx) {
const seg = m[1].split('::').filter(Boolean);
if (RADACINI_PROPRII.has(seg[0])) continue;
const u = locale.get(seg[0]);
const cale = u ? [...u.cale, ...seg.slice(1)] : seg;
if (!CRATE[cale[0]]) continue;
const activ = activConstanta(cale, m[2], ctx, m);
if (activ) adauga(cale[0], m.index, `${cale.join('::')}::${m[2]}`, activ.fel || 'config', activ, m[0]);
const cai = u ? (CRATE[u.crate] ? [[...u.cale, ...seg.slice(1)]] : []) : caiPentru(seg);
for (const cale of cai) {
const activ = activConstanta(cale, m[2], ctx, m);
if (activ) { adauga(cale[0], m.index, `${cale.join('::')}::${m[2]}`, activ.fel || 'config', activ, m[0]); break; }
}
}
// variante importate direct (use jsonwebtoken::Algorithm; Algorithm::RS256) si tipuri parametru PQ scrise singure
for (const m of ctx.potriviri(/(?<![\w:])([A-Z]\w*)::([A-Z][A-Za-z0-9_]*)\b(?!\s*::|\s*\()/g)) {
@@ -440,6 +459,12 @@ function activStatic(r, metoda, generic, ctx, m) {
}
case 'libsignal_protocol':
if (tip === 'PreKeyBundle' && metoda === 'new') return { grup: 'LIB-MULTI', nume: 'libsignal session setup (X3DH/PQXDH)', motiv: 'libsignal prekey bundle: Curve25519 identity and signed prekey; a Kyber prekey in the bundle makes the session PQXDH (hybrid). Which prekeys the bundle carries is decided at run time.' };
if (cale.includes('kem') && /^(KeyPair|PublicKey|SecretKey)$/.test(tip)) {
// perechea KEM a lui libsignal (prekey-ul PQXDH): tipul ei e argumentul KeyType; cand e pe acelasi rand, constanta poarta
// constatarea (pasul 4); cand nu e, nu se ghiceste intre Kyber si ML-KEM
if (/KeyType\s*::\s*\w+/.test(ctx.code.slice(m.index, m.index + 200))) return null;
return { grup: 'UNKNOWN', nume: 'libsignal KEM key pair', motiv: 'libsignal kem::KeyPair: the key type (Kyber-1024 or ML-KEM) is the KeyType argument, not visible on this line.' };
}
if (/^(IdentityKeyPair|KeyPair|PrivateKey)$/.test(tip) && /^(generate|new|from_private_key_bytes|deserialize)$/.test(metoda)) return { grup: 'XDH', nume: 'X25519', functii: ['keygen'], nota: 'libsignal identity and prekey keys are Curve25519 (signatures over them are XEdDSA).' };
if (tip === 'KyberPreKeyRecord' || tip === 'KeyType') return null;
return null;
@@ -477,6 +502,14 @@ function activStatic(r, metoda, generic, ctx, m) {
case 'arti_client':
if (tip === 'TorClient') return { grup: 'UNKNOWN', nume: 'Tor client (arti)', motiv: 'Tor circuit and channel cryptography is negotiated with the relays by the Tor protocol version in use, not visible in this file.' };
return null;
case 'libcrux_ml_kem': {
const k = /MlKem(512|768|1024)/.exec(tip) || /mlkem(512|768|1024)/.exec(cale.join('::'));
return k ? { grup: 'MLKEM', param: k[1], functii: fn(/generate/.test(metoda) ? 'keygen' : /encaps/.test(metoda) ? 'encapsulate' : /decaps/.test(metoda) ? 'decapsulate' : 'other') } : null;
}
case 'libcrux_ml_dsa': {
const k = /MLDSA(44|65|87)|ml_dsa_(44|65|87)/.exec(tip + ' ' + cale.join('::'));
return k ? { grup: 'MLDSA', param: k[1] || k[2], functii: fn(rol) } : null;
}
case 'jsonwebtoken':
return null; // variantele Algorithm (pasul 4)
default:
@@ -505,6 +538,20 @@ function activFunctie(cale, generic, ctx, m) {
if (fnume === 'default_provider' && modul === 'ring') return { grup: 'XDH', nume: 'X25519', functii: ['keygen'], nota: 'rustls with the ring provider: ring implements no ML-KEM, so the key-exchange groups are X25519, P-256 and P-384 only (no X25519MLKEM768).' };
if (fnume === 'default_provider' && modul === 'aws_lc_rs') return { grup: 'UNKNOWN', nume: 'rustls aws-lc-rs provider', motiv: 'rustls with the aws-lc-rs provider: X25519MLKEM768 is offered by default from rustls 0.23.22 (and only with the prefer-post-quantum feature before 0.23.22); the rustls version is in Cargo.lock, not here.' };
return null;
case 'libcrux_ml_kem': {
const k = /^mlkem(512|768|1024)$/.exec(modul || '');
if (!k || !/^(generate_key_pair|encapsulate|decapsulate|validate_public_key|validate_private_key)$/.test(fnume)) return null;
return { grup: 'MLKEM', param: k[1], functii: [/generate/.test(fnume) ? 'keygen' : /encaps/.test(fnume) ? 'encapsulate' : /decaps/.test(fnume) ? 'decapsulate' : 'other'] };
}
case 'libcrux_ml_dsa': {
const k = /^ml_dsa_(44|65|87)$/.exec(modul || '');
if (!k || !/^(generate_key_pair|sign|verify|sign_pre_hashed_shake128|verify_pre_hashed_shake128)$/.test(fnume)) return null;
return { grup: 'MLDSA', param: k[1], functii: [/generate/.test(fnume) ? 'keygen' : /^sign/.test(fnume) ? 'sign' : 'verify'] };
}
case 'libcrux_sha3': {
const k = /^(sha224|sha256|sha384|sha512|shake128|shake256)$/.exec(fnume);
return k ? { grup: 'HASH', hash: k[1].startsWith('shake') ? k[1].toUpperCase() : 'SHA3-' + k[1].slice(3), functii: ['digest'] } : null;
}
case 'libsignal_protocol':
if (fnume === 'process_prekey_bundle') return { grup: 'LIB-MULTI', nume: 'libsignal session setup (X3DH/PQXDH)', motiv: 'libsignal session setup from a prekey bundle: Curve25519 identity and signed prekey; a Kyber prekey in the bundle makes the session PQXDH (hybrid). Which prekeys the bundle carries is decided at run time.' };
return null;