Skip to content

Comments

Check for RSAPrivateCrtKey in WolfCryptCipher for RSA#153

Merged
rlm2002 merged 1 commit intowolfSSL:masterfrom
cconlon:rsaCrtKey
Sep 8, 2025
Merged

Check for RSAPrivateCrtKey in WolfCryptCipher for RSA#153
rlm2002 merged 1 commit intowolfSSL:masterfrom
cconlon:rsaCrtKey

Conversation

@cconlon
Copy link
Member

@cconlon cconlon commented Sep 5, 2025

WolfCryptCipher RSA currently only supports PrivateKey objects of type RSAPrivateCrtKey. This PR adjusts to throw an exception if the key does not include CRT parameters, as required by native wolfSSL. This gives users a more meaningful error/exception up front rather than a mp_exptmod error later on.

JUnit tests included for regression prevention.

This helps fix OpenJDK SunJCE test: crypto/provider/Cipher/RSA/TestRSA.java

…ateKey usage, throw exception if passed something else
@cconlon cconlon self-assigned this Sep 5, 2025
@cconlon cconlon requested a review from Copilot September 5, 2025 17:59
Copy link

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

This PR adds validation to ensure that RSA private keys used with WolfCryptCipher include CRT (Chinese Remainder Theorem) parameters, which are required by the underlying wolfSSL library. Instead of allowing non-CRT keys to fail later with cryptic native errors, the code now throws a clear InvalidKeyException upfront.

  • Adds instanceof check for RSAPrivateCrtKey in WolfCryptCipher.wolfCryptSetKey()
  • Throws descriptive InvalidKeyException when non-CRT RSA private keys are provided
  • Includes comprehensive JUnit tests covering both positive and negative scenarios

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/main/java/com/wolfssl/provider/jce/WolfCryptCipher.java Adds CRT parameter validation for RSA private keys with descriptive error message
src/test/java/com/wolfssl/provider/jce/test/WolfCryptCipherTest.java Adds test coverage for CRT key validation including positive, negative, and public key scenarios

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@cconlon cconlon assigned rlm2002 and unassigned cconlon Sep 5, 2025
@rlm2002 rlm2002 merged commit aa1e2b4 into wolfSSL:master Sep 8, 2025
83 of 84 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