コード例 #1
0
def collect_fingerprints_from_lbb_db(fingerprints: set = None) -> None:
    """
    Connects to the little black box database and converts the certificates to
    compatible fingerprints.

    Args:
        fingerprints (set): A collection of obtained certificates from the
            little black box and the house of keys.

    """
    # Actual database connection
    conn = connect(LITTLE_BLACK_BOX_DATABASE)
    cur = conn.cursor()

    # Obtain all the certificates contained in the database
    cur.execute("SELECT certificate FROM certificates;")

    # Iterate over the items from the database
    for item in cur:

        # Ignore ssh-rsa keys
        if (not item[0].startswith(BEGIN_CERTIFICATE)): continue

        # Convert the text of the certificate and extract the fingerprint
        fingerprints.add(Certificate.from_string(item[0]).fingerprint)

    conn.close()
コード例 #2
0
def collect_fingerprints_from_hok_fp(fingerprints: set = None) -> None:
    """
    Iterates through the House Of Keys directory and converts the certificates
    in the PEM files to compatible fingerprints.

    Args:
        fingerprints (set): A collection of obtained certificates from the
            little black box and the house of keys.

    """
    # Iterate through the content of the directory
    for f in os.listdir(HOUSE_OF_KEYS_PATH):

        # Only interested in the known certificates
        if (not f.endswith("pem")): continue

        # Extract the PEM certificate as string
        pem = open(os.path.join(HOUSE_OF_KEYS_PATH, f), 'r').read()
        pem = pem[pem.rfind(BEGIN_CERTIFICATE):]

        # Convert the PEM certificate to a compatible fingerprint
        fingerprints.add(Certificate.from_string(pem).fingerprint)
コード例 #3
0
def extract_fps_ecs(file_path, fps, ecs):
    """
    Extract the fingerprints and Ellyptic Curve data from a given file.

    Args:
        file_path (str): Full system path to the file.
        fps (dict): Dictionary of all collected fingerprints.
        ecs (dict): Dictionary of all collected Elyptic Curve data.

    """
    try:
        pem = open(file_path, "r").read()

        if (pem.startswith("-----BEGIN PUBLIC KEY-----")):
            pn = SSHKey.from_pem_public_key(pem).public_numbers
            ecs.setdefault(str(pn.x), []).append(file_path)

        elif (CERT_FLAG in pem):
            pem = pem[pem.rfind(CERT_FLAG):].strip()
            cert = Certificate.from_string(pem)
            fps.setdefault(cert.fingerprint, []).append(file_path)

    except Exception as e:
        print(file_path, str(e))