Skip to content

Conversation

@NikSquared
Copy link
Collaborator

This commit adds a JCEKS encoder to the jceks package. Previously, the package was only capable of reading JCEKS files.

Internally, this commmit effectively rewrites the package.

These changes are backward compatible with the previous package API and thus do not require a new major version. However, there are several behavioral changes that have the potential to break existing code that relied on edge cases:

  • The package now returns an error when attempting to parse a JCEKS file that contains an invalid X.509 certificate (either as a trusted certificate entry, or as part of the chain for a private key entry). Previously, the package silently ignored these certificates. JCEKS files containing invalid certificates are invalid, so affected files should be repaired.
  • The package now returns an error by default when parsing a JCEKS file containing a certificate or private key larger than 20MiB. This limit guards against trivial memory exhaustion denial of service attacks from malicious files, but the default is very generous. Callers that need to parse larger certificates or private keys can override the defaults using the new KeyStore.ParseWithOptions method with appropriate options.

The internal changes to the package introduced by this commit are substantial. Some of the highlights include:

  • Fixed a bug with modified UTF-8 parsing.
  • testdata is now generated by go generate, rather than shelling out to openssl and keytool at unit test time.
  • PKCS#5 padding is now removed when parsing.
  • Tests are now far more comprehensive, including fuzz tests.
  • General code cleanup and linter fixes.

This commit adds a JCEKS encoder to the `jceks` package.
Previously, the package was only capable of reading JCEKS files.

Internally, this commmit effectively rewrites the package.

These changes are backward compatible with the previous package API
and thus do not require a new major version. However, there are
several behavioral changes that have the potential to break
existing code that relied on edge cases:

- The package now returns an error when attempting to parse a JCEKS
  file that contains an invalid X.509 certificate (either as a
  trusted certificate entry, or as part of the chain for a private
  key entry). Previously, the package silently ignored these
  certificates. JCEKS files containing invalid certificates are
  invalid, so affected files should be repaired.
- The package now returns an error by default when parsing a JCEKS
  file containing a certificate or private key larger than 20MiB.
  This limit guards against trivial memory exhaustion denial of
  service attacks from malicious files, but the default is very
  generous. Callers that need to parse larger certificates or
  private keys can override the defaults using the new
  `KeyStore.ParseWithOptions` method with appropriate options.

The internal changes to the package introduced by this commit are
substantial. Some of the highlights include:
- Fixed a bug with modified UTF-8 parsing.
- `testdata` is now generated by `go generate`, rather than
  shelling out to `openssl` and `keytool` at unit test time.
- PKCS#5 padding is now removed when parsing.
- Tests are now far more comprehensive, including fuzz tests.
- General code cleanup and linter fixes.
@NikSquared NikSquared requested a review from a team as a code owner August 4, 2025 21:22
Copy link
Contributor

@suzy-huang suzy-huang left a comment

Choose a reason for hiding this comment

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

very comprehensive and well written, thank you!

@NikSquared NikSquared merged commit fe6d52c into master Aug 7, 2025
4 checks passed
@NikSquared NikSquared deleted the nunger.add-jceks-encoder branch August 7, 2025 15:06
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.

3 participants