fix tests
parent
15397ba712
commit
eaa0607f58
|
@ -22,14 +22,12 @@ class Crypto:
|
||||||
key = self.load_pem_private_key(key, password=passphrase, backend=self.default_backend())
|
key = self.load_pem_private_key(key, password=passphrase, backend=self.default_backend())
|
||||||
if self.algorithm in {"rsa-sha1", "rsa-sha256"}:
|
if self.algorithm in {"rsa-sha1", "rsa-sha256"}:
|
||||||
hasher = self.SHA1() if self.algorithm.endswith("sha1") else self.SHA256()
|
hasher = self.SHA1() if self.algorithm.endswith("sha1") else self.SHA256()
|
||||||
signer = key.signer(padding=self.PKCS1v15(), algorithm=hasher)
|
return key.sign(padding=self.PKCS1v15(), algorithm=hasher, data=string_to_sign)
|
||||||
elif self.algorithm in {"rsa-sha512"}:
|
elif self.algorithm in {"rsa-sha512"}:
|
||||||
hasher = self.SHA512()
|
hasher = self.SHA512()
|
||||||
signer = key.signer(padding=self.PKCS1v15(), algorithm=hasher)
|
return key.sign(padding=self.PKCS1v15(), algorithm=hasher, data=string_to_sign)
|
||||||
elif self.algorithm == "ecdsa-sha256":
|
elif self.algorithm == "ecdsa-sha256":
|
||||||
signer = key.signer(signature_algorithm=self.ec.ECDSA(algorithm=self.SHA256()))
|
return key.sign(signature_algorithm=self.ec.ECDSA(algorithm=self.SHA256()), data=string_to_sign)
|
||||||
signer.update(string_to_sign)
|
|
||||||
return signer.finalize()
|
|
||||||
|
|
||||||
def verify(self, signature, string_to_sign, key):
|
def verify(self, signature, string_to_sign, key):
|
||||||
if self.algorithm == "hmac-sha256":
|
if self.algorithm == "hmac-sha256":
|
||||||
|
@ -93,12 +91,8 @@ class HTTPSignatureAuth(requests.auth.AuthBase):
|
||||||
if header.lower() == "host":
|
if header.lower() == "host":
|
||||||
url = urlparse(request.url)
|
url = urlparse(request.url)
|
||||||
value = request.headers.get("host", url.hostname)
|
value = request.headers.get("host", url.hostname)
|
||||||
if (
|
if url.scheme == "http" and url.port not in [None, 80] or url.scheme == "https" \
|
||||||
url.scheme == "http"
|
and url.port not in [443, None]:
|
||||||
and url.port not in [None, 80]
|
|
||||||
or url.scheme == "https"
|
|
||||||
and url.port not in [443, None]
|
|
||||||
):
|
|
||||||
value = "{}:{}".format(value, url.port)
|
value = "{}:{}".format(value, url.port)
|
||||||
else:
|
else:
|
||||||
value = request.headers[header]
|
value = request.headers[header]
|
||||||
|
|
Loading…
Reference in New Issue