From 9655bfd872f4007449bc185204c22c6a0eaef191 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 17 Aug 2018 23:42:30 -0500 Subject: [PATCH] * do not reinsert blocks * warn mail about bad sigs --- onionr/core.py | 20 ++++++++++++------- onionr/onionrpeers.py | 7 +++++-- .../static-data/default-plugins/pms/main.py | 11 +++++----- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/onionr/core.py b/onionr/core.py index f3834ed3..9d97e3f1 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -624,6 +624,18 @@ class Core: ''' retData = False + # check nonce + dataNonce = self._utils.bytesToStr(self._crypto.sha3Hash(data)) + try: + with open(self.dataNonceFile, 'r') as nonces: + if dataNonce in nonces: + return retData + except FileNotFoundError: + pass + # record nonce + with open(self.dataNonceFile, 'a') as nonceFile: + nonceFile.write(dataNonce + '\n') + if meta is None: meta = dict() @@ -683,13 +695,7 @@ class Core: metadata['sig'] = signature metadata['signer'] = signer metadata['time'] = str(self._utils.getEpoch()) - - nonce = self._utils.bytesToStr(self._crypto.sha3Hash(data)) - - # TODO check in advance - with open(self.dataNonceFile, 'a') as nonceFile: - nonceFile.write(nonce + '\n') - + # send block data (and metadata) to POW module to get tokenized block data proof = onionrproofs.POW(metadata, data) payload = proof.waitForResult() diff --git a/onionr/onionrpeers.py b/onionr/onionrpeers.py index cd0745ea..710f698d 100644 --- a/onionr/onionrpeers.py +++ b/onionr/onionrpeers.py @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' -import core, config, logger +import core, config, logger, sqlite3 class PeerProfiles: ''' PeerProfiles @@ -89,7 +89,10 @@ def peerCleanup(coreInst): # Remove peers that go below the negative score if PeerProfiles(address, coreInst).score < minScore: coreInst.removeAddress(address) - coreInst._blacklist.addToDB(address, dataType=1, expire=300) + try: + coreInst._blacklist.addToDB(address, dataType=1, expire=300) + except sqlite3.IntegrityError: #TODO just make sure its not a unique constraint issue + pass logger.warn('Removed address ' + address + '.') # Unban probably not malicious peers TODO improve diff --git a/onionr/static-data/default-plugins/pms/main.py b/onionr/static-data/default-plugins/pms/main.py index 4b7199fd..300c9625 100644 --- a/onionr/static-data/default-plugins/pms/main.py +++ b/onionr/static-data/default-plugins/pms/main.py @@ -109,14 +109,13 @@ class OnionrMail: pass else: readBlock.verifySig() - print('Message recieved from', readBlock.signer) + print('Message recieved from %s' % (readBlock.signer,)) print('Valid signature:', readBlock.validSig) if not readBlock.validSig: - logger.warn('This message has an INVALID signature. Anyone could have sent this message.') - logger.readline('Press enter to continue to message.') - - print(draw_border(self.myCore._utils.escapeAnsi(readBlock.bcontent.decode().strip()))) - + logger.warn('This message has an INVALID signature. ANYONE could have sent this message.') + cancel = logger.readline('Press enter to continue to message, or -q to not open the message (recommended).') + if cancel != '-q': + print(draw_border(self.myCore._utils.escapeAnsi(readBlock.bcontent.decode().strip()))) return def draftMessage(self):