Skip to content

Commit 1bfbc85

Browse files
committed
remove unnecessary artifacts
1 parent 5f3b095 commit 1bfbc85

File tree

8 files changed

+65
-104
lines changed

8 files changed

+65
-104
lines changed

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ repository = "https://example.com/cipherscope/repo"
1616

1717
[workspace.dependencies]
1818
anyhow = "1"
19-
thiserror = "1"
2019
serde = { version = "1", features = ["derive"] }
2120
serde_json = "1"
2221
toml = "0.8"
2322
regex = "1"
2423
aho-corasick = "1"
25-
once_cell = "1"
2624
rayon = "1"
2725
ignore = "0.4"
2826
clap = { version = "4", features = ["derive"] }

crates/cbom-generator/src/algorithm_detector.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::{
1515
};
1616

1717
/// Detector for cryptographic algorithms in source code
18+
#[derive(Default)]
1819
pub struct AlgorithmDetector {
1920
/// Reference to the pattern registry for algorithm definitions
2021
registry: Option<std::sync::Arc<PatternRegistry>>,
@@ -24,10 +25,7 @@ pub struct AlgorithmDetector {
2425

2526
impl AlgorithmDetector {
2627
pub fn new() -> Self {
27-
Self {
28-
registry: None,
29-
deterministic: false,
30-
}
28+
Self::default()
3129
}
3230

3331
pub fn with_registry(registry: std::sync::Arc<PatternRegistry>) -> Self {
@@ -427,12 +425,6 @@ impl AlgorithmDetector {
427425
// Note: all algorithm assets are created via create_algorithm_asset_from_spec using patterns.
428426
}
429427

430-
impl Default for AlgorithmDetector {
431-
fn default() -> Self {
432-
Self::new()
433-
}
434-
}
435-
436428
#[cfg(test)]
437429
mod tests {
438430
use super::*;

crates/cbom-generator/src/certificate_parser.rs

Lines changed: 50 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,17 @@ use uuid::Uuid;
88
use walkdir::WalkDir;
99
use x509_parser::prelude::*;
1010

11-
use crate::{
12-
AlgorithmProperties, AssetProperties, AssetType, CertificateProperties, CryptoAsset,
13-
CryptographicPrimitive,
14-
};
11+
use crate::{AssetProperties, AssetType, CertificateProperties, CryptoAsset};
1512

1613
/// Parser for X.509 certificates and related cryptographic material
14+
#[derive(Default)]
1715
pub struct CertificateParser {
1816
deterministic: bool,
1917
}
2018

2119
impl CertificateParser {
2220
pub fn new() -> Self {
23-
Self {
24-
deterministic: false,
25-
}
21+
Self::default()
2622
}
2723

2824
pub fn with_mode(deterministic: bool) -> Self {
@@ -140,13 +136,9 @@ impl CertificateParser {
140136
let issuer_name = cert.issuer().to_string();
141137
let not_valid_after = self.asn1_time_to_chrono(&cert.validity().not_after)?;
142138

143-
// Extract signature algorithm
144-
let _signature_algorithm = cert.signature_algorithm.algorithm.to_id_string();
145-
let signature_algorithm_ref = if self.deterministic {
146-
Uuid::new_v5(&Uuid::NAMESPACE_URL, b"cert:signature").to_string()
147-
} else {
148-
Uuid::new_v4().to_string()
149-
};
139+
// Extract signature algorithm and map to friendly name
140+
let signature_algorithm_oid = cert.signature_algorithm.algorithm.to_id_string();
141+
let signature_algorithm = self.get_signature_algorithm_name(&signature_algorithm_oid);
150142

151143
// Create the certificate asset
152144
let cert_bom_ref = if self.deterministic {
@@ -163,7 +155,7 @@ impl CertificateParser {
163155
subject_name,
164156
issuer_name,
165157
not_valid_after,
166-
signature_algorithm_ref: signature_algorithm_ref.clone(),
158+
signature_algorithm,
167159
}),
168160
source_library: None,
169161
evidence: None,
@@ -172,142 +164,147 @@ impl CertificateParser {
172164
Ok(cert_asset)
173165
}
174166

175-
/// Create an algorithm asset for a certificate's signature algorithm
176-
pub fn create_signature_algorithm_asset(
177-
&self,
178-
signature_algorithm_oid: &str,
179-
bom_ref: String,
180-
) -> CryptoAsset {
181-
let (name, primitive, nist_level, parameter_set) =
182-
self.map_signature_algorithm(signature_algorithm_oid);
183-
184-
CryptoAsset {
185-
bom_ref,
186-
asset_type: AssetType::Algorithm,
187-
name: Some(name),
188-
asset_properties: AssetProperties::Algorithm(AlgorithmProperties {
189-
primitive,
190-
parameter_set,
191-
nist_quantum_security_level: nist_level,
192-
}),
193-
source_library: None,
194-
evidence: None,
167+
/// Get a friendly name for the signature algorithm
168+
fn get_signature_algorithm_name(&self, oid: &str) -> String {
169+
match oid {
170+
// RSA algorithms
171+
"1.2.840.113549.1.1.11" => "RSA-SHA256".to_string(),
172+
"1.2.840.113549.1.1.12" => "RSA-SHA384".to_string(),
173+
"1.2.840.113549.1.1.13" => "RSA-SHA512".to_string(),
174+
"1.2.840.113549.1.1.5" => "RSA-SHA1".to_string(),
175+
"1.2.840.113549.1.1.4" => "RSA-MD5".to_string(),
176+
177+
// ECDSA algorithms
178+
"1.2.840.10045.4.3.2" => "ECDSA-SHA256".to_string(),
179+
"1.2.840.10045.4.3.3" => "ECDSA-SHA384".to_string(),
180+
"1.2.840.10045.4.3.4" => "ECDSA-SHA512".to_string(),
181+
"1.2.840.10045.4.1" => "ECDSA-SHA1".to_string(),
182+
183+
// DSA algorithms
184+
"1.2.840.10040.4.3" => "DSA-SHA1".to_string(),
185+
"2.16.840.1.101.3.4.3.2" => "DSA-SHA256".to_string(),
186+
187+
// Ed25519
188+
"1.3.101.112" => "Ed25519".to_string(),
189+
190+
_ => format!("Unknown ({oid})"),
195191
}
196192
}
197193

198194
/// Map signature algorithm OID to algorithm properties
195+
#[cfg(test)]
199196
fn map_signature_algorithm(
200197
&self,
201198
oid: &str,
202199
) -> (
203200
String,
204-
CryptographicPrimitive,
201+
crate::CryptographicPrimitive,
205202
u8,
206203
Option<serde_json::Value>,
207204
) {
208205
match oid {
209206
// RSA signature algorithms - all vulnerable to quantum attacks
210207
"1.2.840.113549.1.1.1" => (
211208
"RSA".to_string(),
212-
CryptographicPrimitive::Signature,
209+
crate::CryptographicPrimitive::Signature,
213210
0,
214211
None,
215212
),
216213
"1.2.840.113549.1.1.4" => (
217214
"RSA with MD5".to_string(),
218-
CryptographicPrimitive::Signature,
215+
crate::CryptographicPrimitive::Signature,
219216
0,
220217
None,
221218
),
222219
"1.2.840.113549.1.1.5" => (
223220
"RSA with SHA-1".to_string(),
224-
CryptographicPrimitive::Signature,
221+
crate::CryptographicPrimitive::Signature,
225222
0,
226223
None,
227224
),
228225
"1.2.840.113549.1.1.11" => (
229226
"RSA with SHA-256".to_string(),
230-
CryptographicPrimitive::Signature,
227+
crate::CryptographicPrimitive::Signature,
231228
0,
232229
None,
233230
),
234231
"1.2.840.113549.1.1.12" => (
235232
"RSA with SHA-384".to_string(),
236-
CryptographicPrimitive::Signature,
233+
crate::CryptographicPrimitive::Signature,
237234
0,
238235
None,
239236
),
240237
"1.2.840.113549.1.1.13" => (
241238
"RSA with SHA-512".to_string(),
242-
CryptographicPrimitive::Signature,
239+
crate::CryptographicPrimitive::Signature,
243240
0,
244241
None,
245242
),
246243

247244
// ECDSA signature algorithms - all vulnerable to quantum attacks
248245
"1.2.840.10045.4.1" => (
249246
"ECDSA with SHA-1".to_string(),
250-
CryptographicPrimitive::Signature,
247+
crate::CryptographicPrimitive::Signature,
251248
0,
252249
None,
253250
),
254251
"1.2.840.10045.4.3.1" => (
255252
"ECDSA with SHA-224".to_string(),
256-
CryptographicPrimitive::Signature,
253+
crate::CryptographicPrimitive::Signature,
257254
0,
258255
None,
259256
),
260257
"1.2.840.10045.4.3.2" => (
261258
"ECDSA with SHA-256".to_string(),
262-
CryptographicPrimitive::Signature,
259+
crate::CryptographicPrimitive::Signature,
263260
0,
264261
None,
265262
),
266263
"1.2.840.10045.4.3.3" => (
267264
"ECDSA with SHA-384".to_string(),
268-
CryptographicPrimitive::Signature,
265+
crate::CryptographicPrimitive::Signature,
269266
0,
270267
None,
271268
),
272269
"1.2.840.10045.4.3.4" => (
273270
"ECDSA with SHA-512".to_string(),
274-
CryptographicPrimitive::Signature,
271+
crate::CryptographicPrimitive::Signature,
275272
0,
276273
None,
277274
),
278275

279276
// EdDSA - also vulnerable to quantum attacks
280277
"1.3.101.112" => (
281278
"Ed25519".to_string(),
282-
CryptographicPrimitive::Signature,
279+
crate::CryptographicPrimitive::Signature,
283280
0,
284281
None,
285282
),
286283
"1.3.101.113" => (
287284
"Ed448".to_string(),
288-
CryptographicPrimitive::Signature,
285+
crate::CryptographicPrimitive::Signature,
289286
0,
290287
None,
291288
),
292289

293290
// DSA - vulnerable to quantum attacks
294291
"1.2.840.10040.4.1" => (
295292
"DSA".to_string(),
296-
CryptographicPrimitive::Signature,
293+
crate::CryptographicPrimitive::Signature,
297294
0,
298295
None,
299296
),
300297
"1.2.840.10040.4.3" => (
301298
"DSA with SHA-1".to_string(),
302-
CryptographicPrimitive::Signature,
299+
crate::CryptographicPrimitive::Signature,
303300
0,
304301
None,
305302
),
306303

307304
// Default case for unknown algorithms
308305
_ => (
309306
format!("Unknown Algorithm (OID: {})", oid),
310-
CryptographicPrimitive::Signature,
307+
crate::CryptographicPrimitive::Signature,
311308
0,
312309
None,
313310
),
@@ -338,12 +335,6 @@ impl CertificateParser {
338335
}
339336
}
340337

341-
impl Default for CertificateParser {
342-
fn default() -> Self {
343-
Self::new()
344-
}
345-
}
346-
347338
// Add base64 decoding functionality
348339
mod base64 {
349340
use anyhow::Result;
@@ -388,6 +379,7 @@ mod base64 {
388379
#[cfg(test)]
389380
mod tests {
390381
use super::*;
382+
use crate::CryptographicPrimitive;
391383

392384
#[test]
393385
fn test_certificate_parser_creation() {

0 commit comments

Comments
 (0)