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 2102430 - SecretKey generate/import operations don't add the CKA_SIGN attribute in FIPS mode [rhel-8, openjdk-11]
Summary: SecretKey generate/import operations don't add the CKA_SIGN attribute in FIPS...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: java-11-openjdk
Version: 8.7
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Francisco Ferrari Bihurriet
QA Contact: OpenJDK QA
URL:
Whiteboard:
Depends On:
Blocks: 2029660 2108251 2108252
TreeView+ depends on / blocked
 
Reported: 2022-06-29 22:00 UTC by Francisco Ferrari Bihurriet
Modified: 2022-11-08 09:50 UTC (History)
3 users (show)

Fixed In Version: java-11-openjdk-11.0.15.0.10-5.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 2108251 2108252 (view as bug list)
Environment:
Last Closed: 2022-11-08 09:21:51 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Fedora Package Sources java-11-openjdk pull-request 157 0 None None None 2022-10-14 15:25:44 UTC
Red Hat Issue Tracker RHELPLAN-126671 0 None None None 2022-06-29 22:22:35 UTC
Red Hat Product Errata RHBA-2022:6693 0 None None None 2022-11-08 09:22:48 UTC

Description Francisco Ferrari Bihurriet 2022-06-29 22:00:04 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 8 - OpenJDK 11 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:44:13 UTC
Proposed equivalent Fedora pull request for the fix: https://src.fedoraproject.org/rpms/java-11-openjdk/pull-request/157#request_diff

Comment 10 errata-xmlrpc 2022-11-08 09:21:51 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-11-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:6693


Note You need to log in before you can comment on or make changes to this bug.