Skip to content

Instantly share code, notes, and snippets.

@mopemope
Last active December 21, 2015 02:59
Show Gist options
  • Select an option

  • Save mopemope/6238634 to your computer and use it in GitHub Desktop.

Select an option

Save mopemope/6238634 to your computer and use it in GitHub Desktop.
Get peer certificate
(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