def apply(self, ui): envelope = ui.current_buffer.envelope if self.action == 'rmencrypt': try: for keyid in self.encrypt_keys: tmp_key = crypto.get_key(keyid) del envelope.encrypt_keys[crypto.hash_key(tmp_key)] except GPGProblem as e: ui.notify(e.message, priority='error') if not envelope.encrypt_keys: envelope.encrypt = False ui.current_buffer.rebuild() return elif self.action == 'encrypt': encrypt = True elif self.action == 'unencrypt': encrypt = False elif self.action == 'toggleencrypt': encrypt = not envelope.encrypt envelope.encrypt = encrypt if encrypt: if not self.encrypt_keys: for recipient in envelope.headers['To'][0].split(','): if not recipient: continue match = re.search("<(.*@.*)>", recipient) if match: recipient = match.group(0) self.encrypt_keys.append(recipient) logging.debug("encryption keys: " + str(self.encrypt_keys)) for keyid in self.encrypt_keys: try: key = crypto.get_key(keyid, validate=True, encrypt=True) except GPGProblem as e: if e.code == GPGCode.AMBIGUOUS_NAME: possible_keys = crypto.list_keys(hint=keyid) tmp_choices = [k.uids[0].uid for k in possible_keys] choices = { str(len(tmp_choices) - x): tmp_choices[x] for x in range(0, len(tmp_choices)) } keyid = yield ui.choice("ambiguous keyid! Which " + "key do you want to use?", choices, cancel=None) if keyid: self.encrypt_keys.append(keyid) continue else: ui.notify(e.message, priority='error') continue envelope.encrypt_keys[crypto.hash_key(key)] = key if not envelope.encrypt_keys: envelope.encrypt = False # reload buffer ui.current_buffer.rebuild()
def apply(self, ui): envelope = ui.current_buffer.envelope if self.action == 'rmencrypt': try: for keyid in self.encrypt_keys: tmp_key = crypto.get_key(keyid) del envelope.encrypt_keys[crypto.hash_key(tmp_key)] except GPGProblem as e: ui.notify(e.message, priority='error') if not envelope.encrypt_keys: envelope.encrypt = False ui.current_buffer.rebuild() return elif self.action == 'encrypt': encrypt = True elif self.action == 'unencrypt': encrypt = False elif self.action == 'toggleencrypt': encrypt = not envelope.encrypt envelope.encrypt = encrypt if encrypt: if not self.encrypt_keys: for recipient in envelope.headers['To'][0].split(','): if not recipient: continue match = re.search("<(.*@.*)>", recipient) if match: recipient = match.group(0) self.encrypt_keys.append(recipient) logging.debug("encryption keys: " + str(self.encrypt_keys)) for keyid in self.encrypt_keys: try: key = crypto.get_key(keyid, validate=True, encrypt=True) except GPGProblem as e: if e.code == GPGCode.AMBIGUOUS_NAME: possible_keys = crypto.list_keys(hint=keyid) tmp_choices = [k.uids[0].uid for k in possible_keys] choices = {str(len(tmp_choices) - x): tmp_choices[x] for x in range(0, len(tmp_choices))} keyid = yield ui.choice("ambiguous keyid! Which" + "key do you want to use?", choices, cancel=None) if keyid: self.encrypt_keys.append(keyid) continue else: ui.notify(e.message, priority='error') continue envelope.encrypt_keys[crypto.hash_key(key)] = key if not envelope.encrypt_keys: envelope.encrypt = False # reload buffer ui.current_buffer.rebuild()
def get_keys(ui, encrypt_keyids, block_error=False): keys = {} for keyid in encrypt_keyids: try: key = crypto.get_key(keyid, validate=True, encrypt=True) except GPGProblem as e: if e.code == GPGCode.AMBIGUOUS_NAME: possible_keys = crypto.list_keys(hint=keyid) tmp_choices = [k.uids[0].uid for k in possible_keys] choices = { str(len(tmp_choices) - x): tmp_choices[x] for x in range(0, len(tmp_choices)) } keyid = yield ui.choice("ambiguous keyid! Which " + "key do you want to use?", choices, cancel=None) if keyid: encrypt_keyids.append(keyid) continue else: ui.notify(e.message, priority='error', block=block_error) continue keys[crypto.hash_key(key)] = key returnValue(keys)
def get_keys(ui, encrypt_keyids, block_error=False): keys = {} for keyid in encrypt_keyids: try: key = crypto.get_key(keyid, validate=True, encrypt=True) except GPGProblem as e: if e.code == GPGCode.AMBIGUOUS_NAME: possible_keys = crypto.list_keys(hint=keyid) tmp_choices = [k.uids[0].uid for k in possible_keys] choices = {str(len(tmp_choices) - x): tmp_choices[x] for x in range(0, len(tmp_choices))} keyid = yield ui.choice("ambiguous keyid! Which " + "key do you want to use?", choices, cancel=None) if keyid: encrypt_keyids.append(keyid) continue else: ui.notify(e.message, priority='error', block=block_error) continue keys[crypto.hash_key(key)] = key returnValue(keys)
def apply(self, ui): envelope = ui.current_buffer.envelope if self.action == 'rmencrypt': try: for keyid in self.encrypt_keys: tmp_key = crypto.get_key(keyid) del envelope.encrypt_keys[crypto.hash_key(tmp_key)] except GPGProblem as e: ui.notify(e.message, priority='error') if not envelope.encrypt_keys: envelope.encrypt = False ui.current_buffer.rebuild() return elif self.action == 'encrypt': encrypt = True elif self.action == 'unencrypt': encrypt = False elif self.action == 'toggleencrypt': encrypt = not envelope.encrypt envelope.encrypt = encrypt if encrypt: if not self.encrypt_keys: for recipient in envelope.headers['To'][0].split(','): if not recipient: continue match = re.search("<(.*@.*)>", recipient) if match: recipient = match.group(0) self.encrypt_keys.append(recipient) logging.debug("encryption keys: " + str(self.encrypt_keys)) keys = yield get_keys(ui, self.encrypt_keys) if keys: envelope.encrypt_keys.update(keys) else: envelope.encrypt = False # reload buffer ui.current_buffer.rebuild()
def apply(self, ui): envelope = ui.current_buffer.envelope if self.action == 'rmencrypt': try: for keyid in self.encrypt_keys: tmp_key = crypto.get_key(keyid) del envelope.encrypt_keys[crypto.hash_key(tmp_key)] except GPGProblem as e: ui.notify(e.message, priority='error') if not envelope.encrypt_keys: envelope.encrypt = False ui.current_buffer.rebuild() return elif self.action == 'encrypt': encrypt = True elif self.action == 'unencrypt': encrypt = False elif self.action == 'toggleencrypt': encrypt = not envelope.encrypt envelope.encrypt = encrypt if encrypt: if not self.encrypt_keys: for recipient in envelope.headers['To'][0].split(','): if not recipient: continue match = re.search("<(.*@.*)>", recipient) if match: recipient = match.group(0) self.encrypt_keys.append(recipient) logging.debug("encryption keys: " + str(self.encrypt_keys)) for keyid in self.encrypt_keys: try: key = crypto.get_key(keyid, validate=True, encrypt=True) except GPGProblem as e: if e.code == GPGCode.AMBIGUOUS_NAME: possible_keys = crypto.list_keys(hint=keyid) tmp_choices = [k.uids[0].uid for k in possible_keys]
def get_keys(ui, encrypt_keyids, block_error=False): """Get several keys from the GPG keyring. The keys are selected by keyid and are checked if they can be used for encryption. :param ui: the main user interface object :type ui: alot.ui.UI :param encrypt_keyids: the key ids of the keys to get :type encrypt_keyids: list(str) :param block_error: wether error messages for the user should expire automatically or block the ui :type block_error: bool :returns: the available keys indexed by their key hash :rtype: dict(str->gpgme.Key) """ keys = {} for keyid in encrypt_keyids: try: key = crypto.get_key(keyid, validate=True, encrypt=True) except GPGProblem as e: if e.code == GPGCode.AMBIGUOUS_NAME: possible_keys = crypto.list_keys(hint=keyid) tmp_choices = [k.uids[0].uid for k in possible_keys] choices = {str(len(tmp_choices) - x): tmp_choices[x] for x in range(0, len(tmp_choices))} keyid = yield ui.choice("ambiguous keyid! Which " + "key do you want to use?", choices, cancel=None) if keyid: encrypt_keyids.append(keyid) continue else: ui.notify(e.message, priority='error', block=block_error) continue keys[crypto.hash_key(key)] = key returnValue(keys)
try: key = crypto.get_key(keyid, validate=True, encrypt=True) except GPGProblem as e: if e.code == GPGCode.AMBIGUOUS_NAME: possible_keys = crypto.list_keys(hint=keyid) tmp_choices = [k.uids[0].uid for k in possible_keys] <<<<<<< HEAD choices = {str(len(tmp_choices) - x) : tmp_choices[x] for x in range(0, len(tmp_choices))} keyid = yield ui.choice("This keyid was ambiguous. " + "Which key do you want to use?", choices, cancel=None) ======= choices = {str(len(tmp_choices) - x): tmp_choices[x] for x in range(0, len(tmp_choices))} keyid = yield ui.choice("ambiguous keyid! Which" + "key do you want to use?", choices, cancel=None) >>>>>>> 5820ef46cfff2799abbc63e47443ee82692b25d4 if keyid: self.encrypt_keys.append(keyid) continue else: ui.notify(e.message, priority='error') continue envelope.encrypt_keys[crypto.hash_key(key)] = key if not envelope.encrypt_keys: envelope.encrypt = False # reload buffer ui.current_buffer.rebuild()