“Secmod 模块已配置”重新加载时在小程序中
我正在修改一个签名的小程序,它使用用户证书连接到servlet,然后确认用户的一些信息(他的名字是别名。它是一个官方证书)。
它基本上使用 getLocalCertificates() (连接后),在资源管理器中它可以很好地返回别名并连接到 SSL 安全 servlet 并返回有关用户的信息。在 Firefox(以及 Chrome、Safari...)中,它返回 null 作为别名,并返回 403。
因此,我基于在本地 NSS 数据库中加载证书的方式为 Firefox 实现了 setSSLSocketFactory() 系统。
这是我在 Firefox 的 Java 控制台中遇到的错误。
我收到此错误:
·· _pk11provider
_pk11provider Secmod module already configured
·· Set keyStore:
java.lang.IllegalArgumentException: missing provider
at java.security.KeyStore.getInstance(Unknown Source)
at com.cmt.applets.notif.AppletNotif.setMozillaKeyStore(AppletNotif.java:1635)
at com.cmt.applets.notif.AppletNotif.setAlias(AppletNotif.java:1404)
at com.cmt.applets.notif.AppletNotif.init(AppletNotif.java:223)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.IllegalArgumentException: missing provider
Firefox 的代码(目前仅适用于 Windows)是
[...]
String userProfile = Mozilla.getMozillaUserProfileDirectory();
// Define provider
String providerConfig = "name = NSS" + "\n" + "nssLibraryDirectory = "
+ dir + "\n" + "nssSecmodDirectory = \"" + userProfile + "\"\n"
+ "nssDbMode = readOnly" + "\n" + "nssModule = keystore" + "\n"
+ "\r";
// Load Firefox Dlls
Mozilla.loadDll(dir);
ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(
providerConfig.getBytes());
SunPKCS11 pk11provider = null;
System.out.println(" ·· _pk11provider ");
try {
pk11provider = new SunPKCS11(localByteArrayInputStream);
System.out.println(" ·· addProvider(_pk11provider) ");
Security.addProvider(pk11provider);
System.out.println(" ·· _pk11provider.login ");
pk11provider.login(new Subject(), new DialogCallbackHandler());
//} catch (Throwable e) {
} catch (Exception e) {
System.out.println(" _pk11provider " + e.getMessage());
}
// Set keyStore using PKCS11 (for NSS Firefox)
System.out.println(" ·· Set keyStore: ");
try {
keyStore = KeyStore.getInstance("PKCS11", pk11provider);
} catch (KeyStoreException e) {
System.out.println(" Exception en keyStore.getInstance");
e.printStackTrace();
}
System.out.println(" ·· Load keystore");
try {
keyStore.load(localByteArrayInputStream, null);
} catch (NoSuchAlgorithmException e) {
System.out.println(" NoSuchAlgorithmException en keyStore.load(). ");
e.printStackTrace();
} catch (CertificateException e) {
System.out.println(" CertificateException en keyStore.load(). ");
e.printStackTrace();
} catch (IOException e) {
System.out.println(" IOException en keyStore.load(). ");
e.printStackTrace();
}
System.out.println("localByteArrayInputStream.close() ");
try {
localByteArrayInputStream.close();
} catch(final Exception e)
{
System.out.println("localByteArrayInputStream.close() " + e.getMessage());
}
[...]
此代码正在从 Applet.init() 调用...因此应该仅调用第一个时间。它有效...一次。如果我在同一个 Firefox 选项卡中重新加载小程序,由于“Secmod 模块已配置”,我会收到“缺少提供程序”错误。
在 Google 和 Bing 中搜索“Secmod 模块已配置”时,我得到了 SunPKCS11 的原始 java 库源代码。 java:
if (nssModule.hasInitializedProvider()) {
throw new ProviderException(
"Secmod module already configured");
}
这似乎与错误“缺少提供者”矛盾......
有什么想法吗?
I'm modifying a signed applet which uses a user certificate to connect to a servlet and then confirms some information of the user (his name is the alias. It is an official certificate).
It basically uses getLocalCertificates() (after connecting) and in Explorer it works fine returning the alias and connecting to the SSL secured servlet and returning the information about the user. In Firefox (and Chrome, and Safari...) it returns null as alias, and it returns a 403.
So I've implemented a setSSLSocketFactory() system for Firefox based on loading the certificates in the local NSS database.
This is the error I get in Firefox's Java Console.
I get this error:
·· _pk11provider
_pk11provider Secmod module already configured
·· Set keyStore:
java.lang.IllegalArgumentException: missing provider
at java.security.KeyStore.getInstance(Unknown Source)
at com.cmt.applets.notif.AppletNotif.setMozillaKeyStore(AppletNotif.java:1635)
at com.cmt.applets.notif.AppletNotif.setAlias(AppletNotif.java:1404)
at com.cmt.applets.notif.AppletNotif.init(AppletNotif.java:223)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.IllegalArgumentException: missing provider
The code for Firefox (at this moment only for Windows) is
[...]
String userProfile = Mozilla.getMozillaUserProfileDirectory();
// Define provider
String providerConfig = "name = NSS" + "\n" + "nssLibraryDirectory = "
+ dir + "\n" + "nssSecmodDirectory = \"" + userProfile + "\"\n"
+ "nssDbMode = readOnly" + "\n" + "nssModule = keystore" + "\n"
+ "\r";
// Load Firefox Dlls
Mozilla.loadDll(dir);
ByteArrayInputStream localByteArrayInputStream = new ByteArrayInputStream(
providerConfig.getBytes());
SunPKCS11 pk11provider = null;
System.out.println(" ·· _pk11provider ");
try {
pk11provider = new SunPKCS11(localByteArrayInputStream);
System.out.println(" ·· addProvider(_pk11provider) ");
Security.addProvider(pk11provider);
System.out.println(" ·· _pk11provider.login ");
pk11provider.login(new Subject(), new DialogCallbackHandler());
//} catch (Throwable e) {
} catch (Exception e) {
System.out.println(" _pk11provider " + e.getMessage());
}
// Set keyStore using PKCS11 (for NSS Firefox)
System.out.println(" ·· Set keyStore: ");
try {
keyStore = KeyStore.getInstance("PKCS11", pk11provider);
} catch (KeyStoreException e) {
System.out.println(" Exception en keyStore.getInstance");
e.printStackTrace();
}
System.out.println(" ·· Load keystore");
try {
keyStore.load(localByteArrayInputStream, null);
} catch (NoSuchAlgorithmException e) {
System.out.println(" NoSuchAlgorithmException en keyStore.load(). ");
e.printStackTrace();
} catch (CertificateException e) {
System.out.println(" CertificateException en keyStore.load(). ");
e.printStackTrace();
} catch (IOException e) {
System.out.println(" IOException en keyStore.load(). ");
e.printStackTrace();
}
System.out.println("localByteArrayInputStream.close() ");
try {
localByteArrayInputStream.close();
} catch(final Exception e)
{
System.out.println("localByteArrayInputStream.close() " + e.getMessage());
}
[...]
This code is being called from Applet.init() ... so it should be called only the first time. It works... once. If I reload in the same Firefox tab the applet, I get the "Missing provider" error due to the "Secmod module already configured"
Searching for "Secmod module already configured" in Google and Bing I get the original java library sourcecode for SunPKCS11.java :
if (nssModule.hasInitializedProvider()) {
throw new ProviderException(
"Secmod module already configured");
}
Which seems contradictory with the error "Missing provider"...
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设法用一个相当简单的解决方案来解决它......
我将 SunPKCS11 pk11provider = null 设为私有静态全局变量。然后我只在它为空时初始化。是的,使用全局变量很丑陋,但它确实有效。
Managed to solve it with quite an easy solution...
I made SunPKCS11 pk11provider = null a private static global variable. Then I only initialize if it is null. Yes, it is ugly to use a global variable, but it works.