offline encryption plugin can now decrypt
This commit is contained in:
parent
b8644c0441
commit
a142e8a752
@ -159,6 +159,7 @@ class OnionrCrypto:
|
|||||||
anonBox = nacl.public.SealedBox(privkey)
|
anonBox = nacl.public.SealedBox(privkey)
|
||||||
else:
|
else:
|
||||||
anonBox = nacl.public.SealedBox(ownKey)
|
anonBox = nacl.public.SealedBox(ownKey)
|
||||||
|
print(data)
|
||||||
decrypted = anonBox.decrypt(data, encoder=encoding)
|
decrypted = anonBox.decrypt(data, encoder=encoding)
|
||||||
return decrypted
|
return decrypted
|
||||||
|
|
||||||
|
@ -72,18 +72,34 @@ class PlainEncryption:
|
|||||||
encrypted = self.api.get_core()._crypto.pubKeyEncrypt(plaintext, pubkey, anonymous=True, encodedData=True)
|
encrypted = self.api.get_core()._crypto.pubKeyEncrypt(plaintext, pubkey, anonymous=True, encodedData=True)
|
||||||
encrypted = self.api.get_core()._utils.bytesToStr(encrypted)
|
encrypted = self.api.get_core()._utils.bytesToStr(encrypted)
|
||||||
print('ONIONR ENCRYPTED DATA %s END ENCRYPTED DATA' % (encrypted,))
|
print('ONIONR ENCRYPTED DATA %s END ENCRYPTED DATA' % (encrypted,))
|
||||||
def decrypt(self, data):
|
def decrypt(self):
|
||||||
plaintext = ""
|
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', '')
|
encrypted = data.replace('ONIONR ENCRYPTED DATA ', '').replace('END ENCRYPTED DATA', '')
|
||||||
myPub = self.api.get_core()._crypto.pubKey
|
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:
|
if decrypted == False:
|
||||||
print("Decryption failed")
|
print("Decryption failed")
|
||||||
else:
|
else:
|
||||||
data = json.loads(decrypted)
|
data = json.loads(decrypted)
|
||||||
if not self.api.get_core()._crypto.edVerify(data['data'], data['signer'], data['sig']):
|
print(data['data'])
|
||||||
print("WARNING: THIS MESSAGE HAS AN INVALID SIGNATURE")
|
try:
|
||||||
print(self.api.get_core()._utils.escapeAnsi(data['data']))
|
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
|
return
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user