def createAndSaveSharedSecret(self, foreignPublicKey): '''Takes a public key from someone else and generates a sharedSecret''' keyHandler = self._getKeyHandlerFromDb() try: keyHandler.generate_shared_secret(foreignPublicKey) self._insertKeyHandlerIntoDb(keyHandler) except MalformedPublicKey as e: UniversalUtilities.sendErrorMessageToFrontend(e)
def main(): data = UniversalUtilities.read_in_stdin_json() if data[DictIndex.LOAD.value] == Action.INITIAL.value: createDataBase() createSettingsTable() elif data[DictIndex.LOAD.value] == Action.INSERT.value: message, sender = data[DictIndex.MESSAGE.value], data[DictIndex.SENDER.value] DataBaseUtilities.insertMessageAndSender(sender=sender, message=message) try: UniversalUtilities.connectAndSendTo_6200(message=message) except ConnectionError as e: UniversalUtilities.sendErrorMessageToFrontend(e)
def decryptByteArray(self, encryptedByteArray): '''Returns void if the decryption fails''' keyHandler = self._getKeyHandlerFromDb() blake = blake2b(digest_size=32) try: # Using blake2b hashing algorithm to shorten the shared_key blake.update(keyHandler.shared_key.encode()) # Using the shortened shared_key as encryption key fernet = Fernet(base64.urlsafe_b64encode(blake.digest())) return json.loads(fernet.decrypt(encryptedByteArray)) except AttributeError as e: UniversalUtilities.sendErrorMessageToFrontend(e) return None except InvalidToken as e: UniversalUtilities.sendErrorMessageToFrontend(e) return None
def requestState(): try: address = ('localhost', 6000) conn = Client(address, authkey=b'PyToPyCom') # status, if an local arduino is connected conn.send(RequestToken.ARD_CON_STATE.value) localArdState = str(conn.recv()) # status, if an arduino is connected by infrared conn.send(RequestToken.COMMUNICATION_STATE.value) externalArdState = str(conn.recv()) conn.send(RequestToken.PARTNER_ID.value) partnerID = str(conn.recv()) conn.send('finished') conn.close() return localArdState, externalArdState, partnerID except ConnectionError as e: UniversalUtilities.sendErrorMessageToFrontend(e)
def main(): load = UniversalUtilities.read_in_stdin_json() exp = load[DictIndex.LOAD.value] if exp == Action.INITIAL.value: getInitialLoad() elif exp == Action.ENTRY.value: getInsertedValue() elif exp == Action.LOAD_MORE.value: startID = load[DictIndex.ID.value] loadMoreEntrys(startID=startID)
def main(): # try: inputData = UniversalUtilities.read_in_stdin_json() theme = inputData[DictIndex.THEME.value] if inputData[DictIndex.LOAD.value] == Action.CHECK.value: settings_uuid = getUUIDFromSettings() if settings_uuid == None: insertDefaults(uuid=guid.uuid4(), theme=theme) sendDefaults() if inputData[DictIndex.LOAD.value] == Action.UPDATE_THEME.value: insertThemeOnly(theme=theme)
def main(): load = UniversalUtilities.read_in_stdin_json() exp = load[DictIndex.LOAD.value] if exp == Action.INITIAL.value: try: ardLoc, ardExt, partnerID = requestState() jsonFrontEnd(ardLoc, ardExt, partnerID, None, None) except ConnectionError as e: UniversalUtilities.sendErrorMessageToFrontend(e) else: lastId = load[DictIndex.ID.value] try: ardLoc, ardExt, partnerID = requestState() newMessagesInDb, messages = databaseState(lastId, partnerID) jsonFrontEnd(ardLoc, ardExt, partnerID, newMessagesInDb, messages) except ConnectionError as e: UniversalUtilities.sendErrorMessageToFrontend(e) except sqlite3.Error as e: UniversalUtilities.sendErrorMessageToFrontend(e)