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.