2020-09-06 06:50:23 +00:00
|
|
|
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 *
|
2020-09-06 19:59:14 +00:00
|
|
|
# from komrade.backend.the_telephone import *
|
|
|
|
|
|
|
|
# from komrade.backend.the_telephone import *
|
|
|
|
|
2020-09-06 06:50:23 +00:00
|
|
|
|
|
|
|
class Caller(Operator):
|
|
|
|
"""
|
|
|
|
Variant of an Operator which handles local keys and keymaking.
|
|
|
|
"""
|
|
|
|
|
2020-09-08 11:23:41 +00:00
|
|
|
def ring_ring(self,msg_encr_caller2caller):
|
|
|
|
# ring 1: encrypt caller2phone
|
|
|
|
msg_encr_caller2caller_caller2phone = self.package_msg_to(
|
|
|
|
msg_encr_caller2caller,
|
|
|
|
self.op
|
|
|
|
)
|
|
|
|
self.log('msg_encr_caller2caller_caller2phone',msg_encr_caller2caller_caller2phone)
|
|
|
|
|
|
|
|
|
|
|
|
# ring 2: dial and get response
|
|
|
|
resp_msg_encr_caller2caller_caller2phone = self.phone.ring_ring(
|
|
|
|
msg_encr_caller2caller_caller2phone
|
|
|
|
)
|
|
|
|
self.log('resp_msg_encr_caller2caller_caller2phone',resp_msg_encr_caller2caller_caller2phone)
|
|
|
|
|
|
|
|
|
|
|
|
# ring 3: decrypt and send back
|
|
|
|
resp_msg_encr_caller2caller = self.unpackage_msg_from(
|
|
|
|
resp_msg_encr_caller2caller_caller2phone
|
|
|
|
)
|
|
|
|
self.log('resp_msg_encr_caller2caller',resp_msg_encr_caller2caller)
|
|
|
|
|
|
|
|
return resp_msg_encr_caller2caller
|
|
|
|
|
2020-09-06 06:50:23 +00:00
|
|
|
|
2020-09-08 07:20:42 +00:00
|
|
|
def get_new_keys(self, name = None, passphrase = DEBUG_DEFAULT_PASSPHRASE, is_group=None):
|
2020-09-08 11:23:41 +00:00
|
|
|
# get needed metadata
|
2020-09-06 19:54:00 +00:00
|
|
|
if not name: name=self.name
|
2020-09-07 07:26:32 +00:00
|
|
|
if name is None:
|
|
|
|
name = input('\nWhat is the name for this account? ')
|
|
|
|
if passphrase is None:
|
|
|
|
passphrase = getpass.getpass('\nEnter a memborable password: ')
|
|
|
|
# if is_group is None:
|
|
|
|
# is_group = input('\nIs this a group account? [y/N]').strip().lower() == 'y'
|
|
|
|
|
2020-09-08 06:58:54 +00:00
|
|
|
# form request
|
2020-09-08 11:23:41 +00:00
|
|
|
msg_to_op = {
|
|
|
|
'_please':'forge_new_keys',
|
2020-09-07 07:26:32 +00:00
|
|
|
'name':name,
|
2020-09-07 07:29:50 +00:00
|
|
|
'passphrase':hashish(passphrase.encode())
|
2020-09-07 07:26:32 +00:00
|
|
|
}
|
|
|
|
|
2020-09-08 11:23:41 +00:00
|
|
|
phone_res = self.phone.ring_ring(msg_to_op)
|
2020-09-08 06:58:54 +00:00
|
|
|
|
|
|
|
# URI id
|
2020-09-08 07:01:35 +00:00
|
|
|
uri_id = phone_res.get('uri_id')
|
2020-09-07 08:50:06 +00:00
|
|
|
returned_keys = phone_res.get('_keychain')
|
2020-09-08 06:58:54 +00:00
|
|
|
self.log('got URI from Op:',uri_id)
|
2020-09-07 08:13:08 +00:00
|
|
|
self.log('got returnd keys from Op:',returned_keys)
|
|
|
|
|
2020-09-08 06:58:54 +00:00
|
|
|
stop
|
|
|
|
|
2020-09-07 08:13:08 +00:00
|
|
|
# better have the right keys
|
2020-09-08 09:17:09 +00:00
|
|
|
assert set(KEYMAKER_DEFAULT_KEYS_TO_SAVE_ON_CLIENT) == set(returned_keys.keys())
|
2020-09-07 08:13:08 +00:00
|
|
|
|
|
|
|
# now save these keys!
|
2020-09-08 06:58:54 +00:00
|
|
|
saved_keys = self.save_keychain(name,returned_keys,uri_id=uri_id)
|
2020-09-07 08:13:08 +00:00
|
|
|
self.log('saved keys!',saved_keys)
|
|
|
|
|
|
|
|
# better have the right keys
|
2020-09-07 23:34:27 +00:00
|
|
|
# assert set(KEYMAKER_DEFAULT_KEYS_TO_SAVE) == set(saved_keys.keys())
|
2020-09-07 08:13:08 +00:00
|
|
|
|
|
|
|
# success!
|
|
|
|
self.log('yay!!!!')
|
|
|
|
return saved_keys
|