Merge branch 'master' into py3

This commit is contained in:
j 2014-09-08 21:28:35 +02:00
commit 26d3f1f8fb
10 changed files with 69 additions and 44 deletions

View file

@ -30,7 +30,15 @@ class CertValidatingHTTPSConnection(http.client.HTTPConnection):
self.cert_reqs = ssl.CERT_NONE
def _ValidateCertificateFingerprint(self, cert):
fingerprint = hashlib.sha1(cert).hexdigest()
if len(self.fingerprint) == 40:
fingerprint = hashlib.sha1(cert).hexdigest()
elif len(self.fingerprint) == 64:
fingerprint = hashlib.sha256(cert).hexdigest()
elif len(self.fingerprint) == 128:
fingerprint = hashlib.sha512(cert).hexdigest()
else:
logging.error('unkown fingerprint length %s (%s)', self.fingerprint, len(self.fingerprint))
return False
return fingerprint == self.fingerprint
def connect(self):