Skip to content

Fix parsing of PBES2 encrypted PKCS#8 keys #78904

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 3 commits into from
Oct 18, 2021

Conversation

tvernum
Copy link
Contributor

@tvernum tvernum commented Oct 11, 2021

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

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()

Resolves: #78901, #32021

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

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()

Resolves: elastic#78901
@tvernum tvernum requested a review from jkakavas October 11, 2021 07:26
@elasticmachine elasticmachine added the Team:Security Meta label for security team label Oct 11, 2021
@elasticmachine
Copy link
Collaborator

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

@tvernum
Copy link
Contributor Author

tvernum commented Oct 11, 2021

On backport to 7.x, I'll need to include the same change in the X-Pack version of the PEM Private Key Parser.

- On Java11 the algorithm is an OID rather than the "PBES2" name
- Detect DES based PBES2 encryption and fail in a more meaningful way
}

/**
* This is horrible, but it's the only option other than to parse the encoded ASN.1 value ourselves
Copy link
Member

Choose a reason for hiding this comment

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

👍

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

@tvernum tvernum merged commit 7cc9edb into elastic:master Oct 18, 2021
tvernum added a commit to tvernum/elasticsearch that referenced this pull request 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: elastic#78904
weizijun added a commit to weizijun/elasticsearch that referenced this pull request Oct 18, 2021
* upstream/master:
  Changing test keytab to use aes256-cts-hmac-sha1-96 instead of des3-cbc-sha1-kd (elastic#78703)
  Add support for configuring HNSW parameters (elastic#79193)
  Deprecate resolution loss on date field (elastic#78921)
  Add Optional to Configure bind user (elastic#78303)
  Adapt BWC after backporting elastic#78765 (elastic#79350)
  [DOCS] Add deprecation notice for reset password tool (elastic#78793)
  added test for flattened type in top_metrics.yml (elastic#78960)
  [DOCS] Fixes indentation issue in GET trained models API docs. (elastic#79347)
  Fix parsing of PBES2 encrypted PKCS#8 keys (elastic#78904)
  Mute testReindex (elastic#79343)
  Node level can match action (elastic#78765)
  Fix duplicate license header in source files (elastic#79236)
  AllowAll for indicesAccessControl (elastic#78498)
  Better logging and internal user handling for operator privileges (elastic#79331)

# Conflicts:
#	server/src/main/java/org/elasticsearch/index/mapper/MappingParser.java
tvernum added a commit that referenced this pull request Oct 25, 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
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
>bug :Security/TLS SSL/TLS, Certificates Team:Security Meta label for security team v7.15.2 v7.16.0 v8.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PemUtils fails to parse PKCS#8 private keys when using PBES2
4 participants