Merge branch 'main' of ssh://code.freedombone.net:2222/bashrc/epicyon into main

main
Bob Mottram 2021-04-04 23:53:18 +01:00
commit 76550cc6bf
2 changed files with 13 additions and 18 deletions

View File

@ -18,7 +18,6 @@ from cryptography.hazmat.primitives.serialization import load_pem_public_key
from cryptography.hazmat.primitives.asymmetric import padding from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.primitives import hashes from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import utils as hazutils from cryptography.hazmat.primitives.asymmetric import utils as hazutils
import calendar
import base64 import base64
from time import gmtime, strftime from time import gmtime, strftime
import datetime import datetime
@ -120,11 +119,11 @@ def signPostHeadersNew(dateStr: str, privateKeyPem: str,
timeFormat = "%a, %d %b %Y %H:%M:%S %Z" timeFormat = "%a, %d %b %Y %H:%M:%S %Z"
if not dateStr: if not dateStr:
currTime = gmtime() currTime = gmtime()
secondsSinceEpoch = int(calendar.timegm(currTime))
dateStr = strftime(timeFormat, currTime) dateStr = strftime(timeFormat, currTime)
else: else:
currTime = datetime.datetime.strptime(dateStr, timeFormat) currTime = datetime.datetime.strptime(dateStr, timeFormat)
secondsSinceEpoch = int(currTime.timestamp()) secondsSinceEpoch = \
int((currTime - datetime.datetime(1970, 1, 1)).total_seconds())
keyID = httpPrefix + '://' + domain + '/users/' + nickname + '#main-key' keyID = httpPrefix + '://' + domain + '/users/' + nickname + '#main-key'
if not messageBodyJsonStr: if not messageBodyJsonStr:
headers = { headers = {

View File

@ -224,7 +224,7 @@ def testHttpSigNew():
# "Signature": sig # "Signature": sig
# } # }
dateStr = "Tue, 07 Jun 2014 20:51:35 GMT" dateStr = "Tue, 07 Jun 2014 20:51:35 GMT"
secondsSinceEpoch = 1402170695 secondsSinceEpoch = 1402174295
domain = "example.com" domain = "example.com"
port = 443 port = 443
headers = { headers = {
@ -242,14 +242,12 @@ def testHttpSigNew():
debug = False debug = False
assert verifyPostHeaders(httpPrefix, publicKeyPem, headers, assert verifyPostHeaders(httpPrefix, publicKeyPem, headers,
boxpath, False, None, boxpath, False, None,
messageBodyJsonStr, debug, messageBodyJsonStr, debug, True)
True)
# make a deliberate mistake # make a deliberate mistake
headers['Signature'] = headers['Signature'].replace('V', 'B') headers['Signature'] = headers['Signature'].replace('V', 'B')
assert not verifyPostHeaders(httpPrefix, publicKeyPem, headers, assert not verifyPostHeaders(httpPrefix, publicKeyPem, headers,
boxpath, False, None, boxpath, False, None,
messageBodyJsonStr, debug, messageBodyJsonStr, debug, True)
True)
# test signing # test signing
bodyDigest = messageContentDigest(messageBodyJsonStr) bodyDigest = messageContentDigest(messageBodyJsonStr)
contentLength = len(messageBodyJsonStr) contentLength = len(messageBodyJsonStr)
@ -273,16 +271,16 @@ def testHttpSigNew():
'digest, content-type, content-length)' 'digest, content-type, content-length)'
if signatureIndexHeader != expectedIndexHeader: if signatureIndexHeader != expectedIndexHeader:
print('Unexpected new http header: ' + signatureIndexHeader) print('Unexpected new http header: ' + signatureIndexHeader)
print('Should be: ' + expectedIndexHeader) print('Should be: ' + expectedIndexHeader)
assert signatureIndexHeader == expectedIndexHeader assert signatureIndexHeader == expectedIndexHeader
assert signatureHeader == \ assert signatureHeader == \
'sig1=:LQU1PcJILSp1Q30GWINusfftYYKfTtam7InSu2c+ZzfGC' + \ 'sig1=:euX3O1KSTYXN9/oR2qFezswWm9FbrjtRymK7xBpXNQvTs' + \
'bTSevRgifZFuG2asFi8ubG/uUVHiBwIxxIz1u/JyWC3lYIFgjQF' + \ 'XehtrNdD8nELZKzPXMvMz7PaJd6V+fjzpHoZ9upTdqqQLK2Iwml' + \
'RFM6As2b/ytnMA0LQhNebvk05iUNsz5izSoNTp5h9J7+roWkl6l' + \ 'p4BlHqW6Aopd7sZFCWFq7/Amm5oaizpp3e0jb5XISS5m3cRKuoi' + \
'8d5EA7vPMTQTJZnyU1cXBlvP1MtuVAKR6MbB3Aa/iZ4XOeaNK5E' + \ 'LM0x+OudmAoYGi0TEEJk8bpnJAXfVCDfmOyL3XNqQeShQHeOANG' + \
'1VuPfNFrdnizIELE3nGVoVqNNImgMY3DWhtF3vvezrcT0J2vNGZ' + \ 'okiKktj8ff+KLYLaPTAJkob1k/EhoPIkbw/YzAY8IZjWQNMkf+F' + \
'cvhBfgn/xeAsNxz67SIHMgiXvLL6TFqEI1en9dl9A3ihB6ZO6+W' + \ 'JChApQ5HnDCQPwD5xV9eGzBpAf6D0G19xiTmQye4Hn6tAs3fy3V' + \
'gUoW7OobZNlPxAUkQCc2A6oVjCYOdpKdrMAXQp2TQQ==:' '/aYa/GhW2pSrctDnAKIi4imj9joppr3CB8gqgXZOPQ==:'
def _testHttpsigBase(withDigest): def _testHttpsigBase(withDigest):
@ -3416,8 +3414,6 @@ def testSpeakerReplaceLinks():
'how-to-help-running-snowflake/' 'how-to-help-running-snowflake/'
detectedLinks = [] detectedLinks = []
result = speakerReplaceLinks(text, {'Linked': 'Web link'}, detectedLinks) result = speakerReplaceLinks(text, {'Linked': 'Web link'}, detectedLinks)
print(result)
print(str(detectedLinks))
assert len(detectedLinks) == 1 assert len(detectedLinks) == 1
assert detectedLinks[0] == \ assert detectedLinks[0] == \
'https://support.torproject.org/censorship/' + \ 'https://support.torproject.org/censorship/' + \