小编典典
每个CA都会发布已撤销的证书列表。此列表包括证书的序列号和吊销日期
要获取证书吊销列表(CRL)的URL,请执行以下步骤
打开证书
转到“详细信息”选项卡,然后在详细信息列表中找到“ CRL分发点”字段
它将向您显示诸如此类的价值
[1] CRL分发点分发点名称:全名:URL = mscrl.microsoft.com / pki / mscorp / crl /
msitwww2.crl URL = crl.microsoft.com / pki / mscorp / crl / msitwww2.crl
因此,在您的代码中,您需要下载这些文件并检查其中的证书序列号,以查看其是否被吊销
在下面的示例代码中找到它
public class CertVerification {
public static void main(String[] args) throws Exception {
String certificatePath = "C:\\Users\\user1\\Desktop\\test.cer";
CertificateFactory cf = CertificateFactory.getInstance("X509");
X509Certificate certificate = null;
X509CRLEntry revokedCertificate = null;
X509CRL crl = null;
certificate = (X509Certificate) cf.generateCertificate(new FileInputStream(new File(certificatePath)));
URL url = new URL("http://.crl");
URLConnection connection = url.openConnection();
try(DataInputStream inStream = new DataInputStream(connection.getInputStream())){
crl = (X509CRL)cf.generateCRL(inStream);
}
revokedCertificate = crl.getRevokedCertificate(certificate.getSerialNumber());
if(revokedCertificate !=null){
System.out.println("Revoked");
}
else{
System.out.println("Valid");
}
}
}
请参见
这些列表会定期更新
您也可以从证书中获取这些吊销URL,我刚刚给出了一个示例
这只是一个入门的基本示例
更新资料
我找到了该示例类来检查证书,它还通过证书的CA和证书链颁发的CRL进行验证,因此您也无需提供CRL URL
2020-11-13