summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-06 14:14:08 -0700
committerAndrew Godwin2022-11-06 14:14:08 -0700
commit52c83c67bbb7c3597d2fcc8fd3554927a252fedb (patch)
treecff1a0a103653c74b18b5abb23900c929c7483ba /core
parentdbe57075d386d7474bafc208b654507d9a2d769e (diff)
downloadtakahe-52c83c67bbb7c3597d2fcc8fd3554927a252fedb.tar.gz
takahe-52c83c67bbb7c3597d2fcc8fd3554927a252fedb.tar.bz2
takahe-52c83c67bbb7c3597d2fcc8fd3554927a252fedb.zip
Signing works with OpenSSL.
Will have to ask the cryptography peeps what I was doing wrong.
Diffstat (limited to 'core')
-rw-r--r--core/signatures.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/core/signatures.py b/core/signatures.py
index bcacb68..a5e4fed 100644
--- a/core/signatures.py
+++ b/core/signatures.py
@@ -1,5 +1,5 @@
import base64
-from typing import Any, Dict, List
+from typing import List, TypedDict
from cryptography.hazmat.primitives import hashes
from django.http import HttpRequest
@@ -38,11 +38,23 @@ class HttpSignature:
return "\n".join(f"{name.lower()}: {value}" for name, value in headers.items())
@classmethod
- def parse_signature(cls, signature) -> Dict[str, Any]:
- signature_details = {}
+ def parse_signature(cls, signature) -> "SignatureDetails":
+ bits = {}
for item in signature.split(","):
name, value = item.split("=", 1)
value = value.strip('"')
- signature_details[name.lower()] = value
- signature_details["headers"] = signature_details["headers"].split()
+ bits[name.lower()] = value
+ signature_details: SignatureDetails = {
+ "headers": bits["headers"].split(),
+ "signature": base64.b64decode(bits["signature"]),
+ "algorithm": bits["algorithm"],
+ "keyid": bits["keyid"],
+ }
return signature_details
+
+
+class SignatureDetails(TypedDict):
+ algorithm: str
+ headers: List[str]
+ signature: bytes
+ keyid: str