Skip to content

openjdk: generate cacerts from cacert for JDK 11+ - #576518

Merged
vcunat merged 1 commit into
NixOS:masterfrom
zimbatm:cacert-openjdk
Oct 21, 2026
Merged

vcunat merged 1 commit into
NixOS:masterfrom
zimbatm:cacert-openjdk

Conversation

@zimbatm

@zimbatm zimbatm commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

JDK 8 already builds its cacerts from cacert. JDK 11 and later shipped the CA list that comes with the OpenJDK source. That list does not get the cacert updates, for example the removal of distrusted roots.

Generate the keystore with the bootstrap keytool before configure and give it to --with-cacerts-file. The file goes into the java.base jmod, so jlink images such as jre_minimal also use it.

Write a PKCS12 store without a password, like upstream. The JDK opens cacerts without a password, so it cannot read certificates that a password protects.

Closes: #210241
Related to: #576485
Related to: #576543

This reverses 5a53b98 ("openjdk10: Use included cacerts", 2018). That commit gave no reason. Since then the bundled list has gone stale between JDK releases, and the eMudhra distrust shows the cost: the JDK 11+ store still holds emSign ECC Root CA - G3 and AAA Certificate Services.

Tested on x86_64-linux with openjdk21_headless (same diff on master):

  • keytool -list -cacerts opens without a password: PKCS12, 118 entries. Their SHA-256 fingerprints match the 118 server-auth roots of cacert 3.131.1. AAA (email trust only in cacert) and emSign ECC Root CA - G3 are gone.
  • A jlink minimal JRE gets a byte-identical lib/security/cacerts.
  • HTTPS to github.com works with the default store; with JAVAX_NET_SSL_TRUSTSTORE set to a store without the needed root it fails with "PKIX path building failed".
  • openjdk11, openjdk17_headless, openjdk21, openjdk25 and jre_minimal instantiate on staging.

Note: the cacerts format cannot carry the NSS "distrust after" dates, so those are lost, as they already are for JDK 8.

Assisted-by: Claude Code (claude-opus-5)

Things done

@nixpkgs-ci
nixpkgs-ci Bot requested review from a team and Infinidoge October 20, 2026 19:33
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1001-2500 This PR causes many rebuilds on Linux and should target the staging branches. llm-assisted Contributions that include code generation with LLMs 6.topic: java Including JDK, tooling, other languages, other VMs labels Oct 20, 2026
zimbatm added a commit to zimbatm/nix-cacert-scan that referenced this pull request Oct 20, 2026
cacert has no Java keystore output. Point at jre-generate-cacerts, as
openjdk uses (NixOS/nixpkgs#576518).

Assisted-by: Claude Code (claude-opus-5)
@hesiod hesiod added the 1.severity: security Issues which raise a security issue, or PRs that fix one label Oct 20, 2026

@Infinidoge Infinidoge left a comment

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.

This feels like something that should have a build option, instead of being something we do unilaterally. However, considering that Java 8 doesn't have a build option to toggle it, this is fine as is.

Comment on lines +344 to +355
''
# Build lib/security/cacerts from cacert instead of the bundled CA list.
# It goes into the java.base jmod, so jlink images also get it.
# Like upstream, write a PKCS12 store without a password: the JDK opens
# cacerts without one, and cannot read password-protected certificates.
+ lib.optionalString atLeast11 ''
mkdir "$NIX_BUILD_TOP/cacerts-gen"
pushd "$NIX_BUILD_TOP/cacerts-gen"
JAVA_TOOL_OPTIONS="-Dkeystore.pkcs12.certProtectionAlgorithm=NONE -Dkeystore.pkcs12.macAlgorithm=NONE" \
${jre-generate-cacerts} ${jdk-bootstrap'.home}/bin/keytool ${cacert}/etc/ssl/certs/ca-bundle.crt
popd
configureFlags+=("--with-cacerts-file=$NIX_BUILD_TOP/cacerts-gen/cacerts")

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.

It feels like $NIX_BUILD_TOP/cacerts-gen should be its own variable so it isn't repeated here, but adding a variable feels a bit extra, so it's probably fine as is.

@zimbatm zimbatm added the backport staging-26.05 Backport PR automatically label Oct 20, 2026
@nixpkgs-ci nixpkgs-ci Bot added 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages. labels Oct 20, 2026
JDK 8 already builds its cacerts from cacert. JDK 11 and later shipped
the CA list that comes with the OpenJDK source. That list does not get
the cacert updates, for example the removal of distrusted roots.

Generate the keystore with the bootstrap keytool before configure and
give it to --with-cacerts-file. The file goes into the java.base jmod,
so jlink images such as jre_minimal also use it.

Write a PKCS12 store without a password, like upstream. The JDK opens
cacerts without a password, so it cannot read certificates that a
password protects.

Assisted-by: Claude Code (claude-opus-5)
@vcunat
vcunat marked this pull request as draft October 21, 2026 07:24
@vcunat
vcunat changed the base branch from staging to master October 21, 2026 07:24
@nixpkgs-ci nixpkgs-ci Bot closed this Oct 21, 2026
@vcunat vcunat added backport staging-next-26.05 Backport PR automatically and removed backport staging-26.05 Backport PR automatically labels Oct 21, 2026
@nixpkgs-ci nixpkgs-ci Bot reopened this Oct 21, 2026
@vcunat
vcunat marked this pull request as ready for review October 21, 2026 07:25
@vcunat

vcunat commented Oct 21, 2026

Copy link
Copy Markdown
Member

nixpkgs master has the big cacert rebuild now, so adding this should be insignificant in terms of additional rebuild work.

@nixpkgs-branch-check nixpkgs-branch-check Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The PR's base branch is set to master, but this PR causes 2079 rebuilds.
It is therefore considered a mass rebuild.
Please change the base branch to the right base branch for your changes (probably staging).

@vcunat
vcunat dismissed nixpkgs-branch-check[bot]’s stale review October 21, 2026 07:33

yes, intentional, special situation now

@vcunat
vcunat added this pull request to the merge queue Oct 21, 2026
Merged via the queue into NixOS:master with commit 60f404d Oct 21, 2026
39 of 57 checks passed
@nixpkgs-ci

nixpkgs-ci Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Successfully created backport PR for staging-next-26.05:

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

Labels

1.severity: security Issues which raise a security issue, or PRs that fix one 6.topic: java Including JDK, tooling, other languages, other VMs 8.has: port to stable This PR already has a backport to the stable release. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 1001-2500 This PR causes many rebuilds on Linux and should target the staging branches. 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages. backport staging-next-26.05 Backport PR automatically llm-assisted Contributions that include code generation with LLMs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openjdk, jdk, jre, java missing cacert

4 participants