Retrieving the Certification Path of an SSL Server

This example implements a client that connects to an SSL server and retrieves the server's certificates.

See also Adding a Certificate to a Key Store.

try { // Create the client socket int port = 443; String hostname = "hostname"; SSLSocketFactory factory = HttpsURLConnection.getDefaultSSLSocketFactory(); SSLSocket socket = (SSLSocket)factory.createSocket(hostname, port); // Connect to the server socket.startHandshake(); // Retrieve the server's certificate chain java.security.cert.Certificate[] serverCerts = socket.getSession().getPeerCertificates(); // Close the socket socket.close(); } catch (SSLPeerUnverifiedException e) { } catch (IOException e) { } catch (java.security.cert.CertificateEncodingException e) { }

Comments

9 Mar 2010 - 12:21am by Steven (not verified)

How can i get the expire day for a certification?

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.