work on implementing torgossip

This commit is contained in:
Kevin Froman 2021-01-31 04:40:51 +00:00
parent 418237cfc6
commit ee8b81ead6
19 changed files with 201 additions and 44 deletions

View File

@ -35,6 +35,9 @@ def detect_socket_leaks(socket_event):
try: try:
ip_address = ipaddress.ip_address(ip_address) ip_address = ipaddress.ip_address(ip_address)
except ValueError: except ValueError:
if ip_address == "/":
# unix socket
return
logger.warn(f'Conn made to {ip_address} outside of Tor/similar') logger.warn(f'Conn made to {ip_address} outside of Tor/similar')
raise \ raise \
NetworkLeak('Conn to host/non local IP, this is a privacy issue!') NetworkLeak('Conn to host/non local IP, this is a privacy issue!')

View File

@ -28,6 +28,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
class AlreadyGenerating(Exception): pass # noqa class AlreadyGenerating(Exception): pass # noqa
class PassToSafeDB:
def __init__(self, db: 'SafeDB'):
self.db = db
self.block_creator_queue = BlockCreatorQueue(self.store_kasten)
def store_kasten(self, kasten_object):
self.db.put(kasten_object.id, kasten_object.get_packed())
def queue_then_store(self, block_data, block_type, ttl, **block_metadata):
self.block_creator_queue.queue_block(block_data, block_type, ttl, **block_metadata)
class BlockCreatorQueue: class BlockCreatorQueue:
def __init__( def __init__(
self, callback_func: Callable, *additional_callback_func_args, self, callback_func: Callable, *additional_callback_func_args,
@ -66,4 +79,3 @@ class BlockCreatorQueue:
Thread(target=_do_create, daemon=True).start() Thread(target=_do_create, daemon=True).start()
return digest return digest

View File

@ -62,4 +62,3 @@ def serialized(name: str) -> Response:
if isinstance(attr, int): if isinstance(attr, int):
attr = str(attr) attr = str(attr)
return Response(attr, content_type='application/octet-stream') return Response(attr, content_type='application/octet-stream')

View File

@ -52,6 +52,8 @@ class LANServer:
@app.before_request @app.before_request
def dns_rebinding_prevention(): def dns_rebinding_prevention():
if not ipaddress.ip_address(request.remote_addr).is_private:
abort(403)
if request.remote_addr in lan_ips or \ if request.remote_addr in lan_ips or \
ipaddress.ip_address(request.remote_addr).is_loopback: ipaddress.ip_address(request.remote_addr).is_loopback:
if time.time() - _start_time > 600: if time.time() - _start_time > 600:

View File

@ -93,6 +93,10 @@ class NetController:
if 'bootstrapped 100' in line.decode().lower(): if 'bootstrapped 100' in line.decode().lower():
logger.info(line.decode(), terminal=True) logger.info(line.decode(), terminal=True)
break break
elif 'asking for networkstatus consensus' in line.decode().lower():
logger.warn(
"Tor has to load consensus, this should be faster next time," +
" unless Onionr data is deleted.", terminal=True)
elif 'opening socks listener' in line.decode().lower(): elif 'opening socks listener' in line.decode().lower():
logger.debug(line.decode().replace('\n', '')) logger.debug(line.decode().replace('\n', ''))
else: else:

View File

@ -72,8 +72,6 @@ def generate_torrc(net_controller: 'NetController',
DataDirectory """ + home_dir + """tordata/ DataDirectory """ + home_dir + """tordata/
CookieAuthentication 1 CookieAuthentication 1
KeepalivePeriod 40 KeepalivePeriod 40
SafeSocks 1
TestSocks 1
CircuitsAvailableTimeout 86400 CircuitsAvailableTimeout 86400
ControlPort """ + str(control_port) + """ ControlPort """ + str(control_port) + """
HashedControlPassword """ + str(password) + """ HashedControlPassword """ + str(password) + """

View File

@ -44,21 +44,22 @@ from sneakernet import sneakernet_import_thread
from onionrstatistics.devreporting import statistics_reporter from onionrstatistics.devreporting import statistics_reporter
from setupkvvars import setup_kv from setupkvvars import setup_kv
from communicatorutils.housekeeping import clean_blocks_not_meeting_pow from communicatorutils.housekeeping import clean_blocks_not_meeting_pow
from blockcreatorqueue import BlockCreatorQueue, PassToSafeDB
from .spawndaemonthreads import spawn_client_threads from .spawndaemonthreads import spawn_client_threads
from .loadsafedb import load_safe_db from .loadsafedb import load_safe_db
""" """
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
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
(at your option) any later version. (at your option) any later version.
This program is distributed in the hope that it will be useful, This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. GNU General Public License for more details.
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
""" """
@ -181,6 +182,7 @@ def daemon():
shared_state.get(serializeddata.SerializedData) shared_state.get(serializeddata.SerializedData)
shared_state.add(load_safe_db(config)) shared_state.add(load_safe_db(config))
shared_state.add(PassToSafeDB(shared_state.get_by_string('SafeDB')))
shared_state.share_object() # share the parent object to the threads shared_state.share_object() # share the parent object to the threads

View File

@ -53,9 +53,11 @@ class OnionrRunTestManager:
def __init__(self): def __init__(self):
self.success: bool = True self.success: bool = True
self.run_date: int = 0 self.run_date: int = 0
self.plugin_tests = []
def run_tests(self): def run_tests(self):
tests = list(RUN_TESTS) tests = list(RUN_TESTS)
tests.extend(self.plugin_tests)
SystemRandom().shuffle(tests) SystemRandom().shuffle(tests)
cur_time = epoch.get_epoch() cur_time = epoch.get_epoch()
logger.info(f"Doing runtime tests at {cur_time}") logger.info(f"Doing runtime tests at {cur_time}")

View File

@ -44,3 +44,26 @@ ZABkAWwAbQFaAQEAZABkAmwCbQNaAwEAZQFkA2QEZAVnAoMCWgRlA2QGZQWDAloGZQNkB2UHgwJaCGUD
ZABkAYQAWgBkAlMA ZABkAYQAWgBkAlMA
ZABkAWwAWgBkAGQBbAFaAWQCZAOEAFoCZARkBYQAWgNkAVMA ZABkAWwAWgBkAGQBbAFaAWQCZAOEAFoCZARkBYQAWgNkAVMA
ZABkAWwAWgBlAWQCnAFkA2QEhARaAmQFZAaEAFoDZAFTAA== ZABkAWwAWgBlAWQCnAFkA2QEhARaAmQFZAaEAFoDZAFTAA==
ZABkAWQCZANnBFoAZARkBWwBWgFkBGQFbAJaAmQEZAVsA1oDZARkBWwEWgRkBGQFb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HWgcBAGQFZAaEAFoIZAFTAA==
ZABkAWwAWgBkAGQBbAFaAWQAZAJsAm0DWgMBAGQAZANsBG0FWgUBAGQAZARsBm0HWgcBAGQAZAVsCG0JWgkBAGQAZAZsCm0LWgsBAGQHZAiEAFoMZAFTAA==
ZABkAWwAWgBkAGQBbAFaAWQAZAJsAm0DWgMBAGQAZANsBG0FWgUBAGQAZARsBm0HWgcBAGQAZAVsCG0JWgkBAGQAZAZsCm0LWgsBAGQAZAFsCFoIZAdkCIQAWgxkAVMA
ZABaAGQBZAJsAW0CWgIBAGQBZANsA20EWgQBAGQBZARsBVoFZAFkBGwBWgFkAWQFbAZtB1oHAQBkBmQHhABaCGUJZAicAWQJZAqEBFoKZQlkCJwBZAtkDIQEWgtkDWQOhABaDGQEUwA=

View File

@ -1 +1 @@
https://3g2upl4pq6kufc4m.onion/robots.txt,http://expyuzz4wqqyqhjn.onion/robots.txt,http://archivecaslytosk.onion/robots.txt,http://cockmailwwfvrtqj.onion/robots.txt https://3g2upl4pq6kufc4m.onion/robots.txt,http://expyuzz4wqqyqhjn.onion/robots.txt

View File

@ -1,22 +1,10 @@
''' """Onionr - Private P2P Communication.
Onionr - Private P2P Communication
This default plugin allows users to encrypt/decrypt messages without using blocks This default plugin allows users to encrypt/decrypt messages without using blocks
''' """
''' import locale
This program is free software: you can redistribute it and/or modify locale.setlocale(locale.LC_ALL, '')
it under the terms of the GNU General Public License as published by import binascii
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
# Imports some useful libraries # Imports some useful libraries
import logger, config, threading, time, datetime, sys import logger, config, threading, time, datetime, sys
@ -27,11 +15,20 @@ from nacl.exceptions import TypeError as NaclTypeError
from onionrutils import stringvalidators, bytesconverter from onionrutils import stringvalidators, bytesconverter
from onionrcrypto import encryption, keypair, signing, getourkeypair from onionrcrypto import encryption, keypair, signing, getourkeypair
import onionrexceptions, onionrusers import onionrexceptions, onionrusers
"""
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
import locale This program is distributed in the hope that it will be useful,
locale.setlocale(locale.LC_ALL, '') but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
import binascii You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
plugin_name = 'encrypt' plugin_name = 'encrypt'

View File

@ -1,13 +1,64 @@
"""Onionr - Private P2P Communication.
Handle commands for the torgossip server
"""
from onionrblocks import generators
from onionrblocks.generators import anonvdf
import blockio import blockio
import onionrblocks
from kasten import Kasten
"""
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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
def put_block(safe_db, block):
block_hash = block[:64]
data = block[64:]
try:
blockio.store_block(
Kasten(block_hash, data, onionrblocks.generators.AnonVDFGenerator),
safe_db)
except ValueError:
print("Block was seen before")
pass
except Exception as e:
print("Unknown error" + repr(e))
return b"0"
return b"1"
def get_block(safe_db, block_hash) -> bytes:
# 4
try:
return safe_db.get(block_hash)
except KeyError:
return b"0"
def list_blocks_by_type(safe_db, block_type) -> bytes: def list_blocks_by_type(safe_db, block_type) -> bytes:
# 3
block_type = block_type.decode('utf-8')
print('ty', block_type)
try: try:
return safe_db.get(b'bl-' + block_type) return safe_db.get('bl-' + block_type)
except KeyError: except KeyError:
return b"" return b"0"
def handle_check_block(safe_db, block_hash): def handle_check_block(safe_db, block_hash):
# 2
if block_hash in blockio.list_all_blocks(safe_db): if block_hash in blockio.list_all_blocks(safe_db):
return int(1).to_bytes(1, 'little') return int(1).to_bytes(1, 'little')
else: else:

View File

@ -24,4 +24,6 @@ class GossipCommands(IntEnum):
PING = 1, PING = 1,
CHECK_HAS_BLOCK = 2, CHECK_HAS_BLOCK = 2,
LIST_BLOCKS_BY_TYPE = 3, LIST_BLOCKS_BY_TYPE = 3,
EXIT = 4 GET_BLOCK = 4,
PUT_BLOCK = 5,
EXIT = 6

View File

@ -25,9 +25,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
""" """
plugin_name = 'torgossip' plugin_name = 'torgossip'
from server import start_server from server import start_server
from runtest import torgossip_runtest
def on_init(api, data=None): def on_init(api, data=None):
shared_state = data shared_state = data
print("starting gossip transport")
shared_state.get_by_string(
"OnionrRunTestManager").plugin_tests.append(torgossip_runtest)
Thread(target=start_server, daemon=True, args=[shared_state]).start() Thread(target=start_server, daemon=True, args=[shared_state]).start()

View File

@ -0,0 +1,51 @@
import socket
import os
from threading import local
from utils import identifyhome
from onionrblocks import blockcreator
from blockio import subprocgenerate
from onionrutils import localcommand
import blockio
def torgossip_runtest(test_manager):
s_file = identifyhome.identify_home() + "/torgossip.sock"
bl_test = blockcreator.create_anonvdf_block(b"test", "txt", 10)
#test_manager._too_many.get_by_string("PassToSafeDB").queue_then_store(b"test", "txt", 10)
bl = subprocgenerate.vdf_block(b"test", "txt", 100)
blockio.store_block(bl, test_manager._too_many.get_by_string("SafeDB"))
bl_new = blockcreator.create_anonvdf_block(b"test5", "txt", 10)
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s:
s.connect(s_file)
s.sendall(b'1')
resp = s.recv(5)
assert resp == b"PONG"
s.sendall(b'3txx')
assert s.recv(64) == b"0"
s.sendall(b'3txt')
assert bl.id in s.recv(10000)
# test getting a block that doesn't exist
s.sendall(b'4' + os.urandom(64))
assert s.recv(64) == b"0"
# test getting a block that does exist
s.sendall(b'4' + bl.id)
assert s.recv(64) == bl.get_packed()
s.sendall(b'5' + bl_new.id + bl_new.get_packed())
assert s.recv(2) == b"1"
# test block was uploaded by getting it
s.sendall(b'4' + bl_new.id)
assert s.recv(64) == bl_new.get_packed()

View File

@ -60,6 +60,16 @@ def start_server(shared_state):
conn.sendall(b'PONG') conn.sendall(b'PONG')
elif cmd == GossipCommands.EXIT: elif cmd == GossipCommands.EXIT:
do_close(conn, b'BYE') do_close(conn, b'BYE')
elif cmd == GossipCommands.PUT_BLOCK:
conn.sendall(
commandhandlers.put_block(
shared_state.get_by_string('SafeDB'), data
)
)
elif cmd == GossipCommands.GET_BLOCK:
conn.sendall(
commandhandlers.get_block(
shared_state.get_by_string('SafeDB'), data))
elif cmd == GossipCommands.LIST_BLOCKS_BY_TYPE: elif cmd == GossipCommands.LIST_BLOCKS_BY_TYPE:
conn.sendall( conn.sendall(
commandhandlers.list_blocks_by_type( commandhandlers.list_blocks_by_type(

View File

@ -10,7 +10,7 @@ def client(data):
with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s: with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s:
s.connect(f'{home}/torgossip.sock') s.connect(f'{home}/torgossip.sock')
s.sendall(data) s.sendall(data)
resp = s.recv(1024) resp = s.recv(32)
print("\n", resp) print("\n", resp)
while True: while True:

View File

@ -1 +0,0 @@
1611612283

View File

@ -23,8 +23,6 @@ setup_config()
class TestBlockCreatorQueue(unittest.TestCase): class TestBlockCreatorQueue(unittest.TestCase):
def test_in_queue(self):
def test_blockcreator_queue_1(self): def test_blockcreator_queue_1(self):
received_callback = [False] received_callback = [False]