Set accept type for signed header

merge-requests/30/head
Bob Mottram 2021-09-14 23:03:26 +01:00
parent 0af91ce4b6
commit 20b5805e9a
4 changed files with 13 additions and 7 deletions

View File

@ -202,15 +202,17 @@ def createSignedHeader(dateStr: str, privateKeyPem: str, nickname: str,
domain: str, port: int, domain: str, port: int,
toDomain: str, toPort: int, toDomain: str, toPort: int,
path: str, httpPrefix: str, withDigest: bool, path: str, httpPrefix: str, withDigest: bool,
messageBodyJsonStr: str) -> {}: messageBodyJsonStr: str,
contentType: str) -> {}:
"""Note that the domain is the destination, not the sender """Note that the domain is the destination, not the sender
""" """
headerDomain = getFullDomain(toDomain, toPort) headerDomain = getFullDomain(toDomain, toPort)
if not dateStr: if not dateStr:
dateStr = strftime("%a, %d %b %Y %H:%M:%S %Z", gmtime()) dateStr = strftime("%a, %d %b %Y %H:%M:%S %Z", gmtime())
if not withDigest: if not contentType:
contentType = 'application/activity+json' contentType = 'application/activity+json'
if not withDigest:
headers = { headers = {
'(request-target)': f'get {path}', '(request-target)': f'get {path}',
'host': headerDomain, 'host': headerDomain,
@ -222,7 +224,6 @@ def createSignedHeader(dateStr: str, privateKeyPem: str, nickname: str,
domain, port, toDomain, toPort, domain, port, toDomain, toPort,
path, httpPrefix, None) path, httpPrefix, None)
else: else:
contentType = 'application/activity+json'
bodyDigest = messageContentDigest(messageBodyJsonStr) bodyDigest = messageContentDigest(messageBodyJsonStr)
contentLength = len(messageBodyJsonStr) contentLength = len(messageBodyJsonStr)
headers = { headers = {

View File

@ -2244,7 +2244,8 @@ def sendPost(signingPrivateKeyPem: str, projectVersion: str,
signatureHeaderJson = \ signatureHeaderJson = \
createSignedHeader(None, privateKeyPem, nickname, domain, port, createSignedHeader(None, privateKeyPem, nickname, domain, port,
toDomain, toPort, toDomain, toPort,
postPath, httpPrefix, withDigest, postJsonStr) postPath, httpPrefix, withDigest, postJsonStr,
None)
# if the "to" domain is within the shared items # if the "to" domain is within the shared items
# federation list then send the token for this domain # federation list then send the token for this domain
@ -2603,7 +2604,8 @@ def sendSignedJson(postJsonObject: {}, session, baseDir: str,
signatureHeaderJson = \ signatureHeaderJson = \
createSignedHeader(None, privateKeyPem, nickname, domain, port, createSignedHeader(None, privateKeyPem, nickname, domain, port,
toDomain, toPort, toDomain, toPort,
postPath, httpPrefix, withDigest, postJsonStr) postPath, httpPrefix, withDigest, postJsonStr,
None)
# optionally add a token so that the receiving instance may access # optionally add a token so that the receiving instance may access
# your shared items catalog # your shared items catalog
if sharedItemsToken: if sharedItemsToken:

View File

@ -179,10 +179,13 @@ def _getJsonSigned(session, url: str, domainFull: str, sessionHeaders: {},
path = '/' + url.split(toDomainFull + '/')[1] path = '/' + url.split(toDomainFull + '/')[1]
else: else:
path = '/actor' path = '/actor'
contentType = 'application/activity+json'
if sessionHeaders.get('Accept'):
contentType = sessionHeaders['Accept']
signatureHeaderJson = \ signatureHeaderJson = \
createSignedHeader(None, signingPrivateKeyPem, 'actor', domain, port, createSignedHeader(None, signingPrivateKeyPem, 'actor', domain, port,
toDomain, toPort, path, httpPrefix, withDigest, toDomain, toPort, path, httpPrefix, withDigest,
messageStr) messageStr, contentType)
if debug: if debug:
print('Signed GET signatureHeaderJson ' + str(signatureHeaderJson)) print('Signed GET signatureHeaderJson ' + str(signatureHeaderJson))
# update the session headers from the signature headers # update the session headers from the signature headers

View File

@ -354,7 +354,7 @@ def _testHttpSignedGET():
'epicyon.libreserver.org', 443, 'epicyon.libreserver.org', 443,
host, 443, host, 443,
boxpath, httpPrefix, False, boxpath, httpPrefix, False,
None) None, accept)
signature = signatureHeader['signature'] signature = signatureHeader['signature']
print('') print('')