From 6df56b3205161889bc17a2e2c489c2585862027f Mon Sep 17 00:00:00 2001 From: Nemunaire Date: Sun, 1 Feb 2015 22:17:29 +0100 Subject: [PATCH] WIP certificates tests --- eyespot/certs.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 eyespot/certs.py diff --git a/eyespot/certs.py b/eyespot/certs.py new file mode 100644 index 0000000..14fb909 --- /dev/null +++ b/eyespot/certs.py @@ -0,0 +1,26 @@ +import socket +import ssl + + +def get(host): + # TODO: need convertion + return ssl.get_server_certificate(host) + + +def test(host): + context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) + context.verify_mode = ssl.CERT_REQUIRED + #context.check_hostname = True + context.set_ciphers("ALL") + #context.load_default_certs() + + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: + ssl_sock = context.wrap_socket(s) + try: + ssl_sock.connect(host) + return ssl_sock.getpeercert() + except ssl.SSLError: + pass + except ConnectionResetError: + pass + return None