Repository navigation
feat(csharp): extending detection rules for Crypto namespace and engine now detects chained setter - #560
Merged
Conversation
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: Fynn Thierling <fynnth@outlook.de>
Signed-off-by: Kaldesyvon <martinnovysedlak99@gmail.com>
… csharp-certificate-rules
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>
Signed-off-by: Kaldesyvon <martinnovysedlak99@gmail.com>
Kaldesyvon
marked this pull request as ready for review
October 23, 2026 13:08
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>
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, |
fynnth
approved these changes
Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Many
System.Security.Cryptographycalls name an algorithm but leave the details toneighboring 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
X509Certificatesnew CertificateRequest(...),X509SignatureGenerator.CreateForRSA/CreateForECDsaSignwith hash and, for RSA, paddingX509CertificatesGetCertHash,GetCertHashString,TryGetCertHash(the no-argument forms are the SHA-1 thumbprint)System.Security.Cryptographynew PbeParameters(cipher, hash, iterations),ExportPkcs12(Pkcs12ExportPbeParameters.X, ...)PkcsPkcs12Builder.SealWithMac,Rfc3161TimestampRequest.CreateFromData/Hash/SignerInfoXmlReference.DigestMethod,SignedInfo.SignatureMethod(including the chained form),new EncryptionMethod(...),KeyAlgorithmCosenew CoseSigner(...)Signwith hash and, for RSA, paddingEngine changes (shared code from #559)
CSharpTreeConverter):a.b.c = valueis now converted toa
set_csetter whose receiver is the whole chain (a.b). That text never equals avariable name, so setters attached to a tracked variable ignore it
(
rsa.Options.KeySize = 1does not changersa). Chains with an index or anull-conditional are still ignored. This is what makes the usual
signedXml.SignedInfo.SignatureMethod = …visible.CSharpTypeInference): two different enum or struct types, such asRSASignaturePaddingandHashAlgorithmName, are now treated as incompatible. Withoutthis,
CoseSigner(key, padding, hash)bound the padding to the hash parameter. Classtypes (
RSA,AsymmetricAlgorithm, …) are left out on purpose because they can besubtypes.
Tests
lookup tables and the type check.
unknown URI,
Pkcs12ExportPbeParameters.Default).Known limits
CmsRecipientis not covered: its overloads move the padding argument between positions.Cfg.Rounds) is not resolved for integer parameters.