mirror of https://gitlab.com/bashrc2/epicyon
Set accept type for signed header
parent
0af91ce4b6
commit
20b5805e9a
|
@ -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 = {
|
||||||
|
|
6
posts.py
6
posts.py
|
@ -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:
|
||||||
|
|
|
@ -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
|
||||||
|
|
2
tests.py
2
tests.py
|
@ -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('')
|
||||||
|
|
Loading…
Reference in New Issue