开发者

Clojure and SSL/x.509 certs quetion

开发者 https://www.devze.com 2022-12-21 06:15 出处:网络
I need to write a simple program for work that does the follo开发者_运维问答wing: read a config file

I need to write a simple program for work that does the follo开发者_运维问答wing:

  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 verbose but throughout guide about the inners of Java Cryptographic Extension is found at Oracles website as well: http://docs.oracle.com/javase/6/docs/technotes/guides/security/jsse/JSSERefGuide.html


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号