Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PKCS8 parsing to support PEM ASN.1 Private Keys #708

Merged
merged 2 commits into from
Aug 27, 2021

Conversation

exceptionfactory
Copy link
Contributor

As described in issue #437, OpenSSH and other utilities support generating and storing private keys formatted using PKCS#8. The PKCS8KeyFile class uses the BouncyCastle PEMParser, which returns a PrivateKeyInfo object when reading a PEM file including the header BEGIN PRIVATE KEY. The PKCS8KeyFile.readKeyPair() method logs a debug message indicating that PrivateKeyInfo is not a supported object for parsing.

This pull request adds a KeyPairConverter interface with a primary implementation supporting PrivateKeyInfo objects returned from PEMParser. The PrivateKeyInfoKeyPairConverter delegates to specific implementations based on the Algorithm Object Identifier contained in PrivateKeyInfo. Implementations support reading DSA, ECDSA, and RSA Private Keys, and determining the associated Public Key in order to return a PEMKeyPair.

This pull request includes unit test updates with sample private keys generated using the following ssh-keygen commands:

  • DSA: ssh-keygen -t dsa -m PKCS8
  • ECDSA: ssh-keygen -t ecdsa -m PKCS8
  • RSA: ssh-keygen -t rsa -b 2048 -m PKCS8

Classes included in this pull request should also provide the foundation for an additional implementation that supports reading encrypted private keys.

@exceptionfactory
Copy link
Contributor Author

Thanks for approving the initial workflow run @hierynomus. I pushed a commit adjusting the license header copyright year to match other headers and this passed running ./gradlew check.

@hierynomus
Copy link
Owner

Thanks, merged!

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.

None yet

2 participants