def _show_info_messages(): version.version(verbosity=5, function=logger.info) logger.debug('Python version %s' % platform.python_version()) if onionrvalues.DEVELOPMENT_MODE: logger.warn('Development mode enabled', timestamp=False, terminal=True) logger.info('Using public key: %s' % (logger.colors.underline + getourkeypair.get_keypair()[0][:52]))
def __init__(self, publicKey, saveUser=False): """ OnionrUser is an abstraction for "users" of the network. Takes a base32 encoded ed25519 public key, and a bool saveUser saveUser determines if we should add a user to our peer database or not. """ publicKey = unpaddedbase32.repad( bytesconverter.str_to_bytes(publicKey)).decode() self.trust = 0 self.publicKey = publicKey if saveUser and not publicKey == getourkeypair.get_keypair(): try: keydb.addkeys.add_peer(publicKey) except (AssertionError, ValueError) as _: pass self.trust = keydb.userinfo.get_user_info(self.publicKey, 'trust') return
def decrypt(self): plaintext = "" data = "" logger.info("Please enter your message (ctrl-d or -q to stop):", terminal=True) keypair = getourkeypair.get_keypair() try: for line in sys.stdin: if line == '-q\n': break data += line except KeyboardInterrupt: sys.exit(1) if len(data) <= 1: return encrypted = data.replace('ONIONR ENCRYPTED DATA ', '').replace('END ENCRYPTED DATA', '') myPub = keypair[0] decrypted = encryption.pub_key_decrypt(encrypted, privkey=keypair[1], encodedData=True) if decrypted == False: logger.error("Decryption failed", terminal=True) else: data = json.loads(decrypted) logger.info('Decrypted Message: \n\n%s' % data['data'], terminal=True) try: logger.info("Signing public key: %s" % (data['signer'], ), terminal=True) if not signing.ed_verify(data['data'], data['signer'], data['sig']): raise ValueError except (ValueError, KeyError) as e: logger.warn( "WARNING: THIS MESSAGE HAS A MISSING OR INVALID SIGNATURE", terminal=True) else: logger.info("Message has good signature.", terminal=True) return
#!/usr/bin/env python3 import sys, os sys.path.append(".") sys.path.append("src/") import unittest, uuid from time import sleep TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' print("Test directory:", TEST_DIR) os.environ["ONIONR_HOME"] = TEST_DIR from utils import createdirs createdirs.create_dirs() from onionrcrypto import getourkeypair getourkeypair.get_keypair() from utils import networkmerger from coredb import keydb import onionrsetup as setup from onionrthreads import add_onionr_thread setup.setup_config() class OnionrThreadsTests(unittest.TestCase): def test_onionr_thread(self): l = [] def _test_func(obj_list): obj_list.append(1) add_onionr_thread(_test_func, (l, ), 0.05, 0)
def daemon(): ''' Starts the Onionr communication daemon ''' if not hastor.has_tor(): logger.error("Tor is not present in system path or Onionr directory", terminal=True) cleanup.delete_run_files() sys.exit(1) # remove runcheck if it exists if os.path.isfile(filepaths.run_check_file): logger.debug( 'Runcheck file found on daemon start, deleting in advance.') os.remove(filepaths.run_check_file) # Create shared objects shared_state = toomanyobjs.TooMany() Thread(target=shared_state.get(apiservers.ClientAPI).start, daemon=True, name='client HTTP API').start() Thread(target=shared_state.get(apiservers.PublicAPI).start, daemon=True, name='public HTTP API').start() # Init run time tester (ensures Onionr is running right, for testing purposes) shared_state.get(runtests.OnionrRunTestManager) shared_state.get(serializeddata.SerializedData) shared_state.share_object() # share the parent object to the threads apiHost = '' while apiHost == '': try: with open(filepaths.public_API_host_file, 'r') as hostFile: apiHost = hostFile.read() except FileNotFoundError: pass time.sleep(0.5) logger.raw('', terminal=True) # print nice header thing :) if config.get('general.display_header', True): logoheader.header() version.version(verbosity=5, function=logger.info) logger.debug('Python version %s' % platform.python_version()) if onionrvalues.DEVELOPMENT_MODE: logger.warn('Development mode enabled', timestamp=False, terminal=True) net = NetController(config.get('client.public.port', 59497), apiServerIP=apiHost) shared_state.add(net) logger.info('Tor is starting...', terminal=True) if not net.startTor(): localcommand.local_command('shutdown') cleanup.delete_run_files() sys.exit(1) if len(net.myID) > 0 and config.get('general.security_level', 1) == 0: logger.debug('Started .onion service: %s' % (logger.colors.underline + net.myID)) else: logger.debug('.onion service disabled') logger.info( 'Using public key: %s' % (logger.colors.underline + getourkeypair.get_keypair()[0][:52])) try: time.sleep(1) except KeyboardInterrupt: pass events.event('init', threaded=False) events.event('daemon_start') communicator.startCommunicator(shared_state) localcommand.local_command('shutdown') net.killTor() try: time.sleep( 5 ) # Time to allow threads to finish, if not any "daemon" threads will be slaughtered http://docs.python.org/library/threading.html#threading.Thread.daemon except KeyboardInterrupt: pass cleanup.delete_run_files()