Fixes feeration authentication header

Co-authored-by: thricedotted <thricedotted@gmail.com>
Fixes #1
This commit is contained in:
Mouse Reeve 2020-02-14 19:55:33 -08:00
parent a1fbba1ba3
commit 7123650198

View file

@ -3,12 +3,12 @@ from base64 import b64encode
from Crypto.PublicKey import RSA from Crypto.PublicKey import RSA
from Crypto.Signature import pkcs1_15 from Crypto.Signature import pkcs1_15
from Crypto.Hash import SHA256 from Crypto.Hash import SHA256
from datetime import datetime from django.utils.http import http_date
import json import json
import requests import requests
from urllib.parse import urlparse
from fedireads import incoming from fedireads import incoming
from fedireads.settings import DOMAIN
def get_recipients(user, post_privacy, direct_recipients=None): def get_recipients(user, post_privacy, direct_recipients=None):
@ -51,13 +51,12 @@ def broadcast(sender, activity, recipients):
def sign_and_send(sender, activity, destination): def sign_and_send(sender, activity, destination):
''' crpyto whatever and http junk ''' ''' crpyto whatever and http junk '''
# TODO: handle http[s] with regex inbox_parts = urlparse(destination)
inbox_fragment = sender.inbox.replace('https://%s' % DOMAIN, '') now = http_date()
now = datetime.utcnow().isoformat()
signature_headers = [ signature_headers = [
'(request-target): post %s' % inbox_fragment, '(request-target): post %s' % inbox_parts.path,
'host: https://%s' % DOMAIN, 'host: %s' % inbox_parts.netloc,
'date: %s' % now 'date: %s' % now
] ]
message_to_sign = '\n'.join(signature_headers) message_to_sign = '\n'.join(signature_headers)
@ -79,7 +78,6 @@ def sign_and_send(sender, activity, destination):
headers={ headers={
'Date': now, 'Date': now,
'Signature': signature, 'Signature': signature,
'Host': 'https://%s' % DOMAIN,
'Content-Type': 'application/activity+json; charset=utf-8', 'Content-Type': 'application/activity+json; charset=utf-8',
}, },
) )