diff --git a/komrade/backend/keymaker.py b/komrade/backend/keymaker.py index 6494b09..d6a1cbb 100644 --- a/komrade/backend/keymaker.py +++ b/komrade/backend/keymaker.py @@ -321,7 +321,7 @@ class Keymaker(Logger): return (name,pubkey) - def keychain(self,look_for=KEYMAKER_DEFAULT_ALL_KEY_NAMES): + def keychain(self,look_for=KEYMAKER_DEFAULT_ALL_KEY_NAMES,passphrase=None): # load existing keychain keys = self._keychain @@ -341,7 +341,7 @@ class Keymaker(Logger): if key: keys[keyname]=get_key_obj(keyname,key) # try to assemble - keys = self.assemble(self.assemble(keys)) + keys = self.assemble(self.assemble(keys,passphrase=passphrase),passphrase=passphrase) #store to existing set self._keychain = keys diff --git a/komrade/backend/komrades.py b/komrade/backend/komrades.py index 2aa1cb1..58915b3 100644 --- a/komrade/backend/komrades.py +++ b/komrade/backend/komrades.py @@ -147,6 +147,11 @@ class Komrade(Caller): b64enc(sec_login), prefix='/secret_login/' ) + self.crypt_keys.set( + uri_id, + privkey_encr_obj.data, + prefix='/privkey_encr/' + ) self.log(f'''Now saving name and public key on local device:''') @@ -167,11 +172,24 @@ class Komrade(Caller): prefix='/secret/' ) - def login(self): + def login(self,passphrase=None): + # check hardware 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: + if not self.privkey_encr: + self.log('''Login impossible. I do not have this komrade's private key on this hardware.''') + 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') + + # assemble privkey? + privkey = self.keychain(passphrase=passphrase).get('privkey') + if not privkey: self.log('''Login impossible. I do not have this komrade's private key on this hardware.''') return