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