From 3b04771eb72512b0aae8d15d2ab0591ccaa88317 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Thu, 19 Jul 2018 02:08:51 -0500 Subject: [PATCH] finished inbox and signature validation for private messages --- onionr/onionrblockapi.py | 4 ++-- onionr/onionrutils.py | 10 +++++--- .../static-data/default-plugins/pms/main.py | 24 +++++++++++++++++-- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/onionr/onionrblockapi.py b/onionr/onionrblockapi.py index e67e4cc7..e9b01b2d 100644 --- a/onionr/onionrblockapi.py +++ b/onionr/onionrblockapi.py @@ -66,7 +66,8 @@ class Block: elif not self.update(): logger.debug('Failed to open block %s.' % self.getHash()) else: - logger.debug('Did not update block.') + pass + #logger.debug('Did not update block.') # logic @@ -257,7 +258,6 @@ class Block: Outputs: - (str): the type of the block ''' - return self.btype def getRaw(self): diff --git a/onionr/onionrutils.py b/onionr/onionrutils.py index cb1054bf..5ecf14bc 100644 --- a/onionr/onionrutils.py +++ b/onionr/onionrutils.py @@ -256,9 +256,13 @@ class OnionrUtils: Read metadata from a block and cache it to the block database ''' myBlock = Block(blockHash, self._core) - blockType = myBlock.getType() - if len(blockType) <= 10: - self._core.updateBlockInfo(blockHash, 'dataType', blockType) + myBlock.decrypt() + blockType = myBlock.getMetadata('type') # we would use myBlock.getType() here, but it is bugged with encrypted blocks + try: + if len(blockType) <= 10: + self._core.updateBlockInfo(blockHash, 'dataType', blockType) + except TypeError: + pass def escapeAnsi(self, line): ''' diff --git a/onionr/static-data/default-plugins/pms/main.py b/onionr/static-data/default-plugins/pms/main.py index f4a6ad5a..3da4d268 100644 --- a/onionr/static-data/default-plugins/pms/main.py +++ b/onionr/static-data/default-plugins/pms/main.py @@ -26,6 +26,17 @@ import onionrexceptions plugin_name = 'pms' PLUGIN_VERSION = '0.0.1' +def draw_border(text): + #https://stackoverflow.com/a/20757491 + lines = text.splitlines() + width = max(len(s) for s in lines) + res = ['┌' + '─' * width + '┐'] + for s in lines: + res.append('│' + (s + ' ' * width)[:width] + '│') + res.append('└' + '─' * width + '┘') + return '\n'.join(res) + + class MailStrings: def __init__(self, mailInstance): self.mailInstance = mailInstance @@ -44,6 +55,7 @@ class MailStrings: class OnionrMail: def __init__(self, pluginapi): self.myCore = pluginapi.get_core() + #self.dataFolder = pluginapi.get_data_folder() self.strings = MailStrings(self) return @@ -97,7 +109,11 @@ class OnionrMail: readBlock.verifySig() print('Message recieved from', readBlock.signer) print('Valid signature:', readBlock.validSig) - print(self.myCore._utils.escapeAnsi(readBlock.bcontent.decode())) + if not readBlock.validSig: + logger.warn('This message has an INVALID signature. Anyone could have sent this message.') + logger.readline('Press enter to continue to message.') + + print(draw_border(self.myCore._utils.escapeAnsi(readBlock.bcontent.decode().strip()))) return @@ -143,7 +159,7 @@ class OnionrMail: choice = '' while True: - print(self.strings.programTag + self.strings.mainMenu.title()) # print out main menu + print(self.strings.programTag + '\n\nOur ID: ' + self.myCore._crypto.pubKey + self.strings.mainMenu.title()) # print out main menu try: choice = logger.readline('Enter 1-%s:\n' % (len(self.strings.mainMenuChoices))).lower().strip() @@ -152,8 +168,12 @@ class OnionrMail: if choice in (self.strings.mainMenuChoices[0], '1'): self.inbox() + elif choice in (self.strings.mainMenuChoices[1], '2'): + logger.warn('not implemented yet') elif choice in (self.strings.mainMenuChoices[2], '3'): self.draftMessage() + elif choice in (self.strings.mainMenuChoices[3], '4'): + logger.warn('not implemented yet') elif choice in (self.strings.mainMenuChoices[4], '5'): logger.info('Goodbye.') break