This commit adds tests for the `jceks` package against the
installed JDK's `keytool` CLI. The tests ensure that JCEKS files
created by `keytool` can be read by the package, and vice versa.
These tests are disabled by default and are enabled with the
`-jceks.keytool-tests=true` flag. This commit configures GitHub
Actions to test the package against a wide variety of JDKs.
This commit also restricts GitHub Actions permissions.
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 an explicit `golangci-lint` configuration that
simply matches the default linters previously in use, and then
fixes all current linter findings.
Aside from tweaking error message strings, this commit introduces
one externally visible behavior change: PEM data generated from
PKCS#12 files now correctly identifies private key blocks as
`RSA PRIVATE KEY` or `EC PRIVATE KEY`, whereas previously it
generated invalid `PRIVATE KEY` blocks with non-PKCS#8 data.
This commit lays the groundwork for more aggressive linting in the
future, and identifies some additional issues via TODOs.