Blame SOURCES/rh1996182-login_to_nss_software_token.patch

7b806d
diff --git openjdk.orig/src/java.base/share/classes/module-info.java openjdk/src/java.base/share/classes/module-info.java
ba2829
index 5460efcf8c..f08dc2fafc 100644
7b806d
--- openjdk.orig/src/java.base/share/classes/module-info.java
7b806d
+++ openjdk/src/java.base/share/classes/module-info.java
7b806d
@@ -182,6 +182,7 @@ module java.base {
7b806d
         java.security.jgss,
7b806d
         java.sql,
7b806d
         java.xml,
7b806d
+        jdk.crypto.cryptoki,
7b806d
         jdk.jartool,
7b806d
         jdk.attach,
7b806d
         jdk.charsets,
7b806d
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
3b014a
index 099caac605..ffadb43eb1 100644
7b806d
--- openjdk.orig/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java
7b806d
+++ openjdk/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java
3b014a
@@ -43,6 +43,8 @@ import javax.security.auth.callback.PasswordCallback;
3b014a
 import com.sun.crypto.provider.ChaCha20Poly1305Parameters;
7b806d
 
ba2829
 import jdk.internal.misc.InnocuousThread;
7b806d
+import jdk.internal.misc.SharedSecrets;
7b806d
+
7b806d
 import sun.security.util.Debug;
7b806d
 import sun.security.util.ResourcesMgr;
7b806d
 import static sun.security.util.SecurityConstants.PROVIDER_VER;
3b014a
@@ -60,6 +62,9 @@ import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
7b806d
  */
7b806d
 public final class SunPKCS11 extends AuthProvider {
7b806d
 
7b806d
+    private static final boolean systemFipsEnabled = SharedSecrets
7b806d
+            .getJavaSecuritySystemConfiguratorAccess().isSystemFipsEnabled();
7b806d
+
7b806d
     private static final long serialVersionUID = -1354835039035306505L;
7b806d
 
7b806d
     static final Debug debug = Debug.getInstance("sunpkcs11");
3b014a
@@ -376,6 +381,24 @@ public final class SunPKCS11 extends AuthProvider {
7b806d
             if (nssModule != null) {
7b806d
                 nssModule.setProvider(this);
7b806d
             }
7b806d
+            if (systemFipsEnabled) {
7b806d
+                // The NSS Software Token in FIPS 140-2 mode requires a user
7b806d
+                // login for most operations. See sftk_fipsCheck. The NSS DB
7b806d
+                // (/etc/pki/nssdb) PIN is empty.
7b806d
+                Session session = null;
7b806d
+                try {
7b806d
+                    session = token.getOpSession();
7b806d
+                    p11.C_Login(session.id(), CKU_USER, new char[] {});
7b806d
+                } catch (PKCS11Exception p11e) {
7b806d
+                    if (debug != null) {
7b806d
+                        debug.println("Error during token login: " +
7b806d
+                                p11e.getMessage());
7b806d
+                    }
7b806d
+                    throw p11e;
7b806d
+                } finally {
7b806d
+                    token.releaseSession(session);
7b806d
+                }
7b806d
+            }
7b806d
         } catch (Exception e) {
7b806d
             if (config.getHandleStartupErrors() == Config.ERR_IGNORE_ALL) {
7b806d
                 throw new UnsupportedOperationException