Raise exception instead of using assert

This commit is contained in:
shortcutme 2019-07-03 18:35:55 +02:00
parent 80bfccd9d3
commit ff32f822ba
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE
7 changed files with 27 additions and 12 deletions

View file

@ -52,7 +52,8 @@ class CryptConnectionManager:
sock_wrapped = ssl.wrap_socket(sock, ciphers=ciphers)
if cert_pin:
cert_hash = hashlib.sha256(sock_wrapped.getpeercert(True)).hexdigest()
assert cert_hash == cert_pin, "Socket certificate does not match (%s != %s)" % (cert_hash, cert_pin)
if cert_hash != cert_pin:
raise Exception("Socket certificate does not match (%s != %s)" % (cert_hash, cert_pin))
return sock_wrapped
else:
return sock