From a142e8a75288bcff9ea96be3d1d2057b4348c7aa Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Thu, 25 Oct 2018 19:56:02 -0500 Subject: [PATCH] offline encryption plugin can now decrypt --- onionr/onionrcrypto.py | 1 + .../default-plugins/encrypt/main.py | 26 +++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/onionr/onionrcrypto.py b/onionr/onionrcrypto.py index 678a4457..7b66a7d9 100644 --- a/onionr/onionrcrypto.py +++ b/onionr/onionrcrypto.py @@ -159,6 +159,7 @@ class OnionrCrypto: anonBox = nacl.public.SealedBox(privkey) else: anonBox = nacl.public.SealedBox(ownKey) + print(data) decrypted = anonBox.decrypt(data, encoder=encoding) return decrypted diff --git a/onionr/static-data/default-plugins/encrypt/main.py b/onionr/static-data/default-plugins/encrypt/main.py index d4d9306a..2aa87dcb 100644 --- a/onionr/static-data/default-plugins/encrypt/main.py +++ b/onionr/static-data/default-plugins/encrypt/main.py @@ -72,18 +72,34 @@ class PlainEncryption: encrypted = self.api.get_core()._crypto.pubKeyEncrypt(plaintext, pubkey, anonymous=True, encodedData=True) encrypted = self.api.get_core()._utils.bytesToStr(encrypted) print('ONIONR ENCRYPTED DATA %s END ENCRYPTED DATA' % (encrypted,)) - def decrypt(self, data): + def decrypt(self): plaintext = "" + data = "" + logger.info("Please enter your message (ctrl-d or -q to stop):") + try: + for line in sys.stdin: + if line == '-q\n': + break + data += line + except KeyboardInterrupt: + sys.exit(1) + if len(data) <= 1: + return encrypted = data.replace('ONIONR ENCRYPTED DATA ', '').replace('END ENCRYPTED DATA', '') myPub = self.api.get_core()._crypto.pubKey - decrypted = self.api.get_core()._crypto.pubKeyDecrypt(encrypted, pubkey, anonymous=True, encodedData=True) + decrypted = self.api.get_core()._crypto.pubKeyDecrypt(encrypted, privkey=self.api.get_core()._crypto.privKey, anonymous=True, encodedData=True) if decrypted == False: print("Decryption failed") else: data = json.loads(decrypted) - if not self.api.get_core()._crypto.edVerify(data['data'], data['signer'], data['sig']): - print("WARNING: THIS MESSAGE HAS AN INVALID SIGNATURE") - print(self.api.get_core()._utils.escapeAnsi(data['data'])) + print(data['data']) + try: + logger.info("Signing public key: %s" % (data['signer'],)) + assert self.api.get_core()._crypto.edVerify(data['data'], data['signer'], data['sig']) != False + except (AssertionError, KeyError) as e: + logger.warn("WARNING: THIS MESSAGE HAS A MISSING OR INVALID SIGNATURE") + else: + logger.info("Message has good signature.") return