From 220fda02ce1fcf6ba9b5ea44d38b3075fa0eb9be Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 19 Oct 2018 00:04:11 -0500 Subject: [PATCH] half way done with encryption plugin, fixed encryption bug in onionrcrypto when using non anonymous encryption --- onionr/core.py | 1 + onionr/onionrcrypto.py | 2 +- onionr/onionrusers.py | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/onionr/core.py b/onionr/core.py index df0430c2..65f9f26a 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -732,6 +732,7 @@ class Core: onionrusers.OnionrUser(self, asymPeer).generateForwardKey() else: logger.info(forwardEncrypted) + onionrusers.OnionrUser(self, asymPeer).generateForwardKey() fsKey = onionrusers.OnionrUser(self, asymPeer).getGeneratedForwardKeys()[0] meta['newFSKey'] = fsKey[0] jsonMeta = json.dumps(meta) diff --git a/onionr/onionrcrypto.py b/onionr/onionrcrypto.py index 8285f74d..d93d7c90 100644 --- a/onionr/onionrcrypto.py +++ b/onionr/onionrcrypto.py @@ -128,7 +128,7 @@ class OnionrCrypto: encoding = nacl.encoding.RawEncoder if self.privKey != None and not anonymous: - ownKey = nacl.signing.SigningKey(seed=self.privKey, encoder=nacl.encoding.Base32Encoder) + ownKey = nacl.signing.SigningKey(seed=self.privKey, encoder=nacl.encoding.Base32Encoder).to_curve25519_private_key() key = nacl.signing.VerifyKey(key=pubkey, encoder=nacl.encoding.Base32Encoder).to_curve25519_public_key() ourBox = nacl.public.Box(ownKey, key) retVal = ourBox.encrypt(data.encode(), encoder=encoding) diff --git a/onionr/onionrusers.py b/onionr/onionrusers.py index 7a3f515c..f1ab241c 100644 --- a/onionr/onionrusers.py +++ b/onionr/onionrusers.py @@ -58,6 +58,7 @@ class OnionrUser: def forwardEncrypt(self, data): retData = '' forwardKey = self._getLatestForwardKey() + logger.info('using ' + forwardKey) if self._core._utils.validatePubKey(forwardKey): retData = self._core._crypto.pubKeyEncrypt(data, forwardKey, encodedData=True, anonymous=True) else: @@ -87,7 +88,7 @@ class OnionrUser: conn = sqlite3.connect(self._core.peerDB, timeout=10) c = conn.cursor() - for row in c.execute("SELECT forwardKey FROM forwardKeys WHERE peerKey = ? AND date=(SELECT max(date) FROM forwardKeys)", (self.publicKey,)): + for row in c.execute("SELECT forwardKey FROM forwardKeys WHERE peerKey = ? order by date desc", (self.publicKey,)): key = row[0] break @@ -99,7 +100,7 @@ class OnionrUser: conn = sqlite3.connect(self._core.peerDB, timeout=10) c = conn.cursor() keyList = [] - for row in c.execute("SELECT forwardKey FROM forwardKeys WHERE peerKey = ?", (self.publicKey,)): + for row in c.execute("SELECT forwardKey FROM forwardKeys WHERE peerKey = ? order by date desc", (self.publicKey,)): key = row[0] keyList.append(key)