Skip to content

feat(csharp): extending detection rules for Crypto namespace and engine now detects chained setter - #560

Merged
fynnth merged 22 commits into
cbomkit:mainfrom
fynnth:csharp-certificate-rules
Nov 10, 2026
Merged

fynnth merged 22 commits into
cbomkit:mainfrom
fynnth:csharp-certificate-rules

Conversation

@Kaldesyvon

@Kaldesyvon Kaldesyvon commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Many System.Security.Cryptography calls name an algorithm but leave the details to
neighboring namespaces: the hash and padding of a certificate signature, the cipher and
iteration count that protect an exported key, the URI that names an XML signature algorithm.
Until now the plugin saw none of that. This adds detection rules for those namespaces so the
CBOM records the details as well as the algorithm name.

What is detected

Namespace Calls Reported as
X509Certificates new CertificateRequest(...), X509SignatureGenerator.CreateForRSA/CreateForECDsa Sign with hash and, for RSA, padding
X509Certificates GetCertHash, GetCertHashString, TryGetCertHash (the no-argument forms are the SHA-1 thumbprint) digest
System.Security.Cryptography new PbeParameters(cipher, hash, iterations), ExportPkcs12(Pkcs12ExportPbeParameters.X, ...) PBES2 or PKCS#12 scheme with cipher, hash, iteration count
Pkcs Pkcs12Builder.SealWithMac, Rfc3161TimestampRequest.CreateFromData/Hash/SignerInfo HMAC with hash and iterations; digest
Xml Reference.DigestMethod, SignedInfo.SignatureMethod (including the chained form), new EncryptionMethod(...), KeyAlgorithm digest, signature or HMAC, cipher or key transport
Cose new CoseSigner(...) Sign with hash and, for RSA, padding

Engine changes (shared code from #559)

  1. Chained property assignments (CSharpTreeConverter): a.b.c = value is now converted to
    a set_c setter whose receiver is the whole chain (a.b). That text never equals a
    variable name, so setters attached to a tracked variable ignore it
    (rsa.Options.KeySize = 1 does not change rsa). Chains with an index or a
    null-conditional are still ignored. This is what makes the usual
    signedXml.SignedInfo.SignatureMethod = … visible.
  2. Argument type check (CSharpTypeInference): two different enum or struct types, such as
    RSASignaturePadding and HashAlgorithmName, are now treated as incompatible. Without
    this, CoseSigner(key, padding, hash) bound the padding to the hash parameter. Class
    types (RSA, AsymmetricAlgorithm, …) are left out on purpose because they can be
    subtypes.

Tests

  • 10 new test classes: one per rule set, one for the chained setter, and unit tests for the two
    lookup tables and the type check.
  • Absence is asserted for unresolvable values (unknown hash, unknown iteration count,
    unknown URI, Pkcs12ExportPbeParameters.Default).

Known limits

  • A certificate request is not linked to the key that feeds it; they are separate findings.
  • CmsRecipient is not covered: its overloads move the padding argument between positions.
  • A constant reached through a class (Cfg.Rounds) is not resolved for integer parameters.

fynnth and others added 20 commits October 8, 2026 21:43
Rules declare their parameters by .NET name and declared type instead of
by position, so one rule per method covers every overload and a value
lands on the right algorithm (201 named declarations; withAnyParameters
159 -> 88). Values resolve only where the syntax is certain, and the
guards drop a value rather than guess one.

Adds the call sites that were invisible before: #if regions, creations
that are not statements of their own, the static HashData/TryHashData
helpers, and certificate key accessors in both spellings. A
certificate-derived key is now typed as private or public key material,
so an absent key length reads as a fact rather than a gap.

Dispatch moves from one detection per method body to one per call site,
matching Java and Python. Several calls of the same type in one method
used to share a detection store, so all but the first lost its parameter.

Signed-off-by: Fynn Thierling <fynnth@outlook.de>
Signed-off-by: Fynn Thierling <fynnth@outlook.de>
Signed-off-by: Fynn Thierling <fynnth@outlook.de>
Signed-off-by: Fynn Thierling <fynnth@outlook.de>
Signed-off-by: Fynn Thierling <fynnth@outlook.de>
Signed-off-by: Kaldesyvon <martinnovysedlak99@gmail.com>
Signed-off-by: Kaldesyvon <martinnovysedlak99@gmail.com>
Signed-off-by: Fynn Thierling <fynnth@outlook.de>
Signed-off-by: Kaldesyvon <martinnovysedlak99@gmail.com>
Signed-off-by: Kaldesyvon <martinnovysedlak99@gmail.com>
Signed-off-by: Kaldesyvon <martinnovysedlak99@gmail.com>
Signed-off-by: Kaldesyvon <martinnovysedlak99@gmail.com>
Signed-off-by: Kaldesyvon <martinnovysedlak99@gmail.com>
Signed-off-by: Fynn Thierling <fynnth@outlook.de>
Signed-off-by: Kaldesyvon <martinnovysedlak99@gmail.com>
Signed-off-by: Kaldesyvon <martinnovysedlak99@gmail.com>
Signed-off-by: Kaldesyvon <martinnovysedlak99@gmail.com>
Signed-off-by: Kaldesyvon <martinnovysedlak99@gmail.com>
PR 559 was squash-merged, so its individual commits are not ancestors of main. The squashed tree is identical to the PR head already merged here, so every conflict is resolved to this branch's side and the resulting tree is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Kaldesyvon Kaldesyvon changed the title Csharp certificate rules feat(csharp): extending detection rules for Crypto namespace and engine now detects chained setter Oct 23, 2026
Signed-off-by: Kaldesyvon <martinnovysedlak99@gmail.com>
@Kaldesyvon
Kaldesyvon marked this pull request as ready for review October 23, 2026 13:08
@Kaldesyvon
Kaldesyvon requested a review from a team as a code owner October 23, 2026 13:08
@Kaldesyvon

Copy link
Copy Markdown
Contributor Author

Hello maintainers

I have created PR for extending Crypto namespace crypto algorithms. Please review it. I will be not available whole next week.

Thank you very much

Signed-off-by: Fynn Thierling <fynnth@outlook.de>
@fynnth

fynnth commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Hi Martin,

I have looked at the code and the detection worked well, but there was the issue that the root detection node was the signing operation, which meant that it was not processed further after the detection and it was not able to create the issue and put it in the cbom. So i tried to reverse the detection a bit and detect RSA/ECDSA as the root with the hash and signing operation beneath it. This is just a proposal so lets look at it together next week and talk about it :)

Best regrads,
fynn

@fynnth
fynnth merged commit 817f9d1 into cbomkit:main Nov 10, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants