diff --git a/src/bigbrother/ministry/ofcommunication.py b/src/bigbrother/ministry/ofcommunication.py index ed5b36a7..2e62fcb3 100644 --- a/src/bigbrother/ministry/ofcommunication.py +++ b/src/bigbrother/ministry/ofcommunication.py @@ -35,6 +35,9 @@ def detect_socket_leaks(socket_event): try: ip_address = ipaddress.ip_address(ip_address) except ValueError: + if ip_address == "/": + # unix socket + return logger.warn(f'Conn made to {ip_address} outside of Tor/similar') raise \ NetworkLeak('Conn to host/non local IP, this is a privacy issue!') diff --git a/src/blockcreatorqueue/__init__.py b/src/blockcreatorqueue/__init__.py index 67366878..4b007963 100644 --- a/src/blockcreatorqueue/__init__.py +++ b/src/blockcreatorqueue/__init__.py @@ -28,6 +28,19 @@ along with this program. If not, see . 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: def __init__( self, callback_func: Callable, *additional_callback_func_args, @@ -66,4 +79,3 @@ class BlockCreatorQueue: Thread(target=_do_create, daemon=True).start() return digest - diff --git a/src/httpapi/serializedapi/__init__.py b/src/httpapi/serializedapi/__init__.py index 345ccc3c..83c939e9 100644 --- a/src/httpapi/serializedapi/__init__.py +++ b/src/httpapi/serializedapi/__init__.py @@ -62,4 +62,3 @@ def serialized(name: str) -> Response: if isinstance(attr, int): attr = str(attr) return Response(attr, content_type='application/octet-stream') - diff --git a/src/lan/server/__init__.py b/src/lan/server/__init__.py index acbb183c..0c667c15 100644 --- a/src/lan/server/__init__.py +++ b/src/lan/server/__init__.py @@ -52,6 +52,8 @@ class LANServer: @app.before_request def dns_rebinding_prevention(): + if not ipaddress.ip_address(request.remote_addr).is_private: + abort(403) if request.remote_addr in lan_ips or \ ipaddress.ip_address(request.remote_addr).is_loopback: if time.time() - _start_time > 600: diff --git a/src/netcontroller/torcontrol/__init__.py b/src/netcontroller/torcontrol/__init__.py index a5e57495..760a8769 100644 --- a/src/netcontroller/torcontrol/__init__.py +++ b/src/netcontroller/torcontrol/__init__.py @@ -93,6 +93,10 @@ class NetController: if 'bootstrapped 100' in line.decode().lower(): logger.info(line.decode(), terminal=True) 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(): logger.debug(line.decode().replace('\n', '')) else: diff --git a/src/netcontroller/torcontrol/gentorrc.py b/src/netcontroller/torcontrol/gentorrc.py index 6f80e311..d1dc8749 100644 --- a/src/netcontroller/torcontrol/gentorrc.py +++ b/src/netcontroller/torcontrol/gentorrc.py @@ -72,8 +72,6 @@ def generate_torrc(net_controller: 'NetController', DataDirectory """ + home_dir + """tordata/ CookieAuthentication 1 KeepalivePeriod 40 -SafeSocks 1 -TestSocks 1 CircuitsAvailableTimeout 86400 ControlPort """ + str(control_port) + """ HashedControlPassword """ + str(password) + """ diff --git a/src/onionrcommands/daemonlaunch/__init__.py b/src/onionrcommands/daemonlaunch/__init__.py index d86f4d7a..d92d9b3f 100755 --- a/src/onionrcommands/daemonlaunch/__init__.py +++ b/src/onionrcommands/daemonlaunch/__init__.py @@ -44,21 +44,22 @@ from sneakernet import sneakernet_import_thread from onionrstatistics.devreporting import statistics_reporter from setupkvvars import setup_kv from communicatorutils.housekeeping import clean_blocks_not_meeting_pow +from blockcreatorqueue import BlockCreatorQueue, PassToSafeDB from .spawndaemonthreads import spawn_client_threads from .loadsafedb import load_safe_db """ - 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 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. +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 . +You should have received a copy of the GNU General Public License +along with this program. If not, see . """ @@ -181,6 +182,7 @@ def daemon(): shared_state.get(serializeddata.SerializedData) 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 diff --git a/src/runtests/__init__.py b/src/runtests/__init__.py index 77e26e77..cc802f4c 100644 --- a/src/runtests/__init__.py +++ b/src/runtests/__init__.py @@ -53,9 +53,11 @@ class OnionrRunTestManager: def __init__(self): self.success: bool = True self.run_date: int = 0 + self.plugin_tests = [] def run_tests(self): tests = list(RUN_TESTS) + tests.extend(self.plugin_tests) SystemRandom().shuffle(tests) cur_time = epoch.get_epoch() logger.info(f"Doing runtime tests at {cur_time}") diff --git a/static-data/base64-code-whitelist.txt b/static-data/base64-code-whitelist.txt index 2fc433b2..30c0cf63 100644 --- a/static-data/base64-code-whitelist.txt +++ b/static-data/base64-code-whitelist.txt @@ -44,3 +44,26 @@ ZABkAWwAbQFaAQEAZABkAmwCbQNaAwEAZQFkA2QEZAVnAoMCWgRlA2QGZQWDAloGZQNkB2UHgwJaCGUD ZABkAYQAWgBkAlMA ZABkAWwAWgBkAGQBbAFaAWQCZAOEAFoCZARkBYQAWgNkAVMA ZABkAWwAWgBlAWQCnAFkA2QEhARaAmQFZAaEAFoDZAFTAA== +ZABkAWQCZANnBFoAZARkBWwBWgFkBGQFbAJaAmQEZAVsA1oDZARkBWwEWgRkBGQFbAVaBWQEZAVsBloGZARkBWwHWgdkBGQFbAhaCGQEZAVsCVoJZAZkB2wKbQtaCwEAZAZkCGwKb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0FWgUBAGQAZARsBm0HWgcBAGQAZAVsCG0JWgkBAGQAZAZsCm0LWgsBAGQHZAiEAFoMZAFTAA== +ZABkAWwAWgBkAGQBbAFaAWQAZAJsAm0DWgMBAGQAZANsBG0FWgUBAGQAZARsBm0HWgcBAGQAZAVsCG0JWgkBAGQAZAZsCm0LWgsBAGQAZAFsCFoIZAdkCIQAWgxkAVMA +ZABaAGQBZAJsAW0CWgIBAGQBZANsA20EWgQBAGQBZARsBVoFZAFkBGwBWgFkAWQFbAZtB1oHAQBkBmQHhABaCGUJZAicAWQJZAqEBFoKZQlkCJwBZAtkDIQEWgtkDWQOhABaDGQEUwA= diff --git a/static-data/connect-check.txt b/static-data/connect-check.txt index c776e53e..11495102 100755 --- a/static-data/connect-check.txt +++ b/static-data/connect-check.txt @@ -1 +1 @@ -https://3g2upl4pq6kufc4m.onion/robots.txt,http://expyuzz4wqqyqhjn.onion/robots.txt,http://archivecaslytosk.onion/robots.txt,http://cockmailwwfvrtqj.onion/robots.txt \ No newline at end of file +https://3g2upl4pq6kufc4m.onion/robots.txt,http://expyuzz4wqqyqhjn.onion/robots.txt \ No newline at end of file diff --git a/static-data/default-plugins/encrypt/main.py b/static-data/default-plugins/encrypt/main.py index feed4b03..f3284aa2 100755 --- a/static-data/default-plugins/encrypt/main.py +++ b/static-data/default-plugins/encrypt/main.py @@ -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 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 . -''' +This default plugin allows users to encrypt/decrypt messages without using blocks +""" +import locale +locale.setlocale(locale.LC_ALL, '') +import binascii # Imports some useful libraries import logger, config, threading, time, datetime, sys @@ -27,11 +15,20 @@ from nacl.exceptions import TypeError as NaclTypeError from onionrutils import stringvalidators, bytesconverter from onionrcrypto import encryption, keypair, signing, getourkeypair 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 -locale.setlocale(locale.LC_ALL, '') +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. -import binascii +You should have received a copy of the GNU General Public License +along with this program. If not, see . +""" plugin_name = 'encrypt' diff --git a/static-data/default-plugins/torgossip/commandhandlers.py b/static-data/default-plugins/torgossip/commandhandlers.py index 0f9cd2ec..5691b8f3 100644 --- a/static-data/default-plugins/torgossip/commandhandlers.py +++ b/static-data/default-plugins/torgossip/commandhandlers.py @@ -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 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 . +""" +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: + # 3 + block_type = block_type.decode('utf-8') + print('ty', block_type) try: - return safe_db.get(b'bl-' + block_type) + return safe_db.get('bl-' + block_type) except KeyError: - return b"" + return b"0" + def handle_check_block(safe_db, block_hash): + # 2 if block_hash in blockio.list_all_blocks(safe_db): return int(1).to_bytes(1, 'little') else: diff --git a/static-data/default-plugins/torgossip/commands.py b/static-data/default-plugins/torgossip/commands.py index e38f1311..67d1c5f0 100644 --- a/static-data/default-plugins/torgossip/commands.py +++ b/static-data/default-plugins/torgossip/commands.py @@ -24,4 +24,6 @@ class GossipCommands(IntEnum): PING = 1, CHECK_HAS_BLOCK = 2, LIST_BLOCKS_BY_TYPE = 3, - EXIT = 4 + GET_BLOCK = 4, + PUT_BLOCK = 5, + EXIT = 6 diff --git a/static-data/default-plugins/torgossip/main.py b/static-data/default-plugins/torgossip/main.py index 800085c4..dd982de5 100755 --- a/static-data/default-plugins/torgossip/main.py +++ b/static-data/default-plugins/torgossip/main.py @@ -25,9 +25,13 @@ along with this program. If not, see . """ plugin_name = 'torgossip' from server import start_server +from runtest import torgossip_runtest def on_init(api, data=None): 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() diff --git a/static-data/default-plugins/torgossip/runtest.py b/static-data/default-plugins/torgossip/runtest.py new file mode 100644 index 00000000..fed21b42 --- /dev/null +++ b/static-data/default-plugins/torgossip/runtest.py @@ -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() + + diff --git a/static-data/default-plugins/torgossip/server.py b/static-data/default-plugins/torgossip/server.py index d96380e1..00c0bbfa 100644 --- a/static-data/default-plugins/torgossip/server.py +++ b/static-data/default-plugins/torgossip/server.py @@ -60,6 +60,16 @@ def start_server(shared_state): conn.sendall(b'PONG') elif cmd == GossipCommands.EXIT: 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: conn.sendall( commandhandlers.list_blocks_by_type( diff --git a/static-data/default-plugins/torgossip/server_test.py b/static-data/default-plugins/torgossip/server_test.py index 200c2ee1..18af4c87 100644 --- a/static-data/default-plugins/torgossip/server_test.py +++ b/static-data/default-plugins/torgossip/server_test.py @@ -10,7 +10,7 @@ def client(data): with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as s: s.connect(f'{home}/torgossip.sock') s.sendall(data) - resp = s.recv(1024) + resp = s.recv(32) print("\n", resp) while True: diff --git a/tests/runtime-result.txt b/tests/runtime-result.txt deleted file mode 100644 index ceb63a9e..00000000 --- a/tests/runtime-result.txt +++ /dev/null @@ -1 +0,0 @@ -1611612283 \ No newline at end of file diff --git a/tests/test_blockcreatorqueue.py b/tests/test_blockcreatorqueue.py index 9fb5cb08..6c160f22 100644 --- a/tests/test_blockcreatorqueue.py +++ b/tests/test_blockcreatorqueue.py @@ -23,8 +23,6 @@ setup_config() class TestBlockCreatorQueue(unittest.TestCase): - def test_in_queue(self): - def test_blockcreator_queue_1(self): received_callback = [False]