mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 03:21:05 +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)
|
digest = make_digest(data)
|
||||||
|
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"Date": now,
|
"Date": now,
|
||||||
"Digest": digest,
|
"Digest": digest,
|
||||||
|
@ -557,14 +556,20 @@ async def sign_and_send(
|
||||||
)
|
)
|
||||||
logger.info("Trying again with legacy keyId")
|
logger.info("Trying again with legacy keyId")
|
||||||
# try with incorrect keyId to enable communication with legacy Bookwyrm servers
|
# 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
|
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:
|
if not response.ok:
|
||||||
logger.exception(
|
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
|
return response
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
logger.info("Connection timed out for url: %s", destination)
|
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
|
# sent as objects, not as an array of objects
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
value = [value]
|
value = [value]
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
items = []
|
items = []
|
||||||
for link_json in value:
|
for link_json in value:
|
||||||
|
|
|
@ -138,7 +138,7 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel):
|
||||||
return True
|
return True
|
||||||
# GoToSocial sends single tags as objects
|
# GoToSocial sends single tags as objects
|
||||||
# not wrapped in a list
|
# 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)
|
user_model = apps.get_model("bookwyrm.User", require_ready=True)
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
if (
|
if (
|
||||||
|
|
|
@ -22,7 +22,9 @@ def create_key_pair():
|
||||||
return private_key, public_key
|
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"""
|
"""uses a private key to sign an outgoing message"""
|
||||||
inbox_parts = urlparse(destination)
|
inbox_parts = urlparse(destination)
|
||||||
signature_headers = [
|
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))
|
signer = pkcs1_15.new(RSA.import_key(sender.key_pair.private_key))
|
||||||
signed_message = signer.sign(SHA256.new(message_to_sign.encode("utf8")))
|
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
|
# 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 = {
|
signature = {
|
||||||
"keyId": key_id,
|
"keyId": key_id,
|
||||||
"algorithm": "rsa-sha256",
|
"algorithm": "rsa-sha256",
|
||||||
|
|
|
@ -137,7 +137,9 @@ def has_valid_signature(request, activity):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if signature.key_id != remote_user.key_pair.remote_id:
|
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.")
|
raise ValueError("Wrong actor created signature.")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue