gpt4 book ai didi

java - PKCS#11 PKCS11 dll

转载 作者:行者123 更新时间:2023-12-02 08:01:13 24 4
gpt4 key购买 nike

我们正在尝试实现一个 java 独立应用程序,该应用程序可以连接到 https 网站并使用 PKI 智能卡进行身份验证,但我们遇到了各种各样的问题。

我必须提到,如果我们使用小程序(然后将使用浏览器的 keystore 和trustore),我们就能够运行这种应用程序,一切都工作得很好,我们输入卡密码,我们就可以访问网页。

我有两个问题。首先关于我的代码,有人发现它有问题吗?我包括运行时出现的运行时错误:

public class TestPKCS11 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {

// Set keyStore and trustStore
System.setProperty("javax.net.ssl.trustStoreType", "PKCS11");
System.setProperty("javax.net.ssl.trustStore", "NONE");
System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
System.setProperty("javax.net.ssl.trustStoreProvider", "SunPKCS11-mycard");
String trustStore = System.getProperty("javax.net.ssl.trustStore");
if (trustStore == null) {
System.out.println("javax.net.ssl.trustStore is not defined");
} else {
System.out.println("javax.net.ssl.trustStore = " + trustStore);
}

System.setProperty("javax.net.ssl.keyStoreType", "PKCS11");
System.setProperty("javax.net.ssl.keyStore", "NONE");
System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
System.setProperty("javax.net.ssl.keyStoreProvider", "SunPKCS11-mycard");
String keyStore = System.getProperty("javax.net.ssl.keyStore");
if (keyStore == null) {
System.out.println("javax.net.ssl.keyStore is not defined");
} else {
System.out.println("javax.net.ssl.keyStore = " + keyStore);
}

System.setProperty("javax.net.debug", "ssl"); // dynamic conf of PKCS#11

String configName = "C:\\confDirectory\\pkcs11.cfg";

sun.security.pkcs11.SunPKCS11 sunPKCS11 = new sun.security.pkcs11.SunPKCS11(configName);
Provider p = sunPKCS11;
Security.addProvider(p);


SSLSocketFactory sslFact = (SSLSocketFactory) SSLSocketFactory.getDefault();

try{
SSLSocket sock = (SSLSocket)sslFact.createSocket("myserver", 8081);

sock.startHandshake();

} catch (SSLHandshakeException ex) {
Logger.getLogger(TestPKCS11.class.getName()).log(Level.SEVERE, null, ex);
System.out.println(ex.getMessage());
}
catch (IOException ex) {
Logger.getLogger(TestPKCS11.class.getName()).log(Level.SEVERE, null, ex);
}
}

执行错误:

Exception in thread "main" java.security.ProviderException: Initialization failed
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:340)
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:86)
at TestPKCS11.main(TestPKCS11.java:95)
Caused by: java.io.IOException: The specified procedure could not be found.
at sun.security.pkcs11.wrapper.PKCS11.connect(Native Method)
at sun.security.pkcs11.wrapper.PKCS11.<init>(PKCS11.java:141)
at sun.security.pkcs11.wrapper.PKCS11.getInstance(PKCS11.java:154)
at sun.security.pkcs11.SunPKCS11.<init>(SunPKCS11.java:281)
... 2 more

我的第二个问题是关于 pkcs11 使用的 dll。目前我正在使用IBM Rational 安装中包含的程序(jpkcs11.dll),但我真的不确定它是不是一个好程序。我确实读过有关 OpenSC 的信息,但找不到 OpenSC-pkcs11.dll 文件。我只能看到 opensc.dll。

我在 Windows7 上运行 Java 1.6 27

谢谢

最佳答案

OpenSC PKCS#11 被命名为“opensc-pkcs11.dll”,并被放入 system32。但您需要确保您的智能卡受 OpenSC 支持。一般规则:您需要使用您的卡附带的 PKCS#11 提供程序(通常是闭源)或支持您的卡(如 OpenSC)

关于java - PKCS#11 PKCS11 dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8881536/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com