Set accept type for signed header

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

View File

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

View File

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

View File

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