Skip to content

8381937: Make exceptions in Java_sun_security_mscapi_CKeyPairGenerator generateCKeyPair more specific#30666

Open
MBaesken wants to merge 1 commit intoopenjdk:masterfrom
MBaesken:JDK-8381937
Open

8381937: Make exceptions in Java_sun_security_mscapi_CKeyPairGenerator generateCKeyPair more specific#30666
MBaesken wants to merge 1 commit intoopenjdk:masterfrom
MBaesken:JDK-8381937

Conversation

@MBaesken
Copy link
Copy Markdown
Member

@MBaesken MBaesken commented Apr 10, 2026

Currently in some specific Windows environment, I run into this error/exception (test sun/security/mscapi/EncodingMutability.java) :
java.security.ProviderException: java.security.KeyException: error 2, The system cannot find the file specified.

at jdk.crypto.mscapi/sun.security.mscapi.CKeyPairGenerator$RSA.generateKeyPair(CKeyPairGenerator.java:126)
at java.base/java.security.KeyPairGenerator$Delegate.generateKeyPair(KeyPairGenerator.java:723)
at EncodingMutability.main(EncodingMutability.java:38)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:565)
at com.sun.javatest.regtest.agent.MainActionHelper$AgentVMRunnable.run(MainActionHelper.java:335)
at java.base/java.lang.Thread.run(Thread.java:1527)
Caused by: java.security.KeyException: error 2, The system cannot find the file specified.

at jdk.crypto.mscapi/sun.security.mscapi.CKeyPairGenerator$RSA.generateCKeyPair(Native Method)
at jdk.crypto.mscapi/sun.security.mscapi.CKeyPairGenerator$RSA.generateKeyPair(CKeyPairGenerator.java:121)

Unfortunately in the native generateCKeyPair method we get only the GetLastError output in the exception text. It would be better to also get a hint about the failing method CryptAcquireContext or CryptGenKey.
For this we could use the existing helper ThrowExceptionWithMessageAndErrcode .



Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8381937: Make exceptions in Java_sun_security_mscapi_CKeyPairGenerator generateCKeyPair more specific (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/30666/head:pull/30666
$ git checkout pull/30666

Update a local copy of the PR:
$ git checkout pull/30666
$ git pull https://git.openjdk.org/jdk.git pull/30666/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 30666

View PR using the GUI difftool:
$ git pr show -t 30666

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/30666.diff

Using Webrev

Link to Webrev Comment

@MBaesken MBaesken changed the title JDK-8381937 JDK-8381937: Make exceptions in Java_sun_security_mscapi_CKeyPairGenerator generateCKeyPair more specific Apr 10, 2026
@bridgekeeper
Copy link
Copy Markdown

bridgekeeper bot commented Apr 10, 2026

👋 Welcome back mbaesken! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 10, 2026

@MBaesken This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8381937: Make exceptions in Java_sun_security_mscapi_CKeyPairGenerator generateCKeyPair more specific

Reviewed-by: mdoerr, lucy

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 1 new commit pushed to the master branch:

  • a0af250: 8381006: G1: Wrong IHOP old gen allocation rate calculation in presence of periodic gcs

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot changed the title JDK-8381937: Make exceptions in Java_sun_security_mscapi_CKeyPairGenerator generateCKeyPair more specific 8381937: Make exceptions in Java_sun_security_mscapi_CKeyPairGenerator generateCKeyPair more specific Apr 10, 2026
@openjdk openjdk bot added the security security-dev@openjdk.org label Apr 10, 2026
@openjdk
Copy link
Copy Markdown

openjdk bot commented Apr 10, 2026

@MBaesken The following label will be automatically applied to this pull request:

  • security

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

Copy link
Copy Markdown
Contributor

@TheRealMDoerr TheRealMDoerr left a comment

Choose a reason for hiding this comment

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

LGTM. Please note that "- [x] I confirm that I make this contribution in accordance with the OpenJDK Interim AI Policy." is not matched.

Copy link
Copy Markdown
Contributor

@RealLucy RealLucy left a comment

Choose a reason for hiding this comment

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

Looks good.
... and helpful for issue solving.

@MBaesken
Copy link
Copy Markdown
Member Author

LGTM. Please note that "- [x] I confirm that I make this contribution in accordance with the OpenJDK Interim AI Policy." is not matched.

No idea, maybe a blank too much? Or X instead of x ?

@openjdk openjdk bot added ready Pull request is ready to be integrated rfr Pull request is ready for review labels Apr 10, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge bot commented Apr 10, 2026

Webrevs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready Pull request is ready to be integrated rfr Pull request is ready for review security security-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

3 participants