views:

89

answers:

1

I need to write a simple program for work that does the following:

  1. read a config file
  2. connect to a bunch of servers
  3. establish a ssl socket
  4. pull info form the server's x509 cert, expire date and hostname for now
  5. email a report when its done

items 3 and 4 are things that I have had bad luck researching/googleing and I do not know java well, at all since 1.2 around 2001

A: 

I found a code snipit that tells me what I need to know about java at http://www.exampledepot.com/egs/javax.net.ssl/GetCert.html

here it is:

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) {   
}
ms4720