keychain-uses-objects
quadrismegistus 4 years ago
parent e8a38f9383
commit 19bdc4e7ca

@ -167,6 +167,42 @@ class Komrade(Caller):
# done!
self.log(f'Congratulations. Welcome, Komrade {self}.')
@property
def secret_login(self):
return self.crypt_keys.get(
self.pubkey.data_b64_s,
prefix='/secret/'
)
def login(self):
if not self.pubkey:
self.log('''Login impossible. I do not have this komrade's public key, much less private one.''')
return
if not self.privkey:
self.log('''Login impossible. I do not have this komrade's private key on this hardware.''')
return
# compose message
msg = {
'name':self.name,
'pubkey':self.pubkey.data,
'secret_login':self.secret_login
}
# ask operator and get response
resp_msg = self.ring_ring(
msg,
route='login'
)
# get result
self.log('Got result back from operator:',resp_msg)
def ring_ring(self,msg,route=None,**y):
if type(msg)==dict and not ROUTE_KEYNAME in msg:

@ -171,10 +171,10 @@ class Operator(Keymaker):
raise KomradeException(f'Not a valid route!: {route}')
# route it!
self.log(f'routing msg to {self}.{route}() for msg data:{dict_format(msg_obj.data,tab=4)}')
self.log(f'Routing msg to {self}.{route}() for msg data:\n\n{dict_format(msg_obj.data,tab=4)}')
func = getattr(self,route)
new_data = func(**data)
self.log(f'new data was received from {self}.{route}() = {new_data}')
self.log(f'New data was received back from {self}.{route}() route:\b\b{dict_format(new_data,tab=4)}')
msg_obj.msg = msg_obj.msg_d['msg'] = new_data
# try passing it on?

@ -123,6 +123,46 @@ class TheOperator(Operator):
(self.crypt_keys.get(b64enc_s(pubkey),prefix='/name/'))
)
def login(self,name,pubkey,secret_login,**data):
# get my records
# check name?
if name != self.crypt_keys.get(
b64enc_s(pubkey),
prefix='/name/'
):
success = False
# check pubkey?
elif b64dec(pubkey) != b64dec(self.crypt_keys.get(
name,
prefix='/pubkey/'
)):
success = False
# check secret login
elif b64enc(secret_login) != b64enc(self.crypt_keys.get(
b64enc_s(pubkey),
prefix='/secret_login/'
)):
success = False
# otherwise we succeed
else:
success = True
## return res
if success:
return {
'success': True,
'status':'Login succeeded.'
}
else:
return {
'success': False,
'status':'Login failed.'
}
def register_new_user(self,name,pubkey,**data):
# self.log('setting pubkey under name')
@ -165,25 +205,24 @@ class TheOperator(Operator):
self.log('Operator returning result:',dict_format(res,tab=4))
return res
# give back decryptor
## success msg
#
cvb64=cv_b64#b64encode(cv).decode()
qrstr=self.qr_str(cvb64)
res['status']=self.status(f'''{OPERATOR_INTRO}I have successfully registered Komrade {name}.
# cvb64=cv_b64#b64encode(cv).decode()
# qrstr=self.qr_str(cvb64)
# res['status']=self.status(f'''{OPERATOR_INTRO}I have successfully registered Komrade {name}.
If you're interested, here's what I did. I stored the public key you gave me, {cvb64}, under the name of "{name}". However, I never save that name directly, but record it only in a disguised, "hashed" form: {ck}. I scrambled "{name}" by running it through a 1-way hashing function, which will always yield the same result: provided you know which function I'm using, and what the secret "salt" is that I add to all the input, a string of text which I keep protected and encrypted on my local hard drive.
# If you're interested, here's what I did. I stored the public key you gave me, {cvb64}, under the name of "{name}". However, I never save that name directly, but record it only in a disguised, "hashed" form: {ck}. I scrambled "{name}" by running it through a 1-way hashing function, which will always yield the same result: provided you know which function I'm using, and what the secret "salt" is that I add to all the input, a string of text which I keep protected and encrypted on my local hard drive.
The content of your data will therefore not only be encrypted, but its location in my database is obscured even to me. There's no way for me to reverse-engineer the name of {name} from the record I stored it under, {ck}. Unless you explictly ask me for the public key of {name}, I will have no way of accessing that information.
# The content of your data will therefore not only be encrypted, but its location in my database is obscured even to me. There's no way for me to reverse-engineer the name of {name} from the record I stored it under, {ck}. Unless you explictly ask me for the public key of {name}, I will have no way of accessing that information.
Your name ({name}) and your public key ({cvb64}) are the first two pieces of information you've given me about yourself. Your public key is your 'address' in Komrade: in order for anyone to write to you, or for them to receive messages from you, they'll need to know your public key (and vise versa). The Komrade app should store your public key on your device as a QR code, under ~/.komrade/.contacts/{name}.png. It will look something like this:{qrstr}You can then send this image to anyone by a secure channel (Signal, IRL, etc), or tell them the code directly ({cvb64}).
# Your name ({name}) and your public key ({cvb64}) are the first two pieces of information you've given me about yourself. Your public key is your 'address' in Komrade: in order for anyone to write to you, or for them to receive messages from you, they'll need to know your public key (and vise versa). The Komrade app should store your public key on your device as a QR code, under ~/.komrade/.contacts/{name}.png. It will look something like this:{qrstr}You can then send this image to anyone by a secure channel (Signal, IRL, etc), or tell them the code directly ({cvb64}).
By default, if anyone asks me what your public key is, I won't tell them--though I won't be able to avoid hinting that a user exists under this name should someone try to register under that name and I deny them). Instead, if the person who requested your public key insists, I will send you a message (encrypted end-to-end so only you can read it) that the user who met someone would like to introduce themselves to you; I will then send you their name and public key. It's now your move: up to you whether to save them back your public key.
# By default, if anyone asks me what your public key is, I won't tell them--though I won't be able to avoid hinting that a user exists under this name should someone try to register under that name and I deny them). Instead, if the person who requested your public key insists, I will send you a message (encrypted end-to-end so only you can read it) that the user who met someone would like to introduce themselves to you; I will then send you their name and public key. It's now your move: up to you whether to save them back your public key.
If you'd like to change this default behavior, e.g. by instead allowing anyone to request your public key, except for those whom you explcitly block, I have also created a super secret administrative record for you to change various settings on your account. This is protected by a separate encryption key which I have generated for you; and this key which is itself encrypted with the password you entered earlier. Don't worry: I never saw that password you typed, since it was given to me already hashed and disguised. Without that hashed passphrase, no one will be able to unlock the administration key; and without the administration key, they won't be able to find the hashed record I stored your user settings under, since I also salted that hash with your own hashed passphrase. Even if someone found the record I stored them under, they wouldn't be able to decrypt the existing settings; and if they can't do that, I won't let them overwrite the record.''')
# If you'd like to change this default behavior, e.g. by instead allowing anyone to request your public key, except for those whom you explcitly block, I have also created a super secret administrative record for you to change various settings on your account. This is protected by a separate encryption key which I have generated for you; and this key which is itself encrypted with the password you entered earlier. Don't worry: I never saw that password you typed, since it was given to me already hashed and disguised. Without that hashed passphrase, no one will be able to unlock the administration key; and without the administration key, they won't be able to find the hashed record I stored your user settings under, since I also salted that hash with your own hashed passphrase. Even if someone found the record I stored them under, they wouldn't be able to decrypt the existing settings; and if they can't do that, I won't let them overwrite the record.''')
self.log('Operator returning result:',dict_format(res,tab=2))
# self.log('Operator returning result:',dict_format(res,tab=2))

@ -137,10 +137,8 @@ DEBUG_DEFAULT_PASSPHRASE = None # 'all your base are belong to us'
ROUTE_KEYNAME = 'request'
OPERATOR_ROUTES = [
'forge_new_keys',
'does_username_exist',
'hello_world',
'register_new_user'
'register_new_user',
'login'
]
OPERATOR_INTRO = 'Hello, this is the Operator speaking. '

Loading…
Cancel
Save