解决融云 SDK 4.0 版本配置 https 导航报 SSLHandshakeException
咱们公司最近应用融云 IM 进行集成开发. 咱们是公有云部署, 导航是通过接口进行设置的. 是 Https 的.
之前咱们是应用的2.x 版本, 应用上面接口配置一下即可.
RongIMClient.getInstance().enableHttpsSelfCertificate(false);
然而最近咱们降级融云到 4.0 版本. 忽然发现连贯不上了. 日志中报
javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
这个谬误.
于是征询融云技术支持, 得悉 4.0 须要本人进行证书验证.
需在 application 中增加即可.
try { //应用X509TrustManager代替CertificateTrustManager跳过证书验证。 TrustManager tm[] = new X509TrustManager() { @Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { } @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } @Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; } } }; SSLContext context = SSLContext.getInstance("TLS"); context.init(null, tm, null); SSLUtils.setSSLContext(context); SSLUtils.setHostnameVerifier(new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }); } catch (Throwable e) { throw new IllegalStateException(e);}
留神的是, 因为导航申请是在融云的 ipc 过程中的, 所以在 application 中设置下面代码的时候, 千万不要设置在主过程中. 否则有效.