From b8644c0441d408c44ac942b82ea605a878af81e1 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Tue, 23 Oct 2018 23:54:28 -0500 Subject: [PATCH] work on offline decryption and fixed pubkey encrypt bug --- onionr/onionrcrypto.py | 2 +- onionr/static-data/default-plugins/encrypt/main.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/onionr/onionrcrypto.py b/onionr/onionrcrypto.py index d93d7c90..678a4457 100644 --- a/onionr/onionrcrypto.py +++ b/onionr/onionrcrypto.py @@ -144,7 +144,7 @@ class OnionrCrypto: def pubKeyDecrypt(self, data, pubkey='', privkey='', anonymous=False, encodedData=False): '''pubkey decrypt (Curve25519, taken from Ed25519 pubkey)''' - retVal = False + decrypted = False if encodedData: encoding = nacl.encoding.Base64Encoder else: diff --git a/onionr/static-data/default-plugins/encrypt/main.py b/onionr/static-data/default-plugins/encrypt/main.py index 48508e79..d4d9306a 100644 --- a/onionr/static-data/default-plugins/encrypt/main.py +++ b/onionr/static-data/default-plugins/encrypt/main.py @@ -74,8 +74,16 @@ class PlainEncryption: print('ONIONR ENCRYPTED DATA %s END ENCRYPTED DATA' % (encrypted,)) def decrypt(self, data): plaintext = "" - encrypted = data - + 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) + 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'])) return