diff options
author | Andrew Godwin | 2022-11-06 14:14:08 -0700 |
---|---|---|
committer | Andrew Godwin | 2022-11-06 14:14:08 -0700 |
commit | 52c83c67bbb7c3597d2fcc8fd3554927a252fedb (patch) | |
tree | cff1a0a103653c74b18b5abb23900c929c7483ba /core | |
parent | dbe57075d386d7474bafc208b654507d9a2d769e (diff) | |
download | takahe-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.py | 22 |
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 |