Parcourir la source

Fixes socket monkey patching issue

Alessandro Pilotti il y a 9 ans
Parent
commit
9458d01c09
1 fichiers modifiés avec 6 ajouts et 5 suppressions
  1. 6 5
      coriolis/utils.py

+ 6 - 5
coriolis/utils.py

@@ -227,11 +227,12 @@ def walk_class_hierarchy(clazz, encountered=None):
 
 
 def get_ssl_cert_thumbprint(context, host, port=443, digest_algorithm="sha1"):
-    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
-        ssl_sock = context.wrap_socket(sock, server_hostname=host)
-        ssl_sock.connect((host, port))
-        # binary_form is the only option when the certificate is not validated
-        cert = ssl_sock.getpeercert(binary_form=True)
+    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    ssl_sock = context.wrap_socket(sock, server_hostname=host)
+    ssl_sock.connect((host, port))
+    # binary_form is the only option when the certificate is not validated
+    cert = ssl_sock.getpeercert(binary_form=True)
+    sock.close()
 
     x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_ASN1, cert)
     return x509.digest('sha1').decode()