mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-22 09:31:08 +00:00
formatting
This commit is contained in:
parent
e3261c6b88
commit
a6676718cb
5 changed files with 24 additions and 11 deletions
|
@ -540,7 +540,6 @@ async def sign_and_send(
|
|||
|
||||
digest = make_digest(data)
|
||||
|
||||
|
||||
headers = {
|
||||
"Date": now,
|
||||
"Digest": digest,
|
||||
|
@ -557,14 +556,20 @@ async def sign_and_send(
|
|||
)
|
||||
logger.info("Trying again with legacy keyId")
|
||||
# try with incorrect keyId to enable communication with legacy Bookwyrm servers
|
||||
legacy_signature = make_signature("post", sender, destination, now, digest, True)
|
||||
legacy_signature = make_signature(
|
||||
"post", sender, destination, now, digest, True
|
||||
)
|
||||
headers["Signature"] = legacy_signature
|
||||
async with session.post(destination, data=data, headers=headers) as response:
|
||||
async with session.post(
|
||||
destination, data=data, headers=headers
|
||||
) as response:
|
||||
if not response.ok:
|
||||
logger.exception(
|
||||
"Failed to send broadcast with legacy keyId to %s: %s", destination, response.reason
|
||||
)
|
||||
|
||||
"Failed to send broadcast with legacy keyId to %s: %s",
|
||||
destination,
|
||||
response.reason,
|
||||
)
|
||||
|
||||
return response
|
||||
except asyncio.TimeoutError:
|
||||
logger.info("Connection timed out for url: %s", destination)
|
||||
|
|
|
@ -383,7 +383,7 @@ class TagField(ManyToManyField):
|
|||
# sent as objects, not as an array of objects
|
||||
if isinstance(value, dict):
|
||||
value = [value]
|
||||
else:
|
||||
else:
|
||||
return None
|
||||
items = []
|
||||
for link_json in value:
|
||||
|
|
|
@ -138,7 +138,7 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
|||
return True
|
||||
# GoToSocial sends single tags as objects
|
||||
# not wrapped in a list
|
||||
tags = activity.tag if isinstance(activity.tag, list) else [ activity.tag ]
|
||||
tags = activity.tag if isinstance(activity.tag, list) else [activity.tag]
|
||||
user_model = apps.get_model("bookwyrm.User", require_ready=True)
|
||||
for tag in tags:
|
||||
if (
|
||||
|
|
|
@ -22,7 +22,9 @@ def create_key_pair():
|
|||
return private_key, public_key
|
||||
|
||||
|
||||
def make_signature(method, sender, destination, date, digest=None, use_legacy_key=False):
|
||||
def make_signature(
|
||||
method, sender, destination, date, digest=None, use_legacy_key=False
|
||||
):
|
||||
"""uses a private key to sign an outgoing message"""
|
||||
inbox_parts = urlparse(destination)
|
||||
signature_headers = [
|
||||
|
@ -39,7 +41,11 @@ def make_signature(method, sender, destination, date, digest=None, use_legacy_ke
|
|||
signer = pkcs1_15.new(RSA.import_key(sender.key_pair.private_key))
|
||||
signed_message = signer.sign(SHA256.new(message_to_sign.encode("utf8")))
|
||||
# For legacy reasons we need to use an incorrect keyId for older Bookwyrm versions
|
||||
key_id = f"{sender.remote_id}#main-key" if use_legacy_key else f"{sender.remote_id}/#main-key"
|
||||
key_id = (
|
||||
f"{sender.remote_id}#main-key"
|
||||
if use_legacy_key
|
||||
else f"{sender.remote_id}/#main-key"
|
||||
)
|
||||
signature = {
|
||||
"keyId": key_id,
|
||||
"algorithm": "rsa-sha256",
|
||||
|
|
|
@ -137,7 +137,9 @@ def has_valid_signature(request, activity):
|
|||
return False
|
||||
|
||||
if signature.key_id != remote_user.key_pair.remote_id:
|
||||
if signature.key_id != f"{remote_user.remote_id}#main-key": # legacy Bookwyrm
|
||||
if (
|
||||
signature.key_id != f"{remote_user.remote_id}#main-key"
|
||||
): # legacy Bookwyrm
|
||||
raise ValueError("Wrong actor created signature.")
|
||||
|
||||
try:
|
||||
|
|
Loading…
Reference in a new issue