(gpg, log_if_configured=False)
Configure the local keyring

    Create a keypair and import Blockstream's public key

    Args:
        gpg : Gpg object
        log_if_configured : Print log message if keyring is already configured
Configure the local keyring
Configure the local keyring
def config_keyring(gpg, log_if_configured=False):
    """Configure the local keyring

    Create a keypair and import Blockstream's public key

    Args:
        gpg : Gpg object
        log_if_configured : Print log message if keyring is already configured

    """
    assert (isinstance(gpg, Gpg))
    if _is_gpg_keyring_set(gpg.gpghome):
        if (log_if_configured):
            logger.info("Keyring already configured")
        return

    # Generate new keypair
    logger.info("Generating a GPG keypair to encrypt and decrypt API messages")
    name = input("User name represented by the key: ")
    email = input("E-mail address: ")
    comment = input("Comment to attach to the user ID: ")
    gpg.create_keys(name, email, comment)

    # Import Blockstream's public key
    #
    # NOTE: the order is important here. Add Blockstream's public key only
    # after adding the user key. With that, the user key becomes the first key
    # on the keyring, which is used by default.
    pkg_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    key_path = os.path.join(pkg_dir, 'gpg', defs.blocksat_pubkey + ".gpg")

    with open(key_path) as fd:
        key_data = fd.read()

    import_result = gpg.gpg.import_keys(key_data)

    if (len(import_result.fingerprints) == 0):
        logger.warning("Failed to import key {}".format(defs.blocksat_pubkey))
        return

    logger.info("Imported key {}".format(import_result.fingerprints[0]))

    gpg.gpg.trust_keys(defs.blocksat_pubkey, 'TRUST_ULTIMATE')

    if (not _is_gpg_keyring_set(gpg.gpghome)):
        raise RuntimeError("GPG keyring configuration failed")
def config_keyring ( gpg , log_if_configured = False ) : assert ( isinstance ( gpg , Gpg ) ) if _is_gpg_keyring_set ( gpg . gpghome ) : if ( log_if_configured ) : logger . info ( "Keyring already configured" ) return # Generate new keypair logger . info ( "Generating a GPG keypair to encrypt and decrypt API messages" ) name = input ( "User name represented by the key: " ) email = input ( "E-mail address: " ) comment = input ( "Comment to attach to the user ID: " ) gpg . create_keys ( name , email , comment ) # Import Blockstream's public key # # NOTE: the order is important here. Add Blockstream's public key only # after adding the user key. With that, the user key becomes the first key # on the keyring, which is used by default. pkg_dir = os . path . dirname ( os . path . dirname ( os . path . abspath ( __file__ ) ) ) key_path = os . path . join ( pkg_dir , 'gpg' , defs . blocksat_pubkey + ".gpg" ) with open ( key_path ) as fd : key_data = fd . read ( ) import_result = gpg . gpg . import_keys ( key_data ) if ( len ( import_result . fingerprints ) == 0 ) : logger . warning ( "Failed to import key {}" . format ( defs . blocksat_pubkey ) ) return logger . info ( "Imported key {}" . format ( import_result . fingerprints [ 0 ] ) ) gpg . gpg . trust_keys ( defs . blocksat_pubkey , 'TRUST_ULTIMATE' ) if ( not _is_gpg_keyring_set ( gpg . gpghome ) ) : raise RuntimeError ( "GPG keyring configuration failed" )