I need to create an Https connection with a remote server then retrieve and verify the certificate.
I have established the connection fine:
try {
url = new URL(this.SERVER_URL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
HttpsURLConnection secured = (HttpsURLConnection) con;
secured.connect();
}
But it seems getServerCertificateChain()
method is undefined by the type HttpsURLConnection
.
So how do I retrieve the server certificate chain? My understanding is that getServerCertificateChain()
should return an array of X509Certificate
objects and that this class has methods I can use to interrogate the certificate.
I need to verify that:
- the certificate is valid and trusted,
- check the Certificate Revocation List Distribution Point against the certificate serial number
- make sure it isn't expired and
- check that the URL in the certificate is matches another (which I already have retrieved ).
I'm lost and would really appreciate any help!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…