Blame SOURCES/rh1996182-login_to_nss_software_token.patch

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