From 696e654c8f64175fe8a99072476556454e141428 Mon Sep 17 00:00:00 2001 From: quadrismegistus Date: Tue, 8 Sep 2020 09:13:35 +0100 Subject: [PATCH] sigh --- komrade/backend/keymaker.py | 29 +++++++++++++++++++++++---- komrade/backend/operators.py | 34 ++++++++++++++++++++++++++------ komrade/backend/the_telephone.py | 1 + komrade/constants.py | 2 ++ 4 files changed, 56 insertions(+), 10 deletions(-) diff --git a/komrade/backend/keymaker.py b/komrade/backend/keymaker.py index 4446ff4..28459fc 100644 --- a/komrade/backend/keymaker.py +++ b/komrade/backend/keymaker.py @@ -84,12 +84,26 @@ class Keymaker(Logger): # set defaults self.name=name - self.uri_id=uri_id + self._uri_id=uri_id self._keychain=keychain self.passphrase=passphrase self.path_crypt_keys=path_crypt_keys self.path_crypt_data=path_crypt_data + @property + def uri_id(self): + if not hasattr(self,'_uri_id') or not self._uri_id: + # try to load? + contact_fnfn = os.path.join(PATH_QRCODES,self.name+'.png') + print(contact_fnfn,os.path.exists(contact_fnfn)) + if not os.path.exists(contact_fnfn): return + + # with open(contact_fnfn,'rb') as f: dat=f.read() + from pyzbar.pyzbar import decode + from PIL import Image + self._uri_id = uri_id = decode(Image.open(contact_fnfn))[0].data + return self._uri_id + ### BASE STORAGE @property @@ -234,7 +248,7 @@ class Keymaker(Logger): def save_keychain(self,name,keychain,keys_to_save=None,uri_id=None): if not keys_to_save: keys_to_save = list(keychain.keys()) if not uri_id: uri_id = get_random_id() + get_random_id() - self.uri_id = uri_id + self._uri_id = uri_id # filter for transfer for k,v in keychain.items(): if issubclass(type(v),KomradeKey): @@ -322,17 +336,24 @@ class Keymaker(Logger): def keychain(self, passphrase=DEBUG_DEFAULT_PASSPHRASE, - force=False, - allow_builtin=True, extra_keys={}, keys_to_gen=KEYMAKER_DEFAULT_KEYS_TO_GEN, uri_id=None, **kwargs): # assemble as many keys as we can! + self.log(f'''keychain( + passphrase={passphrase}, + extra_keys={extra_keys}, + keys_to_gen={keys_to_gen}, + uri_id={uri_id}, + **kwargs = {kwargs} + )''') + if not uri_id: uri_id = self.uri_id if not uri_id and not self.uri_id: raise KomradeException('Need URI id to complete finding of keys!') + self.log('getting keychain for uri ID:',uri_id) # if not force and hasattr(self,'_keychain') and self._keychain: return self._keychain if passphrase: self.passphrase=passphrase diff --git a/komrade/backend/operators.py b/komrade/backend/operators.py index d83f3a5..171c5b4 100644 --- a/komrade/backend/operators.py +++ b/komrade/backend/operators.py @@ -129,6 +129,7 @@ class Operator(Keymaker): encrypted_message_from_caller_to_op = b'' encrypted_message_from_caller_to_caller = b'' + print('uri phone',from_phone.uri_id) from_phone_keychain = from_phone.keychain() @@ -148,6 +149,9 @@ class Operator(Keymaker): ### LAYERS OF ENCRYPTION: # 1) unencr header # Telephone sends half its and the operator's public keys + self.log('Layer 1: from_phone_pubkey_encr header:',from_phone_pubkey_encr) + self.log('Layer 1: to_phone_pubkey_decr header:',to_phone_pubkey_decr) + unencr_header = from_phone_pubkey_encr + BSEP2 + to_phone_pubkey_decr self.log('Layer 1: Unencrypted header:',unencr_header) @@ -483,6 +487,29 @@ def connect_phonelines(): print('\n\n\n\nCONNECTING PHONELINES!\n\n\n\n') + # save QR + import shutil + qrfn_op = os.path.join(PATH_QRCODES,OPERATOR_NAME+'.png') + qrfn_ph = os.path.join(PATH_QRCODES,TELEPHONE_NAME+'.png') + if not os.path.exists(qrfn_op): + r1 = komrade_request(PATH_OPERATOR_WEB_CONTACT_OP_URL) + if r1.status_code==200: + with open(qrfn_op,'wb') as of: + print('hello') + # shutil.copyfileobj(r1.raw, of) + of.write(r1.content) + print('>> saved:',qrfn_op) + + # stop + if not os.path.exists(qrfn_ph): + r2 = komrade_request(PATH_OPERATOR_WEB_CONTACT_PH_URL) + if r2.status_code==200: + with open(qrfn_ph,'wb') as of: + print('hello') + # shutil.copyfileobj(r2.raw, of) + of.write(r2.content) + print('>> saved:',qrfn_ph) + # import from komrade.backend.mazes import tor_request from komrade.backend import PATH_OPERATOR_WEB_KEYS_URL @@ -501,12 +528,6 @@ def connect_phonelines(): print('cannot authenticate the keymakers') return - # load remote contacts - qrfn_op = os.path.join(PATH_QRCODES,OPERATOR_NAME+'.png') - qrfn_ph = os.path.join(PATH_QRCODES,TELEPHONE_NAME+'.png') - # if not os.path.exists(qrfn_op): - - # unpack remote pkg pkg = b64decode(r.text) OMEGA_KEY_b,remote_builtin_keychain_encr = pkg.split(BSEP) @@ -534,6 +555,7 @@ def connect_phonelines(): dict_merge(TELEPHONE_KEYCHAIN,remote_builtin_keychain_phone_json) dict_merge(OPERATOR_KEYCHAIN,remote_builtin_keychain_op_json) + return (OPERATOR_KEYCHAIN,TELEPHONE_KEYCHAIN) # # load prime objects? diff --git a/komrade/backend/the_telephone.py b/komrade/backend/the_telephone.py index 5718955..d96ae89 100644 --- a/komrade/backend/the_telephone.py +++ b/komrade/backend/the_telephone.py @@ -24,6 +24,7 @@ class TheTelephone(Operator): print('OP2???',OPERATOR_KEYCHAIN) print('PH2???',TELEPHONE_KEYCHAIN) + stop self.caller=caller self._keychain = TELEPHONE_KEYCHAIN diff --git a/komrade/constants.py b/komrade/constants.py index 23d158d..0cada8f 100644 --- a/komrade/constants.py +++ b/komrade/constants.py @@ -134,6 +134,8 @@ TELEPHONE = None PATH_OPERATOR_WEB_KEYS_FILE = f'/home/ryan/www/website-komrade/.builtin.keys' PATH_OPERATOR_WEB_KEYS_URL = f'http://{KOMRADE_URL}/.builtin.keys' PATH_OPERATOR_WEB_CONTACTS_DIR = '/home/ryan/www/website-komrade/.contacts' +PATH_OPERATOR_WEB_CONTACT_OP_URL = f'http://{KOMRADE_URL}/.contacts/TheOperator.png' +PATH_OPERATOR_WEB_CONTACT_PH_URL = f'http://{KOMRADE_URL}/.contacts/TheTelephone.png'