java - 如何调试 Java HTTPS 证书验证

标签 java ssl

我有一个第三方 Java 应用程序。它尝试通过 HTTPS 下载文件。可悲的是,在我公司的网络中,HTTPS 被拦截,证书被替换为无根自定义证书。

现在虽然我在 /etc/ssl/certs/java/cacerts 中有我们的非根 CA(双重检查)它仍然无法下载:

java.io.IOException: Error downloading [https://zlib.net/zlib-1.2.11.tar.gz] to /tmp/zlib-1.2.11.tar.gz: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

有什么方法可以调试 JAVA 试图在内部进行证书验证的操作吗? 像这样的东西:

  • 它正在加载哪些 CA
  • 验证需要哪些步骤
  • 验证失败的原因(详细)

如果我不需要使用反射或其他晦涩的东西,可以加分;)

最佳答案

我会尝试使用动态调试实用程序。有一个选项可以打开 SSL 调试,这应该对您有所帮助。

根据 official documentation

JSSE provides dynamic debug tracing support. This is similar to the support used for debugging access control failures in the Java SE platform. The generic Java dynamic debug tracing support is accessed with the java.security.debug system property, whereas the JSSE-specific dynamic debug tracing support is accessed with the javax.net.debug system property. Current options are:

all: Turn on all debugging
ssl: Turn on SSL debugging

The following can be used with the ssl option:

record: Enable per-record tracing
handshake: Print each handshake message
keygen: Print key generation data
session: Print session activity
defaultctx: Print default SSL initialization
sslctx: Print SSLContext tracing
sessioncache: Print session cache tracing
keymanager: Print key manager tracing
trustmanager: Print trust manager tracing

我认为这应该对您有所帮助。

关于java - 如何调试 Java HTTPS 证书验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59183640/

相关文章:

java - 以较少冗余的方式创建多个 Jlabels 和 JTextFields?

java - JTable 列标题是否可以垂直对齐?

ssl - Mule cxf :outbound-endpoint (client) and HTTPS/SSL 问题

Python:用urllib3超越SSL验证

java - 通过 gmail 从 java 发送电子邮件时出现异常

php - Drupal 8 curl 60 错误

java - 传递要在 where/having 子句中匹配的列表

java - 下拉菜单中导航栏内的 RouterLink 不起作用(Angular 和 Springboot)

Java——StringBuilder 使用 String 而不是 StringBuilder

ssl - .CER 和 .CRT 有什么区别?