RH2092507: P11Key.getEncoded does not work for DH keys in FIPS mode #16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Search this PR in Red Hat Jira
RH2092507: P11Key.getEncoded does not work for DH keys in FIPS mode
Description
This work fixes the
P11Key.getEncoded()issue by enabling SunJCE's secret key factories in FIPS mode (except for PBKDF2 secret key factories, which perform key derivation [†], a cryptographic operation that should only be handled bySunPKCS11-NSS-FIPS).This issue was introduced in 6e74f28 (RH2052070), when a stripped/locked-down version of the SunJCE provider was added to
java.securityin FIPS mode (by means of theif (!systemFipsEnabled) { /* disabled code */ }patching). SunPKCS11'sP11Key.getEncoded()internally uses SunJCE'sKeyFactoryto encode Diffie-Hellman public keys despite SunJCE not being listed injava.security[‡]. Before 6e74f28, SunJCE didn't need to be stripped/locked-down, so SunPKCS11 was directly using it unpatched, but now that it is listed injava.security(i.e. publicly available as a provider), the lock-down patching is mandatory. Consequently, we are just enabling SunJCE key factories without cryptographic code, required by SunPKCS11 keys encoding (such as theKeyFactoryfor"DiffieHellman"/"DH").[†] See the following code:
jdk/src/java.base/share/classes/com/sun/crypto/provider/SunJCE.java
Lines 623 to 626 in 03b584e
jdk/src/java.base/share/classes/com/sun/crypto/provider/PBKDF2Core.java
Line 70 in 03b584e
jdk/src/java.base/share/classes/com/sun/crypto/provider/PBKDF2KeyImpl.java
Line 119 in 03b584e
[‡] See the following code:
jdk/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java
Lines 167 to 171 in 03b584e
jdk/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java
Lines 966 to 967 in 03b584e
jdk/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Util.java
Lines 71 to 116 in 03b584e