Skip to content

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 hierynomus merged commit bb2c48e into hierynomus:master Aug 27, 2021
@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.

2 participants