我在Java中一起与客户端应用程序,将发布新的许可证请求,并在该服务器上验证现有许可设立发牌的servlet。 该servlet在Tomcat中运行。 我Tomcat配置,使其只允许连接到Servlet通过https,这工作得很好。
我一直在使用创建的自签名证书'keytool -genkey -alias www.mysite.com -keyalg RSA -keystore license.store'
这将创建一个文件license.store
尖tomcat的这个keystoreFile连同密码asdf1234
。
当我尝试从客户端连接到Servlet在Java中HTTPS,我收到了熟悉PKIX path building failed
,因为该证书不在信任。 我试图固定此使用此所得的在下面的代码建议:
private SSLSocketFactory getSSLFactory() throws Exception {
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
InputStream is = this.getClass().getResourceAsStream("license.store");
if(is ==null) {
return null;
}
keyStore.load(is, "asdf1234".toCharArray());
is.close();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, tmf.getTrustManagers(), null);
return ctx.getSocketFactory();
}
这之后,我打电话:
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
con.setSSLSocketFactory(getSSLFactory());
这导致succesfull连接。
现在的问题是,我只能得到这个当我复制工作license.store
到客户端,并且加载到KeyStore.load()
它不罢工我很安全复制私钥和服务器使用的客户端密码。 有没有什么方法提取只能从license.store的公钥和使用? 我一直在寻找这个论坛和其他人现在一天似乎仍不能得到它。