crypto-inventory 0.3.0: Rust detector (use-resolved names, static calls, generics, ring constants, Noise patterns), Cargo.toml manifests, BLAKE3; 44/44, negative control 21/21

This commit is contained in:
Aere Network committed 2026-10-18 05:35:11 +03:00
1 parent 86779c8334
commit f2f6217b4c
16 files changed
+942 -21

No files matched your search

+69 -2
View File
@@ -43,15 +43,33 @@ const GO = [
[/^filippo\.io\/edwards25519$/, 'Edwards25519 group arithmetic'],
[/^github\.com\/open-quantum-safe\/liboqs-go$/, 'post-quantum KEMs and signatures (liboqs)'],
];
// Cargo (0.3.0): crate-urile criptografice cunoscute de detectorul Rust, cu numele lor din registru (liniuta, nu liniuta jos), plus
// cele care se vad numai in manifest (furnizori, legaturi). Versiunea citita e CERINTA declarata ("0.10", "^1.2"), nu versiunea
// rezolvata din Cargo.lock; purl-ul o poarta numai cand e un numar simplu.
import { CRATE_RUST } from './detect-rust.mjs';
const CARGO = [
...Object.entries(CRATE_RUST).map(([c, v]) => [new RegExp('^' + c.replace(/_/g, '-') + '$'), v.ofera]),
[/^md-5$/, 'MD5'],
[/^cfb-mode$/, 'the CFB mode'],
[/^aws-lc-rs$/, 'AWS-LC: AES-GCM, ChaCha20-Poly1305, SHA-2, HMAC, HKDF, Ed25519, ECDSA, RSA, X25519, ML-KEM, ML-DSA'],
[/^rustls-(webpki|pki-types|native-certs|platform-verifier)$/, 'certificate handling for rustls'],
[/^webpki(-roots)?$/, 'WebPKI certificate validation (roots or verifier)'],
[/^openssl-sys$/, 'OpenSSL bindings'],
[/^pqcrypto$/, 'PQClean post-quantum KEMs and signatures (meta-crate)'],
[/^(x509-parser|x509-cert|rcgen)$/, 'X.509 certificates'],
[/^(ed25519|ecdsa|elliptic-curve|signature|aead|cipher|digest|kem)$/, 'RustCrypto trait crate (algorithm chosen by the implementation crate)'],
[/^(sodiumoxide|libsodium-sys|dryoc)$/, 'libsodium (NaCl): X25519, Ed25519, XSalsa20/XChaCha20-Poly1305, Argon2'],
];
export const NUME_MANIFEST = /^(package\.json|requirements[\w.-]*\.txt|pyproject\.toml|pom\.xml|build\.gradle(\.kts)?|go\.mod)$/;
export const NUME_MANIFEST = /^(package\.json|requirements[\w.-]*\.txt|pyproject\.toml|pom\.xml|build\.gradle(\.kts)?|go\.mod|Cargo\.toml)$/;
function lib(ecosistem, nume, versiune, ofera, pos, inceputuri, fisier) {
const { line } = randul(inceputuri, pos);
const purl = ecosistem === 'npm' ? `pkg:npm/${nume.startsWith('@') ? '%40' + nume.slice(1) : nume}${versiune && /^[\w.-]+$/.test(versiune) ? '@' + versiune : ''}`
: ecosistem === 'pypi' ? `pkg:pypi/${nume}${versiune && /^[\w.-]+$/.test(versiune) ? '@' + versiune : ''}`
: ecosistem === 'maven' ? `pkg:maven/${nume.replace(':', '/')}${versiune && /^[\w.-]+$/.test(versiune) ? '@' + versiune : ''}`
: `pkg:golang/${nume}${versiune ? '@' + versiune : ''}`;
: ecosistem === 'cargo' ? `pkg:cargo/${nume}${versiune && /^[\w.-]+$/.test(versiune) ? '@' + versiune : ''}`
: `pkg:golang/${nume}${versiune ? '@' + versiune : ''}`;
return { file: fisier, line, ecosystem: ecosistem, name: nume, version: versiune || undefined, provides: ofera, purl };
}
@@ -129,6 +147,55 @@ export function citesteManifest(text, numeFisier, rel) {
}
pos += linie.length + 1;
}
} else if (numeFisier === 'Cargo.toml') {
// sectiunile [dependencies], [dev-dependencies], [build-dependencies], [workspace.dependencies], [target.'cfg(...)'.dependencies]
// si forma tabel [dependencies.nume] cu `version =` / `package =` pe randurile urmatoare
let pos = 0;
let inDependente = false;
let tabel = null; // { nume, pos, versiune, pachet } pentru [dependencies.nume]
const inchide = () => {
if (!tabel) return;
const nume = tabel.pachet || tabel.nume;
const intrare = CARGO.find(([re]) => re.test(nume));
if (intrare) r.push(lib('cargo', nume, tabel.versiune, intrare[1], tabel.pos, inceputuri, rel));
tabel = null;
};
const valoare = (s) => { const v = /^\s*["']([^"']*)["']/.exec(s); return v ? v[1].trim() : undefined; };
for (const linie of text.split('\n')) {
const t = linie.replace(/\s+#.*$/, '').replace(/^#.*$/, '').trim();
let h;
if ((h = /^\[\s*(.+?)\s*\]$/.exec(t))) {
inchide();
const s = h[1].replace(/\s+/g, '');
const dep = /^(?:workspace\.|target\.(?:'[^']*'|"[^"]*"|[^.]+)\.)?(dependencies|dev-dependencies|build-dependencies)(?:\.(?:"([^"]+)"|([\w.-]+)))?$/.exec(s);
inDependente = !!dep;
const numeTabel = dep && (dep[2] || dep[3]);
if (numeTabel) tabel = { nume: numeTabel, pos: pos + linie.indexOf(numeTabel), versiune: undefined, pachet: null };
} else if (tabel) {
let m;
if ((m = /^version\s*=\s*(.+)$/.exec(t))) tabel.versiune = valoare(m[1]);
else if ((m = /^package\s*=\s*(.+)$/.exec(t))) tabel.pachet = valoare(m[1]);
} else if (inDependente && t) {
const m = /^(?:"([^"]+)"|([\w.-]+))\s*=\s*(.+)$/.exec(t);
if (m) {
let nume = m[1] || m[2];
let versiune;
const val = m[3].trim();
if (val.startsWith('{')) {
const v = /\bversion\s*=\s*["']([^"']*)["']/.exec(val);
const pk = /\bpackage\s*=\s*["']([^"']*)["']/.exec(val);
if (pk) nume = pk[1];
versiune = v ? v[1].trim() : undefined;
} else {
versiune = valoare(val);
}
const intrare = CARGO.find(([re]) => re.test(nume));
if (intrare) r.push(lib('cargo', nume, versiune, intrare[1], pos + linie.indexOf(m[1] || m[2]), inceputuri, rel));
}
}
pos += linie.length + 1;
}
inchide();
}
return { biblioteci: r };
}