我一直在原始文件夹下的android应用程序中使用服务器团队提供的ssl证书密钥。最初运行良好。
CertificateFactory cf = CertificateFactory.getInstance("X.509");
InputStream caInputMmx = new BufferedInputStream(this.getAssets().open("123.crt"));
Certificate caMmx = cf.generateCertificate(caInputMmx);
String keyStoreType = KeyStore.getDefaultType();
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(null, null);
keyStore.setCertificateEntry("caMmx", caMmx);
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(keyStore);
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, tmf.getTrustManagers(), null);
client.setSslSocketFactory(context.getSocketFactory());
Run Code Online (Sandbox Code Playgroud)
几天后,证书过期,服务器团队更新了该证书。从那时起,我们的android应用程序停止工作并出现以下异常
com.android.volley.NoConnectionError:javax.net.ssl.SSLHandshakeException:java.security.cert.CertPathValidatorException:找不到证书路径的信任锚。
在使用服务器上的新证书更新后,我们的应用程序可以正常工作。是否有任何解决方法可从服务器上修复此问题,而不是每次都在应用程序中更新新证书?因为如果用户不更新应用程序,我们的应用程序将无法正常工作。因此,有什么方法可以解决此问题,而不是每次证书过期时都在应用程序中更新证书。
编辑:
评论后,提供一些其他信息。
密钥库:我正在使用默认密钥库。CA:我使用的是Digigicert CA。这些人值得信赖。