Blame SOURCES/rh1996182-login_to_nss_software_token.patch

97e098
commit 53bda6adfacc02b8dddd8f10350c9569bca4eb1e
97e098
Author: Martin Balao <mbalao@redhat.com>
97e098
Date:   Fri Aug 27 19:42:07 2021 +0100
97e098
97e098
    RH1996182: Login to the NSS Software Token in FIPS Mode
97e098
97e098
diff --git openjdk.orig/src/java.base/share/classes/module-info.java openjdk/src/java.base/share/classes/module-info.java
97e098
index 5460efcf8c..f08dc2fafc 100644
97e098
--- openjdk.orig/src/java.base/share/classes/module-info.java
97e098
+++ openjdk/src/java.base/share/classes/module-info.java
97e098
@@ -182,6 +182,7 @@ module java.base {
97e098
         java.security.jgss,
97e098
         java.sql,
97e098
         java.xml,
97e098
+        jdk.crypto.cryptoki,
97e098
         jdk.jartool,
97e098
         jdk.attach,
97e098
         jdk.charsets,
97e098
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
97e098
index 5e227f4531..164de8ff08 100644
97e098
--- openjdk.orig/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java
97e098
+++ openjdk/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java
97e098
@@ -41,6 +41,8 @@ import javax.security.auth.callback.CallbackHandler;
97e098
 import javax.security.auth.callback.PasswordCallback;
97e098
 
97e098
 import jdk.internal.misc.InnocuousThread;
97e098
+import jdk.internal.misc.SharedSecrets;
97e098
+
97e098
 import sun.security.util.Debug;
97e098
 import sun.security.util.ResourcesMgr;
97e098
 import static sun.security.util.SecurityConstants.PROVIDER_VER;
97e098
@@ -58,6 +60,9 @@ import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
97e098
  */
97e098
 public final class SunPKCS11 extends AuthProvider {
97e098
 
97e098
+    private static final boolean systemFipsEnabled = SharedSecrets
97e098
+            .getJavaSecuritySystemConfiguratorAccess().isSystemFipsEnabled();
97e098
+
97e098
     private static final long serialVersionUID = -1354835039035306505L;
97e098
 
97e098
     static final Debug debug = Debug.getInstance("sunpkcs11");
97e098
@@ -374,6 +379,24 @@ public final class SunPKCS11 extends AuthProvider {
97e098
             if (nssModule != null) {
97e098
                 nssModule.setProvider(this);
97e098
             }
97e098
+            if (systemFipsEnabled) {
97e098
+                // The NSS Software Token in FIPS 140-2 mode requires a user
97e098
+                // login for most operations. See sftk_fipsCheck. The NSS DB
97e098
+                // (/etc/pki/nssdb) PIN is empty.
97e098
+                Session session = null;
97e098
+                try {
97e098
+                    session = token.getOpSession();
97e098
+                    p11.C_Login(session.id(), CKU_USER, new char[] {});
97e098
+                } catch (PKCS11Exception p11e) {
97e098
+                    if (debug != null) {
97e098
+                        debug.println("Error during token login: " +
97e098
+                                p11e.getMessage());
97e098
+                    }
97e098
+                    throw p11e;
97e098
+                } finally {
97e098
+                    token.releaseSession(session);
97e098
+                }
97e098
+            }
97e098
         } catch (Exception e) {
97e098
             if (config.getHandleStartupErrors() == Config.ERR_IGNORE_ALL) {
97e098
                 throw new UnsupportedOperationException