Bug 2173792

Summary: C_GetInfo can throw an exception if called before initialization in some PKCS #11 tokens [rhel-9, openjdk-17]
Product: Red Hat Enterprise Linux 9 Reporter: Martin Balao <mbalao>
Component: java-17-openjdkAssignee: Martin Balao <mbalao>
Status: CLOSED CURRENTRELEASE QA Contact: OpenJDK QA <java-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 9.3CC: ahughes, jvanek
Target Milestone: rcKeywords: Triaged, ZStream
Target Release: ---Flags: pm-rhel: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: java-17-openjdk-17.0.7.0.7-3.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2186806 2186807 2186808 (view as bug list) Environment:
Last Closed: 2023-06-26 15:11:11 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2186806, 2186807, 2186808    

Description Martin Balao 2023-02-28 01:11:19 UTC
This bug was initially created as a copy of Bug #2173781

I am copying this bug because: 



In some PKCS #11 tokens, calling C_GetInfo before initialization returns a CKR_CRYPTOKI_NOT_INITIALIZED error [1]. If this happens, the error is then transformed into a PKCS11Exception and thrown in the PKCS11 constructor [2]. Throwing an exception at that point would be unnecessarily fatal: execution should continue and it's only Password-Based Encryption who might, at some point, require the information —hopefully, the token will be initialized by then. Notice that this problem could not be reproduced with the NSS Software Token but with p11-kit-trust.so.

JDK-8255409 [3], available since JDK-18 (OpenJDK upstream), seems to handle a C_GetInfo throwing an exception in the constructor of PKCS11 [4]. It's not the goal of this ticket to backport JDK-8255409 to 17u but to fix this regression. Other options, such as backporting JDK-8255409 to 17u, will be considered in the future once the Password-Based Cryptography enhancement is accepted in OpenJDK head and backported to 17u [5].

PR discussion: https://github.com/rh-openjdk/jdk/pull/26

--
[1] - https://docs.oasis-open.org/pkcs11/pkcs11-spec/v3.1/cs01/pkcs11-spec-v3.1-cs01.html#_Toc111203257
[2] - https://github.com/rh-openjdk/jdk/blob/1e26894969d911776f60eaa557d25a2b389060da/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/wrapper/PKCS11.java#L156
[3] - https://bugs.openjdk.org/browse/JDK-8255409
[4] - https://github.com/openjdk/jdk/commit/83e6a4c0e9e4a9474ae0c1252378b1a09d1d2df0#diff-507046ab6e8d2a75a31fe49822a43729eefa2ca12b4fe1c27f427ebb0702e208R160
[5] - https://github.com/openjdk/jdk/pull/12396