Skip to content

fix(crypto): handle primitive field [Backport release/0.7.z] - #2823

Merged
gildub merged 2 commits into
release/0.7.zfrom
backport-2819-to-release/0.7.z
Oct 28, 2026
Merged

gildub merged 2 commits into
release/0.7.zfrom
backport-2819-to-release/0.7.z

Conversation

@trustify-ci-bot

@trustify-ci-bot trustify-ci-bot Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

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:

  • Correct crypto policy evaluation to read primitive metadata from the field’s actual location.
  • Classify hash algorithms with digests of 128 bits or less as non-compliant.

Tests:

  • Add coverage for short hash digests, sufficient hash sizes, missing primitive metadata, and non-hash primitives.

gildub and others added 2 commits October 28, 2026 16:16
(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)
@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Backports 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 evaluation

sequenceDiagram
    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
Loading

Flow diagram for primitive-aware crypto policy evaluation

flowchart 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]
Loading

File-Level Changes

Change Details Files
Read crypto primitive metadata from the top-level properties object and use it in policy evaluation.
  • Flattened primitive and parameter-set lookups to match the current metadata shape.
  • Added short-hash detection: hash primitives with digests of 128 bits or less are non-compliant.
  • Preserved warning behavior for missing primitives, sufficiently large hashes, and non-hash primitives.
  • Updated and expanded policy tests for the flattened schema and short-digest cases.
modules/fundamental/src/crypto/service/mod.rs
modules/fundamental/src/crypto/service/policy.rs

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@gildub
gildub added this pull request to the merge queue Oct 28, 2026
Merged via the queue into release/0.7.z with commit ae9d207 Oct 28, 2026
10 checks passed
@gildub
gildub deleted the backport-2819-to-release/0.7.z branch October 28, 2026 19:52
@github-project-automation github-project-automation Bot moved this to Done in Trustify Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants