Skip to content

fix(csharp): implement translators for SignatureContext, PRNGContext, and ProtocolContext#422

Closed
pranjal2004838 wants to merge 1 commit into
cbomkit:mainfrom
pranjal2004838:fix/csharp-translator-signature-prng-protocol
Closed

fix(csharp): implement translators for SignatureContext, PRNGContext, and ProtocolContext#422
pranjal2004838 wants to merge 1 commit into
cbomkit:mainfrom
pranjal2004838:fix/csharp-translator-signature-prng-protocol

Conversation

@pranjal2004838
Copy link
Copy Markdown

@pranjal2004838 pranjal2004838 commented May 22, 2026

This PR completes the C# translation layer for cryptographic contexts that were left unimplemented in the initial C# support draft (PR #376, April 6, 2026).

Previously, CSharpTranslator returned Optional.empty() for SignatureContext, PRNGContext, and ProtocolContext, causing detected crypto assets (RSA signing, ECDSA, random number generation, TLS protocols) to be silently discarded from CBOM output.

Changes:

  • CSharpSignatureContextTranslator: maps RSA, ECDSA, DSA to signature nodes
  • CSharpPRNGContextTranslator: maps .NET random generators to PRNG nodes
  • CSharpProtocolContextTranslator: maps TLS and generic protocols to protocol nodes
  • Added unit tests for each translator
  • Updated CSharpTranslator dispatcher to route these contexts instead of discarding them

Fixes silent data loss in C# crypto detection pipeline.

@pranjal2004838 pranjal2004838 requested a review from a team as a code owner May 22, 2026 03:43
Copilot AI review requested due to automatic review settings May 22, 2026 03:43
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds .NET (C#) context translation support for PRNG, protocol, and signature detections and wires these translators into the main C# translation pipeline.

Changes:

  • Introduced context translators for PRNG, Protocol, and Signature contexts in the C# plugin.
  • Updated CSharpTranslator to delegate to the new translators instead of returning Optional.empty().
  • Added JUnit tests covering the new translators’ basic mappings and unknown-value behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
csharp/src/main/java/com/ibm/plugin/translation/translator/CSharpTranslator.java Routes PRNG/Signature/Protocol contexts to dedicated translators.
csharp/src/main/java/com/ibm/plugin/translation/translator/contexts/CSharpPRNGContextTranslator.java Adds PRNG context translation for common .NET RNG types.
csharp/src/main/java/com/ibm/plugin/translation/translator/contexts/CSharpProtocolContextTranslator.java Adds protocol translation (TLS + generic fallback).
csharp/src/main/java/com/ibm/plugin/translation/translator/contexts/CSharpSignatureContextTranslator.java Adds signature algorithm/action translation (RSA/ECDSA/DSA + Sign/Verify).
csharp/src/test/java/com/ibm/plugin/translation/translator/contexts/CSharpPRNGContextTranslatorTest.java Tests PRNG mappings + unknown value.
csharp/src/test/java/com/ibm/plugin/translation/translator/contexts/CSharpProtocolContextTranslatorTest.java Tests TLS mapping + generic protocol fallback.
csharp/src/test/java/com/ibm/plugin/translation/translator/contexts/CSharpSignatureContextTranslatorTest.java Tests signature algorithm/action mappings + unknown value.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +118 to +119
assertThat(node.getKind()).isEqualTo(Signature.class);
assertThat(node.getKind()).isEqualTo(Sign.class);
@Nonnull DetectionLocation detectionLocation) {

if (value instanceof ValueAction<?>) {
String valueStr = value.asString().toUpperCase().trim();
@Nonnull DetectionLocation detectionLocation) {

if (value instanceof ValueAction<?> valueAction) {
String valueStr = valueAction.asString().toUpperCase().trim();
@Nonnull DetectionLocation detectionLocation) {

if (value instanceof ValueAction<?>) {
String valueStr = value.asString().toUpperCase().trim();
Comment on lines +94 to 107
if (detectionValueContext.is(PRNGContext.class)) {
return new CSharpPRNGContextTranslator()
.translate(bundleIdentifier, value, detectionValueContext, detectionLocation);
}

if (detectionValueContext.is(SignatureContext.class)) {
return new CSharpSignatureContextTranslator()
.translate(bundleIdentifier, value, detectionValueContext, detectionLocation);
}

if (detectionValueContext.is(ProtocolContext.class)) {
return new CSharpProtocolContextTranslator()
.translate(bundleIdentifier, value, detectionValueContext, detectionLocation);
}
… and ProtocolContext

Previously, CSharpTranslator returned Optional.empty() for SignatureContext,
PRNGContext, and ProtocolContext, causing detected crypto assets (RSA signing,
ECDSA, random number generation, TLS protocols) to be silently discarded from
CBOM output.

This commit adds three new context translators:
- CSharpSignatureContextTranslator: maps RSA, ECDSA, DSA to signature nodes
- CSharpPRNGContextTranslator: maps .NET random generators to PRNG nodes
- CSharpProtocolContextTranslator: maps TLS and generic protocols to protocol nodes

Also adds corresponding unit tests for each translator.

Fixes silent data loss in C# crypto detection pipeline.

Signed-off-by: pranjal2004838 <pranjaljha58@gmail.com>
@pranjal2004838 pranjal2004838 force-pushed the fix/csharp-translator-signature-prng-protocol branch from b3c323b to aad9370 Compare May 22, 2026 05:38
@fynnth
Copy link
Copy Markdown
Contributor

fynnth commented May 22, 2026

Hi @pranjal2004838,
Thanks for the contribution! Two things caught my eye that suggest this might not have been compiled and run (test pipeline fails because of unused imports, so i assume you have also not run it locally with mvn spotless):

  1. Compilation error in CSharpSignatureContextTranslatorTest
SignatureAction<T> requires two constructor arguments -> Action and a location T. The test calls it with one:


SignatureAction<?> value = new SignatureAction<>(SignatureAction.Action.SIGN);

I believe this won't compile.

  1. Contradictory assertion in testSignAction
assertThat(node.getKind()).isEqualTo(Signature.class);
assertThat(node.getKind()).isEqualTo(Sign.class);

Sign passes Sign.class to its super constructor, so getKind() returns Sign.class. Both can't be true at the same time if im not wrong.

Did you run mvn test -pl csharp against these tests? I'd expect them to fail at build time.

Aside from that, I want to flag some important context for this whole area: I've temporarily excluded the C# module from main due to licensing issues with the ANTLR parser files that were included in the initial draft. I'll be writing a clean ANTLR grammar for C# from scratch, and once that's in place I also need to add more detection rules covering System.Security.Cryptography properly before the translation layer makes sense to extend.

Given that, I'd ask everyone to please hold off on C# enhancements for now and reach out to me first before putting work into this area. With the number of PRs coming in at the moment it's getting hard to keep track, and I'd hate for anyone to invest time in something that will conflict with the rewrite. Happy to coordinate once the grammar and detection rule foundation is solid.

@fynnth fynnth closed this May 22, 2026
@pranjal2004838
Copy link
Copy Markdown
Author

Great no issues, ill rather open it as an issue, if in future, the licensise problem of C# is resolved, do let me know, ill add these too.

Regards

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.

3 participants