implement signature algorithm

This commit is contained in:
Jakob Ketterl
2020-06-10 22:50:16 +02:00
parent 61d03b38b9
commit eebe33f896
3 changed files with 26 additions and 7 deletions

View File

@ -1,5 +1,7 @@
import re
import logging
import hashlib
from datetime import datetime
from owrx.config import Config
logger = logging.getLogger(__name__)
@ -47,7 +49,11 @@ class ReceiverId(object):
raise KeyException("invalid authorization header")
challenge = KeyChallenge(matches.group(1))
key = ReceiverId.findKey(challenge)
# TODO sign challenge and respond
time, signature = ReceiverId.signChallenge(challenge, key)
return {
"Signature": signature,
"Time": time,
}
@staticmethod
def findKey(challenge):
@ -61,3 +67,11 @@ class ReceiverId(object):
if matching_keys:
return matching_keys[0]
return None
@staticmethod
def signChallenge(challenge, key):
now = datetime.utcnow().isoformat()
signString = "{challenge}:{time}".format(challenge=challenge.challenge, time=now)
m = hashlib.sha256()
m.update(signString.encode())
return now, m.hexdigest()