sbom-tools 0.2.0

Semantic SBOM diff and analysis tool
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
//! Cryptographic-suite compliance: NSA CNSA 2.0 and NIST PQC readiness.
//!
//! Both checkers classify algorithms through the shared, input-robust
//! [`crate::model::classify_algorithm`] (family + OID + parameter +
//! elliptic-curve + guarded name fallback), so CycloneDX 1.6 CBOMs — which
//! have no `algorithmFamily` field — are evaluated instead of silently
//! passing. CNSA 2.0 is enforced as the exclusive **allowlist** it is
//! (AES-256, SHA-384/512, ML-KEM-1024, ML-DSA-87, SP 800-208 LMS/XMSS/HSS);
//! anything recognized-but-not-approved is an Error and anything
//! unrecognizable is a Warning, never an implicit pass. Protocol assets
//! (TLS version, cipher suites, IKEv2 transforms, crypto references) are
//! evaluated under both standards by resolving bom-refs through the SBOM
//! index and word-boundary-scanning cipher-suite names.

use super::*;
use crate::model::{
    AlgorithmClass, AlgorithmClassification, Component, CryptoAssetType, NormalizedSbomIndex,
    PqcKind, ProtocolProperties, ProtocolType, classify_algorithm, classify_algorithm_names,
    classify_algorithm_names_guarded, worst_classification,
};

/// Outcome of checking one classified algorithm against the CNSA 2.0
/// allowlist.
enum CnsaVerdict {
    /// On the CNSA 2.0 allowlist.
    Approved,
    /// Recognized and definitively not CNSA 2.0; `detail` completes the
    /// sentence "'<component>' <detail>".
    NotApproved {
        rule_id: &'static str,
        detail: String,
    },
    /// Not recognizable — cannot verify (Warning, never a silent pass).
    Unknown,
}

/// Classify the algorithm identity of a crypto-asset component.
fn classify_crypto_component(comp: &Component) -> AlgorithmClassification {
    let cp = comp.crypto_properties.as_ref();
    let algo = cp.and_then(|c| c.algorithm_properties.as_ref());
    classify_algorithm(
        algo.and_then(|a| a.algorithm_family.as_deref()),
        Some(&comp.name),
        cp.and_then(|c| c.oid.as_deref()),
        algo.and_then(|a| a.parameter_set_identifier.as_deref()),
        algo.and_then(|a| a.elliptic_curve.as_deref()),
    )
}

/// The declared `classicalSecurityLevel` of a component's algorithm
/// properties — evidence of the key size (e.g., AES-256) that must survive
/// bom-ref resolution so referenced assets are judged with the same
/// evidence as directly evaluated ones.
fn classical_bits_of(comp: &Component) -> Option<u32> {
    comp.crypto_properties
        .as_ref()
        .and_then(|c| c.algorithm_properties.as_ref())
        .and_then(|a| a.classical_security_level)
}

/// Classify whatever a crypto bom-ref (signatureAlgorithmRef, cipher-suite
/// algorithm ref, IKEv2 transform ref, …) points at: resolve it through the
/// SBOM index to the referenced component when possible — carrying along its
/// declared `classicalSecurityLevel` — otherwise fall back to guarded
/// word-boundary token matching on the raw ref string, reporting the most
/// severe mention (opaque refs like "sig-algo-42" classify as Unknown rather
/// than silently passing checks).
fn classify_bom_ref(
    bom_ref: &str,
    sbom: &NormalizedSbom,
    index: &NormalizedSbomIndex,
) -> (AlgorithmClassification, Option<u32>) {
    match resolve_component(bom_ref, sbom, index) {
        Some(target) => (classify_crypto_component(target), classical_bits_of(target)),
        None => (
            worst_classification(classify_algorithm_names_guarded(bom_ref))
                .unwrap_or_else(AlgorithmClassification::unknown),
            None,
        ),
    }
}

/// Resolve a bom-ref to the referenced component, if it exists.
fn resolve_component<'a>(
    bom_ref: &str,
    sbom: &'a NormalizedSbom,
    index: &NormalizedSbomIndex,
) -> Option<&'a Component> {
    index
        .resolve_bom_ref(bom_ref)
        .and_then(|id| sbom.components.get(id))
}

/// Judge a classified algorithm against the CNSA 2.0 exclusive allowlist:
/// AES-256, SHA-384/SHA-512, ML-KEM-1024, ML-DSA-87, and the SP 800-208
/// stateful hash-based signatures (LMS/XMSS/HSS). `classical_bits` is the
/// declared `classicalSecurityLevel`, accepted as evidence of the AES key
/// size when no parameter set is present.
fn cnsa2_verdict(cls: &AlgorithmClassification, classical_bits: Option<u32>) -> CnsaVerdict {
    use AlgorithmClass as C;
    match cls.class {
        C::Broken => CnsaVerdict::NotApproved {
            rule_id: "SBOM-CNSA2-ALG-005",
            detail: format!(
                "uses {}, a broken legacy algorithm not permitted by CNSA 2.0",
                cls.label()
            ),
        },
        C::ClassicalQuantumVulnerable => CnsaVerdict::NotApproved {
            rule_id: "SBOM-CNSA2-ALG-006",
            detail: format!(
                "({}) is quantum-vulnerable, must migrate to CNSA 2.0 approved algorithm",
                cls.label()
            ),
        },
        C::Symmetric => {
            if cls.family.as_deref() == Some("AES") {
                let bits = cls.parameter_bits().or(classical_bits);
                if bits == Some(256) {
                    CnsaVerdict::Approved
                } else {
                    let shown = bits.map_or_else(|| "unspecified".to_string(), |b| b.to_string());
                    CnsaVerdict::NotApproved {
                        rule_id: "SBOM-CNSA2-ALG-001",
                        detail: format!("uses AES-{shown}, CNSA 2.0 requires AES-256 only"),
                    }
                }
            } else {
                CnsaVerdict::NotApproved {
                    rule_id: "SBOM-CNSA2-ALG-008",
                    detail: format!(
                        "uses {}, which is not a CNSA 2.0 approved algorithm",
                        cls.label()
                    ),
                }
            }
        }
        C::Sha2 => match cls.parameter_bits() {
            Some(384 | 512) => CnsaVerdict::Approved,
            Some(_) => CnsaVerdict::NotApproved {
                rule_id: "SBOM-CNSA2-ALG-002",
                detail: "uses a SHA-2 digest < 384 bits, CNSA 2.0 requires SHA-384 or SHA-512"
                    .to_string(),
            },
            None => CnsaVerdict::NotApproved {
                rule_id: "SBOM-CNSA2-ALG-002",
                detail: "uses SHA-2 with an unspecified digest size, CNSA 2.0 requires \
                         SHA-384 or SHA-512"
                    .to_string(),
            },
        },
        C::Sha3 | C::OtherHash => CnsaVerdict::NotApproved {
            rule_id: "SBOM-CNSA2-ALG-008",
            detail: format!(
                "uses {}, which is not a CNSA 2.0 approved algorithm (CNSA 2.0 hashes \
                 are SHA-384 and SHA-512)",
                cls.label()
            ),
        },
        C::PostQuantum(kind) => match kind {
            PqcKind::MlKem => match cls.parameter.as_deref() {
                Some("1024") => CnsaVerdict::Approved,
                Some(p) => CnsaVerdict::NotApproved {
                    rule_id: "SBOM-CNSA2-ALG-003",
                    detail: format!("uses ML-KEM-{p}, CNSA 2.0 requires ML-KEM-1024 only"),
                },
                None => CnsaVerdict::NotApproved {
                    rule_id: "SBOM-CNSA2-ALG-003",
                    detail: "uses ML-KEM with an unspecified parameter set, CNSA 2.0 \
                             requires ML-KEM-1024 only"
                        .to_string(),
                },
            },
            PqcKind::MlDsa => match cls.parameter.as_deref() {
                Some("87") => CnsaVerdict::Approved,
                Some(p) => CnsaVerdict::NotApproved {
                    rule_id: "SBOM-CNSA2-ALG-004",
                    detail: format!("uses ML-DSA-{p}, CNSA 2.0 requires ML-DSA-87 only"),
                },
                None => CnsaVerdict::NotApproved {
                    rule_id: "SBOM-CNSA2-ALG-004",
                    detail: "uses ML-DSA with an unspecified parameter set, CNSA 2.0 \
                             requires ML-DSA-87 only"
                        .to_string(),
                },
            },
            // SP 800-208 stateful hash-based signatures are CNSA 2.0 approved
            // (the mandated firmware/software-signing algorithms).
            PqcKind::Lms | PqcKind::Xmss | PqcKind::Hss => CnsaVerdict::Approved,
            PqcKind::SlhDsa => CnsaVerdict::NotApproved {
                rule_id: "SBOM-CNSA2-ALG-008",
                detail: "uses SLH-DSA, which is NIST-approved (FIPS 205) but not part of \
                         CNSA 2.0"
                    .to_string(),
            },
            PqcKind::FnDsa => CnsaVerdict::NotApproved {
                rule_id: "SBOM-CNSA2-ALG-008",
                detail: "uses FN-DSA/Falcon, which is not a CNSA 2.0 approved algorithm"
                    .to_string(),
            },
        },
        C::Unknown => CnsaVerdict::Unknown,
    }
}

/// The requirement string displayed for each CNSA 2.0 rule.
fn cnsa2_requirement(rule_id: &str) -> &'static str {
    match rule_id {
        "SBOM-CNSA2-ALG-001" => "CNSA 2.0 Symmetric",
        "SBOM-CNSA2-ALG-002" => "CNSA 2.0 Hash",
        "SBOM-CNSA2-ALG-003" => "CNSA 2.0 KEM",
        "SBOM-CNSA2-ALG-004" => "CNSA 2.0 Signature",
        "SBOM-CNSA2-ALG-005" => "CNSA 2.0: broken algorithm",
        "SBOM-CNSA2-ALG-006" => "CNSA 2.0 PQC Migration",
        _ => "CNSA 2.0 Approved Algorithms",
    }
}

/// Parse a TLS/DTLS version string tolerantly, shared by the CNSA 2.0 and
/// PQC version gates so the two standards cannot disagree on the same
/// input: "1.3", "TLSv1.3", "tls1.3", "TLS 1.3", "v1.3", "1.3.0", and
/// "DTLSv1.3" all yield `(1, 3)`; "TLSv1" yields `(1, 0)`. Returns `None`
/// when no leading major version can be parsed.
fn parse_tls_version(v: &str) -> Option<(u32, u32)> {
    let s = v.trim().to_ascii_lowercase();
    let s = s
        .strip_prefix("dtls")
        .or_else(|| s.strip_prefix("tls"))
        .unwrap_or(&s)
        .trim_start();
    let s = s.strip_prefix('v').unwrap_or(s).trim_start();
    let mut parts = s.split('.');
    let major: u32 = parts.next()?.trim().parse().ok()?;
    let minor: u32 = parts.next().map_or(Some(0), |p| p.trim().parse().ok())?;
    Some((major, minor))
}

/// Whether the TLS/DTLS `version` string is below `min`. Unparseable
/// versions return `false` (the callers report them as "cannot verify").
fn tls_version_below(version: &str, min: (u32, u32)) -> bool {
    parse_tls_version(version).is_some_and(|v| v < min)
}

/// Whether a protocol asset is SSL (obsolete under every profile here).
fn is_ssl_protocol(proto: &ProtocolProperties) -> bool {
    matches!(&proto.protocol_type, ProtocolType::Other(s) if s.to_lowercase().contains("ssl"))
}

impl ComplianceChecker {
    // ════════════════════════════════════════════════════════════════════
    // CNSA 2.0 compliance checks
    // ════════════════════════════════════════════════════════════════════

    pub(crate) fn check_cnsa2(&self, sbom: &NormalizedSbom, violations: &mut Vec<Violation>) {
        use crate::model::ComponentType;

        let index = sbom.build_index();

        // Count only assets that actually receive CNSA 2.0 evaluation, so an
        // inventory of unevaluable assets cannot satisfy the CNSA2-000 gate.
        let mut crypto_assets_evaluated = 0usize;

        for comp in sbom.components.values() {
            if comp.component_type != ComponentType::Cryptographic {
                continue;
            }
            let Some(cp) = &comp.crypto_properties else {
                continue;
            };

            match cp.asset_type {
                CryptoAssetType::Algorithm => {
                    crypto_assets_evaluated += 1;
                    Self::check_cnsa2_algorithm(comp, cp, violations);
                }
                CryptoAssetType::Certificate => {
                    // CNSA2-CERT-001: cert must use a CNSA 2.0 signature
                    // algorithm. Only certificates carrying a signature
                    // algorithm reference are verifiable (and counted).
                    if let Some(cert) = &cp.certificate_properties
                        && let Some(sig_ref) = &cert.signature_algorithm_ref
                    {
                        crypto_assets_evaluated += 1;
                        let (cls, bits) = classify_bom_ref(sig_ref, sbom, &index);
                        match cnsa2_verdict(&cls, bits) {
                            CnsaVerdict::Approved => {}
                            CnsaVerdict::NotApproved { detail, .. } => {
                                violations.push(Violation {
                                    severity: ViolationSeverity::Error,
                                    category: ViolationCategory::CryptographyInfo,
                                    message: format!(
                                        "Certificate '{}' signed with non-CNSA 2.0 algorithm: \
                                         {detail} (ref: {sig_ref})",
                                        comp.name
                                    ),
                                    element: Some(comp.name.clone()),
                                    requirement: "CNSA 2.0 Certificate".to_string(),
                                    rule_id: "SBOM-CNSA2-CERT-001",
                                    component_id: Some(comp.canonical_id.value().to_string()),
                                    counts: None,
                                    standard_refs: Vec::new(),
                                });
                            }
                            // An unclassifiable signature ref must warn, never
                            // silently pass — mirrors SBOM-CNSA2-ALG-UNKNOWN
                            // (previously a certificate-only CBOM whose sig
                            // ref was opaque reported 100% compliant).
                            CnsaVerdict::Unknown => {
                                violations.push(Violation {
                                    severity: ViolationSeverity::Warning,
                                    category: ViolationCategory::CryptographyInfo,
                                    message: format!(
                                        "Certificate '{}' signature algorithm ref '{sig_ref}' \
                                         cannot be resolved or classified; unable to verify \
                                         against the CNSA 2.0 allowlist",
                                        comp.name
                                    ),
                                    element: Some(comp.name.clone()),
                                    requirement: "CNSA 2.0: certificate signature identification"
                                        .to_string(),
                                    rule_id: "SBOM-CNSA2-CERT-UNKNOWN",
                                    component_id: Some(comp.canonical_id.value().to_string()),
                                    counts: None,
                                    standard_refs: Vec::new(),
                                });
                            }
                        }
                    }
                }
                CryptoAssetType::Protocol => {
                    if let Some(proto) = &cp.protocol_properties {
                        crypto_assets_evaluated += 1;
                        Self::check_cnsa2_protocol(comp, proto, sbom, &index, violations);
                    }
                }
                // Key material and unrecognized asset kinds get no CNSA 2.0
                // evaluation, so they intentionally do NOT count toward the
                // inventory gate: an SBOM documenting only keys would
                // otherwise "pass" a standard that never looked at anything.
                _ => {}
            }
        }

        // CNSA2-000: no cryptographic inventory to evaluate — a "compliant"
        // verdict here would be a false CNSA 2.0 claim, so fail.
        if crypto_assets_evaluated == 0 {
            violations.push(Violation {
                severity: ViolationSeverity::Error,
                category: ViolationCategory::CryptographyInfo,
                message: "No cryptographic inventory (CBOM) with evaluable assets found; \
                          CNSA 2.0 compliance cannot be asserted. Provide algorithm, \
                          certificate, or protocol cryptographic asset components."
                    .to_string(),
                element: None,
                requirement: "CNSA 2.0: cryptographic inventory required".to_string(),
                rule_id: "SBOM-CNSA2-000",
                component_id: None,
                counts: None,
                standard_refs: Vec::new(),
            });
        }
    }

    /// Evaluate a single algorithm asset against the CNSA 2.0 allowlist plus
    /// the declared-quantum-level rules (ALG-006/ALG-007).
    fn check_cnsa2_algorithm(
        comp: &Component,
        cp: &crate::model::CryptoProperties,
        violations: &mut Vec<Violation>,
    ) {
        let cls = classify_crypto_component(comp);

        // Declared-quantum-level rules. Symmetric/hash primitives are allowed
        // at lower declared levels (Grover, not Shor).
        if let Some(algo) = &cp.algorithm_properties
            && let Some(ql) = algo.nist_quantum_security_level
            && ql < 5
        {
            let is_symmetric_or_hash = matches!(
                algo.primitive,
                crate::model::CryptoPrimitive::Ae
                    | crate::model::CryptoPrimitive::BlockCipher
                    | crate::model::CryptoPrimitive::Hash
                    | crate::model::CryptoPrimitive::Mac
                    | crate::model::CryptoPrimitive::Kdf
            );
            if !is_symmetric_or_hash {
                if ql == 0 {
                    // Classified classical families already get the
                    // family-based ALG-006 below — don't double-report.
                    if cls.class != AlgorithmClass::ClassicalQuantumVulnerable {
                        violations.push(Violation {
                            severity: ViolationSeverity::Error,
                            category: ViolationCategory::CryptographyInfo,
                            message: format!(
                                "'{}' is quantum-vulnerable (level {}), must migrate to PQC",
                                comp.name, ql
                            ),
                            element: Some(comp.name.clone()),
                            requirement: "CNSA 2.0 PQC Migration".to_string(),
                            rule_id: "SBOM-CNSA2-ALG-006",
                            component_id: Some(comp.canonical_id.value().to_string()),
                            counts: None,
                            standard_refs: Vec::new(),
                        });
                    }
                } else {
                    violations.push(Violation {
                        severity: ViolationSeverity::Error,
                        category: ViolationCategory::CryptographyInfo,
                        message: format!(
                            "'{}' quantum level {} < 5, CNSA 2.0 requires Level 5",
                            comp.name, ql
                        ),
                        element: Some(comp.name.clone()),
                        requirement: "CNSA 2.0 Level 5".to_string(),
                        rule_id: "SBOM-CNSA2-ALG-007",
                        component_id: Some(comp.canonical_id.value().to_string()),
                        counts: None,
                        standard_refs: Vec::new(),
                    });
                }
            }
        }

        let classical_bits = cp
            .algorithm_properties
            .as_ref()
            .and_then(|a| a.classical_security_level);
        match cnsa2_verdict(&cls, classical_bits) {
            CnsaVerdict::Approved => {}
            CnsaVerdict::NotApproved { rule_id, detail } => {
                violations.push(Violation {
                    severity: ViolationSeverity::Error,
                    category: ViolationCategory::CryptographyInfo,
                    message: format!("'{}' {detail}", comp.name),
                    element: Some(comp.name.clone()),
                    requirement: cnsa2_requirement(rule_id).to_string(),
                    rule_id,
                    component_id: Some(comp.canonical_id.value().to_string()),
                    counts: None,
                    standard_refs: Vec::new(),
                });
            }
            CnsaVerdict::Unknown => {
                // A declared level-0 asset already produced the ALG-006 Error
                // above; the extra "cannot classify" Warning is then noise.
                let declared_vulnerable = cp
                    .algorithm_properties
                    .as_ref()
                    .and_then(|a| a.nist_quantum_security_level)
                    == Some(0);
                if !declared_vulnerable {
                    violations.push(Violation {
                        severity: ViolationSeverity::Warning,
                        category: ViolationCategory::CryptographyInfo,
                        message: format!(
                            "'{}' cannot be classified (no recognizable algorithm family, \
                             OID, or name); unable to verify against the CNSA 2.0 allowlist",
                            comp.name
                        ),
                        element: Some(comp.name.clone()),
                        requirement: "CNSA 2.0: algorithm identification".to_string(),
                        rule_id: "SBOM-CNSA2-ALG-UNKNOWN",
                        component_id: Some(comp.canonical_id.value().to_string()),
                        counts: None,
                        standard_refs: Vec::new(),
                    });
                }
            }
        }
    }

    /// Evaluate a protocol asset under CNSA 2.0: TLS 1.3 required, and every
    /// resolvable cipher-suite algorithm / IKEv2 transform / crypto reference
    /// must be on the allowlist.
    fn check_cnsa2_protocol(
        comp: &Component,
        proto: &ProtocolProperties,
        sbom: &NormalizedSbom,
        index: &NormalizedSbomIndex,
        violations: &mut Vec<Violation>,
    ) {
        // PROTO-001: version gate — CNSA 2.0 network guidance requires TLS 1.3.
        if is_ssl_protocol(proto) {
            violations.push(Violation {
                severity: ViolationSeverity::Error,
                category: ViolationCategory::CryptographyInfo,
                message: format!(
                    "Protocol '{}' uses SSL, which is obsolete; CNSA 2.0 requires TLS 1.3",
                    comp.name
                ),
                element: Some(comp.name.clone()),
                requirement: "CNSA 2.0 Protocol".to_string(),
                rule_id: "SBOM-CNSA2-PROTO-001",
                component_id: Some(comp.canonical_id.value().to_string()),
                counts: None,
                standard_refs: Vec::new(),
            });
        } else if matches!(proto.protocol_type, ProtocolType::Tls | ProtocolType::Dtls)
            && proto.version.as_deref().and_then(parse_tls_version) != Some((1, 3))
        {
            // Tolerant version parsing: "TLSv1.3", "tls1.3", "1.3.0", … all
            // count as TLS 1.3 (previously exact string equality with "1.3"
            // failed spec-compliant spellings). Missing or unparseable
            // versions remain an Error: an allowlist standard cannot
            // affirm TLS 1.3 from a version it cannot read.
            let shown = proto.version.as_deref().map_or_else(
                || "an unspecified version".to_string(),
                |v| format!("version {v}"),
            );
            violations.push(Violation {
                severity: ViolationSeverity::Error,
                category: ViolationCategory::CryptographyInfo,
                message: format!(
                    "Protocol '{}' uses {} {shown}, CNSA 2.0 requires TLS 1.3",
                    comp.name,
                    proto.protocol_type.to_string().to_uppercase()
                ),
                element: Some(comp.name.clone()),
                requirement: "CNSA 2.0 Protocol".to_string(),
                rule_id: "SBOM-CNSA2-PROTO-001",
                component_id: Some(comp.canonical_id.value().to_string()),
                counts: None,
                standard_refs: Vec::new(),
            });
        }

        // Collect non-allowlisted algorithms per source, deduplicated by label.
        let mut push_proto_violation = |context: String, offenders: Vec<String>| {
            if offenders.is_empty() {
                return;
            }
            violations.push(Violation {
                severity: ViolationSeverity::Error,
                category: ViolationCategory::CryptographyInfo,
                message: format!(
                    "Protocol '{}' {context} non-CNSA 2.0 algorithms: {}",
                    comp.name,
                    offenders.join(", ")
                ),
                element: Some(comp.name.clone()),
                requirement: "CNSA 2.0 Protocol".to_string(),
                rule_id: "SBOM-CNSA2-PROTO-002",
                component_id: Some(comp.canonical_id.value().to_string()),
                counts: None,
                standard_refs: Vec::new(),
            });
        };
        // References that resolve nowhere and carry no recognizable token
        // receive no effective check — collect them so the protocol warns
        // instead of silently satisfying the CNSA2-000 inventory gate.
        let mut unverifiable: Vec<String> = Vec::new();
        let record =
            |cls: &AlgorithmClassification, bits: Option<u32>, offenders: &mut Vec<String>| {
                if let CnsaVerdict::NotApproved { .. } = cnsa2_verdict(cls, bits) {
                    let label = cls.label();
                    if !offenders.contains(&label) {
                        offenders.push(label);
                    }
                }
            };

        // PROTO-002: cipher suites — both the algorithm refs (resolved
        // through the index, with the referenced asset's declared
        // classicalSecurityLevel as key-size evidence, or token-scanned when
        // unresolvable) and a word-boundary scan of the suite name.
        for suite in &proto.cipher_suites {
            let mut offenders = Vec::new();
            for algo_ref in &suite.algorithms {
                let (cls, bits) = classify_bom_ref(algo_ref, sbom, index);
                if cls.class == AlgorithmClass::Unknown {
                    unverifiable.push(algo_ref.clone());
                } else {
                    record(&cls, bits, &mut offenders);
                }
            }
            if let Some(name) = &suite.name {
                for cls in classify_algorithm_names(name) {
                    record(&cls, None, &mut offenders);
                }
            }
            push_proto_violation(
                format!(
                    "cipher suite '{}' includes",
                    suite.name.as_deref().unwrap_or("(unnamed)")
                ),
                offenders,
            );
        }

        // PROTO-002: IKEv2 transform types.
        if let Some(ike) = &proto.ikev2_transform_types {
            let mut offenders = Vec::new();
            for r in ike
                .encr
                .iter()
                .chain(&ike.prf)
                .chain(&ike.integ)
                .chain(&ike.ke)
            {
                let (cls, bits) = classify_bom_ref(r, sbom, index);
                if cls.class == AlgorithmClass::Unknown {
                    unverifiable.push(r.clone());
                } else {
                    record(&cls, bits, &mut offenders);
                }
            }
            push_proto_violation("IKEv2 transforms include".to_string(), offenders);
        }

        // PROTO-002: crypto reference array. Only algorithm assets are judged
        // here — referenced certificates/keys are evaluated as their own
        // assets. Unresolvable refs get the token-scan fallback.
        let mut offenders = Vec::new();
        for r in &proto.crypto_ref_array {
            match resolve_component(r, sbom, index) {
                Some(target) => {
                    if target
                        .crypto_properties
                        .as_ref()
                        .is_some_and(|c| c.asset_type == CryptoAssetType::Algorithm)
                    {
                        record(
                            &classify_crypto_component(target),
                            classical_bits_of(target),
                            &mut offenders,
                        );
                    }
                }
                None => {
                    if let Some(cls) = worst_classification(classify_algorithm_names_guarded(r)) {
                        record(&cls, None, &mut offenders);
                    } else {
                        unverifiable.push(r.clone());
                    }
                }
            }
        }
        push_proto_violation("references".to_string(), offenders);

        // A protocol whose references are all opaque, or that documents
        // nothing evaluable at all (no SSL/TLS/DTLS version gate, no cipher
        // suites, no transforms, no references), must warn rather than
        // silently satisfying the CNSA2-000 inventory gate — mirrors
        // SBOM-CNSA2-ALG-UNKNOWN.
        let substantive = is_ssl_protocol(proto)
            || matches!(proto.protocol_type, ProtocolType::Tls | ProtocolType::Dtls)
            || !proto.cipher_suites.is_empty()
            || proto.ikev2_transform_types.is_some()
            || !proto.crypto_ref_array.is_empty();
        if !unverifiable.is_empty() {
            violations.push(Violation {
                severity: ViolationSeverity::Warning,
                category: ViolationCategory::CryptographyInfo,
                message: format!(
                    "Protocol '{}' has crypto references that cannot be resolved or \
                     classified: {}; unable to verify against the CNSA 2.0 allowlist",
                    comp.name,
                    unverifiable.join(", ")
                ),
                element: Some(comp.name.clone()),
                requirement: "CNSA 2.0: protocol algorithm identification".to_string(),
                rule_id: "SBOM-CNSA2-PROTO-UNKNOWN",
                component_id: Some(comp.canonical_id.value().to_string()),
                counts: None,
                standard_refs: Vec::new(),
            });
        } else if !substantive {
            violations.push(Violation {
                severity: ViolationSeverity::Warning,
                category: ViolationCategory::CryptographyInfo,
                message: format!(
                    "Protocol '{}' documents no version, cipher suites, or algorithm \
                     references; protocol algorithms cannot be verified against the \
                     CNSA 2.0 allowlist",
                    comp.name
                ),
                element: Some(comp.name.clone()),
                requirement: "CNSA 2.0: protocol algorithm identification".to_string(),
                rule_id: "SBOM-CNSA2-PROTO-UNKNOWN",
                component_id: Some(comp.canonical_id.value().to_string()),
                counts: None,
                standard_refs: Vec::new(),
            });
        }
    }

    // ════════════════════════════════════════════════════════════════════
    // NIST PQC Readiness checks
    // ════════════════════════════════════════════════════════════════════

    pub(crate) fn check_nist_pqc(&self, sbom: &NormalizedSbom, violations: &mut Vec<Violation>) {
        use crate::model::ComponentType;

        let index = sbom.build_index();

        // Track whether we actually evaluated any cryptographic asset. A tool
        // asserting PQC compliance must not report "compliant" when it found
        // no cryptographic inventory to evaluate. Only assets that receive a
        // substantive check are counted.
        let mut crypto_assets_evaluated = 0usize;

        for comp in sbom.components.values() {
            if comp.component_type != ComponentType::Cryptographic {
                continue;
            }
            let Some(cp) = &comp.crypto_properties else {
                continue;
            };

            match cp.asset_type {
                CryptoAssetType::Algorithm => {
                    crypto_assets_evaluated += 1;
                    Self::check_pqc_algorithm(comp, cp, violations);
                }
                CryptoAssetType::Certificate => {
                    // PQC-CERT-001: certificate signature algorithm must not be
                    // broken or quantum-vulnerable. Resolved through the
                    // bom-ref index, with a token-match fallback on the raw
                    // ref string.
                    if let Some(cert) = &cp.certificate_properties
                        && let Some(sig_ref) = &cert.signature_algorithm_ref
                    {
                        crypto_assets_evaluated += 1;
                        let (cls, _) = classify_bom_ref(sig_ref, sbom, &index);
                        let problem = match cls.class {
                            AlgorithmClass::Broken => Some("broken algorithm (SP 800-131A)"),
                            AlgorithmClass::ClassicalQuantumVulnerable => {
                                Some("quantum-vulnerable algorithm, must migrate to PQC (IR 8547)")
                            }
                            _ => None,
                        };
                        if let Some(problem) = problem {
                            violations.push(Violation {
                                severity: ViolationSeverity::Error,
                                category: ViolationCategory::CryptographyInfo,
                                message: format!(
                                    "Certificate '{}' signed with {}{problem} (ref: {sig_ref})",
                                    comp.name,
                                    cls.label()
                                ),
                                element: Some(comp.name.clone()),
                                requirement: "IR 8547: certificate signature".to_string(),
                                rule_id: "SBOM-PQC-CERT-001",
                                component_id: Some(comp.canonical_id.value().to_string()),
                                counts: None,
                                standard_refs: Vec::new(),
                            });
                        } else if cls.class == AlgorithmClass::Unknown {
                            // An unclassifiable signature ref must warn, never
                            // silently pass — mirrors SBOM-CNSA2-ALG-UNKNOWN
                            // (previously a certificate-only CBOM whose sig
                            // ref was opaque reported 100% PQC-ready).
                            violations.push(Violation {
                                severity: ViolationSeverity::Warning,
                                category: ViolationCategory::CryptographyInfo,
                                message: format!(
                                    "Certificate '{}' signature algorithm ref '{sig_ref}' \
                                     cannot be resolved or classified; unable to verify \
                                     PQC readiness",
                                    comp.name
                                ),
                                element: Some(comp.name.clone()),
                                requirement: "IR 8547: certificate signature identification"
                                    .to_string(),
                                rule_id: "SBOM-PQC-CERT-UNKNOWN",
                                component_id: Some(comp.canonical_id.value().to_string()),
                                counts: None,
                                standard_refs: Vec::new(),
                            });
                        }
                    }
                }
                CryptoAssetType::Protocol => {
                    if let Some(proto) = &cp.protocol_properties {
                        crypto_assets_evaluated += 1;
                        Self::check_pqc_protocol(comp, proto, sbom, &index, violations);
                    }
                }
                CryptoAssetType::RelatedCryptoMaterial => {
                    // PQC-KEY-001: symmetric key < 128 bits. Only material we
                    // actually evaluate (symmetric keys with a declared size)
                    // counts toward the inventory gate.
                    if let Some(mat) = &cp.related_crypto_material_properties
                        && let Some(size) = mat.size
                    {
                        let is_symmetric = matches!(
                            mat.material_type,
                            crate::model::CryptoMaterialType::SymmetricKey
                                | crate::model::CryptoMaterialType::SecretKey
                        );
                        if is_symmetric {
                            crypto_assets_evaluated += 1;
                            if size < 128 {
                                violations.push(Violation {
                                    severity: ViolationSeverity::Error,
                                    category: ViolationCategory::CryptographyInfo,
                                    message: format!(
                                        "'{}' symmetric key size {} bits < 128 minimum",
                                        comp.name, size
                                    ),
                                    element: Some(comp.name.clone()),
                                    requirement: "NIST: minimum key size".to_string(),
                                    rule_id: "SBOM-PQC-KEY-001",
                                    component_id: Some(comp.canonical_id.value().to_string()),
                                    counts: None,
                                    standard_refs: Vec::new(),
                                });
                            }
                        }
                    }
                }
                // Unrecognized asset kinds receive no evaluation and do not
                // count toward the inventory gate.
                _ => {}
            }
        }

        // PQC-000: no cryptographic inventory. Reporting "compliant" when there
        // was nothing to evaluate is a false PQC-readiness claim, so fail.
        if crypto_assets_evaluated == 0 {
            violations.push(Violation {
                severity: ViolationSeverity::Error,
                category: ViolationCategory::CryptographyInfo,
                message: "No cryptographic inventory (CBOM) with evaluable assets found; \
                          NIST PQC readiness cannot be asserted. Provide algorithm, \
                          certificate, or protocol cryptographic asset components."
                    .to_string(),
                element: None,
                requirement: "IR 8547: cryptographic inventory required".to_string(),
                rule_id: "SBOM-PQC-000",
                component_id: None,
                counts: None,
                standard_refs: Vec::new(),
            });
        }
    }

    /// Evaluate a single algorithm asset for NIST PQC readiness.
    fn check_pqc_algorithm(
        comp: &Component,
        cp: &crate::model::CryptoProperties,
        violations: &mut Vec<Violation>,
    ) {
        let algo = cp.algorithm_properties.as_ref();
        let cls = classify_crypto_component(comp);
        let ql = algo.and_then(|a| a.nist_quantum_security_level);

        // PQC-001: quantum-vulnerable algorithm. A classical public-key
        // algorithm (RSA/ECDSA/ECDH/DH/DSA/EdDSA/…) is broken by Shor's
        // algorithm regardless of key size, so the classification alone is
        // authoritative — including via OID, elliptic-curve field, or name
        // when algorithmFamily is absent (CycloneDX 1.6). A declared level 0
        // also fires, unless the asset is already reported as Broken.
        let classical = cls.class == AlgorithmClass::ClassicalQuantumVulnerable;
        if classical || (ql == Some(0) && cls.class != AlgorithmClass::Broken) {
            let shown = if cls.family.is_some() {
                cls.label()
            } else {
                "classical".to_string()
            };
            violations.push(Violation {
                severity: ViolationSeverity::Error,
                category: ViolationCategory::CryptographyInfo,
                message: format!(
                    "'{}' ({shown}) is quantum-vulnerable and must migrate to PQC (IR 8547)",
                    comp.name
                ),
                element: Some(comp.name.clone()),
                requirement: "IR 8547: quantum-vulnerable".to_string(),
                rule_id: "SBOM-PQC-001",
                component_id: Some(comp.canonical_id.value().to_string()),
                counts: None,
                standard_refs: Vec::new(),
            });
        }

        // PQC-012: missing quantum security level
        if ql.is_none() {
            violations.push(Violation {
                severity: ViolationSeverity::Warning,
                category: ViolationCategory::CryptographyInfo,
                message: format!("'{}' missing nistQuantumSecurityLevel field", comp.name),
                element: Some(comp.name.clone()),
                requirement: "IR 8547: quantum assessment required".to_string(),
                rule_id: "SBOM-PQC-012",
                component_id: Some(comp.canonical_id.value().to_string()),
                counts: None,
                standard_refs: Vec::new(),
            });
        }

        // PQC-005: broken/disallowed algorithms per SP 800-131A, via the
        // shared classifier (catches spelling variants like "SHA1"/"TDES"/
        // "ARC4" and OID/name-only CycloneDX 1.6 assets).
        if cls.class == AlgorithmClass::Broken {
            violations.push(Violation {
                severity: ViolationSeverity::Error,
                category: ViolationCategory::CryptographyInfo,
                message: format!(
                    "'{}' ({}) is broken/disallowed per SP 800-131A",
                    comp.name,
                    cls.label()
                ),
                element: Some(comp.name.clone()),
                requirement: "SP 800-131A: disallowed".to_string(),
                rule_id: "SBOM-PQC-005",
                component_id: Some(comp.canonical_id.value().to_string()),
                counts: None,
                standard_refs: Vec::new(),
            });
        }

        // PQC-008: ECB mode
        if algo.and_then(|a| a.mode.as_ref()) == Some(&crate::model::CryptoMode::Ecb) {
            violations.push(Violation {
                severity: ViolationSeverity::Error,
                category: ViolationCategory::CryptographyInfo,
                message: format!(
                    "'{}' uses ECB mode, disallowed per SP 800-131A Rev 3",
                    comp.name
                ),
                element: Some(comp.name.clone()),
                requirement: "SP 800-131A Rev 3: ECB disallowed".to_string(),
                rule_id: "SBOM-PQC-008",
                component_id: Some(comp.canonical_id.value().to_string()),
                counts: None,
                standard_refs: Vec::new(),
            });
        }

        // PQC-009: approved PQC (informational). FIPS 203/204/205 finals and
        // the SP 800-208 stateful hash-based signatures both qualify; FN-DSA
        // (Falcon) is recognized but not yet standardized, so it gets no
        // approval note.
        if let AlgorithmClass::PostQuantum(kind) = cls.class {
            let approval = match kind {
                PqcKind::MlKem | PqcKind::MlDsa | PqcKind::SlhDsa => Some("FIPS 203/204/205"),
                PqcKind::Lms | PqcKind::Xmss | PqcKind::Hss => {
                    Some("SP 800-208 stateful hash-based signature")
                }
                PqcKind::FnDsa => None,
            };
            if let Some(approval) = approval {
                violations.push(Violation {
                    severity: ViolationSeverity::Info,
                    category: ViolationCategory::CryptographyInfo,
                    message: format!(
                        "'{}' uses NIST-approved PQC algorithm ({approval})",
                        comp.name
                    ),
                    element: Some(comp.name.clone()),
                    requirement: "FIPS 203/204/205: approved".to_string(),
                    rule_id: "SBOM-PQC-009",
                    component_id: Some(comp.canonical_id.value().to_string()),
                    counts: None,
                    standard_refs: Vec::new(),
                });
            }
        }

        // PQC-010: hybrid PQC combiner (informational)
        if algo.is_some_and(|a| a.is_hybrid_pqc()) {
            violations.push(Violation {
                severity: ViolationSeverity::Info,
                category: ViolationCategory::CryptographyInfo,
                message: format!(
                    "'{}' is a hybrid PQC combiner — good migration practice",
                    comp.name
                ),
                element: Some(comp.name.clone()),
                requirement: "IR 8547: recommended transition".to_string(),
                rule_id: "SBOM-PQC-010",
                component_id: Some(comp.canonical_id.value().to_string()),
                counts: None,
                standard_refs: Vec::new(),
            });
        }
    }

    /// Evaluate a protocol asset for PQC readiness: no SSL / TLS below 1.2,
    /// and no broken or quantum-vulnerable algorithms in cipher suites,
    /// IKEv2 transforms, or crypto references.
    fn check_pqc_protocol(
        comp: &Component,
        proto: &ProtocolProperties,
        sbom: &NormalizedSbom,
        index: &NormalizedSbomIndex,
        violations: &mut Vec<Violation>,
    ) {
        // PQC-PROTO-001: SSL anything, or TLS/DTLS below 1.2.
        if is_ssl_protocol(proto) {
            violations.push(Violation {
                severity: ViolationSeverity::Error,
                category: ViolationCategory::CryptographyInfo,
                message: format!(
                    "Protocol '{}' uses SSL, which is disallowed; use TLS 1.2 or higher \
                     (SP 800-52 Rev. 2)",
                    comp.name
                ),
                element: Some(comp.name.clone()),
                requirement: "SP 800-52: protocol version".to_string(),
                rule_id: "SBOM-PQC-PROTO-001",
                component_id: Some(comp.canonical_id.value().to_string()),
                counts: None,
                standard_refs: Vec::new(),
            });
        } else if matches!(proto.protocol_type, ProtocolType::Tls | ProtocolType::Dtls)
            && let Some(version) = proto.version.as_deref()
            && tls_version_below(version, (1, 2))
        {
            violations.push(Violation {
                severity: ViolationSeverity::Error,
                category: ViolationCategory::CryptographyInfo,
                message: format!(
                    "Protocol '{}' uses {} {version}, which is disallowed; use TLS 1.2 or \
                     higher (SP 800-52 Rev. 2)",
                    comp.name,
                    proto.protocol_type.to_string().to_uppercase()
                ),
                element: Some(comp.name.clone()),
                requirement: "SP 800-52: protocol version".to_string(),
                rule_id: "SBOM-PQC-PROTO-001",
                component_id: Some(comp.canonical_id.value().to_string()),
                counts: None,
                standard_refs: Vec::new(),
            });
        }

        // Unverifiable evidence: opaque references and unparseable TLS
        // versions receive no effective check, so they are collected for a
        // Warning instead of silently passing the SP 800-52 / IR 8547 gates.
        let mut unverifiable: Vec<String> = Vec::new();
        if matches!(proto.protocol_type, ProtocolType::Tls | ProtocolType::Dtls)
            && let Some(version) = proto.version.as_deref()
            && parse_tls_version(version).is_none()
        {
            unverifiable.push(format!("version '{version}'"));
        }

        let mut push_proto_violation = |context: String, offenders: Vec<String>| {
            if offenders.is_empty() {
                return;
            }
            violations.push(Violation {
                severity: ViolationSeverity::Error,
                category: ViolationCategory::CryptographyInfo,
                message: format!(
                    "Protocol '{}' {context} broken or quantum-vulnerable algorithms: {}",
                    comp.name,
                    offenders.join(", ")
                ),
                element: Some(comp.name.clone()),
                requirement: "IR 8547 / SP 800-131A: protocol algorithms".to_string(),
                rule_id: "SBOM-PQC-PROTO-002",
                component_id: Some(comp.canonical_id.value().to_string()),
                counts: None,
                standard_refs: Vec::new(),
            });
        };
        let record = |cls: &AlgorithmClassification, offenders: &mut Vec<String>| {
            let tag = match cls.class {
                AlgorithmClass::Broken => Some("broken"),
                AlgorithmClass::ClassicalQuantumVulnerable => Some("quantum-vulnerable"),
                _ => None,
            };
            if let Some(tag) = tag {
                let label = format!("{} ({tag})", cls.label());
                if !offenders.contains(&label) {
                    offenders.push(label);
                }
            }
        };

        for suite in &proto.cipher_suites {
            let mut offenders = Vec::new();
            for algo_ref in &suite.algorithms {
                let (cls, _) = classify_bom_ref(algo_ref, sbom, index);
                if cls.class == AlgorithmClass::Unknown {
                    unverifiable.push(algo_ref.clone());
                } else {
                    record(&cls, &mut offenders);
                }
            }
            if let Some(name) = &suite.name {
                for cls in classify_algorithm_names(name) {
                    record(&cls, &mut offenders);
                }
            }
            push_proto_violation(
                format!(
                    "cipher suite '{}' includes",
                    suite.name.as_deref().unwrap_or("(unnamed)")
                ),
                offenders,
            );
        }

        if let Some(ike) = &proto.ikev2_transform_types {
            let mut offenders = Vec::new();
            for r in ike
                .encr
                .iter()
                .chain(&ike.prf)
                .chain(&ike.integ)
                .chain(&ike.ke)
            {
                let (cls, _) = classify_bom_ref(r, sbom, index);
                if cls.class == AlgorithmClass::Unknown {
                    unverifiable.push(r.clone());
                } else {
                    record(&cls, &mut offenders);
                }
            }
            push_proto_violation("IKEv2 transforms include".to_string(), offenders);
        }

        let mut offenders = Vec::new();
        for r in &proto.crypto_ref_array {
            match resolve_component(r, sbom, index) {
                Some(target) => {
                    if target
                        .crypto_properties
                        .as_ref()
                        .is_some_and(|c| c.asset_type == CryptoAssetType::Algorithm)
                    {
                        record(&classify_crypto_component(target), &mut offenders);
                    }
                }
                None => {
                    if let Some(cls) = worst_classification(classify_algorithm_names_guarded(r)) {
                        record(&cls, &mut offenders);
                    } else {
                        unverifiable.push(r.clone());
                    }
                }
            }
        }
        push_proto_violation("references".to_string(), offenders);

        // A protocol whose evidence is all opaque, or that documents nothing
        // evaluable at all, must warn rather than silently satisfying the
        // PQC-000 inventory gate — mirrors SBOM-CNSA2-ALG-UNKNOWN. For the
        // version gate only a parseable TLS/DTLS version counts as evidence
        // (SSL is substantively rejected above).
        let version_evaluated = is_ssl_protocol(proto)
            || (matches!(proto.protocol_type, ProtocolType::Tls | ProtocolType::Dtls)
                && proto
                    .version
                    .as_deref()
                    .is_some_and(|v| parse_tls_version(v).is_some()));
        let substantive = version_evaluated
            || !proto.cipher_suites.is_empty()
            || proto.ikev2_transform_types.is_some()
            || !proto.crypto_ref_array.is_empty();
        if !unverifiable.is_empty() {
            violations.push(Violation {
                severity: ViolationSeverity::Warning,
                category: ViolationCategory::CryptographyInfo,
                message: format!(
                    "Protocol '{}' has crypto evidence that cannot be resolved or \
                     classified: {}; unable to verify PQC readiness",
                    comp.name,
                    unverifiable.join(", ")
                ),
                element: Some(comp.name.clone()),
                requirement: "IR 8547: protocol algorithm identification".to_string(),
                rule_id: "SBOM-PQC-PROTO-UNKNOWN",
                component_id: Some(comp.canonical_id.value().to_string()),
                counts: None,
                standard_refs: Vec::new(),
            });
        } else if !substantive {
            violations.push(Violation {
                severity: ViolationSeverity::Warning,
                category: ViolationCategory::CryptographyInfo,
                message: format!(
                    "Protocol '{}' documents no version, cipher suites, or algorithm \
                     references; protocol algorithms cannot be verified for PQC readiness",
                    comp.name
                ),
                element: Some(comp.name.clone()),
                requirement: "IR 8547: protocol algorithm identification".to_string(),
                rule_id: "SBOM-PQC-PROTO-UNKNOWN",
                component_id: Some(comp.canonical_id.value().to_string()),
                counts: None,
                standard_refs: Vec::new(),
            });
        }
    }
}