From e3517101894426741ad209c629b07debf7ce3998 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Fri, 19 Jul 2019 19:41:15 -0500 Subject: [PATCH] progress in removing core --- onionr/filepaths/__init__.py | 1 + .../static-data/default-plugins/cliui/main.py | 3 +- .../default-plugins/encrypt/main.py | 23 ++++++++------ .../default-plugins/esoteric/controlapi.py | 31 +++++++++---------- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/onionr/filepaths/__init__.py b/onionr/filepaths/__init__.py index 889da5e1..a75d1fb1 100644 --- a/onionr/filepaths/__init__.py +++ b/onionr/filepaths/__init__.py @@ -9,6 +9,7 @@ private_API_host_file = home + 'private-host.txt' bootstrap_file_location = 'static-data/bootstrap-nodes.txt' data_nonce_file = home + 'block-nonces.dat' forward_keys_file = home + 'forward-keys.db' +cached_storage = home + 'cachedstorage.dat' tor_hs_address_file = home + 'hs/hostname' diff --git a/onionr/static-data/default-plugins/cliui/main.py b/onionr/static-data/default-plugins/cliui/main.py index c65917c8..50f3fe3a 100755 --- a/onionr/static-data/default-plugins/cliui/main.py +++ b/onionr/static-data/default-plugins/cliui/main.py @@ -31,7 +31,6 @@ PLUGIN_VERSION = '0.0.1' class OnionrCLIUI: def __init__(self, apiInst): self.api = apiInst - self.myCore = apiInst.get_core() self.shutdown = False self.running = 'undetermined' enabled = onionrplugins.get_enabled_plugins() @@ -49,7 +48,7 @@ class OnionrCLIUI: def isRunning(self): while not self.shutdown: - if localcommand.local_command(self.myCore, 'ping', maxWait=5) == 'pong!': + if localcommand.local_command('ping', maxWait=5) == 'pong!': self.running = 'Yes' else: self.running = 'No' diff --git a/onionr/static-data/default-plugins/encrypt/main.py b/onionr/static-data/default-plugins/encrypt/main.py index 5e5590ad..1effa61d 100755 --- a/onionr/static-data/default-plugins/encrypt/main.py +++ b/onionr/static-data/default-plugins/encrypt/main.py @@ -21,8 +21,9 @@ # Imports some useful libraries import logger, config, threading, time, datetime, sys, json from onionrblockapi import Block -from onionrutils import stringvalidators -import onionrexceptions, onionrusers +from onionrutils import stringvalidators, bytesconverter +from onionrcrypto import encryption, getourkeypair +import onionrexceptions, onionrusers, signing import locale locale.setlocale(locale.LC_ALL, '') plugin_name = 'encrypt' @@ -63,22 +64,24 @@ class PlainEncryption: sys.exit(1) # Build Message to encrypt data = {} - myPub = self.api.get_core()._crypto.pubKey + keypair = getourkeypair.get_our_keypair() + myPub = keypair[0] if sign: - data['sig'] = self.api.get_core()._crypto.edSign(plaintext, key=self.api.get_core()._crypto.privKey, encodeResult=True) - data['sig'] = self.api.get_core()._utils.bytesToStr(data['sig']) + data['sig'] = signing.ed_sign(plaintext, key=keypair[1], encodeResult=True) + data['sig'] = bytesconverter.bytes_to_str(data['sig']) data['signer'] = myPub data['data'] = plaintext data = json.dumps(data) plaintext = data - encrypted = self.api.get_core()._crypto.pubKeyEncrypt(plaintext, pubkey, encodedData=True) - encrypted = self.api.get_core()._utils.bytesToStr(encrypted) + encrypted = encryption.pub_key_encrypt(plaintext, pubkey, encodedData=True) + encrypted = bytesconverter.bytes_to_str(encrypted) logger.info('Encrypted Message: \n\nONIONR ENCRYPTED DATA %s END ENCRYPTED DATA' % (encrypted,), terminal=True) def decrypt(self): plaintext = "" data = "" logger.info("Please enter your message (ctrl-d or -q to stop):", terminal=True) + keypair = getourkeypair.get_our_keypair() try: for line in sys.stdin: if line == '-q\n': @@ -89,8 +92,8 @@ class PlainEncryption: if len(data) <= 1: return encrypted = data.replace('ONIONR ENCRYPTED DATA ', '').replace('END ENCRYPTED DATA', '') - myPub = self.api.get_core()._crypto.pubKey - decrypted = self.api.get_core()._crypto.pubKeyDecrypt(encrypted, privkey=self.api.get_core()._crypto.privKey, encodedData=True) + myPub = keypair[0] + decrypted = encryption.pub_key_decrypt(encrypted, privkey=keypair[1], encodedData=True) if decrypted == False: logger.error("Decryption failed", terminal=True) else: @@ -98,7 +101,7 @@ class PlainEncryption: logger.info('Decrypted Message: \n\n%s' % data['data'], terminal=True) try: logger.info("Signing public key: %s" % (data['signer'],), terminal=True) - assert self.api.get_core()._crypto.edVerify(data['data'], data['signer'], data['sig']) != False + assert signing.ed_verify(data['data'], data['signer'], data['sig']) != False except (AssertionError, KeyError) as e: logger.warn("WARNING: THIS MESSAGE HAS A MISSING OR INVALID SIGNATURE", terminal=True) else: diff --git a/onionr/static-data/default-plugins/esoteric/controlapi.py b/onionr/static-data/default-plugins/esoteric/controlapi.py index 7c298063..0ca8bbe9 100755 --- a/onionr/static-data/default-plugins/esoteric/controlapi.py +++ b/onionr/static-data/default-plugins/esoteric/controlapi.py @@ -19,11 +19,10 @@ ''' import json from flask import Response, request, redirect, Blueprint, send_from_directory -import core - -core_inst = core.Core() +import deadsimplekv as simplekv +import filepaths flask_blueprint = Blueprint('esoteric_control', __name__) - +key_store = simplekv.DeadSimpleKV(filepaths.cachedstorage, refresh_seconds=5) @flask_blueprint.route('/esoteric/ping') def ping(): return 'pong!' @@ -31,18 +30,18 @@ def ping(): @flask_blueprint.route('/esoteric/send/', methods=['POST']) def send_message(peer): data = request.get_json(force=True) - core_inst.keyStore.refresh() - existing = core_inst.keyStore.get('s' + peer) + key_store.refresh() + existing = key_store.get('s' + peer) if existing is None: existing = [] existing.append(data) - core_inst.keyStore.put('s' + peer, existing) - core_inst.keyStore.flush() + key_store.put('s' + peer, existing) + key_store.flush() return Response('success') @flask_blueprint.route('/esoteric/gets/') def get_sent(peer): - sent = core_inst.keyStore.get('s' + peer) + sent = key_store.get('s' + peer) if sent is None: sent = [] return Response(json.dumps(sent)) @@ -50,22 +49,22 @@ def get_sent(peer): @flask_blueprint.route('/esoteric/addrec/', methods=['POST']) def add_rec(peer): data = request.get_json(force=True) - core_inst.keyStore.refresh() - existing = core_inst.keyStore.get('r' + peer) + key_store.refresh() + existing = key_store.get('r' + peer) if existing is None: existing = [] existing.append(data) - core_inst.keyStore.put('r' + peer, existing) - core_inst.keyStore.flush() + key_store.put('r' + peer, existing) + key_store.flush() return Response('success') @flask_blueprint.route('/esoteric/getrec/') def get_messages(peer): - core_inst.keyStore.refresh() - existing = core_inst.keyStore.get('r' + peer) + key_store.refresh() + existing = key_store.get('r' + peer) if existing is None: existing = [] else: existing = list(existing) - core_inst.keyStore.delete('r' + peer) + key_store.delete('r' + peer) return Response(json.dumps(existing)) \ No newline at end of file