work on torgossip, added base64 code whitelist because of a werid plugin issue with bigbrother

This commit is contained in:
Kevin Froman 2021-01-27 05:34:31 +00:00
parent a55055e720
commit 828c78a569
16 changed files with 235 additions and 17 deletions

View File

@ -154,10 +154,12 @@ Donating at least $3 gets you cool Onionr stickers. Get in touch if you want the
* Monero: 4B5BA24d1P3R5aWEpkGY5TP7buJJcn2aSGBVRQCHhpiahxeB4aWsu15XwmuTjC6VF62NApZeJGTS248RMVECP8aW73Uj2ax * Monero: 4B5BA24d1P3R5aWEpkGY5TP7buJJcn2aSGBVRQCHhpiahxeB4aWsu15XwmuTjC6VF62NApZeJGTS248RMVECP8aW73Uj2ax
* USD (Card/Paypal): [Ko-Fi](https://www.ko-fi.com/beardogkf) * USD (Card/Paypal (no account required)): [Ko-Fi](https://www.ko-fi.com/beardogkf)
* [Indiegogo](https://igg.me/at/onionr/x#/) * [Indiegogo](https://igg.me/at/onionr/x#/)
* Sign up for [privacy.com (refferal link)](https://privacy.com/join/FNNDF) to protect your personal information when contributing or shopping elsewhere, we both get $5 USD.
Note: probably not tax deductible Note: probably not tax deductible
# Security # Security

View File

@ -3,11 +3,12 @@
Prevent eval/exec/os.system and log it Prevent eval/exec/os.system and log it
""" """
import base64 import base64
import platform from os import read
import logger import logger
from utils import identifyhome from utils import identifyhome
from onionrexceptions import ArbitraryCodeExec from onionrexceptions import ArbitraryCodeExec
from utils import readstatic
""" """
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
@ -56,14 +57,30 @@ def block_exec(event, info):
'stem/response/mapaddress.py', 'stem/response/mapaddress.py',
'stem/response/protocolinfo.py', 'stem/response/protocolinfo.py',
'apport/__init__.py', 'apport/__init__.py',
'apport/report.py' 'apport/report.py',
'gevent/pool.py',
'gevent/queue.py',
'gevent/lock.py',
'gevent/monkey.py',
'gevent/_semaphore.py',
'gevent/_imap.py'
] ]
try:
whitelisted_source = readstatic.read_static(
'base64-code-whitelist.txt')
whitelisted_source = whitelisted_source.splitlines()
except FileNotFoundError:
logger.warn("Failed to read whitelisted code for bigbrother")
whitelisted_source = [] whitelisted_source = []
home = identifyhome.identify_home()
code_b64 = base64.b64encode(info[0].co_code).decode() code_b64 = base64.b64encode(info[0].co_code).decode()
if code_b64 in whitelisted_source: if code_b64 in whitelisted_source:
return return
# uncomment when you want to build on the whitelist
else:
with open("../static-data/base64-code-whitelist.txt", "a") as f:
f.write(code_b64 + "\n")
return
for source in whitelisted_code: for source in whitelisted_code:
if info[0].co_filename.endswith(source): if info[0].co_filename.endswith(source):

View File

@ -3,7 +3,7 @@
Wrap safedb for storing and fetching blocks Wrap safedb for storing and fetching blocks
""" """
from .store import store_block from .store import store_block
from .load import load_block, list_blocks_by_type from .load import load_block, list_blocks_by_type, list_all_blocks
from .clean import clean_expired_blocks, clean_block_list_entries from .clean import clean_expired_blocks, clean_block_list_entries
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify

View File

@ -32,5 +32,23 @@ def load_block(block: 'BlockChecksumBytes', safe_db: 'SafeDB') -> Kasten:
def list_blocks_by_type( def list_blocks_by_type(
block_type: str, safe_db: 'SafeDB') -> List['BlockChecksumBytes']: block_type: str, safe_db: 'SafeDB') -> List['BlockChecksumBytes']:
try:
block_type = block_type.decode('utf-8')
except AttributeError:
pass
blocks = safe_db.get(f'bl-{block_type}') blocks = safe_db.get(f'bl-{block_type}')
return zip(*[iter(blocks)]*64) return zip(*[iter(blocks)]*64)
def list_all_blocks(safe_db: 'SafeDB'):
# Builds and return a master list of blocks by identifying all type lists
# and iterating them
key = safe_db.db_conn.firstkey()
master_list = []
while key:
if key.startswith(b'bl-'):
master_list.extend(
list(list_blocks_by_type(key.replace(b'bl-', b''), safe_db)))
key = safe_db.db_conn.nextkey(key)
return master_list

View File

@ -20,6 +20,8 @@ config_file = home + 'config.json'
daemon_mark_file = home + '/daemon-true.txt' daemon_mark_file = home + '/daemon-true.txt'
lock_file = home + 'onionr.lock' lock_file = home + 'onionr.lock'
main_safedb = home + "main.safe.db"
site_cache = home + 'onionr-sites.txt' site_cache = home + 'onionr-sites.txt'
tor_hs_loc = home + 'hs/' tor_hs_loc = home + 'hs/'

View File

@ -45,6 +45,7 @@ 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 .spawndaemonthreads import spawn_client_threads from .spawndaemonthreads import spawn_client_threads
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
@ -179,6 +180,8 @@ def daemon():
# Create singleton # Create singleton
shared_state.get(serializeddata.SerializedData) shared_state.get(serializeddata.SerializedData)
shared_state.add(load_safe_db(config))
shared_state.share_object() # share the parent object to the threads shared_state.share_object() # share the parent object to the threads
show_logo() show_logo()
@ -205,7 +208,7 @@ def daemon():
_show_info_messages() _show_info_messages()
logger.info( logger.info(
"Onionr daemon is running under " + str(os.getpid()), terminal=True) "Onionr daemon is running under " + str(os.getpid()), terminal=True)
events.event('init', threaded=False) events.event('init', threaded=False, data=shared_state)
events.event('daemon_start') events.event('daemon_start')
if config.get('transports.lan', True): if config.get('transports.lan', True):
if not onionrvalues.IS_QUBES: if not onionrvalues.IS_QUBES:

View File

@ -0,0 +1,7 @@
import safedb
import filepaths
def load_safe_db(config) -> safedb.SafeDB:
return safedb.SafeDB(
filepaths.main_safedb, config.get('security.encrypt_database', False))

View File

@ -0,0 +1,46 @@
RwBkAGQBhABkAWUAgwNaAUcAZAJkA4QAZANlAYMDWgJHAGQEZAWEAGQFZQGDA1oDRwBkBmQHhABkB2UBgwNaBEcAZAhkCYQAZAllAYMDWgVkClMA
RwBkAGQBhABkAWUAgwNaAUcAZAJkA4QAZANlAYMDWgJHAGQEZAWEAGQFZQGDA1oDRwBkBmQHhABk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VTAA==
ZABkAWwAbQFaAQEAZABkAmwCbQNaAwEAZABkA2wEbQVaBW0GWgYBAGQAZARsB20IWggBAGQAZAVsCW0KWgptC1oLAQBkAGQGbAxtDVoNAQBkAGQHbA5tD1oPbRBaEAEAZABkCGwRbRJaEm0TWhMBAGQAZAlsFG0VWhUBAEcAZApkC4QAZAtlCmoWgwNaF2QMUwA=
ZABkAWwAbQFaAQEAZABkAmwCbQNaAwEAZANTAA==
ZABkAWwAbQFaAQEAZABkAmwCbQNaAwEAZAZkBGQFhAFaBGQDUwA=
ZABkAWwAbQFaAQEAZABkAmwCbQNaAwEAZQFkA2QEZAVnAoMCWgRlA2QGZQWDAloGZQNkB2UHgwJaCGUDZAhlBYMCWgllA2QJZQqDAloLZQNkCmUKgwJaDGQLUwA=
ZABkAYQAWgBkAlMA
ZABkAWwAWgBkAGQBbAFaAWQCZAOEAFoCZARkBYQAWgNkAVMA
ZABkAWwAWgBlAWQCnAFkA2QEhARaAmQFZAaEAFoDZAFTAA==

View File

@ -0,0 +1,14 @@
import blockio
def list_blocks_by_type(safe_db, block_type) -> bytes:
try:
return safe_db.get(b'bl-' + block_type)
except KeyError:
return b""
def handle_check_block(safe_db, block_hash):
if block_hash in blockio.list_all_blocks(safe_db):
return int(1).to_bytes(1, 'little')
else:
return int(2).to_bytes(1, 'little')

View File

@ -0,0 +1,27 @@
"""
Onionr - Private P2P Communication
Gossip plugin commands
"""
from enum import IntEnum
"""
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/>.
"""
class GossipCommands(IntEnum):
PING = 1,
CHECK_HAS_BLOCK = 2,
LIST_BLOCKS_BY_TYPE = 3,
EXIT = 4

View File

@ -0,0 +1,5 @@
{
"name" : "torgossip",
"version" : "0.0.0",
"author" : "onionr"
}

View File

@ -26,8 +26,8 @@ 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
def on_init(api, data=None): def on_init(api, data=None):
shared_state = data
print("starting gossip transport") print("starting gossip transport")
Thread(target=start_server, daemon=True).start() Thread(target=start_server, daemon=True, args=[shared_state]).start()

View File

@ -4,11 +4,17 @@ Onionr - Private P2P Communication
Gossip plugin server, multiplexing using gevent Gossip plugin server, multiplexing using gevent
""" """
import os import os
import sys
import selectors import selectors
import socket import socket
from time import sleep
import filepaths import filepaths
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
from commands import GossipCommands # noqa
import commandhandlers
""" """
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
@ -25,26 +31,48 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
""" """
def start_server(): def start_server(shared_state):
sel = selectors.DefaultSelector() sel = selectors.DefaultSelector()
def accept(sock, mask): def accept(sock, mask):
conn, addr = sock.accept() # Should be ready conn, addr = sock.accept() # Should be ready
print('accepted', conn, 'from', addr)
conn.setblocking(False) conn.setblocking(False)
sel.register(conn, selectors.EVENT_READ, read) sel.register(conn, selectors.EVENT_READ, read)
def read(conn, mask): def do_close(conn, msg=None):
data = conn.recv(1000) # Should be ready if msg:
if data: conn.sendall(msg)
print('echoing', repr(data), 'to', conn) sleep(0.1)
conn.send(data) # Hope it won't block
else:
print('closing', conn)
sel.unregister(conn) sel.unregister(conn)
conn.close() conn.close()
def read(conn, mask):
data = conn.recv(1000) # Should be ready
cmd = None
if data:
try:
cmd = int(int(data[0]).to_bytes(1, 'little'))
data = data[1:]
except IndexError:
do_close(conn, b'MALFORMED COMMAND')
if cmd == GossipCommands.PING:
conn.sendall(b'PONG')
elif cmd == GossipCommands.EXIT:
do_close(conn, b'BYE')
elif cmd == GossipCommands.LIST_BLOCKS_BY_TYPE:
conn.sendall(
commandhandlers.list_blocks_by_type(
shared_state.get_by_string('SafeDB'), data))
elif cmd == GossipCommands.CHECK_HAS_BLOCK:
conn.sendall(
commandhandlers.handle_check_block(
shared_state.get_by_string('SafeDB'), data))
else:
conn.sendall(b'Unknown ' + str(cmd).encode('utf-8'))
else:
do_close(conn)
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
socket_file = filepaths.identifyhome.identify_home() + "torgossip.sock" socket_file = filepaths.identifyhome.identify_home() + "torgossip.sock"
try: try:

View File

@ -0,0 +1,29 @@
#!/usr/bin/env python
import socket
import os
#home = input("Enter Onionr data directory")
home = "/dev/shm/DATA24688"
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)
print("\n", resp)
while True:
print("1. ping")
print('2. check block hash')
print('3 list blocks')
print("4. exit")
inp = input()
if inp == "1":
client(b'1')
elif inp == "3":
client(b"3" + input("type: ").encode('utf8'))
elif inp == "2":
client(b'2' + os.urandom(32))
elif inp == "3":
client(b'3')

View File

@ -49,6 +49,9 @@
"disabled": [], "disabled": [],
"enabled": [] "enabled": []
}, },
"security": {
"encrypt_database": false
},
"statistics": { "statistics": {
"i_dont_want_privacy": false, "i_dont_want_privacy": false,
"server": "" "server": ""

View File

@ -35,6 +35,24 @@ def _remove_db(path):
class TestBlockIO(unittest.TestCase): class TestBlockIO(unittest.TestCase):
def test_list_all_blocks(self):
db_file = identifyhome.identify_home() + 'test.db'
db = safedb.SafeDB(db_file)
expected_l = []
for i in range(5):
bl = blockcreator.create_anonvdf_block(b"hello" + int(i).to_bytes(1, "big"), b"txt" + int(i).to_bytes(1, "big"), 5)
blockio.store_block(bl, db)
expected_l.append(bl.id)
l = blockio.load.list_all_blocks(db)
self.assertEqual(len(l), 5)
for i in l:
self.assertIn(bytes(i), expected_l)
db.close()
_remove_db(db_file)
def test_clean_blocklist_entries(self): def test_clean_blocklist_entries(self):
db_file = identifyhome.identify_home() + 'test.db' db_file = identifyhome.identify_home() + 'test.db'
db = safedb.SafeDB(db_file) db = safedb.SafeDB(db_file)
@ -91,7 +109,6 @@ class TestBlockIO(unittest.TestCase):
bl = blockcreator.create_anonvdf_block(b'test' + int(i).to_bytes(1, 'big'), 'txt', 60) bl = blockcreator.create_anonvdf_block(b'test' + int(i).to_bytes(1, 'big'), 'txt', 60)
blockio.store_block(bl, db) blockio.store_block(bl, db)
expected_list.append(bl.id) expected_list.append(bl.id)
#db.db_conn.sync()
l = blockio.list_blocks_by_type('txt', db) l = blockio.list_blocks_by_type('txt', db)
self.assertEqual(len(list(l)), len(expected_list)) self.assertEqual(len(list(l)), len(expected_list))
for i in l: for i in l: