JDK-8336499 : Failure when creating non-CRT RSA private keys in SunPKCS11
  • Type: Bug
  • Component: security-libs
  • Sub-Component: javax.crypto:pkcs11
  • Affected Version: 17.0.10,21,23
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2024-07-16
  • Updated: 2024-07-29
  • Resolved: 2024-07-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 24
24 b08Fixed
Related Reports
Relates :  
Description
After JDK-8271566, the CKA_MODULUS and CKA_PRIVATE_EXPONENT attributes were added to the list passed to Java's C_GetAttributeValue wrapper when determining if a private RSA key is CRT or non-CRT [1]. The rationale was to make a single query and have both CKA_MODULUS and CKA_PRIVATE_EXPONENT available beforehand, avoiding a potential second query later. Most PKCS #11 tokens benefit from this saving.

Contrary to the native C_GetAttributeValue PKCS #11 API, its Java counterpart does not return any attribute value if there is an error in one of the attributes queried (e.g. if CKR_ATTRIBUTE_TYPE_INVALID is returned) [2]. If a non-CRT key is created in a token (pre PKCS #11 2.40), the query including all attributes will fail and CKA_MODULUS and CKA_PRIVATE_EXPONENT will not be available. An error will be thrown here [3].

This bug was reported by Bob Du (IBM).

--
[1] - https://git.openjdk.org/jdk/blob/jdk-24%2B6/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java#L568
[2] - https://git.openjdk.org/jdk/blob/jdk-24%2B6/src/jdk.crypto.cryptoki/share/native/libj2pkcs11/p11_objmgmt.c#L252
[3] - https://git.openjdk.org/jdk/blob/jdk-24%2B6/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java#L594
Comments
Changeset: 3251eea1 Branch: master Author: Martin Balao <mbalao@openjdk.org> Date: 2024-07-24 02:39:35 +0000 URL: https://git.openjdk.org/jdk/commit/3251eea1f4289a0505052be204407c02ca38b0ad
24-07-2024

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/20204 Date: 2024-07-16 23:22:45 +0000
17-07-2024

This is hard to test because the NSS Software Token does not allow the creation of non-CRT RSA private keys, as commented here [1]. CKA_PUBLIC_EXPONENT is required starting at PKCS #11 v2.40. -- [1] - https://git.openjdk.org/jdk/blob/jdk-24%2B6/test/jdk/sun/security/pkcs11/rsa/TestKeyFactory.java#L206
16-07-2024