Skip to content

Commit 668bbcf

Browse files
cursoragentscript3r
andcommitted
Refactor: Add comprehensive fixtures and improve README
Co-authored-by: script3r <[email protected]>
1 parent e65fbd0 commit 668bbcf

File tree

66 files changed

+1048
-319
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1048
-319
lines changed

README.md

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,24 @@ Each detector implements the `Detector` trait and can be extended independently.
182182
The MV-CBOM generation is implemented in the `cbom-generator` crate with modular components:
183183

184184
- **cbom-generator**: Main CBOM generation and JSON serialization
185-
- **certificate-parser**: X.509 certificate parsing and signature algorithm extraction
186-
- **algorithm-detector**: Deep static analysis for algorithm parameter extraction
185+
- **certificate-parser**: X.509 certificate parsing and signature algorithm extraction
186+
- **algorithm-detector**: **Pattern-driven** algorithm detection using `patterns.toml` definitions
187187
- **dependency-analyzer**: Intelligent "uses" vs "implements" relationship detection
188-
- **cargo-parser**: Rust project metadata and dependency analysis
188+
- **project-parser**: Multi-language project metadata and dependency analysis (Cargo, Maven, go.mod, requirements.txt, Makefile, Bazel, BUCK, etc.)
189+
190+
**Key Innovation: Pattern-Driven Algorithm Detection**
191+
- Algorithm definitions moved from hardcoded Rust to configurable `patterns.toml`
192+
- Each library can define supported algorithms with NIST security levels
193+
- Parameter extraction patterns (key sizes, curves) defined declaratively
194+
- Extensible: new algorithms added by editing patterns, not code
189195

190196
The MV-CBOM pipeline:
191-
1. **Static Analysis**: Scanner finds cryptographic usage patterns
192-
2. **Algorithm Detection**: Extracts specific algorithms and parameters from findings
197+
1. **Static Analysis**: Scanner finds cryptographic usage patterns using `patterns.toml`
198+
2. **Algorithm Detection**: **Pattern-driven** extraction of algorithms and parameters
193199
3. **Certificate Parsing**: Discovers and analyzes X.509 certificates in the project
194-
4. **Dependency Analysis**: Correlates Cargo.toml dependencies with actual code usage
195-
5. **CBOM Generation**: Produces standards-compliant JSON with NIST security levels
200+
4. **Project Analysis**: Multi-language dependency parsing (Cargo, Maven, go.mod, Makefile, Bazel, BUCK, etc.)
201+
5. **Dependency Analysis**: Correlates project dependencies with actual code usage
202+
6. **CBOM Generation**: Produces standards-compliant JSON with NIST security levels
196203

197204
### Tests & Benchmarks
198205

@@ -202,20 +209,53 @@ Run unit tests and integration tests (fixtures):
202209
cargo test
203210
```
204211

205-
#### MV-CBOM Test Cases
212+
#### Comprehensive Fixtures for MV-CBOM Testing
213+
214+
The `fixtures/` directory contains rich, realistic examples for testing MV-CBOM generation across multiple languages and build systems:
215+
216+
**Rust Fixtures:**
217+
- **`rust/rsa-vulnerable`**: RSA 2048-bit usage (PQC vulnerable, "uses" relationship)
218+
- **`rust/aes-gcm-safe`**: Quantum-safe algorithms (AES-256-GCM, ChaCha20Poly1305, SHA-3, BLAKE3)
219+
- **`rust/implements-vs-uses`**: SHA2 "uses" vs P256 "implements" distinction
220+
- **`rust/mixed-crypto`**: Complex multi-algorithm project (RSA, AES, SHA2, Ed25519, Ring)
221+
222+
**Java Fixtures:**
223+
- **`java/maven-bouncycastle`**: Maven project with BouncyCastle RSA/ECDSA
224+
- **`java/bazel-tink`**: Bazel project with Google Tink and BouncyCastle
225+
- **`java/jca-standard`**: Standard JCA/JCE without external dependencies
206226

207-
The `test-cases/` directory contains comprehensive test scenarios for MV-CBOM validation:
227+
**C/C++ Fixtures:**
228+
- **`c/openssl-mixed`**: OpenSSL + libsodium with RSA, ChaCha20Poly1305, AES
229+
- **`c/libsodium-modern`**: Modern libsodium with quantum-safe and vulnerable algorithms
230+
- **`c/makefile-crypto`**: Basic OpenSSL usage with Makefile dependency detection
231+
- **`cpp/botan-modern`**: Botan library with RSA, AES-GCM, SHA-3, BLAKE2b
232+
- **`cpp/cryptopp-legacy`**: Crypto++ library with RSA, AES-GCM, SHA-256/512
208233

209-
- **test-case-1-rsa-uses**: RSA 2048-bit usage (PQC vulnerable, "uses" relationship)
210-
- **test-case-2-implements-vs-uses**: SHA2 "uses" vs P256 "implements" distinction
211-
- **test-case-3-certificate**: X.509 certificate parsing with signature algorithm detection
212-
- **test-case-4-pqc-safe**: Quantum-safe algorithms (AES-256, ChaCha20Poly1305, SHA-3, BLAKE3)
234+
**Go Fixtures:**
235+
- **`go/stdlib-crypto`**: Standard library crypto (RSA, ECDSA, AES-GCM, SHA-256/512)
236+
- **`go/x-crypto-extended`**: Extended crypto with golang.org/x/crypto dependencies
213237

214-
Run tests:
238+
**Python Fixtures:**
239+
- **`python/cryptography-mixed`**: PyCA Cryptography with RSA, AES, PBKDF2
240+
- **`python/pycryptodome-legacy`**: PyCryptodome with RSA signatures and AES
241+
- **`python/requirements-basic`**: Basic requirements.txt with Fernet and hashing
242+
243+
**Certificate Fixtures:**
244+
- **`certificates/x509-rsa-ecdsa`**: X.509 certificates with RSA and ECDSA signatures
245+
246+
Run fixture tests:
215247
```bash
216-
cd test-cases/test-case-1-rsa-uses
217-
../../target/release/cipherscope . --cbom --patterns ../../patterns.toml
218-
cat mv-cbom.json | jq '.cryptoAssets[] | select(.assetProperties.nistQuantumSecurityLevel == 0)'
248+
# Test RSA vulnerability detection
249+
./target/release/cipherscope fixtures/rust/rsa-vulnerable --cbom
250+
cat fixtures/rust/rsa-vulnerable/mv-cbom.json | jq '.cryptoAssets[] | select(.assetProperties.nistQuantumSecurityLevel == 0)'
251+
252+
# Test multi-language support
253+
./target/release/cipherscope fixtures/java/maven-bouncycastle --cbom
254+
./target/release/cipherscope fixtures/go/stdlib-crypto --cbom
255+
./target/release/cipherscope fixtures/python/cryptography-mixed --cbom
256+
257+
# Test certificate parsing
258+
./target/release/cipherscope fixtures/certificates/x509-rsa-ecdsa --cbom
219259
```
220260

221261
Benchmark scan throughput on test fixtures:
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CC=gcc
2+
CFLAGS=-Wall -Wextra -std=c99
3+
LIBS=-lsodium
4+
TARGET=sodium_test
5+
SOURCES=main.c
6+
7+
all: $(TARGET)
8+
9+
$(TARGET): $(SOURCES)
10+
$(CC) $(CFLAGS) -o $(TARGET) $(SOURCES) $(LIBS)
11+
12+
clean:
13+
rm -f $(TARGET)
14+
15+
.PHONY: all clean

fixtures/c/libsodium-modern/main.c

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include <stdio.h>
2+
#include <stdlib.h>
3+
#include <sodium.h>
4+
5+
int main() {
6+
if (sodium_init() < 0) {
7+
fprintf(stderr, "Failed to initialize libsodium\n");
8+
return 1;
9+
}
10+
11+
printf("libsodium initialized successfully\n");
12+
13+
// ChaCha20Poly1305 AEAD encryption
14+
unsigned char key[crypto_aead_chacha20poly1305_ietf_KEYBYTES];
15+
unsigned char nonce[crypto_aead_chacha20poly1305_ietf_NPUBBYTES];
16+
unsigned char ciphertext[1000];
17+
unsigned long long ciphertext_len;
18+
19+
crypto_aead_chacha20poly1305_ietf_keygen(key);
20+
randombytes_buf(nonce, sizeof nonce);
21+
22+
const char *message = "Hello, libsodium World!";
23+
24+
crypto_aead_chacha20poly1305_ietf_encrypt(ciphertext, &ciphertext_len,
25+
(const unsigned char*)message, strlen(message),
26+
NULL, 0,
27+
NULL, nonce, key);
28+
29+
printf("✓ ChaCha20Poly1305 encryption successful\n");
30+
31+
// Ed25519 digital signatures
32+
unsigned char pk[crypto_sign_ed25519_PUBLICKEYBYTES];
33+
unsigned char sk[crypto_sign_ed25519_SECRETKEYBYTES];
34+
unsigned char signature[crypto_sign_ed25519_BYTES];
35+
unsigned long long signature_len;
36+
37+
crypto_sign_ed25519_keypair(pk, sk);
38+
crypto_sign_ed25519_detached(signature, &signature_len,
39+
(const unsigned char*)message, strlen(message), sk);
40+
41+
printf("✓ Ed25519 digital signature created\n");
42+
43+
// Generic hash (BLAKE2b)
44+
unsigned char hash[crypto_generichash_BYTES];
45+
crypto_generichash(hash, sizeof hash,
46+
(const unsigned char*)message, strlen(message),
47+
NULL, 0);
48+
49+
printf("✓ BLAKE2b hash computed\n");
50+
51+
// X25519 key exchange
52+
unsigned char alice_pk[crypto_scalarmult_curve25519_BYTES];
53+
unsigned char alice_sk[crypto_scalarmult_curve25519_SCALARBYTES];
54+
unsigned char bob_pk[crypto_scalarmult_curve25519_BYTES];
55+
unsigned char bob_sk[crypto_scalarmult_curve25519_SCALARBYTES];
56+
unsigned char shared_secret[crypto_scalarmult_curve25519_BYTES];
57+
58+
crypto_scalarmult_curve25519_base(alice_pk, alice_sk);
59+
crypto_scalarmult_curve25519_base(bob_pk, bob_sk);
60+
crypto_scalarmult_curve25519(shared_secret, alice_sk, bob_pk);
61+
62+
printf("✓ X25519 key exchange completed\n");
63+
64+
printf("\nCryptographic algorithms tested:\n");
65+
printf("- ChaCha20Poly1305 (Quantum-safe AEAD)\n");
66+
printf("- Ed25519 (Quantum-vulnerable signatures)\n");
67+
printf("- BLAKE2b (Quantum-safe hash)\n");
68+
printf("- X25519 (Quantum-vulnerable key exchange)\n");
69+
70+
return 0;
71+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CC=gcc
2+
CFLAGS=-Wall -Wextra -std=c99
3+
LIBS=-lcrypto -lssl
4+
TARGET=basic_crypto
5+
SOURCES=main.c
6+
7+
all: $(TARGET)
8+
9+
$(TARGET): $(SOURCES)
10+
$(CC) $(CFLAGS) -o $(TARGET) $(SOURCES) $(LIBS)
11+
12+
clean:
13+
rm -f $(TARGET)
14+
15+
.PHONY: all clean

fixtures/c/makefile-crypto/main.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <stdio.h>
2+
#include <openssl/evp.h>
3+
#include <openssl/rsa.h>
4+
#include <openssl/aes.h>
5+
6+
int main() {
7+
// Basic OpenSSL usage
8+
OpenSSL_add_all_algorithms();
9+
10+
// RSA key generation
11+
EVP_PKEY_CTX *rsa_ctx = EVP_PKEY_CTX_new_id(EVP_PKEY_RSA, NULL);
12+
EVP_PKEY_keygen_init(rsa_ctx);
13+
EVP_PKEY_CTX_set_rsa_keygen_bits(rsa_ctx, 2048);
14+
15+
printf("Basic crypto setup with OpenSSL\n");
16+
printf("RSA 2048-bit key generation configured\n");
17+
18+
EVP_PKEY_CTX_free(rsa_ctx);
19+
EVP_cleanup();
20+
21+
return 0;
22+
}

test-cases/test-case-c-openssl/mv-cbom.json renamed to fixtures/c/openssl-mixed/mv-cbom.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"bomFormat": "MV-CBOM",
33
"specVersion": "1.0",
4-
"serialNumber": "urn:uuid:61406d2a-33dd-4551-9bd8-b2e273503cad",
4+
"serialNumber": "urn:uuid:f7699f6e-deb2-4df5-a35f-cdfc3e75fac2",
55
"version": 1,
66
"metadata": {
77
"component": {
8-
"name": "test-case-c-openssl",
9-
"path": "/workspace/test-cases/test-case-c-openssl"
8+
"name": "openssl-mixed",
9+
"path": "/workspace/fixtures/c/openssl-mixed"
1010
},
11-
"timestamp": "2025-09-15T17:31:16.152158659Z",
11+
"timestamp": "2025-09-15T17:50:59.203450522Z",
1212
"tools": [
1313
{
1414
"name": "cipherscope",
@@ -19,7 +19,7 @@
1919
},
2020
"cryptoAssets": [
2121
{
22-
"bom-ref": "afa4ad33-07f0-4eaf-b26e-c08f508f6ab3",
22+
"bom-ref": "8ec4b990-c242-4dce-b287-f03f5ad7d944",
2323
"assetType": "algorithm",
2424
"name": "RSA",
2525
"assetProperties": {
@@ -28,7 +28,7 @@
2828
}
2929
},
3030
{
31-
"bom-ref": "a6539be2-7d5b-4c82-9e7f-17da0b8cb16e",
31+
"bom-ref": "b0eeb295-734e-4802-84a1-c10c77b8c84d",
3232
"assetType": "algorithm",
3333
"name": "ChaCha20Poly1305",
3434
"assetProperties": {
@@ -37,7 +37,7 @@
3737
}
3838
},
3939
{
40-
"bom-ref": "cc5afa71-5e0b-4c42-ad22-30d3ff17cdcf",
40+
"bom-ref": "618e2556-e493-4d3d-b7a3-e541ccaf533e",
4141
"assetType": "algorithm",
4242
"name": "ChaCha20Poly1305",
4343
"assetProperties": {
@@ -48,9 +48,9 @@
4848
],
4949
"dependencies": [
5050
{
51-
"ref": "5f4e1435-94ed-4e02-bf51-1f2a864ebdf4",
51+
"ref": "7b79d53e-9174-40a2-ab0e-90ce576f0eea",
5252
"dependsOn": [
53-
"afa4ad33-07f0-4eaf-b26e-c08f508f6ab3"
53+
"8ec4b990-c242-4dce-b287-f03f5ad7d944"
5454
],
5555
"dependencyType": "implements"
5656
}

fixtures/c/positive/main.c

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Certificate Fixtures
2+
3+
This directory contains X.509 certificates for testing CBOM certificate parsing:
4+
5+
- `rsa-cert.pem`: RSA 2048-bit self-signed certificate (PQC vulnerable)
6+
- `ecdsa-cert.pem`: ECDSA P-256 self-signed certificate (PQC vulnerable)
7+
8+
Expected CBOM output:
9+
- 2 certificate assets with subject/issuer/validity information
10+
- 2 algorithm assets for the signature algorithms (RSA, ECDSA)
11+
- Dependencies linking certificates to their signature algorithms

0 commit comments

Comments
 (0)