Blame SOURCES/rh1996182-login_to_nss_software_token.patch

53c576
# HG changeset patch
53c576
# User mbalao
53c576
# Date 1630103180 -3600
53c576
#      Fri Aug 27 23:26:20 2021 +0100
53c576
# Node ID b3bd3119fab9bc5adfd7073377aca12bb1af80b3
53c576
# Parent  c90394a76ee02a689f95199559d5724824b4b25e
53c576
RH1996182: Login to the NSS Software Token in FIPS Mode
53c576
53c576
diff --git openjdk.orig/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java openjdk/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java
53c576
--- openjdk.orig/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java
53c576
+++ openjdk/jdk/src/share/classes/sun/security/pkcs11/SunPKCS11.java
53c576
@@ -42,6 +42,8 @@
53c576
 import javax.security.auth.callback.PasswordCallback;
53c576
 import javax.security.auth.callback.TextOutputCallback;
53c576
 
53c576
+import sun.misc.SharedSecrets;
53c576
+
53c576
 import sun.security.util.Debug;
53c576
 import sun.security.util.ResourcesMgr;
53c576
 
53c576
@@ -58,6 +60,9 @@
53c576
  */
53c576
 public final class SunPKCS11 extends AuthProvider {
53c576
 
53c576
+    private static final boolean systemFipsEnabled = SharedSecrets
53c576
+            .getJavaSecuritySystemConfiguratorAccess().isSystemFipsEnabled();
53c576
+
53c576
     private static final long serialVersionUID = -1354835039035306505L;
53c576
 
53c576
     static final Debug debug = Debug.getInstance("sunpkcs11");
53c576
@@ -368,6 +373,24 @@
53c576
             if (nssModule != null) {
53c576
                 nssModule.setProvider(this);
53c576
             }
53c576
+            if (systemFipsEnabled) {
53c576
+                // The NSS Software Token in FIPS 140-2 mode requires a user
53c576
+                // login for most operations. See sftk_fipsCheck. The NSS DB
53c576
+                // (/etc/pki/nssdb) PIN is empty.
53c576
+                Session session = null;
53c576
+                try {
53c576
+                    session = token.getOpSession();
53c576
+                    p11.C_Login(session.id(), CKU_USER, new char[] {});
53c576
+                } catch (PKCS11Exception p11e) {
53c576
+                    if (debug != null) {
53c576
+                        debug.println("Error during token login: " +
53c576
+                                p11e.getMessage());
53c576
+                    }
53c576
+                    throw p11e;
53c576
+                } finally {
53c576
+                    token.releaseSession(session);
53c576
+                }
53c576
+            }
53c576
         } catch (Exception e) {
53c576
             if (config.getHandleStartupErrors() == Config.ERR_IGNORE_ALL) {
53c576
                 throw new UnsupportedOperationException