diff --git a/onionr/onionrcommands/pubkeymanager.py b/onionr/onionrcommands/pubkeymanager.py index 941bbb98..ea55a3fe 100644 --- a/onionr/onionrcommands/pubkeymanager.py +++ b/onionr/onionrcommands/pubkeymanager.py @@ -18,7 +18,7 @@ along with this program. If not, see . ''' -import sys +import sys, getpass import logger from onionrusers import onionrusers def add_ID(o_inst): diff --git a/onionr/onionrusers/onionrusers.py b/onionr/onionrusers/onionrusers.py index ebbac73d..4429cd18 100755 --- a/onionr/onionrusers/onionrusers.py +++ b/onionr/onionrusers/onionrusers.py @@ -33,7 +33,7 @@ def deleteExpiredKeys(coreInst): return def deleteTheirExpiredKeys(coreInst, pubkey): - conn = sqlite3.connect(self._core.peerDB, timeout=10) + conn = sqlite3.connect(coreInst.peerDB, timeout=10) c = conn.cursor() # Prepare the insert @@ -44,8 +44,8 @@ def deleteTheirExpiredKeys(coreInst, pubkey): conn.commit() conn.close() -DEFAULT_KEY_EXPIRE = 604800 -#DEFAULT_KEY_EXPIRE = 600 +#DEFAULT_KEY_EXPIRE = 604800 +DEFAULT_KEY_EXPIRE = 600 class OnionrUser: def __init__(self, coreInst, publicKey, saveUser=False): @@ -99,6 +99,7 @@ class OnionrUser: return decrypted def forwardEncrypt(self, data): + deleteTheirExpiredKeys(self._core, self.publicKey) deleteExpiredKeys(self._core) retData = '' forwardKey = self._getLatestForwardKey() @@ -129,7 +130,7 @@ class OnionrUser: c = conn.cursor() # TODO: account for keys created at the same time (same epoch) - for row in c.execute("SELECT forwardKey, max(DATE) FROM forwardKeys WHERE peerKey = ?", (self.publicKey,)): + for row in c.execute("SELECT forwardKey, max(EXPIRE) FROM forwardKeys WHERE peerKey = ? ORDER BY expire DESC", (self.publicKey,)): key = (row[0], row[1]) break @@ -143,7 +144,7 @@ class OnionrUser: c = conn.cursor() keyList = [] - for row in c.execute("SELECT forwardKey, date FROM forwardKeys WHERE peerKey = ? ORDER BY date DESC", (self.publicKey,)): + for row in c.execute("SELECT forwardKey, date FROM forwardKeys WHERE peerKey = ? ORDER BY expire DESC", (self.publicKey,)): keyList.append((row[0], row[1])) conn.commit() diff --git a/onionr/onionrutils.py b/onionr/onionrutils.py index 0641c37c..f8fd13af 100755 --- a/onionr/onionrutils.py +++ b/onionr/onionrutils.py @@ -281,9 +281,9 @@ class OnionrUtils: break elif i == 'expire': try: - assert int(metadata[i]) < self.getEpoch() + assert int(metadata[i]) > self.getEpoch() except AssertionError: - logger.warn('Block is expired') + logger.warn('Block is expired: %s greater than %s' % (metadata[i], self.getEpoch())) break elif i == 'encryptType': try: