Skip to content

8374808: Add new methods to KeyStore and KeyStoreSpi that return the creation date as an Instant instead of Date#29140

Closed
myankelev wants to merge 15 commits intoopenjdk:masterfrom
myankelev:JDK-8374808
Closed

8374808: Add new methods to KeyStore and KeyStoreSpi that return the creation date as an Instant instead of Date#29140
myankelev wants to merge 15 commits intoopenjdk:masterfrom
myankelev:JDK-8374808

Conversation

@myankelev
Copy link
Copy Markdown
Member

@myankelev myankelev commented Jan 9, 2026

Hi!

This is my proposal to transfer KeyStore and KeyStoreSpi with internal implementations to use Instances instead of Dates.
I would be very grateful for your comments and suggestions.

Thanks!

P.S. this is related to JDK-8350953


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Change requires CSR request JDK-8375012 to be approved
  • Commit message must refer to an issue

Issues

  • JDK-8374808: Add new methods to KeyStore and KeyStoreSpi that return the creation date as an Instant instead of Date (Enhancement - P4)
  • JDK-8375012: Add new methods to KeyStore and KeyStoreSpi that return the creation date as an Instant instead of Date (CSR)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 29140

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented Jan 9, 2026

👋 Welcome back myankelevich! 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 Jan 9, 2026

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

8374808: Add new methods to KeyStore and KeyStoreSpi that return the creation date as an Instant instead of Date

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 446 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 changed the title JDK-8374808: Add an Instance in place of Date for KeyStore and KeyStoreSpi 8374808: Add an Instance in place of Date for KeyStore and KeyStoreSpi Jan 9, 2026
@openjdk openjdk Bot added the security security-dev@openjdk.org label Jan 9, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented Jan 9, 2026

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

Comment thread src/java.base/share/classes/java/security/KeyStoreSpi.java Outdated
Comment thread src/java.base/share/classes/java/security/KeyStore.java Outdated
Copy link
Copy Markdown
Contributor

@wangweij wangweij left a comment

Choose a reason for hiding this comment

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

Mostly looks good. Do you have a plan to update the callers of KeyStore::getCreationDate?

Also, I see you skipped the SunPKCS11 and MSCAPI implementations. Are they too trivial and the default implementation is enough?

Comment thread src/java.base/share/classes/java/security/KeyStore.java Outdated
Comment thread src/java.base/share/classes/java/security/KeyStore.java Outdated
Comment thread src/java.base/share/classes/java/security/KeyStoreSpi.java Outdated
Comment thread src/java.base/share/classes/sun/security/provider/JavaKeyStore.java Outdated
@openjdk openjdk Bot added the csr Pull request needs approved CSR before integration label Jan 12, 2026
@myankelev
Copy link
Copy Markdown
Member Author

Mostly looks good. Do you have a plan to update the callers of KeyStore::getCreationDate?

Also, I see you skipped the SunPKCS11 and MSCAPI implementations. Are they too trivial and the default implementation is enough?

Apologies, missed this comment the last time I went through them.
P11KeyStore has no support for creation date and throws an exception so I think the default should be enough.
As for CKeyStore It seems that it just creates a new date and nothing else. I'm not sure if writing a whole separate method to always provide current time is worth it when we have a default implementation. But if you believe it is - I'm happy to add it

@myankelev myankelev marked this pull request as ready for review January 14, 2026 15:42
@openjdk openjdk Bot added the rfr Pull request is ready for review label Jan 14, 2026
@mlbridge
Copy link
Copy Markdown

mlbridge Bot commented Jan 14, 2026

@seanjmullan
Copy link
Copy Markdown
Member

Can you change the title of the issue to be more descriptive that these are new APIs, ex: "Add new methods to KeyStore and KeyStoreSpi that return the creation date as an Instant instead of Date"

Copy link
Copy Markdown
Contributor

@wangweij wangweij left a comment

Choose a reason for hiding this comment

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

Some comments.

I have a small concern on the Instant.now() calls everywhere. As you can see in your TestKeyStoreBasic.java test, the value is truncated when persisting inside a keystore and when loaded again it's not identical to the old value. Will this create any interop issue in the real world? If we know a keystore implementation only support the precision of milliseconds, should we truncate it early?

Comment thread src/java.base/share/classes/java/security/KeyStore.java Outdated
Comment thread src/java.base/share/classes/java/security/KeyStore.java Outdated
@myankelev myankelev changed the title 8374808: Add an Instance in place of Date for KeyStore and KeyStoreSpi 8374808: Add new methods to KeyStore and KeyStoreSpi that return the creation date as an Instant instead of Date Jan 15, 2026
@myankelev
Copy link
Copy Markdown
Member Author

Some comments.

I have a small concern on the Instant.now() calls everywhere. As you can see in your TestKeyStoreBasic.java test, the value is truncated when persisting inside a keystore and when loaded again it's not identical to the old value. Will this create any interop issue in the real world? If we know a keystore implementation only support the precision of milliseconds, should we truncate it early?

I believe this would be the safest thing to do. Existing implementation is relying on new Date() which is actually calling System.currentTimeMillis() which is sufficient. Even though it shouldn't cause any interop issues as Date still remains unchanged Instant values can cause confusion as in the test.

I have changed these 'Instant.now()' to Instant.now().truncatedTo(ChronoUnit.MILLIS);

Comment thread src/java.base/share/classes/java/security/KeyStore.java Outdated
Comment thread src/java.base/share/classes/java/security/KeyStore.java Outdated
Comment thread src/java.base/share/classes/java/security/KeyStoreSpi.java
Comment thread src/java.base/share/classes/java/security/KeyStoreSpi.java Outdated
Comment thread src/java.base/share/classes/java/security/KeyStore.java Outdated
Comment thread src/java.base/share/classes/java/security/KeyStore.java Outdated
Comment thread src/java.base/share/classes/java/security/KeyStore.java Outdated
Comment thread src/java.base/share/classes/java/security/KeyStoreSpi.java Outdated
Comment thread src/java.base/share/classes/java/security/KeyStoreSpi.java Outdated
@openjdk openjdk Bot removed the csr Pull request needs approved CSR before integration label Jan 27, 2026
Comment thread src/java.base/macosx/classes/apple/security/KeychainStore.java Outdated
dos.writeLong(((TrustedCertEntry)entry).date.getTime());
dos.writeLong(
((TrustedCertEntry)entry).date.toEpochMilli()
);
Copy link
Copy Markdown
Contributor

@wangweij wangweij Feb 5, 2026

Choose a reason for hiding this comment

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

Not very common to write ); on a new line.

Same below on line 659. Also in JavaKeyStore line 633.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'd personally prefer to keep it this way as when it was inline it was really hard to read for me. If you feel strongly about it - I can change it :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No problem. In fact, I see on line 2440 of PKCS12KeyStore you have

                        instant = Instant.ofEpochMilli(
                                Long.parseLong(keyIdStr.substring(5)));

So I thought you're OK to either style.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Actually, I just missed this, changed in the next commit. Hope it looks good to you

Copy link
Copy Markdown
Contributor

@wangweij wangweij left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the fix!

@openjdk openjdk Bot added the ready Pull request is ready to be integrated label Feb 9, 2026
@myankelev
Copy link
Copy Markdown
Member Author

Thanks for the reviews @wangweij @seanjmullan @sisahoo

@myankelev
Copy link
Copy Markdown
Member Author

/integrate

@openjdk
Copy link
Copy Markdown

openjdk Bot commented Feb 10, 2026

Going to push as commit 264fdc5.
Since your change was applied there have been 461 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 Feb 10, 2026
@openjdk openjdk Bot closed this Feb 10, 2026
@openjdk openjdk Bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Feb 10, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented Feb 10, 2026

@myankelev Pushed as commit 264fdc5.

💡 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.

4 participants