From 7390945ebf114404a60c31ecfb4420fb3bc926fd Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Tue, 17 Jul 2018 02:18:17 -0500 Subject: [PATCH] work on mail plugin inbox --- onionr/core.py | 2 +- onionr/onionrblockapi.py | 12 ++++++++---- onionr/static-data/default-plugins/pms/main.py | 18 +++++++++++++----- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/onionr/core.py b/onionr/core.py index 535c6b0a..6798bb12 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -718,7 +718,7 @@ class Core: # sign before encrypt, as unauthenticated crypto should not be a problem here if sign: signature = self._crypto.edSign(jsonMeta.encode() + data, key=self._crypto.privKey, encodeResult=True) - signer = self._crypto.pubKeyHashID() + signer = self._crypto.pubKey if len(jsonMeta) > 1000: raise onionrexceptions.InvalidMetadata('meta in json encoded form must not exceed 1000 bytes') diff --git a/onionr/onionrblockapi.py b/onionr/onionrblockapi.py index 56be7617..8993cbac 100644 --- a/onionr/onionrblockapi.py +++ b/onionr/onionrblockapi.py @@ -42,8 +42,6 @@ class Block: # initialize variables self.valid = True self.raw = None - self.powHash = None - self.powToken = None self.signed = False self.signature = None self.signedData = None @@ -69,6 +67,14 @@ class Block: # logic + def decrypt(self, anonymous=True, encodedData=True): + '''Decrypt a block, loading decrypted data into their vars''' + + # decrypt data + self.getCore()._crypto.pubKeyDecrypt(self.bcontent, anonymous=anonymous, encodedData=encodedData) + + return + def update(self, data = None, file = None): ''' Loads data from a block in to the current object. @@ -126,8 +132,6 @@ class Block: self.bmetadata = json.loads(self.getHeader('meta', None)) self.parent = self.getMetadata('parent', None) self.btype = self.getMetadata('type', None) - self.powHash = self.getMetadata('powHash', None) - self.powToken = self.getMetadata('powToken', None) self.signed = ('sig' in self.getHeader() and self.getHeader('sig') != '') self.signature = self.getHeader('sig', None) self.signedData = (None if not self.isSigned() else self.getHeader('meta') + '\n' + self.getContent()) diff --git a/onionr/static-data/default-plugins/pms/main.py b/onionr/static-data/default-plugins/pms/main.py index 7a331271..5d960735 100644 --- a/onionr/static-data/default-plugins/pms/main.py +++ b/onionr/static-data/default-plugins/pms/main.py @@ -49,9 +49,15 @@ class OnionrMail: return def inbox(self): - print('PM Blocks:') + blockCount = 0 + pmBlockMap = {} + + print('Private Messages:') + for blockHash in self.myCore.getBlocksByType('pm'): - print(blockHash) + blockCount += 1 + pmBlockMap[blockCount] = blockHash + print('%s: %s' % (blockCount, blockHash)) return @@ -88,10 +94,10 @@ class OnionrMail: continue newLine += '\n' message += newLine - + print('Inserting encrypted message as Onionr block....') - self.myCore.insertBlock(message, header='pm', encryptType='asym', asymPeer=recip) + self.myCore.insertBlock(message, header='pm', encryptType='asym', asymPeer=recip, sign=True) def menu(self): choice = '' @@ -100,7 +106,7 @@ class OnionrMail: print(self.strings.programTag + self.strings.mainMenu.title()) # print out main menu try: - choice = logger.readline('Enter 1-%s:\n' % (len(self.strings.mainMenuChoices))).lower() + choice = logger.readline('Enter 1-%s:\n' % (len(self.strings.mainMenuChoices))).lower().strip() except (KeyboardInterrupt, EOFError): choice = '5' @@ -111,6 +117,8 @@ class OnionrMail: elif choice in (self.strings.mainMenuChoices[4], '5'): logger.info('Goodbye.') break + elif choice == '': + pass else: logger.warn('Invalid choice.') return