2
0
mirror of https://github.com/ComradCollective/Comrad synced 2024-11-11 13:10:45 +00:00
This commit is contained in:
quadrismegistus 2020-09-06 21:17:47 +01:00
parent 30f684d80a
commit b69e388408
5 changed files with 38 additions and 22 deletions

View File

@ -12,3 +12,10 @@ from .switchboard import *
from .the_telephone import * from .the_telephone import *
from .callers import * from .callers import *
## define default entities
OPERATOR = TheOperator()
TELEPHONE = TheTelephone()

View File

@ -13,12 +13,9 @@ class Caller(Operator):
@property @property
def phone(self): def phone(self):
""" return TELEPHONE
Operator on the line. @property
""" def op(self): return OPERATOR
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): 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'] 'adminkey_decr_encr', 'adminkey_decr_decr']
try: 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: except TypeError:
return None return None

View File

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

View File

@ -5,9 +5,7 @@ Running on node prime.
# internal imports # internal imports
import os,sys; sys.path.append(os.path.abspath(os.path.join(os.path.abspath(os.path.join(os.path.dirname(__file__),'..')),'..'))) 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 import *
from komrade.backend.crypt import * from komrade.backend import *
from komrade.backend.operators import *
from komrade.backend.mazes import *
@ -15,6 +13,9 @@ class TheOperator(Operator):
""" """
The remote operator The remote operator
""" """
@property
def phone(self):
return TELEPHONE
def __init__(self, name = OPERATOR_NAME, passphrase='acc'): 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> ') 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) super().__init__(name,passphrase,path_crypt_keys=PATH_CRYPT_OP_KEYS,path_crypt_data=PATH_CRYPT_OP_DATA)
def decrypt_incoming(self,data): def decrypt_incoming(self,data):
# step 1 split: # step 1 split:
data_unencr,data_encr = data.split(BSEP) data_encr_by_phone,data_encr_by_caller = data.split(BSEP)
self.log('data_unencr =',data_unencr)
self.log('data_encr =',data_encr) 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: if data_encr and 'name' in data_unencr:
name=data_unencr['name'] name=data_unencr['name']
keychain=data_unencr.get('keychain',{}) keychain=data_unencr.get('keychain',{})
# decrypt using this user's pubkey on record # decrypt using this user's pubkey on record
caller = Operator(name) caller = Caller(name)
from_pubkey = user.pubkey(keychain=keychain) data_unencr2 = SMessage(self.privkey_, caller.pubkey_).unwrap(data_encr)
data_unencr2 = SMessage(OPERATOR.privkey_, from_pubkey).unwrap(data_encr)
if type(data_unencr)==dict and type(data_unencr2)==dict: if type(data_unencr)==dict and type(data_unencr2)==dict:
data = data_unencr data = data_unencr

View File

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