crypto-inventory 0.3.0 and the control-plane planner after the second run on a tree that is not ours (libsignal): BoringSSL, Noise hfs, libcrux Kyber, the libsignal Java/Node API; self-signed trust anchors are blocked, test code is LOW with its own scope
This commit is contained in:
1 parent
42b049ef04
commit
e453c0c42d
35 files changed
+675
-51
No files matched your search
@@ -19,11 +19,11 @@ An API name that appears only inside a comment or inside a string literal is not
|
||||
|
||||
| Language | What is recognized |
|
||||
|---|---|
|
||||
| JavaScript / TypeScript | `node:crypto` (`createHash`, `createHmac`, `createCipheriv`, `createSign`/`createVerify`, `generateKeyPair(Sync)` for `rsa`, `rsa-pss`, `dsa`, `ec`, `ed25519`, `x25519`, `dh`, `ml-dsa-*`, `ml-kem-*`, `slh-dsa-*`, `createECDH`, `getDiffieHellman`, `publicEncrypt`, `pbkdf2`, `hkdf`, `crypto.sign`/`verify`, `createPrivateKey`/`createPublicKey`, `X509Certificate`); WebCrypto `subtle` (RSA-OAEP, RSASSA-PKCS1-v1_5, RSA-PSS, ECDSA, ECDH, Ed25519, X25519, AES-GCM/CBC/CTR/KW, HMAC, HKDF, PBKDF2, `digest`); TLS options `minVersion`, `maxVersion`, `secureProtocol`, `ecdhCurve`; libraries from imports: `ethers`, `web3`, `viem` (secp256k1 ECDSA), `secp256k1`, `elliptic`, `node-forge`, `jsonwebtoken`/`jose` (JWS algorithms), `@noble/curves`, `@noble/post-quantum`, `@noble/hashes`, `crypto-js`, `tweetnacl`/libsodium, `node-rsa`, bcrypt/argon2 |
|
||||
| JavaScript / TypeScript | `node:crypto` (`createHash`, `createHmac`, `createCipheriv`, `createSign`/`createVerify`, `generateKeyPair(Sync)` for `rsa`, `rsa-pss`, `dsa`, `ec`, `ed25519`, `x25519`, `dh`, `ml-dsa-*`, `ml-kem-*`, `slh-dsa-*`, `createECDH`, `getDiffieHellman`, `publicEncrypt`, `pbkdf2`, `hkdf`, `crypto.sign`/`verify`, `createPrivateKey`/`createPublicKey`, `X509Certificate`); WebCrypto `subtle` (RSA-OAEP, RSASSA-PKCS1-v1_5, RSA-PSS, ECDSA, ECDH, Ed25519, X25519, AES-GCM/CBC/CTR/KW, HMAC, HKDF, PBKDF2, `digest`); TLS options `minVersion`, `maxVersion`, `secureProtocol`, `ecdhCurve`; libraries from imports: `ethers`, `web3`, `viem` (secp256k1 ECDSA), `secp256k1`, `elliptic`, `node-forge`, `jsonwebtoken`/`jose` (JWS algorithms), `@noble/curves`, `@noble/post-quantum`, `@noble/hashes`, `crypto-js`, `tweetnacl`/libsodium, `node-rsa`, bcrypt/argon2, `@signalapp/libsignal-client` (`PrivateKey.generate`, `IdentityKeyPair.generate`, `KEMKeyPair.generate`, `hkdf`, `Aes256GcmSiv.new`, `PreKeyBundle.new` / `processPreKeyBundle`, anchored on the package import) |
|
||||
| Python | `cryptography.hazmat` (`rsa`, `ec`, `dsa`, `dh`, `ed25519`, `x25519`, `padding`, `hashes`, `algorithms`/`modes`, AEAD classes); PyCryptodome (`Crypto`/`Cryptodome`: `RSA`, `DSA`, `ECC`, ciphers and modes, `PKCS1_OAEP`, `pss`, `DSS`, hash `.new`); `hashlib` (including `hashlib.new` and `pbkdf2_hmac`); `hmac` with `digestmod`; `ecdsa`; PyJWT / python-jose algorithms; `oqs` (liboqs-python); `ssl` protocol constants and `TLSVersion` |
|
||||
| Java | `KeyPairGenerator`, `Signature`, `Cipher`, `KeyAgreement`, `MessageDigest`, `Mac`, `KeyGenerator`, `KeyFactory`, `SecretKeyFactory`, `KEM`, `SSLContext` `getInstance("...")`; `ECGenParameterSpec`, `NamedParameterSpec`; `setEnabledProtocols`; JSSE system properties (`jdk.tls.namedGroups`, protocol lists); Bouncy Castle imports and post-quantum parameter sets (`org.bouncycastle.pqc`, `MLKEMParameters`, `MLDSAParameters`, `SLHDSAParameters`, `FalconParameters`, ...) |
|
||||
| Java | `KeyPairGenerator`, `Signature`, `Cipher`, `KeyAgreement`, `MessageDigest`, `Mac`, `KeyGenerator`, `KeyFactory`, `SecretKeyFactory`, `KEM`, `SSLContext` `getInstance("...")`; `ECGenParameterSpec`, `NamedParameterSpec`; `setEnabledProtocols`; JSSE system properties (`jdk.tls.namedGroups`, protocol lists); Bouncy Castle imports and post-quantum parameter sets (`org.bouncycastle.pqc`, `MLKEMParameters`, `MLDSAParameters`, `SLHDSAParameters`, `FalconParameters`, ...); the libsignal Java/Android API (`org.signal.libsignal`, anchored on its import or package: `ECKeyPair.generate`, `IdentityKeyPair.generate`, `KEMKeyPair.generate(KEMKeyType.KYBER_1024)`, `HKDF.deriveSecrets`, `new Aes256GcmSiv` / `Aes256GcmEncryption` / `Aes256Ctr32`, `new PreKeyBundle`) |
|
||||
| Go | imports of `crypto/rsa`, `crypto/ecdsa`, `crypto/elliptic`, `crypto/ecdh`, `crypto/ed25519`, `crypto/md5`, `crypto/sha1`, `crypto/des`, `crypto/rc4`, `crypto/mlkem`, `crypto/tls`, `golang.org/x/crypto/...`, go-ethereum `crypto`, CIRCL ML-KEM/ML-DSA; calls with parameters (`rsa.GenerateKey` size, `ecdsa.GenerateKey` curve, `hmac.New` hash, `mlkem.GenerateKey768`); `tls.Config` `MinVersion`, `MaxVersion`, `CurvePreferences` (including `tls.X25519MLKEM768`) |
|
||||
| Rust | `use`/`extern crate` resolution of names to crates; static calls `Type::method` (`Sha256::new`, `SigningKey::generate`, `Aes256Gcm::new_from_slice`, `RsaPrivateKey::new(rng, 2048)`, `MlDsa65::key_gen`, `MlKem768::generate`); generic parameters (`Hmac::<Sha256>`, `Hkdf::<Sha512>`, `type HmacSha256 = Hmac<Sha256>`, `SigningKey::<Sha2_128s>`); path functions (`blake3::hash`, `pbkdf2::pbkdf2_hmac::<Sha256>`, `pqcrypto_kyber::kyber1024::keypair`, `rustls::crypto::ring::default_provider`); `ring` constants (`aead::AES_256_GCM`, `signature::ED25519`, `agreement::X25519`); `jsonwebtoken::Algorithm::*`, `oqs::Algorithm::*`, libsignal `kem::KeyType::Kyber1024`; RustCrypto modes (`ecb::Encryptor<Aes128>`, `cbc::Decryptor<Aes256>`); `snow` Noise patterns (`Noise_XX_25519_ChaChaPoly_SHA256`); `openssl` (`MessageDigest::*`, `Cipher::*`, `Rsa::generate`, `EcKey::generate` + `Nid`, `PKey::generate_ed25519`, `set_min_proto_version`); `secp256k1` `.sign_ecdsa`/`.sign_schnorr`; libcrux (`libcrux_ml_kem::mlkem1024::generate_key_pair`, `libcrux_ml_dsa::ml_dsa_65::sign`); a name brought in by a glob import (`use libsignal_protocol::*`) is resolved by trying the glob-imported crates in order |
|
||||
| Rust | `use`/`extern crate` resolution of names to crates; static calls `Type::method` (`Sha256::new`, `SigningKey::generate`, `Aes256Gcm::new_from_slice`, `RsaPrivateKey::new(rng, 2048)`, `MlDsa65::key_gen`, `MlKem768::generate`); generic parameters (`Hmac::<Sha256>`, `Hkdf::<Sha512>`, `type HmacSha256 = Hmac<Sha256>`, `SigningKey::<Sha2_128s>`); path functions (`blake3::hash`, `pbkdf2::pbkdf2_hmac::<Sha256>`, `pqcrypto_kyber::kyber1024::keypair`, `rustls::crypto::ring::default_provider`); `ring` constants (`aead::AES_256_GCM`, `signature::ED25519`, `agreement::X25519`); `jsonwebtoken::Algorithm::*`, `oqs::Algorithm::*`, libsignal `kem::KeyType::Kyber1024`; RustCrypto modes (`ecb::Encryptor<Aes128>`, `cbc::Decryptor<Aes256>`); `snow` Noise patterns (`Noise_XX_25519_ChaChaPoly_SHA256`); `openssl` and the BoringSSL bindings `boring` / `boring-signal` with the same API (`MessageDigest::*`, `Cipher::*`, `Rsa::generate`, `EcKey::generate` + `Nid`, `PKey::generate_ed25519`, `SslConnector::builder`, `set_min_proto_version`); `secp256k1` `.sign_ecdsa`/`.sign_schnorr`; libcrux (`libcrux_ml_kem::mlkem1024::generate_key_pair`, the pre-standard `kyber768` / `kyber1024` modules, `libcrux_ml_dsa::ml_dsa_65::sign`); `x25519_dalek::x25519(...)`; `HmacReset`; a mode type brought in by name (`use cbc::Decryptor; Decryptor::<Aes256>::new`); the hybrid Noise pattern `Noise_NKhfs_25519+Kyber1024_...` as one hybrid key exchange; a name brought in by a glob import (`use libsignal_protocol::*`) is resolved by trying the glob-imported crates in order |
|
||||
| Any text file | complete PEM blocks: certificates (parsed for subject, validity and key algorithm), public keys, private keys |
|
||||
| Manifests | `package.json`, `requirements*.txt`, `pyproject.toml`, `pom.xml`, `build.gradle(.kts)`, `go.mod`, `Cargo.toml`: cryptographic libraries that are declared |
|
||||
|
||||
@@ -194,14 +194,22 @@ console.log(renderSummary(result));
|
||||
## Tests
|
||||
|
||||
```
|
||||
node test/proba.mjs # 37 probes: fixtures per language with the exact expected findings
|
||||
node test/control-negativ.mjs # breaks the scanner in a copy, one rule at a time (18 mutations), and
|
||||
node test/proba.mjs # 52 probes: fixtures per language with the exact expected findings
|
||||
node test/control-negativ.mjs # breaks the scanner in a copy, one rule at a time (25 mutations), and
|
||||
# requires the matching probe to fail while the rest of the suite still runs
|
||||
node test/proba-timp.mjs # 8 hostile inputs, each at two sizes: the cost must grow linearly
|
||||
node test/control-negativ-timp.mjs # puts each quadratic form back and requires the cost probe to turn red
|
||||
node test/echivalenta-0.1.0.mjs # same findings as 0.1.0 (needs the git history; skipped without it)
|
||||
node test/echivalenta-0.1.0.mjs # same findings as 0.1.0 (needs the git history; skipped without it); detectors
|
||||
# added after 0.1.0 (Rust, the libsignal Java/Node API) are counted apart, and
|
||||
# a finding that 0.1.0 had and the current version lacks is always a difference
|
||||
```
|
||||
|
||||
Measured on 2026-10-18 on the libsignal tree (1,788 files; 596 Rust, 343 Java, 173 TypeScript, 210 Swift, 111 Kotlin): before the
|
||||
additions of that day the inventory returned 450 findings, all in Rust and Python, and zero for Java and TypeScript, because
|
||||
libsignal does not call JCA or `node:crypto` but its own API over the native bridge; Swift and Kotlin (20.5% of the source lines)
|
||||
are not analyzed at all. After: 759 findings (Java 262). The Node side of libsignal itself still returns zero, because its own
|
||||
tree imports by relative path, not by the package name the detector anchors on.
|
||||
|
||||
Fixtures mark each expected finding on its own line (`EXPECT: <name> | <class>`), and a probe fails on
|
||||
a missing finding, an extra finding, a wrong line or a wrong class. Negative fixtures cover comments,
|
||||
docstrings, strings that mention crypto APIs, a file without cryptography, algorithms from
|
||||
|
||||
@@ -289,7 +289,10 @@ export function evalueaza(a) {
|
||||
}
|
||||
if (g === 'HYBRID-KEX') {
|
||||
const pq = /1024/.test(a.nume) ? 5 : 3;
|
||||
return f({ nume: a.nume, primitiv: 'kem', ...rez({ c: CLS.S, motiv: `${a.nume}: hybrid key exchange (classical ECDH + ML-KEM); stays secure if either component holds. The NIST category given is that of the ML-KEM component.`, q: pq }) });
|
||||
const nota = a.nota ? ` ${a.nota}` : '';
|
||||
// 2026-10-18 (libsignal): un hibrid cu Kyber pre-standard (Noise hfs) ramane hibrid, dar poarta recomandarea de trecere la ML-KEM
|
||||
if (/kyber/i.test(a.nume)) return f({ nume: a.nume, primitiv: 'kem', ...rez({ c: CLS.S, motiv: `${a.nume}: hybrid key exchange (classical ECDH + Kyber, the pre-standard form of ML-KEM); stays secure if either component holds. The NIST category given is that of the Kyber component.${nota}`, rec: REC.PREPQ, q: pq }) });
|
||||
return f({ nume: a.nume, primitiv: 'kem', ...rez({ c: CLS.S, motiv: `${a.nume}: hybrid key exchange (classical ECDH + ML-KEM); stays secure if either component holds. The NIST category given is that of the ML-KEM component.${nota}`, q: pq }) });
|
||||
}
|
||||
if (g === 'TLS') return tls(a, f);
|
||||
if (g === 'JWT-HMAC') {
|
||||
|
||||
@@ -237,9 +237,44 @@ export function detecteazaJava(ctx) {
|
||||
const act = bcParam(m[1], m[2]);
|
||||
if (act) ctx.adauga(m.index, `${m[1]}Parameters.${m[2]}`, 'call', act, { bucata: m[0] });
|
||||
}
|
||||
detecteazaLibsignalJava(ctx);
|
||||
void curbaCanonica;
|
||||
}
|
||||
|
||||
// libsignal, API-ul Java/Android (org.signal.libsignal; 2026-10-18, dupa rularea pe arborele libsignal: 343 de fisiere Java si zero
|
||||
// constatari, fiindca biblioteca nu trece prin JCA, ci prin propriile clase peste puntea nativa). Ancora e importul sau pachetul
|
||||
// org.signal.libsignal, ca numele scurte (ECKeyPair, HKDF, Aes256GcmSiv) sa nu fie luate drept libsignal in alt cod.
|
||||
const LIBSIGNAL_NOTA_EC = 'libsignal Curve25519 key pair: used for Diffie-Hellman (X3DH/PQXDH, Double Ratchet) and for XEdDSA signatures over the same key.';
|
||||
const LIBSIGNAL_NOTA_KYBER = 'Signal PQXDH prekeys: CRYSTALS-Kyber (the pre-standard form of ML-KEM).';
|
||||
const LIBSIGNAL_BUNDLE = { 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.' };
|
||||
export function kemLibsignal(tip) {
|
||||
let k;
|
||||
if ((k = /^KYBER_?(768|1024)$/i.exec(tip || ''))) return { grup: 'PREPQ', nume: `Kyber-${k[1]}`, primitiv: 'kem', functii: ['keygen'], nota: LIBSIGNAL_NOTA_KYBER };
|
||||
if ((k = /^ML_?KEM_?(768|1024)$/i.exec(tip || ''))) return { grup: 'MLKEM', param: k[1], functii: ['keygen'] };
|
||||
return { grup: 'UNKNOWN', nume: 'libsignal KEM key pair', motiv: 'libsignal KEMKeyPair: the key type (Kyber-1024 or ML-KEM) is the KEMKeyType argument, not visible on this line.' };
|
||||
}
|
||||
function detecteazaLibsignalJava(ctx) {
|
||||
const ancore = ctx.potriviri(/(?<![\w.])(?:import\s+(?:static\s+)?org\.signal\.libsignal\.(?:protocol|crypto|metadata|zkgroup|svr|keytrans)\b|package\s+org\.signal\.libsignal\b)/g);
|
||||
if (!ancore.length) return;
|
||||
for (const m of ctx.potriviri(/(?<![\w.])(?:(ECKeyPair|IdentityKeyPair|ECPrivateKey)\s*\.\s*generate|(Curve)\s*\.\s*generateKeyPair)\s*\(/g)) {
|
||||
ctx.adauga(m.index, `${m[1] || m[2]}.${m[1] ? 'generate' : 'generateKeyPair'}`, 'call', { grup: 'XDH', nume: 'X25519', functii: ['keygen'], nota: LIBSIGNAL_NOTA_EC }, { bucata: m[0] });
|
||||
}
|
||||
for (const m of ctx.potriviri(/(?<![\w.])KEMKeyPair\s*\.\s*generate\s*\(\s*(?:KEMKeyType\s*\.\s*([A-Za-z_0-9]+))?/g)) {
|
||||
ctx.adauga(m.index, 'KEMKeyPair.generate', 'call', kemLibsignal(m[1]), { bucata: m[0].trim() });
|
||||
}
|
||||
for (const m of ctx.potriviri(/(?<![\w.])HKDF\s*\.\s*deriveSecrets\s*\(/g)) {
|
||||
ctx.adauga(m.index, 'HKDF.deriveSecrets', 'call', { grup: 'KDF', nume: 'HKDF', hash: 'SHA256', functii: ['keyderive'], nota: 'libsignal HKDF is HKDF-SHA-256.' }, { bucata: m[0] });
|
||||
}
|
||||
for (const m of ctx.potriviri(/(?<![\w.])new\s+(Aes256GcmSiv|Aes256GcmEncryption|Aes256GcmDecryption|Aes256Ctr32)\s*\(/g)) {
|
||||
const mod = m[1] === 'Aes256GcmSiv' ? 'gcm-siv' : m[1] === 'Aes256Ctr32' ? 'ctr' : 'gcm';
|
||||
ctx.adauga(m.index, `new ${m[1]}`, 'call', { grup: 'CIPHER', nume: 'AES', param: '256', mod, functii: [m[1] === 'Aes256GcmDecryption' ? 'decrypt' : 'encrypt'] }, { bucata: m[0] });
|
||||
}
|
||||
for (const m of ctx.potriviri(/(?<![\w.])new\s+PreKeyBundle\s*\(/g)) ctx.adauga(m.index, 'new PreKeyBundle', 'call', LIBSIGNAL_BUNDLE, { bucata: m[0] });
|
||||
// importul: dovada slaba, o singura data pe fisier, suprimata de orice apel recunoscut de mai sus
|
||||
const imp = ancore.find((a) => /^import/.test(a[0]));
|
||||
if (imp) ctx.adauga(imp.index, 'import org.signal.libsignal', 'import', { grup: 'LIB-MULTI', nume: 'libsignal (org.signal.libsignal)', motiv: 'Imports the Signal protocol library (Curve25519 identity and prekeys, Kyber prekeys (PQXDH), Double Ratchet, SPQR, sealed sender); no specific call recognized in this file.' }, { suprimaDe: ['XDH', 'PREPQ', 'MLKEM', 'KDF', 'CIPHER', 'LIB-MULTI'], bucata: imp[0].trim() });
|
||||
}
|
||||
|
||||
function bcParam(fam, p) {
|
||||
let m;
|
||||
if (fam === 'MLKEM' && (m = /(512|768|1024)/.exec(p))) return { grup: 'MLKEM', param: m[1] };
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Detectorul JavaScript / TypeScript: node:crypto, WebCrypto, optiuni TLS, biblioteci din importuri.
|
||||
import { argumente, imparteArgumente, valoareArgument, necunoscut, obiectulDin, cifruOpenssl, identificator, rezolva } from './context.mjs';
|
||||
import { argumente, imparteArgumente, valoareArgument, necunoscut, obiectulDin, cifruOpenssl, identificator, rezolva, escapeRe } from './context.mjs';
|
||||
import { hashCanonic, grupTls, jws, JWS_RE } from './catalog.mjs';
|
||||
|
||||
const MODP = { modp1: 768, modp2: 1024, modp5: 1536, modp14: 2048, modp15: 3072, modp16: 4096, modp17: 6144, modp18: 8192 };
|
||||
@@ -487,6 +487,38 @@ function detecteazaBiblioteci(ctx, imp, importa, jwtLib) {
|
||||
ctx.adauga(nacl[0].pos, `import ${nacl[0].spec}`, 'import', { grup: 'LIB-MULTI', nume: nacl[0].spec }, { suprimaDe: ['EDDSA', 'XDH', 'CIPHER'], bucata: `import ${nacl[0].spec}` });
|
||||
}
|
||||
|
||||
// @signalapp/libsignal-client (Node; 2026-10-18, dupa rularea pe arborele libsignal: 173 de fisiere TypeScript si zero constatari,
|
||||
// fiindca API-ul lui sta peste puntea nativa, nu peste node:crypto). Ancora e importul pachetului: numele scurte (PrivateKey, hkdf)
|
||||
// nu inseamna libsignal in alt cod. Arborele libsignal insusi importa prin cai relative, deci acolo ramane nevazut; aici se recunoaste
|
||||
// ce foloseste un CLIENT al bibliotecii.
|
||||
const lsc = importa(/^@signalapp\/libsignal-client(\/.*)?$/);
|
||||
if (lsc.length) {
|
||||
const notaEc = 'libsignal Curve25519 key pair: used for Diffie-Hellman (X3DH/PQXDH, Double Ratchet) and for XEdDSA signatures over the same key.';
|
||||
const bundle = { 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.' };
|
||||
for (const m of ctx.potriviri(/(?<![\w$.])(?:[\w$]+\s*\.\s*)?(PrivateKey|IdentityKeyPair)\s*\.\s*generate\s*\(/g)) {
|
||||
ctx.adauga(m.index, `${m[1]}.generate`, 'call', { grup: 'XDH', nume: 'X25519', functii: ['keygen'], nota: notaEc }, { bucata: m[0] });
|
||||
}
|
||||
for (const m of ctx.potriviri(/(?<![\w$.])(?:[\w$]+\s*\.\s*)?KEMKeyPair\s*\.\s*generate\s*\(/g)) {
|
||||
ctx.adauga(m.index, 'KEMKeyPair.generate', 'call', { grup: 'PREPQ', nume: 'Kyber-1024', primitiv: 'kem', functii: ['keygen'], nota: 'libsignal-client KEMKeyPair.generate() produces a Kyber-1024 pair (the PQXDH prekey; the only KEM type the Node API exposed when this rule was written).' }, { bucata: m[0] });
|
||||
}
|
||||
// hkdf: numai numele importat din pachet sau prin aliasul lui de spatiu de nume (node:crypto are si el un hkdf, recunoscut mai sus)
|
||||
const numeHkdf = lsc.flatMap((i) => i.locale.filter((_, k) => i.importate[k] === 'hkdf'));
|
||||
const aliasuri = lsc.map((i) => i.implicit).filter(Boolean);
|
||||
const forme = [...numeHkdf.map((n) => `${escapeRe(n)}`), ...aliasuri.map((a) => `${escapeRe(a)}\\s*\\.\\s*hkdf`)];
|
||||
if (forme.length) {
|
||||
for (const m of ctx.potriviri(new RegExp(`(?<![\\w$.])(?:${forme.join('|')})\\s*\\(`, 'g'))) {
|
||||
ctx.adauga(m.index, 'hkdf', 'call', { grup: 'KDF', nume: 'HKDF', hash: 'SHA256', functii: ['keyderive'], nota: 'libsignal HKDF is HKDF-SHA-256.' }, { bucata: m[0] });
|
||||
}
|
||||
}
|
||||
for (const m of ctx.potriviri(/(?<![\w$.])(?:[\w$]+\s*\.\s*)?Aes256GcmSiv\s*\.\s*new\s*\(/g)) {
|
||||
ctx.adauga(m.index, 'Aes256GcmSiv.new', 'call', { grup: 'CIPHER', nume: 'AES', param: '256', mod: 'gcm-siv', functii: ['encrypt'] }, { bucata: m[0] });
|
||||
}
|
||||
for (const m of ctx.potriviri(/(?<![\w$.])(?:[\w$]+\s*\.\s*)?(PreKeyBundle\s*\.\s*new|processPreKeyBundle)\s*\(/g)) {
|
||||
ctx.adauga(m.index, m[1].replace(/\s+/g, ''), 'call', bundle, { bucata: m[0] });
|
||||
}
|
||||
ctx.adauga(lsc[0].pos, `import ${lsc[0].spec}`, 'import', { grup: 'LIB-MULTI', nume: '@signalapp/libsignal-client', motiv: 'Imports the Signal protocol library for Node (Curve25519 identity and prekeys, Kyber prekeys (PQXDH), Double Ratchet, SPQR, sealed sender); no specific call recognized in this file.' }, { suprimaDe: ['XDH', 'PREPQ', 'MLKEM', 'KDF', 'CIPHER', 'LIB-MULTI'], bucata: `import ${lsc[0].spec}` });
|
||||
}
|
||||
|
||||
// node-rsa
|
||||
const nrsa = importa(/^node-rsa$/);
|
||||
if (nrsa.length) {
|
||||
|
||||
@@ -68,6 +68,11 @@ const CRATE = {
|
||||
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'] },
|
||||
// 2026-10-18 (libsignal): BoringSSL bindings, acelasi API ca `openssl`; `boring-signal` e forkul lui Signal, stiva TLS a lui libsignal
|
||||
boring: { ofera: 'BoringSSL bindings (same API as openssl)', grupuri: ['HASH', 'CIPHER', 'RSA', 'EC', 'ECDSA', 'EDDSA', 'XDH', 'TLS'] },
|
||||
boring_signal: { ofera: "BoringSSL bindings (Signal's fork of boring; the TLS stack under libsignal)", grupuri: ['HASH', 'CIPHER', 'RSA', 'EC', 'ECDSA', 'EDDSA', 'XDH', 'TLS'] },
|
||||
tokio_boring: { ofera: 'TLS over tokio (BoringSSL)', grupuri: ['TLS'] },
|
||||
tokio_boring_signal: { ofera: 'TLS over tokio (BoringSSL, Signal fork)', grupuri: ['TLS'] },
|
||||
rustls: { ofera: 'TLS (versions and key-exchange groups come from the crypto provider and the Cargo features)', grupuri: ['TLS', 'XDH', 'UNKNOWN'] },
|
||||
tokio_rustls: { ofera: 'TLS over tokio (rustls)', grupuri: ['TLS'] },
|
||||
hyper_rustls: { ofera: 'HTTPS for hyper (rustls)', grupuri: ['TLS'] },
|
||||
@@ -87,7 +92,7 @@ for (const [crate, tipuri] of Object.entries({
|
||||
sha1: ['Sha1'], md5: ['Md5'],
|
||||
sha3: ['Sha3_224', 'Sha3_256', 'Sha3_384', 'Sha3_512', 'Keccak256', 'Shake128', 'Shake256'],
|
||||
blake2: ['Blake2b512', 'Blake2s256', 'Blake2b', 'Blake2s', 'Blake2bMac', 'Blake2sMac'],
|
||||
hmac: ['Hmac', 'SimpleHmac'], hkdf: ['Hkdf'], argon2: ['Argon2'],
|
||||
hmac: ['Hmac', 'SimpleHmac', 'HmacReset', 'SimpleHmacReset'], hkdf: ['Hkdf'], argon2: ['Argon2'],
|
||||
chacha20poly1305: ['ChaCha20Poly1305', 'XChaCha20Poly1305', 'ChaCha8Poly1305', 'ChaCha12Poly1305', 'XChaCha8Poly1305', 'XChaCha12Poly1305'],
|
||||
aes_gcm: ['Aes128Gcm', 'Aes256Gcm'], aes_gcm_siv: ['Aes128GcmSiv', 'Aes256GcmSiv'], aes_siv: ['Aes128SivAead', 'Aes256SivAead'],
|
||||
aes: ['Aes128', 'Aes192', 'Aes256'],
|
||||
@@ -233,7 +238,7 @@ export function detecteazaRust(ctx) {
|
||||
}
|
||||
|
||||
// 2. aliasuri de tip cu parametru generic: type HmacSha256 = Hmac<Sha256>; type Kdf = Hkdf<Sha512>;
|
||||
for (const m of ctx.potriviri(/(?<![\w:])type\s+\w+\s*=\s*((?:[A-Za-z_]\w*::)*)(Hmac|SimpleHmac|Hkdf)\s*<\s*([^>;]+)>/g)) {
|
||||
for (const m of ctx.potriviri(/(?<![\w:])type\s+\w+\s*=\s*((?:[A-Za-z_]\w*::)*)(Hmac|SimpleHmac|HmacReset|SimpleHmacReset|Hkdf)\s*<\s*([^>;]+)>/g)) {
|
||||
const r = rezolvaCale(m[1], m[2]);
|
||||
if (!r) continue;
|
||||
const h = hashDinTip(m[3]);
|
||||
@@ -255,9 +260,11 @@ export function detecteazaRust(ctx) {
|
||||
}
|
||||
}
|
||||
// functii importate direct: use pbkdf2::pbkdf2_hmac; use blake3::hash; use libsignal_protocol::process_prekey_bundle;
|
||||
// (2026-10-18: nu si DEFINITIA unei functii cu acelasi nume, `fn decapsulate(`: pe libsignal, `use libcrux_ml_kem::kyber1024::decapsulate`
|
||||
// dintr-un modul de test facea din cele sase metode `fn encapsulate/decapsulate` ale trait-ului Parameters sase apeluri Kyber)
|
||||
for (const [local, u] of locale) {
|
||||
if (!/^[a-z_]\w*$/.test(local) || !CRATE[u.crate] || u.cale.length < 2) continue;
|
||||
for (const m of ctx.potriviri(new RegExp(`(?<![\\w:.])${escapeRe(local)}\\s*(?:::\\s*<([^;{}()=]*?)>)?\\s*\\(`, 'g'))) {
|
||||
for (const m of ctx.potriviri(new RegExp(`(?<![\\w:.])(?<!\\bfn\\s+)${escapeRe(local)}\\s*(?:::\\s*<([^;{}()=]*?)>)?\\s*\\(`, 'g'))) {
|
||||
const activ = activFunctie(u.cale, m[1], ctx, m);
|
||||
if (activ) adauga(u.crate, m.index, u.cale.join('::'), 'call', activ, m[0].trim() + (activ.bucataExtra || ''));
|
||||
}
|
||||
@@ -306,17 +313,34 @@ export function detecteazaRust(ctx) {
|
||||
// 5. modurile de operare ale RustCrypto: cbc::Encryptor<Aes256>, ecb::Decryptor<aes::Aes128>, ctr::Ctr128BE<Aes256>
|
||||
for (const m of ctx.potriviri(/(?<![\w:])(cbc|ecb|ctr|cfb_mode|ofb|ccm)::(Encryptor|Decryptor|Ctr\w*|Ccm)\s*(?:::)?\s*<\s*(?:aes::)?Aes(128|192|256)\b/g)) {
|
||||
const mod = m[1] === 'cfb_mode' ? 'cfb' : m[1];
|
||||
folosite.add(m[1]); // crate-ul modului e folosit, nu doar aes (altfel `use cbc` iesea 'import fara apel' langa propriul lui apel)
|
||||
adauga('aes', m.index, `${m[1]}::${m[2]}<Aes${m[3]}>`, 'call', { grup: 'CIPHER', nume: 'AES', param: m[3], mod, functii: [m[2] === 'Decryptor' ? 'decrypt' : 'encrypt'] }, m[0]);
|
||||
}
|
||||
// 2026-10-18 (libsignal): acelasi tip de mod adus prin `use cbc::Decryptor;` si scris fara prefix (Decryptor::<Aes256>::new)
|
||||
for (const m of ctx.potriviri(/(?<![\w:])(Encryptor|Decryptor|Ctr\w*|Ccm)\s*(?:::)?\s*<\s*(?:aes::)?Aes(128|192|256)\b/g)) {
|
||||
const u = locale.get(m[1]);
|
||||
if (!u || !/^(cbc|ecb|ctr|cfb_mode|ofb|ccm)$/.test(u.crate)) continue;
|
||||
const mod = u.crate === 'cfb_mode' ? 'cfb' : u.crate;
|
||||
folosite.add(u.crate);
|
||||
adauga('aes', m.index, `${u.crate}::${m[1]}<Aes${m[2]}>`, 'call', { grup: 'CIPHER', nume: 'AES', param: m[2], mod, functii: [m[1] === 'Decryptor' ? 'decrypt' : 'encrypt'] }, m[0]);
|
||||
}
|
||||
|
||||
// 6. tiparul Noise al lui snow, scris ca sir: Noise_XX_25519_ChaChaPoly_SHA256
|
||||
// 2026-10-18 (libsignal): si forma hibrida hfs, Noise_NKhfs_25519+Kyber1024_ChaChaPoly_SHA256: X25519 si KEM-ul in aceeasi strangere
|
||||
// de mana (hybrid forward secrecy), deci un schimb de cheie HIBRID, nu un X25519 singur peste care sa se ceara ML-KEM
|
||||
if ([...locale.values()].some((u) => u.crate === 'snow') || /(?<![\w:])snow::/.test(ctx.code)) {
|
||||
for (const m of ctx.code.matchAll(/Noise_(\w+?)_(25519|448)_(ChaChaPoly|AESGCM)_(SHA256|SHA512|BLAKE2s|BLAKE2b)\b/g)) {
|
||||
for (const m of ctx.code.matchAll(/Noise_(\w+?)_(25519|448)(?:\+(Kyber|MLKEM|ML_KEM|mlkem)(512|768|1024))?_(ChaChaPoly|AESGCM)_(SHA256|SHA512|BLAKE2s|BLAKE2b)\b/g)) {
|
||||
if (!ctx.inSir(m.index)) continue;
|
||||
const pos = m.index;
|
||||
adauga('snow', pos, 'snow Noise pattern', 'config', { grup: 'XDH', nume: m[2] === '448' ? 'X448' : 'X25519', functii: ['keygen'] }, m[0]);
|
||||
adauga('snow', pos, 'snow Noise pattern', 'config', m[3] === 'AESGCM' ? { grup: 'CIPHER', nume: 'AES', param: '256', mod: 'gcm', functii: ['encrypt'] } : { grup: 'CIPHER', nume: 'ChaCha20-Poly1305', functii: ['encrypt'] }, m[0]);
|
||||
adauga('snow', pos, 'snow Noise pattern', 'config', { grup: 'HASH', hash: m[4] === 'SHA256' ? 'SHA256' : m[4] === 'SHA512' ? 'SHA512' : m[4] === 'BLAKE2s' ? 'BLAKE2S' : 'BLAKE2B', functii: ['digest'] }, m[0]);
|
||||
const dh = m[2] === '448' ? 'X448' : 'X25519';
|
||||
if (m[3]) {
|
||||
const kem = /kyber/i.test(m[3]) ? `Kyber${m[4]}` : `ML-KEM-${m[4]}`;
|
||||
adauga('snow', pos, 'snow Noise pattern (hfs)', 'config', { grup: 'HYBRID-KEX', nume: `${dh}+${kem} (Noise hfs)`, nota: `Noise hybrid forward secrecy: the ${dh} and the ${kem} shared secrets both enter the handshake key schedule.` }, m[0]);
|
||||
} else {
|
||||
adauga('snow', pos, 'snow Noise pattern', 'config', { grup: 'XDH', nume: dh, functii: ['keygen'] }, m[0]);
|
||||
}
|
||||
adauga('snow', pos, 'snow Noise pattern', 'config', m[5] === 'AESGCM' ? { grup: 'CIPHER', nume: 'AES', param: '256', mod: 'gcm', functii: ['encrypt'] } : { grup: 'CIPHER', nume: 'ChaCha20-Poly1305', functii: ['encrypt'] }, m[0]);
|
||||
adauga('snow', pos, 'snow Noise pattern', 'config', { grup: 'HASH', hash: m[6] === 'SHA256' ? 'SHA256' : m[6] === 'SHA512' ? 'SHA512' : m[6] === 'BLAKE2s' ? 'BLAKE2S' : 'BLAKE2B', functii: ['digest'] }, m[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,11 +352,13 @@ export function detecteazaRust(ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
// 8. openssl: versiunea minima/maxima TLS
|
||||
if ([...locale.values()].some((u) => u.crate === 'openssl') || /(?<![\w:])openssl::/.test(ctx.code)) {
|
||||
// 8. openssl (si boring / boring-signal, acelasi API): versiunea minima/maxima TLS
|
||||
const crateSsl = [...locale.values()].map((u) => u.crate).find((c) => /^(openssl|boring|boring_signal)$/.test(c))
|
||||
|| (/(?<![\w:])(openssl|boring_signal|boring)::/.exec(ctx.code) || [])[1] || null;
|
||||
if (crateSsl) {
|
||||
const vers = { SSL3: 'ssl3', TLS1: '1.0', TLS1_1: '1.1', TLS1_2: '1.2', TLS1_3: '1.3' };
|
||||
for (const m of ctx.potriviri(/\.\s*set_(min|max)_proto_version\s*\(\s*Some\s*\(\s*(?:openssl::ssl::)?SslVersion::(SSL3|TLS1_3|TLS1_2|TLS1_1|TLS1)\b/g)) {
|
||||
adauga('openssl', m.index, `openssl set_${m[1]}_proto_version`, 'config', { grup: 'TLS', param: vers[m[2]], rol: m[1] }, m[0]);
|
||||
for (const m of ctx.potriviri(/\.\s*set_(min|max)_proto_version\s*\(\s*Some\s*\(\s*(?:(?:openssl|boring|boring_signal)::ssl::)?SslVersion::(SSL3|TLS1_3|TLS1_2|TLS1_1|TLS1)\b/g)) {
|
||||
adauga(crateSsl, m.index, `${NUME_CARGO(crateSsl)} set_${m[1]}_proto_version`, 'config', { grup: 'TLS', param: vers[m[2]], rol: m[1] }, m[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,7 +403,7 @@ function activStatic(r, metoda, generic, ctx, m) {
|
||||
case 'blake3':
|
||||
return tip === 'Hasher' && /^(new|new_keyed|new_derive_key|default)$/.test(metoda) ? { grup: 'HASH', hash: 'BLAKE3', functii: ['digest'] } : null;
|
||||
case 'hmac': {
|
||||
if (!/^(Hmac|SimpleHmac)$/.test(tip) || !/^(new|new_from_slice|new_varkey|default)$/.test(metoda)) return null;
|
||||
if (!/^(Hmac|SimpleHmac|HmacReset|SimpleHmacReset)$/.test(tip) || !/^(new|new_from_slice|new_varkey|default)$/.test(metoda)) return null;
|
||||
const h = hashDinTip(generic);
|
||||
return h ? { grup: 'MAC', hash: h, functii: ['tag'], crateHash: crateHashDinTip(generic) } : { grup: 'UNKNOWN', motiv: generic ? `HMAC over "${generic.trim()}", a hash this tool does not resolve.` : 'HMAC whose hash is a type alias or an inferred type parameter, not visible at this call.' };
|
||||
}
|
||||
@@ -474,13 +500,13 @@ function activStatic(r, metoda, generic, ctx, m) {
|
||||
if (tip === 'EcdsaKeyPair') { const c = /P(256|384)/.exec(ctx.code.slice(m.index, m.index + 200)); return { grup: 'ECDSA', curba: c ? `secp${c[1]}r1` : undefined, functii: fn(/generate/.test(metoda) ? 'keygen' : 'other') }; }
|
||||
if (tip === 'EphemeralPrivateKey' && metoda === 'generate') { const c = /(X25519|ECDH_P256|ECDH_P384)/.exec(ctx.code.slice(m.index, m.index + 200)); return c && c[1] !== 'X25519' ? { grup: 'ECDH', curba: c[1] === 'ECDH_P256' ? 'secp256r1' : 'secp384r1', functii: ['keygen'] } : { grup: 'XDH', nume: 'X25519', functii: ['keygen'] }; }
|
||||
return null;
|
||||
case 'openssl': {
|
||||
case 'openssl': case 'boring': case 'boring_signal': {
|
||||
if (tip === 'MessageDigest') { const h = { md5: 'MD5', sha1: 'SHA1', sha224: 'SHA224', sha256: 'SHA256', sha384: 'SHA384', sha512: 'SHA512', sha3_224: 'SHA3-224', sha3_256: 'SHA3-256', sha3_384: 'SHA3-384', sha3_512: 'SHA3-512', ripemd160: 'RIPEMD160', shake_128: 'SHAKE128', shake_256: 'SHAKE256' }[metoda]; return h ? { grup: 'HASH', hash: h, functii: ['digest'] } : null; }
|
||||
if (tip === 'Cipher') { const k = /^(aes|des_ede3|des|rc4|rc2|bf|chacha20_poly1305|chacha20|camellia|sm4|aria)_?(\d{3})?_?(\w+)?$/.exec(metoda); if (!k) return null; const nume = k[1] === 'des_ede3' ? '3DES' : k[1] === 'bf' ? 'Blowfish' : k[1] === 'chacha20_poly1305' ? 'ChaCha20-Poly1305' : k[1] === 'chacha20' ? 'ChaCha20' : k[1].toUpperCase(); return { grup: 'CIPHER', nume, param: k[2], mod: k[3] ? k[3].replace(/_/g, '-') : undefined, functii: ['encrypt'] }; }
|
||||
if (tip === 'Rsa' && /^(generate|generate_with_e)$/.test(metoda)) { const b = /^\s*(\d{3,5})\s*(?:,|$)/.exec(argsDupa(ctx, m)); return { grup: 'RSA', param: b ? b[1] : undefined, functii: ['keygen'], bucataExtra: b ? ` ${b[1]}` : '' }; }
|
||||
if (tip === 'EcKey' && /^(generate|from_curve_name)$/.test(metoda)) { const c = /Nid::(X9_62_PRIME256V1|SECP256K1|SECP384R1|SECP521R1|SECP224R1|BRAINPOOL_P256R1|BRAINPOOL_P384R1|BRAINPOOL_P512R1)/.exec(ctx.code.slice(m.index, m.index + 300)); const curba = c ? ({ X9_62_PRIME256V1: 'secp256r1', SECP256K1: 'secp256k1', SECP384R1: 'secp384r1', SECP521R1: 'secp521r1', SECP224R1: 'secp224r1', BRAINPOOL_P256R1: 'brainpoolP256r1', BRAINPOOL_P384R1: 'brainpoolP384r1', BRAINPOOL_P512R1: 'brainpoolP512r1' })[c[1]] : undefined; return { grup: 'EC', curba, functii: ['keygen'] }; }
|
||||
if (tip === 'PKey') { const k = /^generate_(ed25519|ed448|x25519|x448)$/.exec(metoda); if (!k) return null; return /^ed/.test(k[1]) ? { grup: 'EDDSA', nume: k[1] === 'ed448' ? 'Ed448' : 'Ed25519', functii: ['keygen'] } : { grup: 'XDH', nume: k[1] === 'x448' ? 'X448' : 'X25519', functii: ['keygen'] }; }
|
||||
if (/^(SslConnector|SslAcceptor|SslContext)$/.test(tip) && /^(builder|mozilla_modern|mozilla_intermediate|mozilla_modern_v5|mozilla_intermediate_v5)$/.test(metoda)) return { grup: 'TLS', param: 'negotiated', nume: `openssl ${tip}` };
|
||||
if (/^(SslConnector|SslAcceptor|SslContext)$/.test(tip) && /^(builder|mozilla_modern|mozilla_intermediate|mozilla_modern_v5|mozilla_intermediate_v5)$/.test(metoda)) return { grup: 'TLS', param: 'negotiated', nume: `${NUME_CARGO(crate)} ${tip}` };
|
||||
return null;
|
||||
}
|
||||
case 'rustls': case 'tokio_rustls': case 'hyper_rustls': case 'native_tls':
|
||||
@@ -503,8 +529,12 @@ function activStatic(r, metoda, generic, ctx, m) {
|
||||
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 f = fn(/generate/.test(metoda) ? 'keygen' : /encaps/.test(metoda) ? 'encapsulate' : /decaps/.test(metoda) ? 'decapsulate' : 'other');
|
||||
// 2026-10-18 (libsignal): modulele kyber512/768/1024 ale lui libcrux sunt Kyber pre-standard (prekey-urile PQXDH de dinaintea ML-KEM)
|
||||
const ky = cale.map((s) => /^kyber(512|768|1024)$/.exec(s)).find(Boolean);
|
||||
if (ky) return { grup: 'PREPQ', nume: `Kyber-${ky[1]}`, primitiv: 'kem', functii: f, nota: 'libcrux kyber module: CRYSTALS-Kyber, the pre-standard form of 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;
|
||||
return k ? { grup: 'MLKEM', param: k[1], functii: f } : null;
|
||||
}
|
||||
case 'libcrux_ml_dsa': {
|
||||
const k = /MLDSA(44|65|87)|ml_dsa_(44|65|87)/.exec(tip + ' ' + cale.join('::'));
|
||||
@@ -539,10 +569,16 @@ function activFunctie(cale, generic, ctx, m) {
|
||||
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': {
|
||||
if (!/^(generate_key_pair|encapsulate|decapsulate|validate_public_key|validate_private_key)$/.test(fnume)) return null;
|
||||
const f = [/generate/.test(fnume) ? 'keygen' : /encaps/.test(fnume) ? 'encapsulate' : /decaps/.test(fnume) ? 'decapsulate' : 'other'];
|
||||
const ky = /^kyber(512|768|1024)$/.exec(modul || '');
|
||||
if (ky) return { grup: 'PREPQ', nume: `Kyber-${ky[1]}`, primitiv: 'kem', functii: f, nota: 'libcrux kyber module: CRYSTALS-Kyber, the pre-standard form of 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'] };
|
||||
return k ? { grup: 'MLKEM', param: k[1], functii: f } : null;
|
||||
}
|
||||
case 'x25519_dalek':
|
||||
// 2026-10-18 (libsignal): functia libera x25519(secret, point), nu numai tipurile StaticSecret/EphemeralSecret
|
||||
return fnume === 'x25519' ? { grup: 'XDH', nume: 'X25519', functii: ['other'] } : null;
|
||||
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;
|
||||
|
||||
@@ -32,6 +32,38 @@ const MUTATII = [
|
||||
tinta: 'rust: acelasi nume de tip e clasificat dupa crate-ul din use (SigningKey)',
|
||||
martor: B,
|
||||
},
|
||||
{
|
||||
nume: 'API-ul libsignal Java recunoscut fara ancora de import/pachet (orice ECKeyPair.generate devine libsignal)',
|
||||
fisier: 'lib/detect-java.mjs',
|
||||
ancora: 'if (!ancore.length) return;',
|
||||
cu: 'if (false) return;',
|
||||
tinta: 'negativ: numele API-ului libsignal fara importul lui nu produc gasiri (Java si TypeScript), iar cu import se recunosc',
|
||||
martor: B,
|
||||
},
|
||||
{
|
||||
nume: 'pachetul @signalapp/libsignal-client nu mai e recunoscut (JS)',
|
||||
fisier: 'lib/detect-js.mjs',
|
||||
ancora: "const lsc = importa(/^@signalapp\\/libsignal-client(\\/.*)?$/);",
|
||||
cu: 'const lsc = [];',
|
||||
tinta: 'pozitiv: js/libsignal-client.ts',
|
||||
martor: B,
|
||||
},
|
||||
{
|
||||
nume: 'modulele kyber ale lui libcrux citite ca ML-KEM (Rust)',
|
||||
fisier: 'lib/detect-rust.mjs',
|
||||
ancora: "const ky = /^kyber(512|768|1024)$/.exec(modul || '');",
|
||||
cu: 'const ky = null;',
|
||||
tinta: 'pozitiv: rust/libsignal.rs',
|
||||
martor: B,
|
||||
},
|
||||
{
|
||||
nume: 'tiparul Noise hibrid (hfs) citit ca X25519 singur (Rust)',
|
||||
fisier: 'lib/detect-rust.mjs',
|
||||
ancora: 'if (m[3]) {',
|
||||
cu: 'if (false) {',
|
||||
tinta: 'pozitiv: rust/libsignal.rs',
|
||||
martor: B,
|
||||
},
|
||||
{
|
||||
nume: 'Cargo.toml scos din manifeste',
|
||||
fisier: 'lib/manifeste.mjs',
|
||||
|
||||
@@ -53,8 +53,14 @@ try {
|
||||
if (rustN || cargoN) console.log(` (in afara echivalentei: ${rustN} gasiri Rust, ${cargoN} biblioteci Cargo; 0.1.0 nu le stia)`);
|
||||
const ka = a.findings.map(norm), kb = b.findings.map(norm);
|
||||
const sa = new Set(ka), sb = new Set(kb);
|
||||
const doarV = ka.filter((x) => !sb.has(x)), doarN = kb.filter((x) => !sa.has(x));
|
||||
const ok = !doarV.length && !doarN.length && ka.length === kb.length && JSON.stringify(a.libraries) === JSON.stringify(b.libraries);
|
||||
// 0.3.0 (2026-10-18, libsignal): detectoarele noi pe limbaje pe care 0.1.0 le STIA (API-ul libsignal in Java si Node) sunt adaugiri,
|
||||
// nu rescrieri: o gasire numai in versiunea noua, cu un API din lista de mai jos, se numara si se spune, nu e diferenta. O gasire
|
||||
// numai in 0.1.0 ramane intotdeauna diferenta: echivalenta pazeste ca rescrierea nu a PIERDUT nimic.
|
||||
const ADAUGIRI = /"api":"(?:(?:ECKeyPair|IdentityKeyPair|ECPrivateKey|PrivateKey|KEMKeyPair)\.generate|Curve\.generateKeyPair|HKDF\.deriveSecrets|new (?:Aes256GcmSiv|Aes256GcmEncryption|Aes256GcmDecryption|Aes256Ctr32|PreKeyBundle)|import org\.signal\.libsignal|hkdf|Aes256GcmSiv\.new|PreKeyBundle\.new|processPreKeyBundle|import @signalapp\/libsignal-client(?:\/[^"]*)?)"/;
|
||||
const doarV = ka.filter((x) => !sb.has(x)), doarN0 = kb.filter((x) => !sa.has(x));
|
||||
const adaugate = doarN0.filter((x) => ADAUGIRI.test(x)), doarN = doarN0.filter((x) => !ADAUGIRI.test(x));
|
||||
if (adaugate.length) console.log(` (in afara echivalentei: ${adaugate.length} gasiri ale detectoarelor adaugate dupa 0.1.0, API-ul libsignal Java/Node)`);
|
||||
const ok = !doarV.length && !doarN.length && ka.length + adaugate.length === kb.length && JSON.stringify(a.libraries) === JSON.stringify(b.libraries);
|
||||
comparate += ka.length;
|
||||
if (!ok) dif++;
|
||||
console.log(`${ok ? 'IDENTIC ' : 'DIFERIT '} ${d}: ${a.stats.filesSeen} fisiere, gasiri ${ka.length}/${kb.length}, biblioteci ${a.libraries.length}/${b.libraries.length}`);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// Fixtura: API-ul Java/Android al libsignal (org.signal.libsignal), 2026-10-18. Fisierul nu se compileaza; e doar text pentru scaner.
|
||||
// Ancora e importul org.signal.libsignal.*; fara el, numele scurte (ECKeyPair, HKDF, Aes256GcmSiv) nu inseamna libsignal.
|
||||
package fixturi;
|
||||
|
||||
import org.signal.libsignal.protocol.IdentityKeyPair;
|
||||
import org.signal.libsignal.protocol.ecc.ECKeyPair;
|
||||
import org.signal.libsignal.protocol.kem.KEMKeyPair;
|
||||
import org.signal.libsignal.protocol.kem.KEMKeyType;
|
||||
import org.signal.libsignal.protocol.kdf.HKDF;
|
||||
import org.signal.libsignal.protocol.state.PreKeyBundle;
|
||||
import org.signal.libsignal.crypto.Aes256GcmSiv;
|
||||
import org.signal.libsignal.crypto.Aes256GcmEncryption;
|
||||
import org.signal.libsignal.crypto.Aes256Ctr32;
|
||||
|
||||
public class Libsignal {
|
||||
public void exemple(byte[] key, byte[] nonce, byte[] ikm, KEMKeyType tipDinParametru) throws Exception {
|
||||
ECKeyPair ec = ECKeyPair.generate(); // EXPECT: X25519 | quantum-vulnerable
|
||||
IdentityKeyPair id = IdentityKeyPair.generate(); // EXPECT: X25519 | quantum-vulnerable
|
||||
KEMKeyPair kem = KEMKeyPair.generate(KEMKeyType.KYBER_1024); // EXPECT: Kyber-1024 | quantum-safe
|
||||
KEMKeyPair kem2 = KEMKeyPair.generate(tipDinParametru); // EXPECT: libsignal KEM key pair | unknown
|
||||
byte[] okm = HKDF.deriveSecrets(ikm, "info".getBytes(), 32); // EXPECT: HKDF | quantum-safe
|
||||
Aes256GcmSiv siv = new Aes256GcmSiv(key); // EXPECT: AES-256-GCM-SIV | quantum-safe
|
||||
Aes256GcmEncryption gcm = new Aes256GcmEncryption(key, nonce, new byte[0]); // EXPECT: AES-256-GCM | quantum-safe
|
||||
Aes256Ctr32 ctr = new Aes256Ctr32(key, nonce, 0); // EXPECT: AES-256-CTR | quantum-safe
|
||||
PreKeyBundle bundle = new PreKeyBundle(1, 1, 2, ec.getPublicKey(), 3, ec.getPublicKey(), new byte[64], id.getPublicKey()); // EXPECT: libsignal session setup (X3DH/PQXDH) | unknown
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Fixtura: un fisier care importa libsignal fara niciun apel recunoscut: importul e dovada slaba (unknown), o singura data.
|
||||
// Si un fisier FARA importul libsignal nu primeste nimic pentru aceleasi nume scurte (vezi negative/FaraLibsignal.java).
|
||||
package fixturi;
|
||||
|
||||
import org.signal.libsignal.protocol.SessionCipher; // EXPECT: libsignal (org.signal.libsignal) | unknown
|
||||
import org.signal.libsignal.protocol.SignalProtocolAddress;
|
||||
|
||||
public class LibsignalImport {
|
||||
public Object cifru(Object store, SignalProtocolAddress adresa) {
|
||||
return new SessionCipher(store, adresa);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Fixtura: importul pachetului fara niciun apel recunoscut e dovada slaba (unknown), o singura data pe fisier.
|
||||
import { SessionCipher, ProtocolAddress } from '@signalapp/libsignal-client'; // EXPECT: @signalapp/libsignal-client | unknown
|
||||
|
||||
export function adresa(nume: string) {
|
||||
return { cipher: SessionCipher, address: ProtocolAddress.new(nume, 1) };
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// Fixtura: un client al bibliotecii Signal pentru Node (@signalapp/libsignal-client), 2026-10-18. Ancora e importul pachetului.
|
||||
import * as SignalClient from '@signalapp/libsignal-client';
|
||||
import { PrivateKey, KEMKeyPair, hkdf, Aes256GcmSiv } from '@signalapp/libsignal-client';
|
||||
|
||||
export function chei(ikm: Buffer, key: Buffer) {
|
||||
const priv = PrivateKey.generate(); // EXPECT: X25519 | quantum-vulnerable
|
||||
const id = SignalClient.IdentityKeyPair.generate(); // EXPECT: X25519 | quantum-vulnerable
|
||||
const kem = KEMKeyPair.generate(); // EXPECT: Kyber-1024 | quantum-safe
|
||||
const okm = hkdf(32, ikm, Buffer.from('info'), null); // EXPECT: HKDF | quantum-safe
|
||||
const okm2 = SignalClient.hkdf(32, ikm, Buffer.from('info'), null); // EXPECT: HKDF | quantum-safe
|
||||
const siv = Aes256GcmSiv.new(key); // EXPECT: AES-256-GCM-SIV | quantum-safe
|
||||
const bundle = SignalClient.PreKeyBundle.new(1, 1, 2, priv.getPublicKey(), 3, priv.getPublicKey(), Buffer.alloc(64), id.publicKey); // EXPECT: libsignal session setup (X3DH/PQXDH) | unknown
|
||||
return { priv, id, kem, okm, okm2, siv, bundle };
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// Fixtura negativa: aceleasi nume scurte ca in API-ul libsignal (ECKeyPair.generate, HKDF.deriveSecrets, new Aes256GcmSiv), dar FARA
|
||||
// importul org.signal.libsignal: nu sunt libsignal, deci nu produc nicio gasire. Fisierul nu se compileaza; e doar text pentru scaner.
|
||||
package fixturi;
|
||||
|
||||
import com.exemplu.chei.ECKeyPair;
|
||||
import com.exemplu.kdf.HKDF;
|
||||
import com.exemplu.cifru.Aes256GcmSiv;
|
||||
|
||||
public class FaraLibsignal {
|
||||
public Object exemple(byte[] key, byte[] ikm) {
|
||||
ECKeyPair ec = ECKeyPair.generate();
|
||||
byte[] okm = HKDF.deriveSecrets(ikm, "info".getBytes(), 32);
|
||||
return new Aes256GcmSiv(key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// Fixtura negativa: aceleasi nume scurte ca in API-ul @signalapp/libsignal-client (PrivateKey.generate, KEMKeyPair.generate, hkdf,
|
||||
// Aes256GcmSiv.new), dar importate din alta parte: nu sunt libsignal, deci nu produc nicio gasire.
|
||||
import { PrivateKey, KEMKeyPair, hkdf, Aes256GcmSiv } from '../chei-proprii';
|
||||
|
||||
export function chei(ikm: Buffer, key: Buffer) {
|
||||
const priv = PrivateKey.generate();
|
||||
const kem = KEMKeyPair.generate();
|
||||
const okm = hkdf(32, ikm, Buffer.from('info'), null);
|
||||
return { priv, kem, okm, siv: Aes256GcmSiv.new(key) };
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// Fixtura: ce a scapat inventarului pe libsignal (2026-10-18): BoringSSL prin `boring` / `boring-signal` (stiva TLS a lui libsignal,
|
||||
// acelasi API ca openssl), HmacReset din hmac 0.13, tipul de mod adus prin `use cbc::Decryptor`, functia libera x25519(), modulele
|
||||
// kyber ale lui libcrux (Kyber pre-standard) si tiparul Noise hibrid hfs (X25519 + Kyber1024 in aceeasi strangere de mana).
|
||||
use boring_signal::ssl::{SslConnector, SslMethod, SslVersion};
|
||||
use boring::rsa::Rsa;
|
||||
use boring::hash::MessageDigest;
|
||||
use hmac::{HmacReset, Mac};
|
||||
use sha2::Sha256;
|
||||
use aes::Aes256;
|
||||
use cbc::Decryptor;
|
||||
use cbc::cipher::KeyIvInit;
|
||||
use x25519_dalek as x25519;
|
||||
use libcrux_ml_kem::kyber1024;
|
||||
use libcrux_ml_kem::mlkem768;
|
||||
use snow::Builder;
|
||||
|
||||
pub const NOISE_HFS: &str = "Noise_NKhfs_25519+Kyber1024_ChaChaPoly_SHA256"; // EXPECT: X25519+Kyber1024 (Noise hfs) | quantum-safe ; ChaCha20-Poly1305 | quantum-safe ; SHA-256 | quantum-safe
|
||||
|
||||
pub fn exemple(key: &[u8; 32], iv: &[u8; 16], secret: [u8; 32], randomness: [u8; 64]) {
|
||||
let mut ssl = SslConnector::builder(SslMethod::tls()).unwrap(); // EXPECT: boring-signal SslConnector | unknown
|
||||
ssl.set_min_proto_version(Some(SslVersion::TLS1_3)).unwrap(); // EXPECT: TLSv1.3 | unknown
|
||||
let rsa = Rsa::generate(2048).unwrap(); // EXPECT: RSA-2048 | quantum-vulnerable
|
||||
let md = MessageDigest::sha256(); // EXPECT: SHA-256 | quantum-safe
|
||||
let mac = HmacReset::<Sha256>::new_from_slice(key).unwrap(); // EXPECT: HMAC-SHA-256 | quantum-safe
|
||||
let dec = Decryptor::<Aes256>::new(key.into(), iv.into()); // EXPECT: AES-256-CBC | quantum-safe
|
||||
let pk = x25519::x25519(secret, x25519::X25519_BASEPOINT_BYTES); // EXPECT: X25519 | quantum-vulnerable
|
||||
let kp = kyber1024::generate_key_pair(randomness); // EXPECT: Kyber-1024 | quantum-safe
|
||||
let kp2 = mlkem768::generate_key_pair(randomness); // EXPECT: ML-KEM-768 | quantum-safe
|
||||
let _ = (ssl, rsa, md, mac, dec, pk, kp, kp2, Builder::new(NOISE_HFS.parse().unwrap()));
|
||||
}
|
||||
@@ -18,8 +18,8 @@ const lx = await import(pathToFileURL(join(dirname(CALE_MODUL), 'lib', 'lexer.mj
|
||||
const CA_JSON = process.argv.includes('--json');
|
||||
|
||||
// numarul total de marcaje EXPECT scrise de mana in fixturi; o schimbare aici se face constient
|
||||
const MARCAJE_ASTEPTATE = 128;
|
||||
const FISIERE_CU_MARCAJE = ['js/node-crypto.mjs', 'js/webcrypto.js', 'js/biblioteci.ts', 'js/tls.cjs', 'python/crypto_py.py', 'java/Crypto.java', 'go/crypto.go', 'rust/cripto.rs', 'rust/ambiguu.rs', 'rust/glob.rs', 'negative/variabile.js'];
|
||||
const MARCAJE_ASTEPTATE = 158;
|
||||
const FISIERE_CU_MARCAJE = ['js/node-crypto.mjs', 'js/webcrypto.js', 'js/biblioteci.ts', 'js/tls.cjs', 'js/libsignal-client.ts', 'js/libsignal-client-import.ts', 'python/crypto_py.py', 'java/Crypto.java', 'java/Libsignal.java', 'java/LibsignalImport.java', 'go/crypto.go', 'rust/cripto.rs', 'rust/ambiguu.rs', 'rust/glob.rs', 'rust/libsignal.rs', 'negative/variabile.js'];
|
||||
|
||||
const probe = [];
|
||||
const proba = (nume, fn) => probe.push({ nume, fn });
|
||||
@@ -254,11 +254,26 @@ proba('rust: Cargo.toml: forma tabel, workspace = true fara versiune, redenumire
|
||||
|
||||
proba('negativ: fisier fara criptografie da zero gasiri, si a fost citit', () => {
|
||||
const rez = scan(join(FIX, 'negative'));
|
||||
asigura(rez.stats.filesSeen === 8 && rez.stats.codeFilesTotal === 8, `vazute ${rez.stats.filesSeen}, analizate ${rez.stats.codeFilesTotal}`);
|
||||
asigura(rez.stats.filesSeen === 10 && rez.stats.codeFilesTotal === 10, `vazute ${rez.stats.filesSeen}, analizate ${rez.stats.codeFilesTotal}`);
|
||||
const g = gasiriDin(rez, 'fara-cripto.js');
|
||||
asigura(g.length === 0, `fara-cripto.js a produs ${g.length}`);
|
||||
});
|
||||
|
||||
// 2026-10-18 (libsignal): API-ul libsignal se recunoaste numai cu ancora lui (importul org.signal.libsignal / @signalapp/libsignal-client)
|
||||
proba('negativ: numele API-ului libsignal fara importul lui nu produc gasiri (Java si TypeScript), iar cu import se recunosc', () => {
|
||||
const rez = scan(FIX);
|
||||
asigura(gasiriDin(rez, 'java/Libsignal.java').some((x) => x.name === 'Kyber-1024') && gasiriDin(rez, 'js/libsignal-client.ts').some((x) => x.name === 'Kyber-1024'), 'controlul pozitiv: Kyber-1024 din fixturile libsignal lipseste');
|
||||
const g = [...gasiriDin(rez, 'negative/FaraLibsignal.java'), ...gasiriDin(rez, 'negative/fara-libsignal.ts')];
|
||||
asigura(g.length === 0, `fara ancora au produs: ${g.map((x) => `${x.file}:${x.line} ${x.name}`).join(', ')}`);
|
||||
// ancora de pachet: un fisier din chiar arborele libsignal (package org.signal.libsignal...) nu are import, dar e libsignal
|
||||
const d = mkdtempSync(join(tmpdir(), 'ci-libsignal-'));
|
||||
try {
|
||||
writeFileSync(join(d, 'ECKeyPairTest.java'), 'package org.signal.libsignal.protocol.ecc;\n\npublic class ECKeyPairTest {\n void t() { ECKeyPair kp = ECKeyPair.generate(); }\n}\n');
|
||||
const r = inv.scan(d);
|
||||
asigura(r.findings.length === 1 && r.findings[0].name === 'X25519' && r.findings[0].line === 4, `ancora de pachet: ${JSON.stringify(r.findings.map((x) => [x.line, x.name]))}`);
|
||||
} finally { rmSync(d, { recursive: true, force: true }); }
|
||||
});
|
||||
|
||||
proba('negativ: algoritm din variabila reasignata sau din parametru iese unknown, nu ghicit', () => {
|
||||
comparaExact('negative/variabile.js');
|
||||
const g = gasiriDin(scan(FIX), 'negative/variabile.js');
|
||||
|
||||
Reference in new issue
Block a user