feat(csharp): add ML-DSA (FIPS 204) detection rules for .NET 10#387
feat(csharp): add ML-DSA (FIPS 204) detection rules for .NET 10#387Chennamma-Hotkar wants to merge 3 commits intocbomkit:mainfrom
Conversation
Signed-off-by: Chennamma <channuhotkar@gmail.com>
Signed-off-by: Chennamma <channuhotkar@gmail.com>
|
Hey @Chennamma-Hotkar , The core issue: the class names don't exist in the .NET API The detection rules target MLDsa44, MLDsa65, MLDsa87, MLKem512, MLKem768, and MLKem1024 as object types. As far as I can tell from the official System.Security.Cryptography documentation, these are not class names. The actual classes are MLDsa and MLKem (abstract base classes), and what you're referencing are static properties on the algorithm descriptor classes MLDsaAlgorithm and MLKemAlgorithm: // This is the actual API: // MLDsa44.GenerateKey() - this class does not exist to the best of my knowledge Please correct me if I'm wrong here, but there are no MLDsa44 or MLKem512 concrete classes in the docs for .net 10: https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography?view=net-10.0 This also means the .withoutParameters() call will never match anything even if the class names were fixed -> GenerateKey always requires an MLDsaAlgorithm / MLKemAlgorithm argument. There is no parameterless overload. Just to set expectations: the tests and detection rules currently in this C# branch are mostly placeholder / dummy coverage while the module is still being built out. Please don't use those as a model for correctness.
Coverage goes beyond just object construction: depending rules capture encrypt/decrypt operations, mode/padding property setters, key generation, etc. Summary
Happy to help get this into shape if you want to iterate -> the intent is absolutely right, it just needs to match the actual API structure. Here some detection rule for AES in .net for reference. This is not yet approved or merged into sonar-cryptography so take it with a grain of salt, but i think it will get my point across: |
|
Hi @fynnth, thank you for the detailed review — this is exactly You're completely right on all three points:
I'll rework both PRs (#385 and #387) to target the correct API:
Also downloading the reference files you attached now. |
Signed-off-by: Chennamma <channuhotkar@gmail.com>
|
@fynnth all three points addressed in the latest commit. Switched the object types to Will follow up with |
|
Hey, One remaining problem though: all three rules for both ML-DSA and ML-KEM now have identical matchers with the same object type (MLDsa / MLKem), same method (GenerateKey), same parameter pattern (withMethodParameter(ANY)). The engine matches on types and counts, not on argument values, so all three rules fire on every single MLDsa.GenerateKey(...) call regardless of which MLDsaAlgorithm is passed. That means every usage produces three findings which isn't correct. I have not tested this but i think that is what should happen and it does not fail the test because you use Beyond that, I don't really see the value in detecting generic factory methods without proper argument-value differentiation and without depending detection rules for the operation surface (SignData, VerifyData, Encapsulate, Decapsulate, import methods etc.). If you'd like to contribute this properly I'd love to see a comprehensive PR that covers all of that end to end, but in its current form I won't be able to merge it. There's also a practical constraint worth flagging: our current C# parser only guarantees correct parsing up to C# 7. ML-KEM and ML-DSA landed in .NET 10 with C# 13 syntax in practice. I'm currently working on a commit that brings full coverage up to C# 7, and I'll be working toward C# 10+ support from there. If the rules only target factory methods without the broader operation surface, the value added on top of that is fairly limited, so a comprehensive PR covering the full API surface of the PQC algorithms would be a much stronger contribution and worth the extra effort. Happy to review once it's more complete! If you dont want to work on that i will definitely include it in my work on complete security.cryptography coverage. Porbably in the next few months there should be progress from my side in that regard. |
Summary
Adds ML-DSA (FIPS 204) detection rules for .NET 10 System.Security.Cryptography.
Follows the same pattern as #385 (ML-KEM).
Changes
DotNetMLDsa.java: detectMLDsa.GenerateKey(MLDsaAlgorithm)DotNetMLDsaTestFile.cs: C# test file using correct .NET 10 APIDotNetMLDsaTest.java: unit test verifying detection and translationCSharpDetectionRules.java: registers DotNetMLDsa in rule aggregatorCSharpKeyContextTranslator.java: maps MLDSA kind to MLDSA model nodeTesting
Planned follow-up
Note: This PR branches from local main which includes #385 (ML-KEM).
Once #385 merges, this PR will show only the ML-DSA changes (5 files).