【发布时间】:2020-10-08 17:16:48
【问题描述】:
我正在使用 Java Websocket 服务器 (TooTallNate)。 Javascript 应用程序通过 LetsEncrypt 证书安全连接。它通过 certbot 自动更新,并且也在同一台机器上为 Apache 提供服务。在所有经过测试的浏览器上一切正常,对于 https 和 wss。
我想将我的应用作为打包的 FireTV 应用提交。我在“Web App Tester”应用程序中对其进行了测试。一旦 JS 尝试连接到 WSS,它就会引发 SSL 错误,读取 adb-logcat
I/X509util: Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
但有时只是
E/chromium(13208): [ERROR:ssl_client_socket_impl.cc(947)] handshake failed; returned -1, SSL error code 1, net_error -202
从 TooTallNate 填充 SSLContext 的相关 Java 代码是:
private static SSLContext getContext() {
SSLContext context;
String password = "CHANGEIT";
String pathname = "pem";
try {
context = SSLContext.getInstance("TLS");
byte[] certBytes = parseDERFromPEM(getBytes(new File(pathname + File.separator + "cert.pem")),"-----BEGIN CERTIFICATE-----", "-----END CERTIFICATE-----");
byte[] keyBytes = parseDERFromPEM(getBytes(new File(pathname + File.separator + "privkey.pem")),"-----BEGIN PRIVATE KEY-----", "-----END PRIVATE KEY-----");
X509Certificate cert = generateCertificateFromDER(certBytes);
RSAPrivateKey key = generatePrivateKeyFromDER(keyBytes);
KeyStore keystore = KeyStore.getInstance("JKS");
keystore.load(null);
keystore.setCertificateEntry("cert-alias", cert);
keystore.setKeyEntry("key-alias", key, password.toCharArray(), new Certificate[]{cert});
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(keystore, password.toCharArray());
KeyManager[] km = kmf.getKeyManagers();
context.init(km, null, null);
}
catch (Exception e) {
context = null;
}
return context;
}
【问题讨论】:
标签: ssl websocket lets-encrypt