updates
parent
97c8ff63a0
commit
3e64dcbeeb
@ -0,0 +1,10 @@
|
||||
from .operators import *
|
||||
from .callers import *
|
||||
from .crypt import *
|
||||
from .ether import *
|
||||
from .keymaker import *
|
||||
from .mazes import *
|
||||
|
||||
from .switchboard import *
|
||||
from .the_operator import *
|
||||
from .the_telephone import *
|
@ -0,0 +1,31 @@
|
||||
import os,sys; sys.path.append(os.path.abspath(os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__),'..')),'..')))
|
||||
from komrade import *
|
||||
from komrade.backend import *
|
||||
|
||||
class Caller(Operator):
|
||||
"""
|
||||
Variant of an Operator which handles local keys and keymaking.
|
||||
"""
|
||||
|
||||
@property
|
||||
def phone(self):
|
||||
"""
|
||||
Operator on the line.
|
||||
"""
|
||||
if not hasattr(self,'_phone'):
|
||||
self._phone = TheTelephone(caller = self)
|
||||
return self._phone
|
||||
|
||||
def get_new_keys(self,pubkey_pass = None, privkey_pass = None, adminkey_pass = None):
|
||||
"""
|
||||
This is the local caller's version.
|
||||
He never touches the encrypted keys. Only the Operator does!
|
||||
"""
|
||||
|
||||
# Get decryptor keys back from The Operator (one half of the Keymaker)
|
||||
keychain = self.forge_new_keys(self.name)
|
||||
self.log('create_keys() res from Operator? <-',keychain)
|
||||
|
||||
# Now lock the decryptor keys away, sealing it with a password of memory!
|
||||
self.lock_new_keys(keychain)
|
||||
|
@ -0,0 +1,83 @@
|
||||
"""
|
||||
There is only one operator!
|
||||
Running on node prime.
|
||||
"""
|
||||
# internal imports
|
||||
import os,sys; sys.path.append(os.path.abspath(os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__),'..')),'..')))
|
||||
from komrade import *
|
||||
from komrade.backend.crypt import *
|
||||
from komrade.backend.operators import *
|
||||
from komrade.backend.mazes import *
|
||||
|
||||
|
||||
|
||||
class TheOperator(Operator):
|
||||
"""
|
||||
The remote operator! Only one!
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, name = OPERATOR_NAME, passphrase='acc'):
|
||||
"""
|
||||
Boot up the operator. Requires knowing or setting a password of memory.
|
||||
"""
|
||||
# init req paths
|
||||
if not os.path.exists(PATH_OPERATOR): os.makedirs(PATH_OPERATOR)
|
||||
if not passphrase:
|
||||
passphrase=getpass.getpass('Hello, this is the Operator speaking. What is the passphrase?\n> ')
|
||||
super().__init__(name,passphrase)
|
||||
|
||||
def route(self, data):
|
||||
# step 1 split:
|
||||
data_unencr,data_encr = data.split(BSEP)
|
||||
if data_encr and 'name' in data_unencr:
|
||||
name=data_unencr['name']
|
||||
keychain=data_unencr.get('keychain',{})
|
||||
|
||||
# decrypt using this user's pubkey on record
|
||||
caller = Operator(name)
|
||||
from_pubkey = user.pubkey(keychain=keychain)
|
||||
data_unencr2 = SMessage(OPERATOR.privkey_, from_pubkey).unwrap(data_encr)
|
||||
|
||||
if type(data_unencr)==dict and type(data_unencr2)==dict:
|
||||
data = data_unencr
|
||||
dict_merge(data_unencr2, data)
|
||||
else:
|
||||
data=(data_unencr,data_unencr2)
|
||||
else:
|
||||
data = data_unencr
|
||||
|
||||
print(data)
|
||||
|
||||
|
||||
def init_operators():
|
||||
op = Operator(name=OPERATOR_NAME)
|
||||
phone = Operator(name=TELEPHONE_NAME)
|
||||
|
||||
op.get_new_keys()
|
||||
phone.get_new_keys()
|
||||
|
||||
op_pub = op.pubkey_
|
||||
phone_pub = phone.pubkey_
|
||||
phone_priv = phone.privkey_
|
||||
|
||||
print('OPERATOR_PUBKEY =',b64encode(op_pub))
|
||||
print('TELEPHONE_PUBKEY =',b64encode(phone_pub))
|
||||
print('TELEPHONE_PRIVKEY =',b64encode(phone_priv))
|
||||
|
||||
|
||||
def test_op():
|
||||
op = TheOperator()
|
||||
#op.boot()
|
||||
#pubkey = op.keychain()['pubkey']
|
||||
#pubkey_b64 = b64encode(pubkey)
|
||||
#print(pubkey_b64)
|
||||
keychain = op.keychain(force=True)
|
||||
from pprint import pprint
|
||||
pprint(keychain)
|
||||
|
||||
pubkey = op.keychain()['pubkey']
|
||||
pubkey_b64 = b64encode(pubkey)
|
||||
print(pubkey)
|
||||
|
||||
if __name__ == '__main__': test_op()
|
@ -0,0 +1,98 @@
|
||||
# internal imports
|
||||
import os,sys; sys.path.append(os.path.abspath(os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__),'..')),'..')))
|
||||
from komrade import *
|
||||
from komrade.backend.crypt import *
|
||||
from komrade.backend.operators import *
|
||||
from komrade.backend.mazes import *
|
||||
|
||||
### ACTUAL PHONE CONNECTIONS
|
||||
class TheTelephone(Logger):
|
||||
"""
|
||||
API client class for Caller to interact with The Operator.
|
||||
"""
|
||||
def __init__(self, caller):
|
||||
self.caller = caller
|
||||
|
||||
@property
|
||||
def op_pubkey(self):
|
||||
return b64decode(OPERATOR_PUBKEY)
|
||||
|
||||
def dial_operator(self,msg):
|
||||
msg=msg.replace('/','_')
|
||||
URL = OPERATOR_API_URL + msg + '/'
|
||||
self.log("DIALING THE OPERATOR:",URL)
|
||||
r=tor_request_in_python(URL)
|
||||
print(r)
|
||||
print(r.text)
|
||||
return r
|
||||
|
||||
@property
|
||||
def sess(self):
|
||||
"""
|
||||
Get connection to Tor
|
||||
"""
|
||||
if not hasattr(self,'_sess'):
|
||||
self._sess = get_tor_proxy_session()
|
||||
return self._sess
|
||||
|
||||
def req(self,json_coming_from_phone={},json_coming_from_caller={}):
|
||||
# Two parts of every request:
|
||||
|
||||
# 1) only overall encryption layer E2EE Telephone -> Operator:
|
||||
|
||||
req_data = []
|
||||
if json_coming_from_phone:
|
||||
json_coming_from_phone_s = json.dumps(json_coming_from_phone)
|
||||
json_coming_from_phone_b = json_coming_from_phone_s.encode()
|
||||
#json_coming_from_phone_b_encr = SMessage(TELEPHONE_PRIVKEY,OPERATOR_PUBKEY).wrap(json_coming_from_phone_b)
|
||||
else:
|
||||
json_coming_from_phone_b=b''
|
||||
|
||||
# 2) (optional) extra E2EE encrypted layer Caller -> Operator
|
||||
if json_coming_from_caller:
|
||||
json_coming_from_caller_s = json.dumps(json_coming_from_caller)
|
||||
json_coming_from_caller_b = json_coming_from_caller_s.encode()
|
||||
op_pubkey
|
||||
json_coming_from_caller_b_encr = SMessage(self.caller.privkey_,self.op_pubkey).wrap(json_coming_from_caller_b)
|
||||
else:
|
||||
json_coming_from_caller_b_encr = b''
|
||||
|
||||
# encrypt whole package E2EE, Telephone to Operator
|
||||
req_data = json_coming_from_phone_b + BSEP + json_coming_from_caller_b_encr
|
||||
req_data_encr = SMessage(
|
||||
b64decode(TELEPHONE_PRIVKEY),
|
||||
b64decode(OPERATOR_PUBKEY)
|
||||
).wrap(req_data)
|
||||
req_data_encr_b64 = b64encode(req_data_encr)
|
||||
self.log('req_data_encr_b64 <--',req_data_encr_b64)
|
||||
|
||||
# send!
|
||||
req_data_encr_b64_str = req_data_encr_b64.decode('utf-8')
|
||||
|
||||
# escape slashes
|
||||
req_data_encr_b64_str_esc = req_data_encr_b64_str.replace('/','_')
|
||||
|
||||
res = self.dial_operator(req_data_encr_b64_str)
|
||||
self.log('result from operator?',res)
|
||||
return res
|
||||
|
||||
|
||||
def forge_new_keys(self, name, pubkey_is_public=False):
|
||||
req_json = {'name':name, 'pubkey_is_public':pubkey_is_public}
|
||||
req_json_s = jsonify(req_json)
|
||||
req_json_s_encr = SMessage()
|
||||
return self.sess.post(json=req_json)
|
||||
|
||||
|
||||
|
||||
|
||||
def test_call():
|
||||
caller = Operator('marx3') #Caller('marx')
|
||||
# caller.boot(create=True)
|
||||
# print(caller.keychain())
|
||||
phone = TheTelephone(caller=caller)
|
||||
res = phone.req({'name':'marx', 'pubkey_is_public':True})
|
||||
print(res)
|
||||
|
||||
## main
|
||||
if __name__=='__main__': test_call()
|
Loading…
Reference in New Issue