有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

安全Java客户端身份验证异常

我是java安全方面的新手,我的任务是为我的web服务器进行客户端身份验证

我从Web服务器获得的文件是服务器。jks客户端。jks,客户。第12页,客户端。pem,我需要使用客户端证书对我的客户端到服务器进行身份验证

我有这段代码,我需要知道我是否遗漏了一些信息,因为这段代码引发了下面发布的异常

系统。setProperty(“javax.net.debug”、“ssl”)

KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
KeyStore keyStore = KeyStore.getInstance("PKCS12");



InputStream is = new FileInputStream(new File("client.p12"));
keyStore.load(is,"ccCert".toCharArray());
is.close();
keyManagerFactory.init(keyStore,"ccCert".toCharArray());

SSLContext context = SSLContext.getInstance("TLS");

TrustManagerFactory trustManagerFactory = TrustManagerFactory
        .getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
context.init(keyManagerFactory.getKeyManagers(),trustManagerFactory.getTrustManagers(), new SecureRandom());


URL url = new URL("https://localhost:8787");
HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
con.setSSLSocketFactory(context.getSocketFactory());
con.connect();
Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target.

如果有人能给我一些提示我的代码有什么问题,或者我遗漏了什么,那将非常有帮助

提前谢谢


共 (0) 个答案