def load_key(self, key): """ @param key: @return: True or False, True only if a key is effectively importable and listed. """ try: sanitized_key = self.sanitize_gpg_string(key) import_result = self.gpgh.import_keys(sanitized_key) except Exception as excep: log.err("Error in GPG import_keys: %s" % excep) raise errors.GPGKeyInvalid if len(import_result.fingerprints) != 1: raise errors.GPGKeyInvalid fingerprint = import_result.fingerprints[0] # looking if the key is effectively reachable try: all_keys = self.gpgh.list_keys() except Exception as excep: log.err("Error in GPG list_keys: %s" % excep) raise errors.GPGKeyInvalid info = u"" expiration = datetime.utcfromtimestamp(0) for key in all_keys: if key['fingerprint'] == fingerprint: if key['expires']: expiration = datetime.utcfromtimestamp(int(key['expires'])) exp_date = datetime_to_day_str(expiration) else: exp_date = u'Never' info += "Key length: %s\n" % key['length'] info += "Key expiration: %s\n" % exp_date try: for uid in key['uids']: info += "\t%s\n" % uid except Exception as excep: log.err("Error in GPG key format/properties: %s" % excep) raise errors.GPGKeyInvalid break if not len(info): log.err("Key apparently imported but unable to reload it") raise errors.GPGKeyInvalid ret = { 'fingerprint': fingerprint, 'expiration': expiration, 'info': info } return ret
def PGPKeyInfoList(self): ret = '' for r in self.data['users']: fingerprint = r['pgp_key_fingerprint'] key = fingerprint[:7] if fingerprint is not None else '' ret += '\t%s, %s (%s)\n' % ( r['name'], key, datetime_to_day_str(r['pgp_key_expiration'])) return ret
def load_key(self, key): """ @param key: @return: True or False, True only if a key is effectively importable and listed. """ try: import_result = self.pgph.import_keys(key) except Exception as excep: log.err("Error in PGP import_keys: %s" % excep) raise errors.PGPKeyInvalid if len(import_result.fingerprints) != 1: raise errors.PGPKeyInvalid fingerprint = import_result.fingerprints[0] # looking if the key is effectively reachable try: all_keys = self.pgph.list_keys() except Exception as excep: log.err("Error in PGP list_keys: %s" % excep) raise errors.PGPKeyInvalid info = u"" expiration = datetime.utcfromtimestamp(0) for key in all_keys: if key['fingerprint'] == fingerprint: if key['expires']: expiration = datetime.utcfromtimestamp(int(key['expires'])) exp_date = datetime_to_day_str(expiration) else: exp_date = u'Never' info += "Key length: %s\n" % key['length'] info += "Key expiration: %s\n" % exp_date try: for uid in key['uids']: info += "\t%s\n" % uid except Exception as excep: log.err("Error in PGP key format/properties: %s" % excep) raise errors.PGPKeyInvalid break if not len(info): log.err("Key apparently imported but unable to reload it") raise errors.PGPKeyInvalid ret = { 'fingerprint': fingerprint, 'expiration': expiration, 'info': info } return ret
def PGPKeyInfo(self): fingerprint = self.data['user']['pgp_key_fingerprint'] key = fingerprint[:7] if fingerprint is not None else '' return '\t0x%s (%s)' % ( key, datetime_to_day_str(self.data['user']['pgp_key_expiration']))