【发布时间】:2016-05-23 11:32:43
【问题描述】:
在 Apache 服务器中启用请求客户端证书并配置 SSL。全部适用于 Chrome 等浏览器。但是我们正在尝试直接创建客户端应用程序以使用 SmartCard 证书 PKCS11 进行身份验证(无需浏览器)。
这里是主要代码:
String configName = "d:/config.txt";
SunPKCS11 sunpkcs11 = new SunPKCS11(configName);
Security.addProvider(sunpkcs11);
KeyStore keyStore = null;
keyStore = KeyStore.getInstance("PKCS11",sunpkcs11);
keyStore.load(null, pin.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, pin.toCharArray());
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(kmf.getKeyManagers(), null, null);
SSLContext.setDefault(ctx);
final SSLSocketFactory factory = ctx.getSocketFactory();
final SSLSocket socket = (SSLSocket) factory.createSocket("xx.xx.xx.xx", 443);
socket.startHandshake();
PrintWriter out = new PrintWriter(socket.getOutputStream());
String fileName = "/Login";
out.print("GET " + fileName + " HTTP/1.0\r\n");
out.print("\r\n");
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String line;
while ((line = in.readLine()) != null)
System.out.println(line);
握手步骤运行时发生错误。
堆栈跟踪异常:
main, called closeSocket()
main, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
Exception in thread "main" javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failu
在 Apache 日志中我们得到这个:
Certificate Verification: Error (20): unable to get local issuer certificate
而Java App出现这个错误:
Warning: no suitable certificate found - continuing without client authentication
*** Certificate chain
<Empty>
【问题讨论】: