Skip to content

Add experimental crypto behavior taxonomy with contextual auth evidence - #494

Open
n1ckl0sk0rtge wants to merge 67 commits into
mainfrom
feature/crypto-behavior-taxonomy
Open

n1ckl0sk0rtge wants to merge 67 commits into
mainfrom
feature/crypto-behavior-taxonomy

Conversation

@n1ckl0sk0rtge

@n1ckl0sk0rtge n1ckl0sk0rtge commented Jul 14, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds experimental security behavior annotations to CBOMs. It uses security:cryptography:* values from the draft CycloneDX behavior taxonomy, such as encryptsData, wrapsKey and validatesToken.

The idea is to describe application behavior alongside the crypto inventory using a shared vocabulary. The annotations come from crypto operations and authentication APIs detected in source code.

Behavior instances are stored as JSON in the cbomkit:behaviors metadata property, keeping the CBOM valid for CycloneDX 1.6. Each instance has a stable ID and references the application as its actor. Native blueprints and behavior graphs remain outside this PR.

It also adds SecureRandom and key-unwrapping detection. Creating a SecureRandom is enough to add a random-generation behavior.

Design spec

Validation: 409 tests, seven skipped; Spotless and Checkstyle pass.

@n1ckl0sk0rtge
n1ckl0sk0rtge requested a review from a team as a code owner July 14, 2026 06:10
@n1ckl0sk0rtge n1ckl0sk0rtge self-assigned this Jul 14, 2026
@n1ckl0sk0rtge
n1ckl0sk0rtge marked this pull request as draft July 14, 2026 14:28
@n1ckl0sk0rtge n1ckl0sk0rtge added the enhancement New feature or request label Jul 14, 2026

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

Hi @n1ckl0sk0rtge,

The build fails due to a failing test RuleMemoizationEnforcementTest.everyStaticRulesMethodIsMemoized. The CI log is blurred with lots of log messages like

11:09:13.386 [main] INFO com.ibm.engine.language.java.JavaDetectionEngine -- Detected constructor definition has more then one argument to resolve. Redefine the rule to explicitly define the param to resolve

so it's hard to find. Is this still work in progress or is it ready merging?

[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR]   RuleMemoizationEnforcementTest.everyStaticRulesMethodIsMemoized:119 [detection-rule classes whose static rules() is not memoized — wrap the body with Memoize.of(...) so shared subtrees are built once (see #476)]
Expecting empty but was: ["com.ibm.plugin.rules.detection.auth.PrincipalAuthRules",
    "com.ibm.plugin.rules.detection.auth.JwtAuthRules",
    "com.ibm.plugin.rules.detection.auth.MtlsAuthRules",
    "com.ibm.plugin.rules.detection.auth.AuthDetectionRules",
    "com.ibm.plugin.rules.detection.auth.SamlAuthRules",
    "com.ibm.plugin.rules.detection.auth.ApiKeyAuthRules",
    "com.ibm.plugin.rules.detection.auth.OAuthAuthRules"]
[INFO]
[ERROR] Tests run: 165, Failures: 1, Errors: 0, Skipped: 7
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for sonar-cryptography 2.0.0-SNAPSHOT:
[INFO]
[INFO] sonar-cryptography ................................. SUCCESS [  0.646 s]
[INFO] common ............................................. SUCCESS [  1.696 s]
[INFO] engine ............................................. SUCCESS [  5.281 s]
[INFO] mapper ............................................. SUCCESS [  6.105 s]
[INFO] output ............................................. SUCCESS [  1.609 s]
[INFO] enricher ........................................... SUCCESS [  0.999 s]
[INFO] rules .............................................. SUCCESS [  0.545 s]
[INFO] java ............................................... FAILURE [ 10.387 s]
[INFO] python ............................................. SKIPPED
[INFO] go ................................................. SKIPPED
[INFO] sonar-cryptography-plugin .......................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  27.490 s
[INFO] Finished at: 2026-07-20T11:09:14+02:00
[INFO] ------------------------------------------------------------------------

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
…olish

FIX 1: Move behaviour accumulation from add() forEach into createAlgorithmComponent()
so TLS/cipher-suite constituent algorithms (reached via direct calls) now contribute
their behaviours to metadata.component; add regression test (RED→GREEN).
FIX 2: Relocate CryptoBehaviorTaxonomyTest to correctly-spelled cyclonedx package
(git mv); add CryptoBehavior import now required from different package.
FIX 3: Extend CryptoBehaviorMapperTest with 11 new cases covering Decrypt/Verify/
Digest/Tag/KeyGeneration operations, GenericKDF, AE/PKE/KEM/PRNG fallbacks, and
non-Algorithm empty-return.
FIX 4: Reference CryptoBehaviorMapper.BEHAVIOR_PROPERTY_NAME constant instead of
inline string literal in CryptoBehaviorMetadataTest.
FIX 5: Document METADATA_COMPONENT_NAME intentional simplification (spec §4.4).

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
…neratesRandomValue)

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
…sRandomValue)

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
…unwrap-test comments

- Add CryptoBehaviorMapperTest.decapsulateOnKeyWrapCipherYieldsWrapsKey() to verify Decapsulate
  functionality yields wrapsKey behavior on KeyWrap ciphers
- Add clarifying comment on SECURE_RANDOM_NO_ARG probe key indirection (maps to generic PRNG)
- Add comment on JcaCipherUnwrapTest scope noting end-to-end behavior validated elsewhere

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
…ce signals

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
…e enum

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
…ehaviors

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
…ixed output

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
…ontext signals

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
…eStore

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
…CBOM output

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
The SecureRandom key-generation scaffolding removed from detection tests
in this branch is restored, now that new SecureRandom()/getInstance is
itself detected as a PRNG asset.

Each restored construct is annotated with the expected PRNG finding, and
every affected asserts() gains a PRNGContext guard so the extra finding
is accounted for without disturbing the existing cipher assertions.
findingId-keyed tests are renumbered for the interleaved PRNG findings.

All 25 affected tests pass; full java suite green (162 tests, 7 skipped).

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
…edes sidecar store)

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
…d rule variants

Extend AuthInterfaceTestFile with a bare Jwts.parser().build() (must not be
detected) plus the previously unexercised variants: parseClaimsJws,
JWSObject.verify, ReactiveJwtDecoder.decode, SSLSession.getPeerCertificates,
and pac4j ParameterClient. Strengthen AuthInterfaceDetectionTest from
kind-was-seen to exact per-kind finding counts so the parser-construction
negative is actually asserted.

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
…rypto

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
…ceEngine

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
@n1ckl0sk0rtge
n1ckl0sk0rtge force-pushed the feature/crypto-behavior-taxonomy branch from 40091e9 to d8df295 Compare October 1, 2026 11:18
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
@n1ckl0sk0rtge

Copy link
Copy Markdown
Contributor Author

SecureRandomGetInstance is registered at the top level so the scan can detect standalone PRNG usage, such as creating a SecureRandom and calling nextBytes, even when it is never passed to another detected crypto API.

A depending detection rule would only run when a parent crypto rule follows that argument. No other production rule currently references SecureRandomGetInstance, so registering it here makes these rules reachable during normal scans.

This intentionally expands detection: recognized SecureRandom construction/factory calls produce a PRNG component and contribute generatesRandomValue to the new behavior summary. Construction alone currently counts as evidence; the rule does not require a subsequent nextBytes call.

Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
@n1ckl0sk0rtge
n1ckl0sk0rtge marked this pull request as ready for review November 6, 2026 15:34
@n1ckl0sk0rtge
n1ckl0sk0rtge requested a review from san-zrl November 6, 2026 15:36
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Signed-off-by: Nicklas Körtge <Nicklas.Koertge1@ibm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants