apsig 0.3.1__tar.gz → 0.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {apsig-0.3.1 → apsig-0.3.2}/PKG-INFO +1 -1
- {apsig-0.3.1 → apsig-0.3.2}/pyproject.toml +1 -1
- {apsig-0.3.1 → apsig-0.3.2}/src/apsig/draft/verify.py +7 -5
- {apsig-0.3.1 → apsig-0.3.2}/tests/test_draft.py +2 -2
- {apsig-0.3.1 → apsig-0.3.2}/COPYING.md +0 -0
- {apsig-0.3.1 → apsig-0.3.2}/LICENSE +0 -0
- {apsig-0.3.1 → apsig-0.3.2}/README.md +0 -0
- {apsig-0.3.1 → apsig-0.3.2}/src/apsig/__init__.py +0 -0
- {apsig-0.3.1 → apsig-0.3.2}/src/apsig/__polyfill/datetime.py +0 -0
- {apsig-0.3.1 → apsig-0.3.2}/src/apsig/actor/keytools.py +0 -0
- {apsig-0.3.1 → apsig-0.3.2}/src/apsig/draft/sign.py +0 -0
- {apsig-0.3.1 → apsig-0.3.2}/src/apsig/exceptions.py +0 -0
- {apsig-0.3.1 → apsig-0.3.2}/src/apsig/ld_signature.py +0 -0
- {apsig-0.3.1 → apsig-0.3.2}/src/apsig/proof/sign.py +0 -0
- {apsig-0.3.1 → apsig-0.3.2}/src/apsig/proof/verify.py +0 -0
- {apsig-0.3.1 → apsig-0.3.2}/tests/__init__.py +0 -0
- {apsig-0.3.1 → apsig-0.3.2}/tests/test_ld.py +0 -0
- {apsig-0.3.1 → apsig-0.3.2}/tests/test_multibase_ed25519.py +0 -0
- {apsig-0.3.1 → apsig-0.3.2}/tests/test_proof.py +0 -0
|
@@ -10,11 +10,11 @@ from urllib.parse import urlparse
|
|
|
10
10
|
class draftVerifier:
|
|
11
11
|
def _generate_digest(body: bytes | str):
|
|
12
12
|
digest = hashes.Hash(hashes.SHA256(), backend=default_backend())
|
|
13
|
-
digest.update(body.encode("utf-8") if
|
|
13
|
+
digest.update(body.encode("utf-8") if isinstance(body, str) else body)
|
|
14
14
|
hash_bytes = digest.finalize()
|
|
15
15
|
return "SHA-256=" + base64.b64encode(hash_bytes).decode("utf-8")
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
@staticmethod
|
|
18
18
|
def verify(public_pem: str, method: str, url: str, headers: dict, body: bytes=b"") -> tuple[bool, str]:
|
|
19
19
|
"""Verifies the digital signature of an HTTP request.
|
|
20
20
|
|
|
@@ -33,7 +33,9 @@ class draftVerifier:
|
|
|
33
33
|
Raises:
|
|
34
34
|
ValueError: If the signature header is missing or if the algorithm is unsupported.
|
|
35
35
|
"""
|
|
36
|
-
|
|
36
|
+
case_insensitive_headers = {key.lower(): value for key, value in headers.items()}
|
|
37
|
+
|
|
38
|
+
signature_header = case_insensitive_headers.get("signature")
|
|
37
39
|
if not signature_header:
|
|
38
40
|
return False, "Signature header is missing"
|
|
39
41
|
|
|
@@ -43,7 +45,7 @@ class draftVerifier:
|
|
|
43
45
|
signature_parts[key.strip()] = value.strip().strip('"')
|
|
44
46
|
|
|
45
47
|
signature = base64.b64decode(signature_parts["signature"])
|
|
46
|
-
|
|
48
|
+
keyId = signature_parts["keyId"]
|
|
47
49
|
algorithm = signature_parts["algorithm"]
|
|
48
50
|
|
|
49
51
|
if algorithm != "rsa-sha256":
|
|
@@ -74,7 +76,7 @@ class draftVerifier:
|
|
|
74
76
|
return False, "Invalid signature"
|
|
75
77
|
|
|
76
78
|
expected_digest = draftVerifier._generate_digest(body)
|
|
77
|
-
if
|
|
79
|
+
if case_insensitive_headers.get("digest") != expected_digest:
|
|
78
80
|
return False, "Digest mismatch"
|
|
79
81
|
|
|
80
82
|
date_header = headers.get("date")
|
|
@@ -33,7 +33,7 @@ class TestSignatureFunctions(unittest.TestCase):
|
|
|
33
33
|
|
|
34
34
|
signed_headers = draftSigner.sign(self.private_key, method, url, headers, "https://example.com/users/johndoe#main-key", body)
|
|
35
35
|
|
|
36
|
-
is_valid, message = draftVerifier.verify(self.public_pem, method, url, signed_headers, body.encode("utf-8"))
|
|
36
|
+
is_valid, message = draftVerifier.verify(public_pem=self.public_pem, method=method, url=url, headers=signed_headers, body=body.encode("utf-8"))
|
|
37
37
|
|
|
38
38
|
self.assertTrue(is_valid)
|
|
39
39
|
self.assertEqual(message, "Signature is valid")
|
|
@@ -44,7 +44,7 @@ class TestSignatureFunctions(unittest.TestCase):
|
|
|
44
44
|
headers = {
|
|
45
45
|
"Content-Type": "application/json",
|
|
46
46
|
"Date": "Wed, 21 Oct 2015 07:28:00 GMT",
|
|
47
|
-
"
|
|
47
|
+
"Signature": 'keyId="your-key-id",algorithm="rsa-sha256",headers="(request-target) Content-Type Date",signature="invalid_signature"'
|
|
48
48
|
}
|
|
49
49
|
body = '{"key": "value"}'
|
|
50
50
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|