Skip to content

Commit 8f6bbc1

Browse files
martinuygnu-andrew
authored andcommitted
RH1996182: Login to the NSS Software Token in FIPS Mode
1 parent ac28a35 commit 8f6bbc1

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/java.base/share/classes/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
java.security.jgss,
183183
java.sql,
184184
java.xml,
185+
jdk.crypto.cryptoki,
185186
jdk.jartool,
186187
jdk.attach,
187188
jdk.charsets,

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/SunPKCS11.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import javax.security.auth.callback.PasswordCallback;
4242

4343
import jdk.internal.misc.InnocuousThread;
44+
import jdk.internal.misc.SharedSecrets;
45+
4446
import sun.security.util.Debug;
4547
import sun.security.util.ResourcesMgr;
4648
import static sun.security.util.SecurityConstants.PROVIDER_VER;
@@ -58,6 +60,9 @@
5860
*/
5961
public final class SunPKCS11 extends AuthProvider {
6062

63+
private static final boolean systemFipsEnabled = SharedSecrets
64+
.getJavaSecuritySystemConfiguratorAccess().isSystemFipsEnabled();
65+
6166
private static final long serialVersionUID = -1354835039035306505L;
6267

6368
static final Debug debug = Debug.getInstance("sunpkcs11");
@@ -374,6 +379,24 @@ private static <T> T checkNull(T obj) {
374379
if (nssModule != null) {
375380
nssModule.setProvider(this);
376381
}
382+
if (systemFipsEnabled) {
383+
// The NSS Software Token in FIPS 140-2 mode requires a user
384+
// login for most operations. See sftk_fipsCheck. The NSS DB
385+
// (/etc/pki/nssdb) PIN is empty.
386+
Session session = null;
387+
try {
388+
session = token.getOpSession();
389+
p11.C_Login(session.id(), CKU_USER, new char[] {});
390+
} catch (PKCS11Exception p11e) {
391+
if (debug != null) {
392+
debug.println("Error during token login: " +
393+
p11e.getMessage());
394+
}
395+
throw p11e;
396+
} finally {
397+
token.releaseSession(session);
398+
}
399+
}
377400
} catch (Exception e) {
378401
if (config.getHandleStartupErrors() == Config.ERR_IGNORE_ALL) {
379402
throw new UnsupportedOperationException

0 commit comments

Comments
 (0)