Add crypto-inventory: a cryptographic inventory of source code as a CycloneDX 1.6 CBOM, with linear cost on hostile input; PKI DER messages in English
This commit is contained in:
1 parent
7d814d1bb8
commit
0f081f0847
49 files changed
+4342
-33
No files matched your search
@@ -0,0 +1,19 @@
|
||||
// Fixtura: biblioteci recunoscute din importuri (TypeScript).
|
||||
import { Wallet, verifyMessage } from 'ethers';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { secp256k1 } from '@noble/curves/secp256k1'; // EXPECT: ECDSA-secp256k1 | quantum-vulnerable
|
||||
import { ml_dsa65 } from '@noble/post-quantum/ml-dsa'; // EXPECT: ML-DSA-65 | quantum-safe
|
||||
import { ml_kem768 } from '@noble/post-quantum/ml-kem'; // EXPECT: ML-KEM-768 | quantum-safe
|
||||
import elliptic from 'elliptic';
|
||||
import { sha1 } from '../vendor/node_modules/@noble/hashes/legacy.js'; // EXPECT: SHA-1 | weak-now
|
||||
|
||||
const ec = new elliptic.ec('p256'); // EXPECT: EC-secp256r1 | quantum-vulnerable
|
||||
|
||||
export async function semneaza(privateKey: string, payload: object) {
|
||||
const w = new Wallet(privateKey); // EXPECT: ECDSA-secp256k1 | quantum-vulnerable
|
||||
const sig = await w.signMessage('hello'); // EXPECT: ECDSA-secp256k1 | quantum-vulnerable
|
||||
const ok = verifyMessage('hello', sig); // EXPECT: ECDSA-secp256k1 | quantum-vulnerable
|
||||
const t1 = jwt.sign(payload, privateKey, { algorithm: 'RS256' }); // EXPECT: JWS RS256 | quantum-vulnerable
|
||||
const t2 = jwt.verify(t1, privateKey, { algorithms: ['ES256', 'HS256'] }); // EXPECT: JWS ES256 | quantum-vulnerable ; JWS HS256 | quantum-safe
|
||||
return { ec, ok, t2, secp256k1, ml_dsa65, ml_kem768, sha1 };
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// Fixtura: node:crypto. Fiecare rand cu o folosire poarta marcajul EXPECT al gasirii asteptate.
|
||||
// Fisierul nu se executa niciodata; e doar text pentru scaner.
|
||||
import crypto from 'node:crypto';
|
||||
import { createHash, generateKeyPairSync } from 'crypto';
|
||||
|
||||
const HASH_ALG = 'sha256';
|
||||
|
||||
export function exemple(data, key, iv, algDinParametru, pemDinConfig) {
|
||||
const a = createHash('md5').update(data).digest('hex'); // EXPECT: MD5 | weak-now
|
||||
const b = crypto.createHash('sha1'); // EXPECT: SHA-1 | weak-now
|
||||
const c = crypto.createHash(HASH_ALG); // EXPECT: SHA-256 | quantum-safe
|
||||
const d = crypto.createHash(algDinParametru); // EXPECT: createHash | unknown
|
||||
const { publicKey } = generateKeyPairSync('rsa', { modulusLength: 2048 }); // EXPECT: RSA-2048 | quantum-vulnerable
|
||||
const k2 = crypto.generateKeyPairSync('ec', { namedCurve: 'secp256k1' }); // EXPECT: EC-secp256k1 | quantum-vulnerable
|
||||
const k3 = crypto.generateKeyPairSync('ed25519'); // EXPECT: Ed25519 | quantum-vulnerable
|
||||
const k4 = crypto.generateKeyPairSync('ml-dsa-65'); // EXPECT: ML-DSA-65 | quantum-safe
|
||||
const k5 = crypto.generateKeyPairSync('ml-kem-768'); // EXPECT: ML-KEM-768 | quantum-safe
|
||||
const s = crypto.createSign('RSA-SHA256'); // EXPECT: RSA | quantum-vulnerable
|
||||
const v = crypto.createVerify('SHA1'); // EXPECT: signature-with-SHA-1 | weak-now
|
||||
const e = crypto.createECDH('prime256v1'); // EXPECT: ECDH-secp256r1 | quantum-vulnerable
|
||||
const c1 = crypto.createCipheriv('aes-256-gcm', key, iv); // EXPECT: AES-256-GCM | quantum-safe
|
||||
const c2 = crypto.createCipheriv('des-ede3-cbc', key, iv); // EXPECT: 3DES-CBC | weak-now
|
||||
const c3 = crypto.createCipheriv('aes-128-ecb', key, null); // EXPECT: AES-128-ECB | weak-now
|
||||
const c4 = crypto.createDecipheriv('aes-128-cbc', key, iv); // EXPECT: AES-128-CBC | quantum-safe
|
||||
const enc = crypto.publicEncrypt(publicKey, data); // EXPECT: RSA | quantum-vulnerable
|
||||
const h = crypto.createHmac('sha256', key); // EXPECT: HMAC-SHA-256 | quantum-safe
|
||||
const dh = crypto.getDiffieHellman('modp2'); // EXPECT: DH-1024 | weak-now
|
||||
const sig = crypto.sign(null, data, key); // EXPECT: crypto.sign | unknown
|
||||
const pk = crypto.createPrivateKey(pemDinConfig); // EXPECT: createPrivateKey | unknown
|
||||
return [a, b, c, d, k2, k3, k4, k5, s, v, e, c1, c2, c3, c4, enc, h, dh, sig, pk];
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Fixtura: optiuni TLS in Node.
|
||||
const tls = require('node:tls');
|
||||
const https = require('https');
|
||||
|
||||
const server = tls.createServer({
|
||||
minVersion: 'TLSv1', // EXPECT: TLSv1.0 | weak-now
|
||||
ecdhCurve: 'X25519MLKEM768:X25519:prime256v1', // EXPECT: X25519MLKEM768 | quantum-safe ; X25519 | quantum-vulnerable ; ECDH-secp256r1 | quantum-vulnerable
|
||||
});
|
||||
|
||||
const agent = new https.Agent({ minVersion: 'TLSv1.2', maxVersion: 'TLSv1.3' }); // EXPECT: TLSv1.2 | quantum-vulnerable ; TLSv1.3 | unknown
|
||||
|
||||
const PQ = 'X25519MLKEM768';
|
||||
const GRUPURI = { hibrid: 'X25519MLKEM768' };
|
||||
const a2 = tls.connect({ ecdhCurve: PQ }); // EXPECT: X25519MLKEM768 | quantum-safe
|
||||
const a3 = tls.connect({ ecdhCurve: `${PQ}:X25519` }); // EXPECT: X25519MLKEM768 | quantum-safe ; X25519 | quantum-vulnerable
|
||||
const a4 = tls.connect({ ecdhCurve: GRUPURI[process.env.MOD] }); // EXPECT: tls ecdhCurve | unknown
|
||||
|
||||
module.exports = { server, agent, a2, a3, a4 };
|
||||
@@ -0,0 +1,15 @@
|
||||
// Fixtura: WebCrypto (browser sau globalThis.crypto in Node).
|
||||
const subtle = globalThis.crypto.subtle;
|
||||
|
||||
export async function webcrypto(data) {
|
||||
const rsa = await subtle.generateKey(
|
||||
{ name: 'RSA-OAEP', modulusLength: 3072, publicExponent: new Uint8Array([1, 0, 1]), hash: 'SHA-256' }, // EXPECT: RSA-3072 | quantum-vulnerable
|
||||
true, ['encrypt', 'decrypt']);
|
||||
const ec = await subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-384' }, true, ['sign', 'verify']); // EXPECT: ECDSA-secp384r1 | quantum-vulnerable
|
||||
const ed = await subtle.generateKey('Ed25519', true, ['sign', 'verify']); // EXPECT: Ed25519 | quantum-vulnerable
|
||||
const x = await subtle.generateKey({ name: 'X25519' }, true, ['deriveBits']); // EXPECT: X25519 | quantum-vulnerable
|
||||
const aes = await subtle.generateKey({ name: 'AES-GCM', length: 256 }, true, ['encrypt']); // EXPECT: AES-256-GCM | quantum-safe
|
||||
const d1 = await subtle.digest('SHA-1', data); // EXPECT: SHA-1 | weak-now
|
||||
const d2 = await subtle.digest({ name: 'SHA-384' }, data); // EXPECT: SHA-384 | quantum-safe
|
||||
return [rsa, ec, ed, x, aes, d1, d2];
|
||||
}
|
||||
Reference in new issue
Block a user