Skip to content

8353749: Improve security warning when using JKS or JCEKS keystores#27624

Closed
haimaychao wants to merge 10 commits intoopenjdk:masterfrom
haimaychao:JDK-8353749
Closed

8353749: Improve security warning when using JKS or JCEKS keystores#27624
haimaychao wants to merge 10 commits intoopenjdk:masterfrom
haimaychao:JDK-8353749

Conversation

@haimaychao
Copy link
Contributor

@haimaychao haimaychao commented Oct 3, 2025

This PR improves security warning when using JKS or JCEKS keystores.


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-8353749: Improve security warning when using JKS or JCEKS keystores (Enhancement - P3)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27624

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 3, 2025

👋 Welcome back hchao! 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

openjdk bot commented Oct 3, 2025

@haimaychao 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:

8353749: Improve security warning when using JKS or JCEKS keystores

Reviewed-by: weijun

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 136 new commits pushed to 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 added the security security-dev@openjdk.org label Oct 3, 2025
@openjdk
Copy link

openjdk bot commented Oct 3, 2025

@haimaychao 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.

@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 3, 2025
@mlbridge
Copy link

mlbridge bot commented Oct 3, 2025

Webrevs

jar.contains.internal.inconsistencies.result.in.different.contents.via.jarfile.and.jarinputstream=This JAR file contains internal inconsistencies that may result in different contents when reading via JarFile and JarInputStream:
signature.verification.failed.on.entry.1.when.reading.via.jarinputstream=Signature verification failed on entry %s when reading via JarInputStream
signature.verification.failed.on.entry.1.when.reading.via.jarfile=Signature verification failed on entry %s when reading via JarFile
outdated.storetype.warning=%1$s uses outdated cryptographic algorithms and will be removed in a future release. Migrate to PKCS12 using:\n\
Copy link
Member

Choose a reason for hiding this comment

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

Call this "jks.storetype.warning" so it is consistent with keytool.properties.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

private boolean signerSelfSigned = false;
private boolean allAliasesFound = true;
private boolean hasMultipleManifests = false;
private boolean outdatedFormat = false;
Copy link
Member

Choose a reason for hiding this comment

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

Suggest calling this variable "weakKeyStore".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines +2411 to +2419
File storeFile = new File(keyStoreName);
if (storeFile.isFile()) {
KeyStore keyStore = KeyStore.getInstance(storeFile, storepass);
realStoreType = keyStore.getType();
if (realStoreType.equalsIgnoreCase("JKS")
|| realStoreType.equalsIgnoreCase("JCEKS")) {
outdatedFormat = true;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you need the realStoreType field. If you move this check to the end of the else block starting on line 2424 (which means the keystore is a file), and just check the KeyStore.type() I think it should be sufficient, ex:

if (store.getType().equalsIgnoreCase("JKS")
        || store.getType().equalsIgnoreCase("JCEKS")) {
    weakKeyStore = true;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

if (outdatedFormat) {
warnings.add(String.format(rb.getString(
"outdated.storetype.warning"),
realStoreType, keystore));
Copy link
Member

Choose a reason for hiding this comment

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

You can pass store.getType() instead of realStoreType here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

return (provider == null) ? "(no provider)" : provider.getName();
}

private static void outdatedKeyStoreLog(String type) {
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be simpler to include this warning in the constructor of sun.security.provider.JavaKeyStore. Then you don't need to call this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the warning to engineLoad() in JceKeyStore and JavaKeyStore, instead of in their constructors. Otherwise, we may get false positive warnings from KeyStore.getInstance() when it goes thru the list of providers to probe for the right keystore.

/*
* @test
* @bug 8217375 8260286 8267319
* @bug 8217375 8260286 8267319 8353749
Copy link
Member

Choose a reason for hiding this comment

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

This is not specifically testing this issue, so I don't think you should include the bugid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the bugid.

Copy link
Member

Choose a reason for hiding this comment

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

I think you should create a new test which is a subclass of this Test which checks that JKS and JCEKS produce the proper warnings when using jarsigner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A new test was created under sun/security/tools/keytool to provide test coverage for keytool on JKS and JCEKS followed by using jarsigner.

is.close();
}
}
if (store.getType().equalsIgnoreCase("JKS")
Copy link
Member

Choose a reason for hiding this comment

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

We should put in the same logic here as in keytool to check if the real storetype is JKS or JCEKS. See

// Probe for real type. A JKS can be loaded as PKCS12 because

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@wangweij
Copy link
Contributor

Do we need to add a warning at store? For example, someone getInstance("JKS") and load(null, null), and finally store it.

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 7, 2025

@haimaychao This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply issue a /touch or /keepalive command to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@haimaychao
Copy link
Contributor Author

Do we need to add a warning at store? For example, someone getInstance("JKS") and load(null, null), and finally store it.

Added warning at engineStore(), and added a testcase for this scenario.

+ "release. Migrate to PKCS12 using:\n"
+ "keytool -importkeystore -srckeystore <keystore> "
+ "-destkeystore <keystore> -deststoretype pkcs12");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Currently the debug output has a long prefix containing timestamp etc. If the warning is separated on two lines, does it make sense to call debug.println twice so both lines have the prefix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 21, 2025
@haimaychao
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Nov 21, 2025

Going to push as commit c2ea75b.
Since your change was applied there have been 137 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Nov 21, 2025
@openjdk openjdk bot closed this Nov 21, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 21, 2025
@openjdk
Copy link

openjdk bot commented Nov 21, 2025

@haimaychao Pushed as commit c2ea75b.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

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

Labels

integrated Pull request has been integrated security security-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

3 participants