admin
我为我的应用程序实例和我的应用程序实例生成了自签名证书judge
。这些实例在不同的机器上运行,并且它们都有彼此证书和自己证书的副本。我想在这两者之间进行交流,我想知道我目前的方法是否是正确的方法:
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Certificate certificate = cf.generateCertificate(new FileInputStream(...));
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, "test".toCharArray());
keyStore.setCertificateEntry("admin", certificate);
// Code omitted which repeats the above to set the judge certificate
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, tmf.getTrustManagers(), null);
factory = ctx.getSocketFactory(); // Or #getServerSocketFactory() if admin and not judge
有了这个,我将能够与两个实例安全地通信,对吗?