您必须将服务器证书包含在https://dctm-rest
进入您的 JRE(信任库)的白名单
Options
1) 将服务器证书包含在 JRE 密钥库中 (jre/lib/security/cacerts
) (不建议)
要下载服务器证书,请使用浏览器打开站点,右键单击绿色锁,选择“查看证书”并下载
探索 cacerts 和导入受信任证书的最简单方法是使用像 portecle 这样的 GUI 工具(http://portecle.sourceforge.net/ http://portecle.sourceforge.net/)。您还可以使用密钥工具
keytool -import -trustcacerts -keystore /opt/java/jre/lib/security/cacerts -alias mycert -noprompt -storepass changeit -file /tmp/examplecert.crt
See 如何将自签名证书正确导入到默认情况下可供所有 Java 应用程序使用的 Java 密钥库中? https://stackoverflow.com/questions/11617210/how-to-properly-import-a-selfsigned-certificate-into-java-keystore-that-is-avail
2) 使用您自己的信任库并包含服务器证书(受到推崇的)
System.setProperty ("javax.net.ssl.trustStore", path_to_your_trustore_jks_file);
System.setProperty ("javax.net.ssl.trustStorePassword", "password");
您还可以创建 SSLSocketFactory 并在连接之前添加到您的连接或使用静态方法应用于所有连接
HttpsURLConnection.setDefaultSSLSocketFactory(sslFactory);
这是创建套接字工厂的示例
//Load JKS keystore that includes the server certificate or the root
KeyStore keyStore = ...
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(keyStore);
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, tmf.getTrustManagers(), null);
sslFactory = ctx.getSocketFactory();
3) 根本不要使用信任库(完全不推荐)
See 为单个连接禁用 SSLHandshakeException https://stackoverflow.com/questions/37724901/disable-sslhandshakeexception-for-a-single-connection/37861267#37861267(我不会复制解决方案)