Bug 2099840

Summary: rh1991003 patch breaks sun.security.pkcs11.wrapper.PKCS11.getInstance() [rhel-8, openjdk-17]
Product: Red Hat Enterprise Linux 8 Reporter: Andrew John Hughes <ahughes>
Component: java-17-openjdkAssignee: Andrew John Hughes <ahughes>
Status: CLOSED ERRATA QA Contact: OpenJDK QA <java-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 8.7CC: fferrari, jandrlik, pmikova
Target Milestone: rcKeywords: Triaged, ZStream
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: java-17-openjdk-17.0.3.0.7-4.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2099913 2099914 (view as bug list) Environment:
Last Closed: 2022-11-08 09:32: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:
Bug Depends On:    
Bug Blocks: 2099913, 2099914    

Description Andrew John Hughes 2022-06-21 19:35:34 UTC
This bug was initially created as a copy of Bug #2097152

I am copying this bug because: 

Need to cover OpenJDK 17 on RHEL 8 too

This bug was initially created as a copy of Bug #2036462

I am copying this bug because: 

Original is for Fedora and we have a RHEL customer issue related to this now.

Description of problem:

The sun.security.pkcs11.wrapper.PKCS11 class contains a public method, getInstance with 4 arguments. The patch related to bug 1991003, modifies this method by adding an additional 5th argument, fipsKeyImporter, of type MethodHandle.

https://src.fedoraproject.org/rpms/java-1.8.0-openjdk/blob/f35/f/rh1991003-enable_fips_keys_import.patch#_446

Possibly due to an oversight, the patch lacks public API compatible method with the same argument count to use with existing software. Due to this, existing applications could fail, showing exceptions like the following:

java.lang.NoSuchMethodError: sun.security.pkcs11.wrapper.PKCS11.getInstance(Ljava/lang/String;Ljava/lang/String;Lsun/security/pkcs11/wrapper/CK_C_INITIALIZE_ARGS;Z)Lsun/security/pkcs11/wrapper/PKCS11;


Version-Release number of selected component (if applicable):

java-1.8.0-openjdk-1.8.0.312.b07-2.fc35

And likely the equivalent in other versions (11, etc.).


How reproducible:

Always.


Steps to Reproduce:
1. Create a file Test.java with the following:

class Test {
    public static void main(String[] args) throws Exception {
        sun.security.pkcs11.wrapper.CK_C_INITIALIZE_ARGS initArgs = new sun.security.pkcs11.wrapper.CK_C_INITIALIZE_ARGS();
        initArgs.flags = 0;
        sun.security.pkcs11.wrapper.PKCS11 pkcs11 = sun.security.pkcs11.wrapper.PKCS11.getInstance("/usr/lib64/opensc-pkcs11.so", "C_GetFunctionList", initArgs, false);

        long[] slotList = pkcs11.C_GetSlotList(true);
        for (long slot : slotList) {
            sun.security.pkcs11.wrapper.CK_TOKEN_INFO tokenInfo = pkcs11.C_GetTokenInfo(slot);
            System.out.println("Slot info:\n" + tokenInfo.toString());
        }
    }
}

2. save and compile with: javac Test.java


Actual results:

test.java:5: error: method getInstance in class PKCS11 cannot be applied to given types;
        sun.security.pkcs11.wrapper.PKCS11 pkcs11 = sun.security.pkcs11.wrapper.PKCS11.getInstance("/usr/lib64/opensc-pkcs11.so", "C_GetFunctionList", initArgs, false);
                                                                                      ^
  required: String,String,CK_C_INITIALIZE_ARGS,boolean,MethodHandle
  found: String,String,CK_C_INITIALIZE_ARGS,boolean
  reason: actual and formal argument lists differ in length
1 error


Expected results:

It builds as is.


Additional info:

The affected API is widely used by applications needing to handle available tokens and their slots also for handle public certificates on tokens without requiring login.

If you add a null as a 5th argument, it builds. But will fail to run on JREs not affected by the patch.

If you build the source from a JDK not affected by the patch and run the class with java Test on an affected JRE, it will fail as mentioned in the "Description of problem" section.

Comment 10 errata-xmlrpc 2022-11-08 09:32:03 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-17-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:6691