Repository navigation
fix(crypto): handle primitive field [Backport release/0.7.z] - #2823
Conversation
(cherry picked from commit bf61861)
Parse the primitive field in AlgorithmProps so evaluate_algorithm actually consumes it. Hash primitives with short digests (≤128 bits) are now classified as NonCompliant, and a dedicated test proves the verdict changes when the primitive field is absent or mislocated. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> (cherry picked from commit 48e5577)
Reviewer's GuideBackports the crypto policy fix to release/0.7.z by aligning primitive-field parsing with the top-level metadata schema and marking hash algorithms with digests of 128 bits or less as non-compliant, with focused regression coverage. Sequence diagram for primitive field handling in crypto evaluationsequenceDiagram
participant S as CryptoService
participant P as evaluate_algorithm
participant A as AlgorithmProps
S->>P: evaluate_algorithm(name, properties)
P->>A: AlgorithmProps::from_value(properties)
A->>A: Read primitive from top-level field
P->>P: is_weak(algorithm, props)
alt primitive is hash and key_size <= 128
P-->>S: PolicyVerdict::NonCompliant
else Otherwise
P-->>S: Continue existing policy evaluation
end
Flow diagram for primitive-aware crypto policy evaluationflowchart TD
A[Crypto properties] --> B[AlgorithmProps::from_value]
B --> C{primitive == hash}
C -- Yes --> D{key_size <= 128}
D -- Yes --> E[PolicyVerdict::NonCompliant]
D -- No --> F[Continue policy checks]
C -- No --> F
F --> G[PolicyVerdict::Warning or compliant result]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="modules/fundamental/src/crypto/service/policy.rs" line_range="20-21" />
<code_context>
- let ap = &v["algorithmProperties"];
Self {
- parameter_set_identifier: ap["parameterSetIdentifier"].as_str(),
+ parameter_set_identifier: v["parameterSetIdentifier"].as_str(),
+ primitive: v["primitive"].as_str(),
}
}
</code_context>
<issue_to_address>
**Nested policy metadata is ignored**
When an external caller passes the previously accepted `{"algorithmProperties": {...}}` shape, `AlgorithmProps::from_value` reads only top-level fields, so `evaluate_algorithm` misses a weak key size or short hash digest inside `algorithmProperties` and returns a less severe verdict than the caller expects.
Read metadata from the top level or, when absent there, from the nested `algorithmProperties` object.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 1 finding to address first, and the new rule marks every algorithm identified as a hash with a parameter-set value of 128 or less as noncompliant, changing a crypto policy threshold. If the threshold or primitive metadata is wrong, matching algorithms are misclassified from the moment it ships; reverting restores future evaluations but cannot undo decisions already made from earlier verdicts.
Blocking findings: modules/fundamental/src/crypto/service/policy.rs:21
Description
Backport of #2819 to
release/0.7.z.Summary by Sourcery
Fix crypto policy evaluation for primitive fields and reject hash algorithms with insufficient digest sizes.
Bug Fixes:
Tests: