Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accept hs2019-obfuscated http signatures #2811

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions bookwyrm/signatures.py
Expand Up @@ -57,16 +57,20 @@ def make_digest(data):
def verify_digest(request):
"""checks if a digest is syntactically valid and matches the message"""
algorithm, digest = request.headers["digest"].split("=", 1)
if algorithm == "SHA-256":
if algorithm in ("SHA-256", "hs2019"):
hash_function = hashlib.sha256
elif algorithm == "SHA-512":
hash_function = hashlib.sha512
else:
raise ValueError(f"Unsupported hash function: {algorithm}")

expected = hash_function(request.body).digest()
if algorithm == "hs2019" and b64decode(digest) != expected:
hash_function = hashlib.sha512
expected = hash_function(request.body).digest()

if b64decode(digest) != expected:
raise ValueError("Invalid HTTP Digest header")
raise ValueError(f"Invalid HTTP Digest header: {algorithm}")


class Signature:
Expand Down