![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e501. Retrieving the Certification Path of an SSL ServerThis example implements a client that connects to an SSL server and retrieves the server's certificates.See also e211 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) { }
e500. Creating an SSL Server Socket e502. Disabling Certificate Validation in an HTTPS Connection © 2002 Addison-Wesley. |