Java SSL 信任库设置
在一个应用程序中,我通过 SSL 使用三种不同的连接。 其中两个已签名证书,但我正在对其进行身份验证:
System.setProperty("javax.net.ssl.trustStore","F:\\eclipse\\terefere\\testkeystore");
System.setProperty("javax.net.ssl.trustStorePassword","123456");
问题是 - 如何在连接结束时删除这些设置,以便下一个连接使用新服务器的证书?
In one application i'm using three different connections by SSL.
Two of them have signed certificates, but one I'm authenticating with:
System.setProperty("javax.net.ssl.trustStore","F:\\eclipse\\terefere\\testkeystore");
System.setProperty("javax.net.ssl.trustStorePassword","123456");
Question is - how to get rid of these settings at the end of connection so that next connection is using new server's certificate ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您当然可以记住这些属性的旧值并在调用后重新设置它们。
但这会引入竞争条件:如果另一个线程在设置此信任存储时建立 SSL 连接,它也将使用此信任存储而不是标准信任存储。
更好的方法是使用此信任存储来专门用于此连接,而不触及系统属性。不过,这是否容易(甚至可能)取决于哪个库正在建立 SSL 连接。
You could of course remember the old values of these properties and re-set them after this call.
This would introduce a race condition though: if another thread makes an SSL connection while this trust store has been set, it will also use this trust store instead of the standard one.
Better would be to use this trust store for specifically this connection without touching the system properties. Whether this is easy (or even possible) depends on what library is making the SSL connection, though.