Store uploaded device key

main
Bob Mottram 2020-08-06 22:23:17 +01:00
parent 4b3e6dc65c
commit 4a34ee0e80
2 changed files with 28 additions and 1 deletions

View File

@ -195,6 +195,7 @@ from followingCalendar import addPersonToCalendar
from followingCalendar import removePersonFromCalendar from followingCalendar import removePersonFromCalendar
from devices import E2EEdevicesCollection from devices import E2EEdevicesCollection
from devices import E2EEvalidDevice from devices import E2EEvalidDevice
from devices import E2EEaddDevice
import os import os
@ -1051,6 +1052,8 @@ class PubServer(BaseHTTPRequestHandler):
return 1 return 1
def _isAuthorized(self) -> bool: def _isAuthorized(self) -> bool:
self.authorizedNickname = None
if self.path.startswith('/icons/') or \ if self.path.startswith('/icons/') or \
self.path.startswith('/avatars/') or \ self.path.startswith('/avatars/') or \
self.path.startswith('/favicon.ico'): self.path.startswith('/favicon.ico'):
@ -1064,6 +1067,7 @@ class PubServer(BaseHTTPRequestHandler):
tokenStr = tokenStr.split(';')[0].strip() tokenStr = tokenStr.split(';')[0].strip()
if self.server.tokensLookup.get(tokenStr): if self.server.tokensLookup.get(tokenStr):
nickname = self.server.tokensLookup[tokenStr] nickname = self.server.tokensLookup[tokenStr]
self.authorizedNickname = nickname
# default to the inbox of the person # default to the inbox of the person
if self.path == '/': if self.path == '/':
self.path = '/users/' + nickname + '/inbox' self.path = '/users/' + nickname + '/inbox'
@ -5778,6 +5782,8 @@ class PubServer(BaseHTTPRequestHandler):
return pageNumber return pageNumber
def _cryptoAPIreadJson(self) -> {}: def _cryptoAPIreadJson(self) -> {}:
"""Obtains json from POST to the crypto API
"""
messageBytes = None messageBytes = None
maxCryptoMessageLength = 10240 maxCryptoMessageLength = 10240
length = int(self.headers['Content-length']) length = int(self.headers['Content-length'])
@ -5808,8 +5814,10 @@ class PubServer(BaseHTTPRequestHandler):
return json.loads(messageBytes) return json.loads(messageBytes)
def _cryptoAPI(self, path: str, authorized: bool) -> None: def _cryptoAPI(self, path: str, authorized: bool) -> None:
# TODO
if authorized and path.startswith('/api/v1/crypto/keys/upload'): if authorized and path.startswith('/api/v1/crypto/keys/upload'):
if not self.authorizedNickname:
self._400()
return
deviceKeys = self._cryptoAPIreadJson() deviceKeys = self._cryptoAPIreadJson()
if not deviceKeys: if not deviceKeys:
self._400() self._400()
@ -5817,17 +5825,32 @@ class PubServer(BaseHTTPRequestHandler):
if not E2EEvalidDevice(deviceKeys): if not E2EEvalidDevice(deviceKeys):
self._400() self._400()
return return
E2EEaddDevice(self.server.baseDir,
self.authorizedNickname,
self.server.domain,
deviceKeys['deviceId'],
deviceKeys['name'],
deviceKeys['claim'],
deviceKeys['fingerprintKey']['publicKeyBase64'],
deviceKeys['identityKey']['publicKeyBase64'],
deviceKeys['fingerprintKey']['type'],
deviceKeys['identityKey']['type'])
self._200() self._200()
elif path.startswith('/api/v1/crypto/keys/query'): elif path.startswith('/api/v1/crypto/keys/query'):
# TODO
self._200() self._200()
elif path.startswith('/api/v1/crypto/keys/claim'): elif path.startswith('/api/v1/crypto/keys/claim'):
# TODO
self._200() self._200()
elif authorized and path.startswith('/api/v1/crypto/delivery'): elif authorized and path.startswith('/api/v1/crypto/delivery'):
# TODO
self._200() self._200()
elif (authorized and elif (authorized and
path.startswith('/api/v1/crypto/encrypted_messages/clear')): path.startswith('/api/v1/crypto/encrypted_messages/clear')):
# TODO
self._200() self._200()
elif path.startswith('/api/v1/crypto/encrypted_messages'): elif path.startswith('/api/v1/crypto/encrypted_messages'):
# TODO
self._200() self._200()
else: else:
self._400() self._400()

View File

@ -59,6 +59,10 @@ def E2EEvalidDevice(deviceJson: {}) -> bool:
return False return False
if not isinstance(deviceJson['type'], str): if not isinstance(deviceJson['type'], str):
return False return False
if not deviceJson.get('name'):
return False
if not isinstance(deviceJson['name'], str):
return False
if deviceJson['type'] != 'Device': if deviceJson['type'] != 'Device':
return False return False
if not deviceJson.get('claim'): if not deviceJson.get('claim'):