def from_keybase(username): """Will attempt to retrieve a GPG public key from Keybase, importing if neccesary""" public_key = key_from_keybase(username) fingerprint = public_key['fingerprint'][-8:].upper().encode('ascii') key = public_key['bundle'].encode('ascii') if not has_gpg_key(fingerprint): LOG.debug("Importing gpg key for %s", username) if not import_gpg_key(key): raise aomi.exceptions.KeybaseAPI("import key for %s" % username) return fingerprint
def from_keybase(username): """Will attempt to retrieve a GPG public key from Keybase, importing if neccesary""" public_key = key_from_keybase(username) fingerprint = public_key['fingerprint'][-8:].upper().encode('ascii') key = public_key['bundle'].encode('ascii') if not has_gpg_key(fingerprint): LOG.debug("Importing gpg key for %s", username) if not import_gpg_key(key): raise aomi.exceptions.KeybaseAPI("import key for %s" % username) return fingerprint
def import_keybase(useropt): """Imports a public GPG key from Keybase""" public_key = None u_bits = useropt.split(':') username = u_bits[0] if len(u_bits) == 1: public_key = cryptorito.key_from_keybase(username) else: fingerprint = u_bits[1] public_key = cryptorito.key_from_keybase(username, fingerprint) if cryptorito.has_gpg_key(public_key['fingerprint']): sys.exit(2) cryptorito.import_gpg_key(public_key['bundle'].encode('ascii')) sys.exit(0)
def grok_keys(config): """Will retrieve a GPG key from either Keybase or GPG directly""" key_ids = [] for key in config['pgp_keys']: if key.startswith('keybase:'): key_id = from_keybase(key[8:]) LOG.debug("Encrypting for keybase user %s", key[8:]) else: if not has_gpg_key(key): raise aomi.exceptions.GPG("Do not actually have key %s" % key) LOG.debug("Encrypting for gpg id %s", key) key_id = key validate_gpg_fingerprint(key_id) key_ids.append(key_id) return key_ids
def grok_keys(config): """Will retrieve a GPG key from either Keybase or GPG directly""" key_ids = [] for key in config['pgp_keys']: if key.startswith('keybase:'): key_id = from_keybase(key[8:]) LOG.debug("Encrypting for keybase user %s", key[8:]) else: if not has_gpg_key(key): raise aomi.exceptions.GPG("Do not actually have key %s" % key) LOG.debug("Encrypting for gpg id %s", key) key_id = key validate_gpg_fingerprint(key_id) key_ids.append(key_id) return key_ids
def test_unhappypath(self): flexmock(subprocess) \ .should_receive('check_output') \ .replace_with(key_blank) self.assertFalse(cryptorito.has_gpg_key(TEST_KEY))
def test_happypath(self): flexmock(subprocess) \ .should_receive('check_output') \ .replace_with(key_resp) assert (cryptorito.has_gpg_key(TEST_KEY))
def has_key(key): """Checks to see if we actually have a key installed""" if not cryptorito.has_gpg_key(key): sys.exit(1) sys.exit(0)