Skip to content

fix(crypto): handle primitive field - #2819

Merged
gildub merged 2 commits into
guacsec:mainfrom
gildub:fix/crypto/primitive
Oct 28, 2026
Merged

gildub merged 2 commits into
guacsec:mainfrom
gildub:fix/crypto/primitive

Conversation

@gildub

@gildub gildub commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary by Sourcery

Fix crypto policy handling for primitive fields and enforce minimum hash digest strength.

Bug Fixes:

  • Correct crypto policy evaluation to read primitive and parameter metadata from the top-level properties.
  • Classify hash algorithms with digests of 128 bits or less as non-compliant.

Tests:

  • Update policy tests for the revised property structure and short hash digest compliance behavior.

@sourcery-ai

sourcery-ai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR fixes crypto policy and reporting logic for the flattened metadata schema by reading primitive and parameterSetIdentifier directly from the properties object, and updates the associated tests and fixtures.

File-Level Changes

Change Details Files
Read cryptographic metadata fields directly from the properties object instead of a nested algorithmProperties object.
  • Update primitive extraction used for package crypto counts.
  • Update parameter-set identifier parsing used by policy evaluation.
  • Revise policy fixtures and assertions to cover the flattened metadata schema.
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="110" />
<code_context>
     fn props_with_primitive(primitive: &str) -> serde_json::Value {
         json!({
-            "algorithmProperties": {
-                "primitive": primitive
-            }
+            "primitive": primitive
</code_context>
<issue_to_address>
**Primitive-field regression passes unnoticed**

When `evaluate_algorithm` does not use the primitive field, `sha1_is_noncompliant` and `keycloak_cbom_algorithms` still pass if `evaluate_algorithm` ignores `primitive`: SHA1 is rejected by its name, while ECDH and EC-secp521r1 return the default Warning. The changed direct-field fixtures therefore do not verify primitive handling.

Add a test whose observable result changes when the direct primitive field is ignored or read from the wrong location.

Also at `modules/fundamental/src/crypto/service/policy.rs:300-302`, `modules/fundamental/src/crypto/service/policy.rs:310`, `modules/fundamental/src/crypto/service/policy.rs:319`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and if the incoming crypto properties still use the nested algorithmProperties shape, the service will stop reading the primitive and parameter-set identifier and can report an incorrect algorithm policy verdict. This changes crypto-policy evaluation; reverting restores the previous lookups, but any incorrect verdicts already acted on would not be undone.

Blocking findings: modules/fundamental/src/crypto/service/policy.rs:110


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

@gildub gildub added the backport release/0.7.z Backport (0.7.z) label Oct 28, 2026

@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.

Sourcery assessment

Approved.

@gildub
gildub added this pull request to the merge queue Oct 28, 2026
@gildub
gildub removed this pull request from the merge queue due to a manual request Oct 28, 2026
@gildub
gildub added this pull request to the merge queue Oct 28, 2026
gildub and others added 2 commits October 28, 2026 15:12
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>
@gildub
gildub force-pushed the fix/crypto/primitive branch from 9602a06 to ed6bee2 Compare October 28, 2026 14:12
@gildub
gildub removed this pull request from the merge queue due to a manual request Oct 28, 2026
@gildub
gildub added this pull request to the merge queue Oct 28, 2026
Merged via the queue into guacsec:main with commit 48e5577 Oct 28, 2026
11 checks passed
@gildub
gildub deleted the fix/crypto/primitive branch October 28, 2026 16:16
@github-project-automation github-project-automation Bot moved this to Done in Trustify Oct 28, 2026
@trustify-ci-bot

Copy link
Copy Markdown

Successfully created backport PR for release/0.7.z:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport release/0.7.z Backport (0.7.z)

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant