如何忽略 Java 应用程序外部的过期证书?
我们有一个 Java 应用程序,需要忽略过期的自签名证书,但是我们无法修改代码来执行此操作。我想知道我们是否可以在启动时提供一个系统属性或环境变量,以便我们暂时忽略所有过期的证书,或者甚至更具体,并从外部提供我们希望过期的特定证书被忽略。
有人有任何可行的想法吗?
We have a Java application that we need to ignore an expired self-signed cert, however we cannot modify the code to do this. I wondering if there was a System Property or environment variable that we could provide at start up that would allow us to have all expired cert's ignored for now, or even be more specific and provide externally the specific cert that we would like to have the expiration ignored.
Anyone have any ideas that would work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是通过组合 java - 忽略过期的 ssl 证书 和 Java SSL:如何禁用主机名验证。
然后只需将
-javaagent:IgnoreExpiredServerCertificateAgent.jar
添加到程序的 java 启动参数中即可。另请参阅 SSL 和 TLS 之间的差异及其在 Java 中的用法 和 Java 8 SSLContext.getInstance("TLSv1. 2") 这意味着什么? 在您的情况下获取
SSLContext.getInstance()
的适当参数。另请注意,证书过期的服务器也可能会自行检查匹配的客户端证书是否过期:
如果您遇到这样的堆栈跟踪,那么没有办法在不接触服务器的情况下缓解问题。
正确的解决方案是重新颁发具有未来到期日期的证书。
Here is the solution obtained by combining java - ignore expired ssl certificate and Java SSL: how to disable hostname verification.
Then just add
-javaagent:IgnoreExpiredServerCertificateAgent.jar
to program's java startup arguments.See also Difference between SSL and TLS and their usage in Java and Java 8 SSLContext.getInstance("TLSv1.2") what does it mean? for appropriate argument for
SSLContext.getInstance()
in your case.Also note that the server with expired certificate may also itself check the expiry of the matching client certificate:
If you meet such stacktrace then there is no way to mitigate the problem without touching the server.
And the proper solution would be to reissue the certificate with future expiry date.