2
0
mirror of https://github.com/ComradCollective/Comrad synced 2024-11-05 21:20:51 +00:00
This commit is contained in:
quadrismegistus 2020-09-13 19:47:25 +01:00
parent 89e78cac90
commit 7a07babe4c
4 changed files with 58 additions and 63 deletions

View File

@ -34,10 +34,11 @@ class KomradeSymmetricKey(KomradeKey):
@property
def cell(self):
if not hasattr(self,'_cell'):
if hasattr(self,'passphrase') and self.passphrase:
self._cell = SCellSeal(passphrase=hasher(self.passphrase))
elif hasattr(self,'key') and self.key:
self._cell = SCellSeal(key=self.key)
# if hasattr(self,'passphrase') and self.passphrase:
# self._cell = SCellSeal(passphrase=hasher(self.passphrase))
# elif hasattr(self,'key') and self.key:
# self._cell = SCellSeal(key=self.key)
self._cell = SCellSeal(key=self.key)
return self._cell
def encrypt(self,msg,**kwargs):
if hasattr(msg,'data'): msg=msg.data
@ -70,16 +71,24 @@ class KomradeSymmetricKeyWithPassphrase(KomradeSymmetricKey):
def hash(self,x): return self.crypt_keys.hash(x)
def __init__(self,passphrase=DEBUG_DEFAULT_PASSPHRASE, why=WHY_MSG):
if not passphrase:
# raise KomradeException
self.passphrase=None #getpass(why)
else:
self.passphrase=passphrase
# if passphrase: self.passphrase=passphrase
# if not passphrase:
# # raise KomradeException
# passphrase=getpass(why)
# else:
# self.passphrase=passphrase
# # if passphrase: self.passphrase=passphrase
pass
@property
def data(self): return KEY_TYPE_SYMMETRIC_WITH_PASSPHRASE.encode('utf-8')
def __repr__(self): return f'[Symmetric Key] (generated by password)'
@property
def cell(self):
if not hasattr(self,'_cell'):
from getpass import getpass
self._cell = SCellSeal(passphrase=hasher(getpass(WHY_MSG)))
return self._cell
class KomradeSymmetricKeyWithoutPassphrase(KomradeSymmetricKey):
def __init__(self,key=None):
@ -238,10 +247,12 @@ class Keymaker(Logger):
self._uri_id=uri_id
self._pubkey=None
self._keychain=keychain
self.passphrase=passphrase
self.path_crypt_keys=path_crypt_keys
self.path_crypt_data=path_crypt_data
# boot keychain
self._keychain = self.keychain(passphrase=passphrase)
def find_pubkey(self,name=None):
if not name: name=self.name
@ -614,7 +625,8 @@ Keymaker ({self}) is forging new keys for {name}
# self.log(encr_key_name,decr_key_name,unencr_key_name)
if decrypt and unencr_key_name in keychain: continue
if not decr_key_name in keychain:
keychain[decr_key_name] = KomradeSymmetricKeyWithPassphrase(passphrase=passphrase if passphrase else self.passphrase)
# self.log('looking for decr key name:',decr_key_name,keychain)
keychain[decr_key_name] = KomradeSymmetricKeyWithPassphrase(passphrase=passphrase)
else:
continue
decr_key = keychain.get(decr_key_name)

View File

@ -7,24 +7,23 @@ class Komrade(Caller):
def __init__(self, name=None, passphrase=DEBUG_DEFAULT_PASSPHRASE):
super().__init__(name=name,passphrase=passphrase)
self.passphrase=passphprase if passphrase else None
if SHOW_STATUS:
from komrade.cli import CLI
self.cli = CLI(name=name, persona=self)
# self.boot(create=False)
self.cli = CLI(name=name, komrade=self)
self.boot(create=False)
# def boot(self,create=False):
# # Do I already have my keys?
# # yes? -- login
def boot(self,create=False):
# Do I already have my keys?
# yes? -- login
# keys = self.keychain()
# if keys.get('pubkey') and keys.get('privkey'):
# self.log('booted!')
# return True
keys = self.keychain()
if keys.get('pubkey') and keys.get('privkey'):
self.log('booted!')
return True
# # If not, forge them -- only once!
# if not have_keys and create:
# self.get_new_keys()
# If not, forge them -- only once!
if not have_keys and create:
self.get_new_keys()
def exists_locally_as_contact(self):
@ -82,7 +81,6 @@ class Komrade(Caller):
while not passphrase:
passphrase=getpass(f'@Keymaker: Enter a memorable password to encrypt your private key with: \n\n@{self.name}: ')
clear_screen()
self.passphrase=passphrase
## 4) Get hashed password
passhash = hasher(passphrase)
self.log(f'''@Keymaker: I have replaced your password with a disguised, hashed version\nusing a salted SHA-256 algorithm from python's hashlib:\n\n\t{make_key_discreet_str(passhash)}''')
@ -191,7 +189,6 @@ class Komrade(Caller):
return
# check password
if not passphrase: passphrase=self.passphrase
# while not passphrase:
# from getpass import getpass
# passphrase = getpass('@Keymaker: Enter password for {self} in order to decrypt the encrypted private key:\n\n')

View File

@ -27,7 +27,6 @@ class TheOperator(Operator):
"""
Boot up the operator. Requires knowing or setting a password of memory.
"""
self.passphrase=passphrase
super().__init__(
name,
passphrase,

View File

@ -19,13 +19,13 @@ class CLI(Logger):
}
def __init__(self,name='',cmd='',persona=None):
self._name=name
self.name=name
self.cmd=cmd
self._komrade=None
self._loggedin=False
self.komrade=None
self.loggedin=False
def run(self,inp='',name=''):
# if name: self._name=name
# if name: self.name=name
# clear_screen()
# self.boot()
self.help()
@ -70,52 +70,39 @@ class CLI(Logger):
def register(self,name=None):
if not name: name=input('name: ')
if not name: return
self._komrade = Komrade(name)
res=self._komrade.register()
self.komrade = Komrade(name)
res=self.komrade.register()
if res and type(res)==dict and 'success' in res and res['success']:
self._name=self._komrade.name
self._loggedin=True
self.name=self.komrade.name
self.loggedin=True
else:
self._name=None
self._loggedin=False
self._komrade=None
self.name=None
self.loggedin=False
self.komrade=None
if 'status' in res:
print('@Operator: '+res.get('status','?'))
def login(self,name):
print(self,name,self.name,self.komrade,self.loggedin)
if not name: name=input('name: ')
if not name: return
self._komrade=Komrade(name)
self.komrade=Komrade(name)
res = self._komrade.login()
res = self.komrade.login()
if res and type(res)==dict and 'success' in res and res['success']:
self._name=self._komrade.name
self._loggedin=True
self.name=self.komrade.name
self.loggedin=True
else:
self._name=None
self._loggedin=False
self._komrade=None
self.name=None
self.loggedin=False
self.komrade=None
if 'status' in res:
print('@Operator: '+res.get('status','?')+'\n')
@property
def komrade(self):
if not hasattr(self,'_komrade'):
self._komrade = Komrade(self._name)
return self._komrade
@property
def name(self):
if not hasattr(self,'_name'):
if hasattr(self,'_komrade'):
self._name=self._komrade.name
else:
return None
return self._name
@property
def logged_in(self):
return (self._loggedin and self._komrade and self._name)
return (self.loggedin and self.komrade and self.name)
def meet(self,name):
if not self.logged_in:
@ -176,11 +163,11 @@ class CLI(Logger):
None,{ART_OLDPHONE4},f'''@{name}: Hm, ok. Well, could you patch me through to the remote operator then?''',
f'''@{TELEPHONE_NAME}: I could, but it's not safe yet. Your information could be exposed. You need to cut your encryption keys first.''',
f'''@{TELEPHONEname}: I could, but it's not safe yet. Your information could be exposed. You need to cut your encryption keys first.''',
f'@{name}: Fine, but how do I do that?',
f'@{TELEPHONE_NAME}: Visit the Keymaker.',
f'@{TELEPHONEname}: Visit the Keymaker.',
clear=False,pause=True)