|
41 | 41 | import javax.security.auth.callback.PasswordCallback; |
42 | 42 |
|
43 | 43 | import jdk.internal.misc.InnocuousThread; |
| 44 | +import jdk.internal.misc.SharedSecrets; |
| 45 | + |
44 | 46 | import sun.security.util.Debug; |
45 | 47 | import sun.security.util.ResourcesMgr; |
46 | 48 | import static sun.security.util.SecurityConstants.PROVIDER_VER; |
|
58 | 60 | */ |
59 | 61 | public final class SunPKCS11 extends AuthProvider { |
60 | 62 |
|
| 63 | + private static final boolean systemFipsEnabled = SharedSecrets |
| 64 | + .getJavaSecuritySystemConfiguratorAccess().isSystemFipsEnabled(); |
| 65 | + |
61 | 66 | private static final long serialVersionUID = -1354835039035306505L; |
62 | 67 |
|
63 | 68 | static final Debug debug = Debug.getInstance("sunpkcs11"); |
@@ -374,6 +379,24 @@ private static <T> T checkNull(T obj) { |
374 | 379 | if (nssModule != null) { |
375 | 380 | nssModule.setProvider(this); |
376 | 381 | } |
| 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 | + } |
377 | 400 | } catch (Exception e) { |
378 | 401 | if (config.getHandleStartupErrors() == Config.ERR_IGNORE_ALL) { |
379 | 402 | throw new UnsupportedOperationException |
|
0 commit comments