operator-time
quadrismegistus 4 years ago
parent 30f684d80a
commit b69e388408

@ -11,4 +11,11 @@ from .the_operator import *
from .switchboard import *
from .the_telephone import *
from .callers import *
from .callers import *
## define default entities
OPERATOR = TheOperator()
TELEPHONE = TheTelephone()

@ -13,12 +13,9 @@ class Caller(Operator):
@property
def phone(self):
"""
Operator on the line.
"""
if not hasattr(self,'_phone'):
self._phone = TheTelephone(caller = self)
return self._phone
return TELEPHONE
@property
def op(self): return OPERATOR
def get_new_keys(self,pubkey_pass = None, privkey_pass = None, adminkey_pass = None):
"""
@ -44,6 +41,6 @@ class Caller(Operator):
'adminkey_decr_encr', 'adminkey_decr_decr']
try:
return await self.phone.req(json_coming_from_phone = req_json)
return await self.phone.req(json_coming_from_phone = req_json, caller=self)
except TypeError:
return None

@ -75,8 +75,8 @@ class TheSwitchboard(FlaskView, Logger):
def run_forever(port='8080'):
global OPERATOR,TELEPHONE
OPERATOR = TheOperator()
TELEPHONE = TheTelephone()
OPERATOR = TheOperator(phone=TELEPHONE)
app = Flask(__name__)
TheSwitchboard.register(app, route_base='/op/', route_prefix=None)
app.run(debug=True, port=port, host='0.0.0.0')

@ -5,9 +5,7 @@ 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 *
from komrade.backend import *
@ -15,6 +13,9 @@ class TheOperator(Operator):
"""
The remote operator
"""
@property
def phone(self):
return TELEPHONE
def __init__(self, name = OPERATOR_NAME, passphrase='acc'):
@ -27,20 +28,31 @@ class TheOperator(Operator):
passphrase=getpass.getpass('Hello, this is the Operator speaking. What is the passphrase?\n> ')
super().__init__(name,passphrase,path_crypt_keys=PATH_CRYPT_OP_KEYS,path_crypt_data=PATH_CRYPT_OP_DATA)
def decrypt_incoming(self,data):
# step 1 split:
data_unencr,data_encr = data.split(BSEP)
self.log('data_unencr =',data_unencr)
self.log('data_encr =',data_encr)
data_encr_by_phone,data_encr_by_caller = data.split(BSEP)
self.log('data_encr_by_phone =',data_encr_by_phone)
self.log('data_encr_by_caller =',data_encr_by_caller)
if data_encr_by_phone:
# then try to unwrap telephone encryption
try:
data_unencr_by_phone = SMessage(self.privkey_, self.phone.pubkey_).unwrap(data)
self.log('decrypted data !!!:',data_unencr_by_phone)
except ThemisError:
self.log('not really from the telephone?')
return OPERATOR_INTERCEPT_MESSAGE
data_by_phone = TELEPHONE.
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)
caller = Caller(name)
data_unencr2 = SMessage(self.privkey_, caller.pubkey_).unwrap(data_encr)
if type(data_unencr)==dict and type(data_unencr2)==dict:
data = data_unencr

@ -9,15 +9,15 @@ class TheTelephone(Operator):
API client class for Caller to interact with The Operator.
"""
def __init__(self, caller=None):
self.op = TheOperator()
self.caller = None
super().__init__(
name=TELEPHONE_NAME,
path_crypt_keys=PATH_CRYPT_CA_KEYS,
path_crypt_data=PATH_CRYPT_CA_KEYS
)
@property
def op(self): return OPERATOR
async def dial_operator(self,msg):
msg=msg.replace('/','_')
URL = OPERATOR_API_URL + msg + '/'

Loading…
Cancel
Save