progress in removing core

This commit is contained in:
Kevin Froman 2019-07-19 19:41:15 -05:00
parent e1676ef168
commit e351710189
4 changed files with 30 additions and 28 deletions

View File

@ -9,6 +9,7 @@ private_API_host_file = home + 'private-host.txt'
bootstrap_file_location = 'static-data/bootstrap-nodes.txt' bootstrap_file_location = 'static-data/bootstrap-nodes.txt'
data_nonce_file = home + 'block-nonces.dat' data_nonce_file = home + 'block-nonces.dat'
forward_keys_file = home + 'forward-keys.db' forward_keys_file = home + 'forward-keys.db'
cached_storage = home + 'cachedstorage.dat'
tor_hs_address_file = home + 'hs/hostname' tor_hs_address_file = home + 'hs/hostname'

View File

@ -31,7 +31,6 @@ PLUGIN_VERSION = '0.0.1'
class OnionrCLIUI: class OnionrCLIUI:
def __init__(self, apiInst): def __init__(self, apiInst):
self.api = apiInst self.api = apiInst
self.myCore = apiInst.get_core()
self.shutdown = False self.shutdown = False
self.running = 'undetermined' self.running = 'undetermined'
enabled = onionrplugins.get_enabled_plugins() enabled = onionrplugins.get_enabled_plugins()
@ -49,7 +48,7 @@ class OnionrCLIUI:
def isRunning(self): def isRunning(self):
while not self.shutdown: 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' self.running = 'Yes'
else: else:
self.running = 'No' self.running = 'No'

View File

@ -21,8 +21,9 @@
# Imports some useful libraries # Imports some useful libraries
import logger, config, threading, time, datetime, sys, json import logger, config, threading, time, datetime, sys, json
from onionrblockapi import Block from onionrblockapi import Block
from onionrutils import stringvalidators from onionrutils import stringvalidators, bytesconverter
import onionrexceptions, onionrusers from onionrcrypto import encryption, getourkeypair
import onionrexceptions, onionrusers, signing
import locale import locale
locale.setlocale(locale.LC_ALL, '') locale.setlocale(locale.LC_ALL, '')
plugin_name = 'encrypt' plugin_name = 'encrypt'
@ -63,22 +64,24 @@ class PlainEncryption:
sys.exit(1) sys.exit(1)
# Build Message to encrypt # Build Message to encrypt
data = {} data = {}
myPub = self.api.get_core()._crypto.pubKey keypair = getourkeypair.get_our_keypair()
myPub = keypair[0]
if sign: if sign:
data['sig'] = self.api.get_core()._crypto.edSign(plaintext, key=self.api.get_core()._crypto.privKey, encodeResult=True) data['sig'] = signing.ed_sign(plaintext, key=keypair[1], encodeResult=True)
data['sig'] = self.api.get_core()._utils.bytesToStr(data['sig']) data['sig'] = bytesconverter.bytes_to_str(data['sig'])
data['signer'] = myPub data['signer'] = myPub
data['data'] = plaintext data['data'] = plaintext
data = json.dumps(data) data = json.dumps(data)
plaintext = data plaintext = data
encrypted = self.api.get_core()._crypto.pubKeyEncrypt(plaintext, pubkey, encodedData=True) encrypted = encryption.pub_key_encrypt(plaintext, pubkey, encodedData=True)
encrypted = self.api.get_core()._utils.bytesToStr(encrypted) encrypted = bytesconverter.bytes_to_str(encrypted)
logger.info('Encrypted Message: \n\nONIONR ENCRYPTED DATA %s END ENCRYPTED DATA' % (encrypted,), terminal=True) logger.info('Encrypted Message: \n\nONIONR ENCRYPTED DATA %s END ENCRYPTED DATA' % (encrypted,), terminal=True)
def decrypt(self): def decrypt(self):
plaintext = "" plaintext = ""
data = "" data = ""
logger.info("Please enter your message (ctrl-d or -q to stop):", terminal=True) logger.info("Please enter your message (ctrl-d or -q to stop):", terminal=True)
keypair = getourkeypair.get_our_keypair()
try: try:
for line in sys.stdin: for line in sys.stdin:
if line == '-q\n': if line == '-q\n':
@ -89,8 +92,8 @@ class PlainEncryption:
if len(data) <= 1: if len(data) <= 1:
return return
encrypted = data.replace('ONIONR ENCRYPTED DATA ', '').replace('END ENCRYPTED DATA', '') encrypted = data.replace('ONIONR ENCRYPTED DATA ', '').replace('END ENCRYPTED DATA', '')
myPub = self.api.get_core()._crypto.pubKey myPub = keypair[0]
decrypted = self.api.get_core()._crypto.pubKeyDecrypt(encrypted, privkey=self.api.get_core()._crypto.privKey, encodedData=True) decrypted = encryption.pub_key_decrypt(encrypted, privkey=keypair[1], encodedData=True)
if decrypted == False: if decrypted == False:
logger.error("Decryption failed", terminal=True) logger.error("Decryption failed", terminal=True)
else: else:
@ -98,7 +101,7 @@ class PlainEncryption:
logger.info('Decrypted Message: \n\n%s' % data['data'], terminal=True) logger.info('Decrypted Message: \n\n%s' % data['data'], terminal=True)
try: try:
logger.info("Signing public key: %s" % (data['signer'],), terminal=True) 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: except (AssertionError, KeyError) as e:
logger.warn("WARNING: THIS MESSAGE HAS A MISSING OR INVALID SIGNATURE", terminal=True) logger.warn("WARNING: THIS MESSAGE HAS A MISSING OR INVALID SIGNATURE", terminal=True)
else: else:

View File

@ -19,11 +19,10 @@
''' '''
import json import json
from flask import Response, request, redirect, Blueprint, send_from_directory from flask import Response, request, redirect, Blueprint, send_from_directory
import core import deadsimplekv as simplekv
import filepaths
core_inst = core.Core()
flask_blueprint = Blueprint('esoteric_control', __name__) flask_blueprint = Blueprint('esoteric_control', __name__)
key_store = simplekv.DeadSimpleKV(filepaths.cachedstorage, refresh_seconds=5)
@flask_blueprint.route('/esoteric/ping') @flask_blueprint.route('/esoteric/ping')
def ping(): def ping():
return 'pong!' return 'pong!'
@ -31,18 +30,18 @@ def ping():
@flask_blueprint.route('/esoteric/send/<peer>', methods=['POST']) @flask_blueprint.route('/esoteric/send/<peer>', methods=['POST'])
def send_message(peer): def send_message(peer):
data = request.get_json(force=True) data = request.get_json(force=True)
core_inst.keyStore.refresh() key_store.refresh()
existing = core_inst.keyStore.get('s' + peer) existing = key_store.get('s' + peer)
if existing is None: if existing is None:
existing = [] existing = []
existing.append(data) existing.append(data)
core_inst.keyStore.put('s' + peer, existing) key_store.put('s' + peer, existing)
core_inst.keyStore.flush() key_store.flush()
return Response('success') return Response('success')
@flask_blueprint.route('/esoteric/gets/<peer>') @flask_blueprint.route('/esoteric/gets/<peer>')
def get_sent(peer): def get_sent(peer):
sent = core_inst.keyStore.get('s' + peer) sent = key_store.get('s' + peer)
if sent is None: if sent is None:
sent = [] sent = []
return Response(json.dumps(sent)) return Response(json.dumps(sent))
@ -50,22 +49,22 @@ def get_sent(peer):
@flask_blueprint.route('/esoteric/addrec/<peer>', methods=['POST']) @flask_blueprint.route('/esoteric/addrec/<peer>', methods=['POST'])
def add_rec(peer): def add_rec(peer):
data = request.get_json(force=True) data = request.get_json(force=True)
core_inst.keyStore.refresh() key_store.refresh()
existing = core_inst.keyStore.get('r' + peer) existing = key_store.get('r' + peer)
if existing is None: if existing is None:
existing = [] existing = []
existing.append(data) existing.append(data)
core_inst.keyStore.put('r' + peer, existing) key_store.put('r' + peer, existing)
core_inst.keyStore.flush() key_store.flush()
return Response('success') return Response('success')
@flask_blueprint.route('/esoteric/getrec/<peer>') @flask_blueprint.route('/esoteric/getrec/<peer>')
def get_messages(peer): def get_messages(peer):
core_inst.keyStore.refresh() key_store.refresh()
existing = core_inst.keyStore.get('r' + peer) existing = key_store.get('r' + peer)
if existing is None: if existing is None:
existing = [] existing = []
else: else:
existing = list(existing) existing = list(existing)
core_inst.keyStore.delete('r' + peer) key_store.delete('r' + peer)
return Response(json.dumps(existing)) return Response(json.dumps(existing))