Skip to content

Conversation

@cshamrick
Copy link
Contributor

This PR adds support for verifying TDF assertions using JWK and X.509 certificates embedded in the JWT header.

  • CryptoUtils.java: A new getPublicKeyJWK method was added to convert an RSA public key into a JWK string.
  • Manifest.java: The assertion verification logic was updated. It now checks for and uses jwk and x5c (X.509 certificate chain) headers within the JWT to verify signatures before falling back to the previous verification method.
  • TDF.java: Exception handling was updated to catch CertificateException.
  • TDFTest.java: New tests, testSimpleTDFWithAssertionWithJWK and testSimpleTDFWithAssertionWithX5C, were added to validate the new verification flows.
  • TestUtil.java: A createTestCertificate method was added to generate self-signed X.509 certificates for testing.

…tificates

Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @cshamrick, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly extends the TDF SDK's capability to verify assertions by integrating support for public keys embedded directly within JSON Web Token (JWT) headers. Specifically, it enables the SDK to validate assertion signatures using either JSON Web Keys (JWK) or X.509 certificate chains (x5c) found in the JWT header. This enhancement provides greater flexibility and adherence to modern cryptographic practices for assertion validation, ensuring more robust and interoperable security for TDF-protected data.

Highlights

  • JWK Conversion Utility: A new method getPublicKeyJWK has been added to CryptoUtils.java to facilitate the conversion of RSA public keys into JSON Web Key (JWK) string format.
  • Enhanced Assertion Verification: The Manifest.java file now includes updated logic to verify TDF assertions. It prioritizes checking for and utilizing JWK and X.509 certificate chain (x5c) headers within the JWT for signature verification before falling back to existing methods.
  • Certificate Exception Handling: The TDF.java file has been updated to properly catch java.security.cert.CertificateException during the assertion verification process, improving error handling.
  • New Verification Tests: TDFTest.java now contains two new test cases, testSimpleTDFWithAssertionWithJWK and testSimpleTDFWithAssertionWithX5C, to validate the newly implemented JWK and X.509 certificate-based assertion verification flows.
  • Test Certificate Generation: A createTestCertificate method has been added to TestUtil.java to generate self-signed X.509 certificates, which are used for testing the new certificate-based verification.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances assertion verification by adding support for JWK and X.509 certificates from the JWT header, with a fallback to configured keys. The implementation is mostly sound, but I've identified a few areas for improvement. There's a bug in the exception handling within Manifest.java that could lead to incorrect error propagation. I've also suggested a simplification for creating a JWS verifier to improve maintainability. Most importantly, the new verification paths that use jwk and x5c from the JWT header are not covered by tests, which is a critical gap. Please add tests to cover these new code paths.

Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
@cshamrick
Copy link
Contributor Author

@gemini-code-assist review

@cshamrick cshamrick marked this pull request as ready for review January 8, 2026 15:04
@cshamrick cshamrick requested review from a team as code owners January 8, 2026 15:04
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for verifying TDF assertions using JWK and X.509 certificates from the JWT header, which is a great enhancement. The changes are well-structured and include corresponding tests.

However, I've identified a few areas for improvement:

  1. A critical security vulnerability in the handling of X.509 certificates from the x5c header, where the certificate chain is not validated.
  2. A potential for an unhandled exception when processing non-RSA keys from a jwk header.
  3. An opportunity to simplify and improve the robustness of JWK string generation by using the existing nimbus-jose-jwt library features.

My review includes specific comments and suggestions to address these points.

Comment on lines +428 to +440
// Check for X.509 certificate chain in header
if (verifier == null && header.getX509CertChain() != null && !header.getX509CertChain().isEmpty()) {
try {
X509Certificate cert = X509CertUtils.parse(header.getX509CertChain().get(0).decode());
if (cert.getPublicKey() instanceof RSAPublicKey) {
verifier = createVerifier((RSAPublicKey) cert.getPublicKey());
} else {
throw new SDKException("Unsupported public key type in X.509 certificate");
}
} catch (IllegalArgumentException e) {
throw new SDKException("Invalid Base64 in X.509 certificate in JWT header", e);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The current implementation for handling the x5c header in the JWT simply extracts the public key from the first certificate in the chain without performing any trust validation. This is a significant security vulnerability. An attacker could forge a JWT, sign it with their own key, and embed the corresponding public key within the x5c header. The system would then trust this key and validate the signature, effectively bypassing all trust checks.

The certificate chain provided in x5c should be validated against a configured trust store (containing trusted root or intermediate CAs) before its public key is used for signature verification.

I am not providing a code suggestion as a full implementation would require significant changes, including setting up a trust store. However, this vulnerability must be addressed. A possible approach would involve using java.security.cert.CertPathValidator.

Comment on lines +419 to +428
// Check for JWK in header
if (header.getJWK() != null) {
try {
verifier = createVerifier(header.getJWK());
} catch (JOSEException e) {
throw new SDKException("Invalid JWK in JWT header", e);
}
}

// Check for X.509 certificate chain in header
Copy link
Member

Choose a reason for hiding this comment

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

good

}

@Test
void testVerifyAssertionWithX5cHeaderInJWT() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

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

I was hoping the JOSE API would support a x5c chain more gracefully

pflynn-virtru
pflynn-virtru previously approved these changes Jan 8, 2026
Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 9, 2026

@github-actions
Copy link

github-actions bot commented Jan 9, 2026

@github-actions
Copy link

github-actions bot commented Jan 9, 2026

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