Skip to content

[Backport] Fix parsing of PBES2 encrypted PKCS#8 keys #79352

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

Merged
merged 9 commits into from
Oct 25, 2021

Conversation

tvernum
Copy link
Contributor

@tvernum tvernum commented Oct 18, 2021

This commit adds support for decrypting PKCS#8 encoded private keys
that have been encrypted using a PBES2 based scheme (AES only).

Unfortunately java.crypto.EncryptedPrivateKeyInfo doesn't make this
easy as the underlying encryption algorithm is hidden within the
AlgorithmParameters, and can only be extracted by calling
toString() on the parameters object.

See: https://datatracker.ietf.org/doc/html/rfc8018#appendix-A.4
See: AlgorithmParameters#toString()
See: com.sun.crypto.provider.PBES2Parameters#toString()

Backport of: #78904

This commit adds support for decrypting PKCS#8 encoded private keys
that have been encrypted using a PBES2 based scheme (AES only).

Unfortunately `java.crypto.EncryptedPrivateKeyInfo` doesn't make this
easy as the underlying encryption algorithm is hidden within the
`AlgorithmParameters`, and can only be extracted by calling
`toString()` on the parameters object.

See: https://datatracker.ietf.org/doc/html/rfc8018#appendix-A.4
See: AlgorithmParameters#toString()
See: com.sun.crypto.provider.PBES2Parameters#toString()

Backport of: elastic#78904
@tvernum tvernum added :Security/TLS SSL/TLS, Certificates backport auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) labels Oct 18, 2021
@elasticmachine elasticmachine added the Team:Security Meta label for security team label Oct 18, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-security (Team:Security)

@tvernum tvernum removed the auto-merge-without-approval Automatically merge pull request when CI checks pass (NB doesn't wait for reviews!) label Oct 19, 2021
@tvernum tvernum requested a review from jkakavas October 19, 2021 03:13
@tvernum
Copy link
Contributor Author

tvernum commented Oct 19, 2021

@jkakavas As part of the backport, I added special case code for JDK8 because the JDK enhancements we rely on were backported to 8
That means PBES2 isn't supported at all on JDK8, but at least we give a good error message.

@tvernum
Copy link
Contributor Author

tvernum commented Oct 19, 2021

That means PBES2 isn't supported at all on JDK8, but at least we give a good error message.

Turns out it is supported on Oracle JDK8, but not OpenJDK8

@tvernum
Copy link
Contributor Author

tvernum commented Oct 20, 2021

@elasticmachine update branch

Copy link
Member

@jkakavas jkakavas left a comment

Choose a reason for hiding this comment

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

LGTM, sorry I missed the original ping for the review. I added a comment about the oracle vs openjdk 8 case but I'm fine as it is now.

}
if (JavaVersion.current().compareTo(JavaVersion.parse("11.0.0")) < 0) {
// PBES2 appears to be supported on Oracle 8, but not OpenJDK8
// We don't both clarifying that here because it is supported on the bundled JDK, and that's what people should use
Copy link
Member

Choose a reason for hiding this comment

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

both -> bother ( in case you need to make another commit for another reason)

@tvernum tvernum merged commit 7d8601e into elastic:7.16 Oct 25, 2021
tvernum added a commit to tvernum/elasticsearch that referenced this pull request Oct 26, 2021
This commit adds support for decrypting PKCS#8 encoded private keys
that have been encrypted using a PBES2 based scheme (AES only).

Unfortunately `java.crypto.EncryptedPrivateKeyInfo` doesn't make this
easy as the underlying encryption algorithm is hidden within the
`AlgorithmParameters`, and can only be extracted by calling
`toString()` on the parameters object.

See: https://datatracker.ietf.org/doc/html/rfc8018#appendix-A.4
See: AlgorithmParameters#toString()
See: com.sun.crypto.provider.PBES2Parameters#toString()

This support is conditional on the underlying support in the JDK, which is absent from OpenJDK 8, but should work on all other supported JDKs.

Backport of: elastic#78904
Backport of: elastic#79352
elasticsearchmachine pushed a commit that referenced this pull request Oct 26, 2021
This commit adds support for decrypting PKCS#8 encoded private keys
that have been encrypted using a PBES2 based scheme (AES only).

Unfortunately `java.crypto.EncryptedPrivateKeyInfo` doesn't make this
easy as the underlying encryption algorithm is hidden within the
`AlgorithmParameters`, and can only be extracted by calling
`toString()` on the parameters object.

See: https://datatracker.ietf.org/doc/html/rfc8018#appendix-A.4
See: AlgorithmParameters#toString()
See: com.sun.crypto.provider.PBES2Parameters#toString()

This support is conditional on the underlying support in the JDK, which is absent from OpenJDK 8, but should work on all other supported JDKs.

Backport of: #78904
Backport of: #79352
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport :Security/TLS SSL/TLS, Certificates Team:Security Meta label for security team v7.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants