plaintext block fixes with sharing, fixed peer lookup

This commit is contained in:
Kevin Froman 2020-10-10 23:23:22 +00:00
parent 835c2e527e
commit 3ef29077e7
9 changed files with 23 additions and 12 deletions

View File

@ -111,6 +111,9 @@ def download_blocks_from_communicator(comm_inst: "OnionrCommunicatorDaemon"):
try: try:
metadata_validation_result = \ metadata_validation_result = \
validatemetadata.validate_metadata(metadata, metas[2]) validatemetadata.validate_metadata(metadata, metas[2])
except onionrexceptions.PlaintextNotSupported:
logger.debug(f"Not saving {blockHash} due to plaintext not enabled")
removeFromQueue = True
except onionrexceptions.DataExists: except onionrexceptions.DataExists:
metadata_validation_result = False metadata_validation_result = False
if metadata_validation_result: # check if metadata is valid, and verify nonce if metadata_validation_result: # check if metadata is valid, and verify nonce

View File

@ -64,3 +64,4 @@ def lookup_new_peer_transports_with_communicator(shared_state):
except ValueError: except ValueError:
pass pass
kv.get('newPeers').extend(newPeers) kv.get('newPeers').extend(newPeers)
shared_state.get_by_string("OnionrCommunicatorDaemon").decrementThreadCount('clean_old_blocks')

View File

@ -38,7 +38,7 @@ def block_mixer(upload_list: List[onionrtypes.BlockHash],
to the said block list to the said block list
""" """
bl = onionrblockapi.Block(block_to_mix) bl = onionrblockapi.Block(block_to_mix)
print(bl.raw)
if time.time() - bl.claimedTime > onionrvalues.BLOCK_POOL_MAX_AGE: if time.time() - bl.claimedTime > onionrvalues.BLOCK_POOL_MAX_AGE:
raise ValueError raise ValueError
if block_to_mix: if block_to_mix:

View File

@ -65,6 +65,9 @@ def accept_upload(request):
resp = 'proof' resp = 'proof'
except onionrexceptions.DataExists: except onionrexceptions.DataExists:
resp = 'exists' resp = 'exists'
except onionrexceptions.PlaintextNotSupported:
logger.debug("attempted plaintext upload to us: {b_hash}")
resp = 'failure'
if resp == 'failure': if resp == 'failure':
abort(400) abort(400)
elif resp == 'proof': elif resp == 'proof':

View File

@ -6,6 +6,7 @@ from coredb import blockmetadb
from onionrstorage.removeblock import remove_block from onionrstorage.removeblock import remove_block
import onionrstorage import onionrstorage
from .onionrblockapi import Block from .onionrblockapi import Block
import onionrexceptions
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -28,7 +29,7 @@ def delete_plaintext_no_blacklist():
block_list = blockmetadb.get_block_list() block_list = blockmetadb.get_block_list()
for block in block_list: for block in block_list:
block = Block(hash=block) block = Block(hash=block, decrypt=False)
if not block.isEncrypted: if not block.isEncrypted:
remove_block(block.hash) remove_block(block.hash) # delete metadata entry
onionrstorage.deleteBlock(block.hash) onionrstorage.deleteBlock(block.hash) # delete block data

View File

@ -3,7 +3,6 @@
OnionrBlocks class for abstraction of blocks OnionrBlocks class for abstraction of blocks
""" """
import binascii import binascii
import os
import datetime import datetime
import onionrstorage import onionrstorage
@ -17,7 +16,6 @@ from onionrusers import onionrusers
from onionrutils import stringvalidators, epoch from onionrutils import stringvalidators, epoch
from coredb import blockmetadb from coredb import blockmetadb
from onionrutils import bytesconverter from onionrutils import bytesconverter
from onionrstorage import removeblock
import onionrblocks import onionrblocks
from onionrcrypto import encryption, cryptoutils as cryptoutils, signing from onionrcrypto import encryption, cryptoutils as cryptoutils, signing
""" """

View File

@ -48,6 +48,9 @@ class SignatureError(Exception):
# block exceptions # block exceptions
class PlaintextNotSupported(Exception):
pass
class ReplayAttack(Exception): class ReplayAttack(Exception):
pass pass

View File

@ -35,7 +35,10 @@ def remove_block(block):
**You may want blacklist.addToDB(blockHash) **You may want blacklist.addToDB(blockHash)
""" """
if stringvalidators.validate_hash(block): if stringvalidators.validate_hash(block):
dataSize = sys.getsizeof(onionrstorage.getData(block)) try:
data_size = sys.getsizeof(onionrstorage.getData(block))
except onionrexceptions.NoDataAvailable:
data_size = 0
conn = sqlite3.connect( conn = sqlite3.connect(
dbfiles.block_meta_db, timeout=DATABASE_LOCK_TIMEOUT) dbfiles.block_meta_db, timeout=DATABASE_LOCK_TIMEOUT)
c = conn.cursor() c = conn.cursor()
@ -43,6 +46,7 @@ def remove_block(block):
c.execute('Delete from hashes where hash=?;', t) c.execute('Delete from hashes where hash=?;', t)
conn.commit() conn.commit()
conn.close() conn.close()
storage_counter.remove_bytes(dataSize) if data_size:
storage_counter.remove_bytes(data_size)
else: else:
raise onionrexceptions.InvalidHexHash raise onionrexceptions.InvalidHexHash

View File

@ -76,8 +76,6 @@ def validate_metadata(metadata, block_data) -> bool:
elif i == 'encryptType': elif i == 'encryptType':
try: try:
if not metadata[i] in ('asym', 'sym', ''): raise ValueError if not metadata[i] in ('asym', 'sym', ''): raise ValueError
if not config.get('general.store_plaintext_blocks', True):
break
except ValueError: except ValueError:
logger.warn('Invalid encryption mode') logger.warn('Invalid encryption mode')
break break
@ -100,9 +98,9 @@ def validate_metadata(metadata, block_data) -> bool:
if not config.get('general.store_plaintext_blocks', True): if not config.get('general.store_plaintext_blocks', True):
try: try:
if not metadata['encryptType']: if not metadata['encryptType']:
raise onionrexceptions.DataExists raise onionrexceptions.PlaintextNotSupported
except KeyError: except KeyError:
raise onionrexceptions.DataExists raise onionrexceptions.PlaintextNotSupported
try: try:
metadata['time'] metadata['time']
except KeyError: except KeyError: