Blame SOURCES/rh1996182-login_to_nss_software_token.patch

c0ba06
commit 93c9f6330bf2b4405c789bf893a5256c3f4a4923
c0ba06
Author: Martin Balao <mbalao@redhat.com>
c0ba06
Date:   Sat Aug 28 00:35:44 2021 +0100
c0ba06
c0ba06
    RH1996182: Login to the NSS Software Token in FIPS Mode
c0ba06
c0ba06
diff --git openjdk.orig/src/java.base/share/classes/module-info.java openjdk/src/java.base/share/classes/module-info.java
c5ecb0
index 238735c0c8c..dbbf11bbb22 100644
c0ba06
--- openjdk.orig/src/java.base/share/classes/module-info.java
c0ba06
+++ openjdk/src/java.base/share/classes/module-info.java
c5ecb0
@@ -152,6 +152,7 @@ module java.base {
c0ba06
         java.naming,
c0ba06
         java.rmi,
c5ecb0
         jdk.charsets,
c0ba06
+        jdk.crypto.cryptoki,
c0ba06
         jdk.crypto.ec,
c0ba06
         jdk.jartool,
c0ba06
         jdk.jlink,
c0ba06
diff --git openjdk.orig/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java openjdk/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java
c0ba06
index 112b639aa96..5d3963ea893 100644
c0ba06
--- openjdk.orig/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java
c0ba06
+++ openjdk/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java
c0ba06
@@ -42,6 +42,7 @@ import javax.security.auth.callback.PasswordCallback;
c0ba06
 
c0ba06
 import com.sun.crypto.provider.ChaCha20Poly1305Parameters;
c0ba06
 
c0ba06
+import jdk.internal.access.SharedSecrets;
c0ba06
 import jdk.internal.misc.InnocuousThread;
c0ba06
 import sun.security.util.Debug;
c0ba06
 import sun.security.util.ResourcesMgr;
c0ba06
@@ -62,6 +63,9 @@ import static sun.security.pkcs11.wrapper.PKCS11Exception.*;
c0ba06
  */
c0ba06
 public final class SunPKCS11 extends AuthProvider {
c0ba06
 
c0ba06
+    private static final boolean systemFipsEnabled = SharedSecrets
c0ba06
+            .getJavaSecuritySystemConfiguratorAccess().isSystemFipsEnabled();
c0ba06
+
c0ba06
     private static final long serialVersionUID = -1354835039035306505L;
c0ba06
 
c0ba06
     static final Debug debug = Debug.getInstance("sunpkcs11");
c0ba06
@@ -379,6 +383,24 @@ public final class SunPKCS11 extends AuthProvider {
c0ba06
             if (nssModule != null) {
c0ba06
                 nssModule.setProvider(this);
c0ba06
             }
c0ba06
+            if (systemFipsEnabled) {
c0ba06
+                // The NSS Software Token in FIPS 140-2 mode requires a user
c0ba06
+                // login for most operations. See sftk_fipsCheck. The NSS DB
c0ba06
+                // (/etc/pki/nssdb) PIN is empty.
c0ba06
+                Session session = null;
c0ba06
+                try {
c0ba06
+                    session = token.getOpSession();
c0ba06
+                    p11.C_Login(session.id(), CKU_USER, new char[] {});
c0ba06
+                } catch (PKCS11Exception p11e) {
c0ba06
+                    if (debug != null) {
c0ba06
+                        debug.println("Error during token login: " +
c0ba06
+                                p11e.getMessage());
c0ba06
+                    }
c0ba06
+                    throw p11e;
c0ba06
+                } finally {
c0ba06
+                    token.releaseSession(session);
c0ba06
+                }
c0ba06
+            }
c0ba06
         } catch (Exception e) {
c0ba06
             if (config.getHandleStartupErrors() == Config.ERR_IGNORE_ALL) {
c0ba06
                 throw new UnsupportedOperationException