finished inbox and signature validation for private messages

master
Kevin Froman 2018-07-19 02:08:51 -05:00
parent 732fe70ff4
commit 3b04771eb7
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
3 changed files with 31 additions and 7 deletions

View File

@ -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):

View File

@ -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):
'''

View File

@ -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