Last active
December 21, 2015 02:59
-
-
Save mopemope/6238634 to your computer and use it in GitHub Desktop.
Get peer certificate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns cert | |
| (import | |
| (javax.net.ssl HttpsURLConnection SSLSession SSLSocket SSLSocketFactory))) | |
| (defn- get-sever-certs [host port] | |
| (let [factory (HttpsURLConnection/getDefaultSSLSocketFactory)] | |
| (with-open [socket (doto | |
| (.createSocket factory host port) | |
| (.startHandshake))] | |
| (-> | |
| (.getSession socket) | |
| (.getPeerCertificates))))) | |
| (defn get-certs [host port] | |
| (doseq [[i c] (map-indexed vector (get-server-certs host port))] | |
| (do | |
| (println (format "i=%d" i)) | |
| (println (.getIssuerX500Principal c)) | |
| (println (.getNotBefore c)) | |
| (println (.getNotAfter c)) | |
| (println (.getSubjectX500Principal c))))) | |
| (get-certs "github.com" 443) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment