formatting

This commit is contained in:
Hugh Rundle 2023-04-13 13:27:51 +10:00
parent e3261c6b88
commit a6676718cb
5 changed files with 24 additions and 11 deletions

View file

@ -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)

View file

@ -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:

View file

@ -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 (

View file

@ -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",

View file

@ -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: