I want to verify the X509 certificate presented by a client against a CRL to see if it has been revoked.
I have successfully instanciated a java.security.cert.X509CRL
, but I am having problems retrieving the certificate of the session:
try {
SSLSocket s = (SSLSocket) serverSocket.accept();
s.setSoTimeout(TIMEOUT_RW * 1000);
s.startHandshake();
SSLSession session = s.getSession();
X509Certificate[] cert = session.getPeerCertificateChain();
if (crl.isRevoked(cert[0])) {
System.err.println("Attempted to stablish connection using revoked certificate");
} else {
...
}
} catch (Exception ex) {
System.err.println("Something went wrong");
}
SSLSession belongs to the javax.net.ssl
package, and its method getPeerCertificateChain()
returns a javax.security.cert.X509Certificate[]
, which cannot be converted to the java.security.cert.X509Certificate[]
that I need to feed the java.security.cert.X509CRL
.
How can it be done?