Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 2102435

Summary: SecretKey generate/import operations don't add the CKA_SIGN attribute in FIPS mode [rhel-9, openjdk-8]
Product: Red Hat Enterprise Linux 9 Reporter: Francisco Ferrari Bihurriet <fferrari>
Component: java-1.8.0-openjdkAssignee: Francisco Ferrari Bihurriet <fferrari>
Status: CLOSED ERRATA QA Contact: OpenJDK QA <java-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 9.1CC: ahughes, jandrlik, jvanek, pmikova
Target Milestone: rcKeywords: Triaged, ZStream
Target Release: ---Flags: fferrari: mirror+
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: java-1.8.0-openjdk-1.8.0.332.b09-2.el9 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2107956 (view as bug list) Environment:
Last Closed: 2022-11-15 10:19:32 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: 2029668, 2107956    

Description Francisco Ferrari Bihurriet 2022-06-29 22:01:20 UTC
This bug was initially created as a copy of Bug #2007331

I am copying this bug because: 

We need to fix this for RHEL 9 - OpenJDK 8 too.

Mac keys generated by KeyGenerator do not work with the corresponding Mac in FIPS mode. The same failure is obtained with keys imported from plain bytes (through the Bug 1991003 work). This second case had already been identified and fixed in Bug 2020290 (and reported upstream [5]).

The Mac service initialization fails with CKR_KEY_TYPE_INCONSISTENT because the generated key doesn't have the CKA_SIGN attribute: see how NSC_SignInit() calls sftk_InitGeneric(..., CKA_SIGN) to verify the attribute [1], this ends up calling sftk_isTrue(key, operation) with operation=CKA_SIGN [2].


Reproducer, for the 'generate' operation:
/////////////////////////////////////////
import javax.crypto.KeyGenerator;
import javax.crypto.Mac;
import java.security.Key;

public class MacTest {
    public static void main(String[] args) throws Exception {
        Mac mac = Mac.getInstance("HmacSHA256");
        KeyGenerator kg = KeyGenerator.getInstance("HmacSHA256");
        Key key = kg.generateKey();
        System.out.println("key: " + key);
        mac.init(key);
    }
}


Reproducer, for the 'import' operation (adapted from bug 2007331, comment 2):
/////////////////////////////////////////////////////////////////////////////
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.Mac;
import java.security.Key;

public class MacTest {
    public static void main(String[] args) throws Exception {
        Mac mac = Mac.getInstance("HmacSHA256");
        final byte keyBytes[] = "ThisIsAPlainKey!".getBytes();
        Key key = new SecretKeySpec(keyBytes, "HmacSHA256");
        System.out.println("key: " + key);
        mac.init(key);
    }
}


Failure (the same for both reproducers):
////////////////////////////////////////
Exception in thread "main" java.security.InvalidKeyException: init() failed
	at jdk.crypto.cryptoki/sun.security.pkcs11.P11Mac.engineInit(P11Mac.java:214)
	at java.base/javax.crypto.Mac.chooseProvider(Mac.java:365)
	at java.base/javax.crypto.Mac.init(Mac.java:434)
	at MacTest.main(MacTest.java:11)
Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_KEY_TYPE_INCONSISTENT
	at jdk.crypto.cryptoki/sun.security.pkcs11.wrapper.PKCS11.C_SignInit(Native Method)
	at jdk.crypto.cryptoki/sun.security.pkcs11.P11Mac.initialize(P11Mac.java:183)
	at jdk.crypto.cryptoki/sun.security.pkcs11.P11Mac.engineInit(P11Mac.java:212)
	... 3 more


Additional info:
////////////////
Mac however works with key obtained from "SunTls12KeyMaterial" (internal class) following way: [3]. Note that SunPKCS11 provider in earlier JDKs did not provide Mac key generators and this was the only way (I am aware of) to obtain Mac key. Mac key generators were added to SunPKCS11 together with SHA3 support [4].

This means that the 'generate' operation isn't available in earlier JDKs, however the issue for the 'import' operation is reproducible in 8 & 11.

[1] https://github.com/nss-dev/nss/blob/NSS_3_67_RTM/lib/softoken/pkcs11c.c#L2777-L2778
[2] https://github.com/nss-dev/nss/blob/NSS_3_67_RTM/lib/softoken/pkcs11c.c#L444
[3] https://github.com/judovana/CryptoTest/blob/a4bb593d6faa2052606fffb0554141c63468efbb/cryptotest/utils/KeysNaiveGenerator.java#L144
[4] https://bugs.openjdk.java.net/browse/JDK-8242332
[5] https://bugs.openjdk.java.net/browse/JDK-8278640

Comment 1 Francisco Ferrari Bihurriet 2022-06-30 18:45:10 UTC
Proposed equivalent Fedora pull request for the fix: https://src.fedoraproject.org/rpms/java-1.8.0-openjdk/pull-request/161#request_diff

Comment 11 errata-xmlrpc 2022-11-15 10:19:32 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (java-1.8.0-openjdk bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2022:6692