From c4dcd89dfe8622fff43dd14973d86cba10c6a6ae Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Tue, 11 Sep 2018 21:58:51 -0500 Subject: [PATCH] + added methods to import and select new forward secrecy keys --- onionr/core.py | 2 +- onionr/onionrusers.py | 22 +++++++++++++++++-- .../default-plugins/metadataprocessor/main.py | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/onionr/core.py b/onionr/core.py index c1edf921..15c862c5 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -693,7 +693,7 @@ class Core: data = data.encode() except AttributeError: pass - # sign before encrypt, as unauthenticated crypto should not be a problem here + if sign: signature = self._crypto.edSign(jsonMeta.encode() + data, key=self._crypto.privKey, encodeResult=True) signer = self._crypto.pubKey diff --git a/onionr/onionrusers.py b/onionr/onionrusers.py index 10e2be33..4b74258e 100644 --- a/onionr/onionrusers.py +++ b/onionr/onionrusers.py @@ -50,7 +50,7 @@ class OnionrUser: encrypted = coreInst._crypto.pubKeyEncrypt(data, self.publicKey, encodedData=True) return encrypted - def decrypt(self, data): + def decrypt(self, data, anonymous=True): decrypted = coreInst._crypto.pubKeyDecrypt(data, self.publicKey, encodedData=True) return decrypted @@ -59,8 +59,26 @@ class OnionrUser: def forwardDecrypt(self, encrypted): return - + + def _getLatestForwardKey(self): + # Get the latest forward secrecy key for a peer + conn = sqlite3.connect(self._core.peerDB) + c = conn.cursor() + # Prepare the insert + time = self._core._utils.getEpoch() + key = '' + + for row in c.execute("SELECT forwardKey FROM forwardKeys WHERE DATE=(SELECT max(date) FROM forwardKeys);"): + key = row[0] + break + + conn.commit() + conn.close() + return key + def addForwardKey(self, newKey): + if not self._core._utils.validatePubKey(newKey): + raise onionrexceptions.InvalidPubkey # Add a forward secrecy key for the peer conn = sqlite3.connect(self._core.peerDB) c = conn.cursor() diff --git a/onionr/static-data/default-plugins/metadataprocessor/main.py b/onionr/static-data/default-plugins/metadataprocessor/main.py index 994bf818..74397c12 100644 --- a/onionr/static-data/default-plugins/metadataprocessor/main.py +++ b/onionr/static-data/default-plugins/metadataprocessor/main.py @@ -54,7 +54,7 @@ def _processForwardKey(api, myBlock): def on_processBlocks(api): myBlock = api.data['block'] blockType = api.data['type'] - print('blockType is ' + blockType) + logger.info('blockType is ' + blockType) # Process specific block types