Skip to content

Instantly share code, notes, and snippets.

@lokedhs
Created March 29, 2013 12:49
Show Gist options
  • Save lokedhs/5270622 to your computer and use it in GitHub Desktop.
Save lokedhs/5270622 to your computer and use it in GitHub Desktop.
How to get CN from an SSL connection
(usocket:with-client-socket (socket stream "encrypted.google.com" 443)
(let* ((enc (cl+ssl:make-ssl-client-stream stream))
(crypto (cl+ssl::ssl-stream-handle enc))
(cert (cl+ssl::ssl-get-peer-certificate crypto))
(subj (cl+ssl::x509-get-subject-name cert)))
(format t "entry count: ~s~%" (cl+ssl::x509-name-entry-count subj))
(cffi:with-foreign-pointer (buf 10240)
(let ((result (cl+ssl::x509-name-get-text-by-nid subj 13 buf 10240)))
(if (= result -1)
(format t "Could not find nid~%")
(format t "Subject name: ~s~%" (cffi:foreign-string-to-lisp buf)))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment