finished inbox and signature validation for private messages
parent
732fe70ff4
commit
3b04771eb7
|
@ -66,7 +66,8 @@ class Block:
|
||||||
elif not self.update():
|
elif not self.update():
|
||||||
logger.debug('Failed to open block %s.' % self.getHash())
|
logger.debug('Failed to open block %s.' % self.getHash())
|
||||||
else:
|
else:
|
||||||
logger.debug('Did not update block.')
|
pass
|
||||||
|
#logger.debug('Did not update block.')
|
||||||
|
|
||||||
# logic
|
# logic
|
||||||
|
|
||||||
|
@ -257,7 +258,6 @@ class Block:
|
||||||
Outputs:
|
Outputs:
|
||||||
- (str): the type of the block
|
- (str): the type of the block
|
||||||
'''
|
'''
|
||||||
|
|
||||||
return self.btype
|
return self.btype
|
||||||
|
|
||||||
def getRaw(self):
|
def getRaw(self):
|
||||||
|
|
|
@ -256,9 +256,13 @@ class OnionrUtils:
|
||||||
Read metadata from a block and cache it to the block database
|
Read metadata from a block and cache it to the block database
|
||||||
'''
|
'''
|
||||||
myBlock = Block(blockHash, self._core)
|
myBlock = Block(blockHash, self._core)
|
||||||
blockType = myBlock.getType()
|
myBlock.decrypt()
|
||||||
if len(blockType) <= 10:
|
blockType = myBlock.getMetadata('type') # we would use myBlock.getType() here, but it is bugged with encrypted blocks
|
||||||
self._core.updateBlockInfo(blockHash, 'dataType', blockType)
|
try:
|
||||||
|
if len(blockType) <= 10:
|
||||||
|
self._core.updateBlockInfo(blockHash, 'dataType', blockType)
|
||||||
|
except TypeError:
|
||||||
|
pass
|
||||||
|
|
||||||
def escapeAnsi(self, line):
|
def escapeAnsi(self, line):
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -26,6 +26,17 @@ import onionrexceptions
|
||||||
plugin_name = 'pms'
|
plugin_name = 'pms'
|
||||||
PLUGIN_VERSION = '0.0.1'
|
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:
|
class MailStrings:
|
||||||
def __init__(self, mailInstance):
|
def __init__(self, mailInstance):
|
||||||
self.mailInstance = mailInstance
|
self.mailInstance = mailInstance
|
||||||
|
@ -44,6 +55,7 @@ class MailStrings:
|
||||||
class OnionrMail:
|
class OnionrMail:
|
||||||
def __init__(self, pluginapi):
|
def __init__(self, pluginapi):
|
||||||
self.myCore = pluginapi.get_core()
|
self.myCore = pluginapi.get_core()
|
||||||
|
#self.dataFolder = pluginapi.get_data_folder()
|
||||||
self.strings = MailStrings(self)
|
self.strings = MailStrings(self)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -97,7 +109,11 @@ class OnionrMail:
|
||||||
readBlock.verifySig()
|
readBlock.verifySig()
|
||||||
print('Message recieved from', readBlock.signer)
|
print('Message recieved from', readBlock.signer)
|
||||||
print('Valid signature:', readBlock.validSig)
|
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
|
return
|
||||||
|
|
||||||
|
@ -143,7 +159,7 @@ class OnionrMail:
|
||||||
choice = ''
|
choice = ''
|
||||||
while True:
|
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:
|
try:
|
||||||
choice = logger.readline('Enter 1-%s:\n' % (len(self.strings.mainMenuChoices))).lower().strip()
|
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'):
|
if choice in (self.strings.mainMenuChoices[0], '1'):
|
||||||
self.inbox()
|
self.inbox()
|
||||||
|
elif choice in (self.strings.mainMenuChoices[1], '2'):
|
||||||
|
logger.warn('not implemented yet')
|
||||||
elif choice in (self.strings.mainMenuChoices[2], '3'):
|
elif choice in (self.strings.mainMenuChoices[2], '3'):
|
||||||
self.draftMessage()
|
self.draftMessage()
|
||||||
|
elif choice in (self.strings.mainMenuChoices[3], '4'):
|
||||||
|
logger.warn('not implemented yet')
|
||||||
elif choice in (self.strings.mainMenuChoices[4], '5'):
|
elif choice in (self.strings.mainMenuChoices[4], '5'):
|
||||||
logger.info('Goodbye.')
|
logger.info('Goodbye.')
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue