Bug 2038477

Summary: keytool import is failing in FIPS mode with PKCS11Exception CKR_SESSION_READ_ONLY
Product: Red Hat Enterprise Linux 8 Reporter: Magesh Jayapandian <mjayapa>
Component: java-1.8.0-openjdkAssignee: Martin Balao <mbalao>
Status: CLOSED MIGRATED QA Contact: OpenJDK QA <java-qa>
Severity: urgent Docs Contact:
Priority: unspecified    
Version: 8.5CC: dvilkola, fferrari, jvanek, rkshirsa, tidawson
Target Milestone: rcKeywords: MigratedToJIRA
Target Release: ---Flags: pm-rhel: mirror+
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2023-09-12 22:34:03 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:

Description Magesh Jayapandian 2022-01-08 00:23:31 UTC
Description of problem:

Adding a custom certificate (.pem) file to a keystore with FIPS enabled fails with a PKCS11Exception (CKR_SESSION_READ_ONLY).

Here is the command we used:

keytool -import -file $filename -alias ${name} -keystore /etc/pki/java/cacerts -storepass XXXXXXXXXX -noprompt -v 

Here is the error we get:

keytool error: java.security.KeyStoreException: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_SESSION_READ_ONLY
java.security.KeyStoreException: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_SESSION_READ_ONLY
at sun.security.pkcs11.P11KeyStore.engineSetEntry(P11KeyStore.java:1048)
at sun.security.pkcs11.P11KeyStore.engineSetCertificateEntry(P11KeyStore.java:514)
at java.security.KeyStore.setCertificateEntry(KeyStore.java:1201)
at sun.security.tools.keytool.Main.addTrustedCert(Main.java:2885)
at sun.security.tools.keytool.Main.doCommands(Main.java:1063)
at sun.security.tools.keytool.Main.run(Main.java:377)
at sun.security.tools.keytool.Main.main(Main.java:370)
Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_SESSION_READ_ONLY
at sun.security.pkcs11.wrapper.PKCS11.C_CreateObject(Native Method)
at sun.security.pkcs11.wrapper.PKCS11$FIPSPKCS11.C_CreateObject(PKCS11.java:1946)
at sun.security.pkcs11.P11KeyStore.storeCert(P11KeyStore.java:1566)
at sun.security.pkcs11.P11KeyStore.engineSetEntry(P11KeyStore.java:1044)

Version-Release number of selected component (if applicable):
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)

Comment 3 Diana Krepinska 2022-09-29 21:05:27 UTC
I am getting the same "PKCS11Exception: CKR_SESSION_READ_ONLY" error on FIPS enabled RHEL8.6 and RHEL9, openjdk version "11.0.16" 2022-07-19 LTS, when running the following keytool command: 

keytool -keystore NONE -storetype PKCS11 -storepass storepass -genseckey -alias examplekey -keyalg AES -keysize 256 

I was able to run the command successfully by using sudo with the command: 

sudo keytool -keystore NONE -storetype PKCS11 -storepass storepass -genseckey -alias examplekey -keyalg AES -keysize 256

Comment 5 RHEL Program Management 2023-09-12 22:33:24 UTC
Issue migration from Bugzilla to Jira is in process at this time. This will be the last message in Jira copied from the Bugzilla bug.

Comment 6 RHEL Program Management 2023-09-12 22:34:03 UTC
This BZ has been automatically migrated to the issues.redhat.com Red Hat Issue Tracker. All future work related to this report will be managed there.

Due to differences in account names between systems, some fields were not replicated.  Be sure to add yourself to Jira issue's "Watchers" field to continue receiving updates and add others to the "Need Info From" field to continue requesting information.

To find the migrated issue, look in the "Links" section for a direct link to the new issue location. The issue key will have an icon of 2 footprints next to it, and begin with "RHEL-" followed by an integer.  You can also find this issue by visiting https://issues.redhat.com/issues/?jql= and searching the "Bugzilla Bug" field for this BZ's number, e.g. a search like:

"Bugzilla Bug" = 1234567

In the event you have trouble locating or viewing this issue, you can file an issue by sending mail to rh-issues. You can also visit https://access.redhat.com/articles/7032570 for general account information.