以下代码是我目前拥有的代码。它从服务器获取证书,并检查有效性。但是,我想知道如何添加支票以查看它是否已被撤销? (我知道如果我得到它,并立即检查它,它不会被撤销,但我会在解决之后修改它,以便稍后检查它。)我最初问过类似的问题,当我不知道自己想做什么时,因为它被写了而删除了它。提前谢谢!
protected boolean testCert() throws Exception
{
// Get the current environment.
Environment myTestEnvironment = Environment.valueOf(env);
URL verificationUrl = environmentService.getProfile(myTestEnvironment).getConnectUrl();
boolean result = false;
HttpsURLConnection conn = (HttpsURLConnection) verificationUrl.openConnection();
conn.connect();
Certificate[] certs = conn.getServerCertificates();
// This is set in order to have a readable output for debugging.
this.testURL = verificationUrl.toString().replaceFirst("^(https://www\\.|https://|www\\.)","");
for (Certificate cert : certs) {
if (cert instanceof X509Certificate) {
try {
((X509Certificate) cert).checkValidity();
result = true;
} catch (CertificateExpiredException cee) {
result = false;}
}
}
return result;
}