Skip to content

Instantly share code, notes, and snippets.

@mark05e
Last active November 1, 2024 03:21
Show Gist options
  • Save mark05e/8ffe4173c16c665e81e71856ecce0f73 to your computer and use it in GitHub Desktop.
Save mark05e/8ffe4173c16c665e81e71856ecce0f73 to your computer and use it in GitHub Desktop.

Exploring Available Certificate Authorities in AWS Lambda

Analysis of the Certificate Authorities accessible within AWS Lambda.

Instructions

import json
import ssl
from cryptography import x509
from cryptography.hazmat.backends import default_backend

def list_root_ca_names():
    names = []
    logs = []  # Collect all log messages here
    cafile = ssl.get_default_verify_paths().cafile
    logs.append(f"Default CA file path: {cafile}")

    try:
        with open(cafile, 'rb') as f:
            cert_data = f.read()
            logs.append("Successfully read CA file.")

            # Split each certificate in PEM format
            pem_certs = cert_data.split(b"-----END CERTIFICATE-----")
            logs.append(f"Number of certificates found: {len(pem_certs) - 1}")

            for pem_cert in pem_certs:
                if pem_cert.strip():  # Ignore empty splits
                    pem_cert = pem_cert.strip() + b"\n-----END CERTIFICATE-----\n"
                    try:
                        # Load the certificate
                        cert = x509.load_pem_x509_certificate(pem_cert, default_backend())
                        # Extract the Common Name (CN)
                        cn = cert.subject.get_attributes_for_oid(x509.NameOID.COMMON_NAME)[0].value
                        logs.append(f"Found CN: {cn}")
                        names.append(cn)
                    except Exception as cert_error:
                        logs.append(f"Error processing certificate: {cert_error}")
    except Exception as e:
        error_message = f"Error reading {cafile}: {e}"
        logs.append(error_message)
        names.append(error_message)

    logs.append(f"Total CN names found: {len(names)}")
    # Join all logs into a single string
    full_log = "\n".join(logs)
    print(full_log)  # Log the full output once

    return names

def lambda_handler(event, context):
    # Retrieve root CA certificate names
    root_certificate_names = list_root_ca_names()

    return {
        'statusCode': 200,
        'rootCertificateNames': root_certificate_names  # Return the list directly
    }
@mark05e
Copy link
Author

mark05e commented Nov 1, 2024

Response as of 2024-10-31

{
  "statusCode": 200,
  "rootCertificateNames": [
    "Amazon RDS ap-south-2 Root CA RSA4096 G1",
    "Amazon RDS eu-west-2 Root CA ECC384 G1",
    "Amazon RDS ap-southeast-5 Root CA RSA2048 G1",
    "Amazon RDS eu-south-1 CA",
    "Amazon RDS ap-southeast-3 Root CA RSA4096 G1",
    "Amazon RDS af-south-1 Root CA RSA4096 G1",
    "Amazon RDS eu-central-2 Root CA RSA4096 G1",
    "Amazon RDS sa-east-1 Root CA ECC384 G1",
    "Amazon RDS ap-southeast-1 2019 CA",
    "Amazon RDS ap-northeast-2 Root CA RSA4096 G1",
    "Amazon RDS us-east-1 Root CA RSA2048 G1",
    "Amazon RDS af-south-1 CA",
    "Amazon RDS ap-northeast-3 2019 CA",
    "Amazon RDS eu-south-1 Root CA",
    "Amazon RDS ca-central-1 2019 CA",
    "Amazon RDS ap-southeast-3 Root CA RSA2048 G1",
    "Amazon RDS eu-central-2 Root CA RSA2048 G1",
    "Amazon RDS eu-north-1 Root CA RSA4096 G1",
    "Amazon RDS eu-central-1 Root CA RSA2048 G1",
    "Amazon RDS us-west-1 2019 CA",
    "Amazon RDS ap-northeast-1 Root CA ECC384 G1",
    "Amazon RDS ap-northeast-1 Root CA RSA4096 G1",
    "Amazon RDS eu-central-2 Root CA ECC384 G1",
    "Amazon RDS Preview us-east-2 2019 CA",
    "Amazon RDS ap-south-2 Root CA ECC384 G1",
    "Amazon RDS Beta us-east-1 Root CA RSA2048 G1",
    "Amazon RDS af-south-1 Root CA",
    "Amazon RDS ap-southeast-4 Root CA RSA2048 G1",
    "Amazon RDS me-central-1 Root CA RSA2048 G1",
    "Amazon RDS Preview us-east-2 Root CA RSA2048 G1",
    "Amazon RDS eu-west-2 Root CA RSA2048 G1",
    "Amazon RDS ap-east-1 Root CA RSA2048 G1",
    "Amazon RDS eu-west-3 Root CA RSA4096 G1",
    "Amazon RDS eu-central-1 Root CA ECC384 G1",
    "Amazon RDS Beta us-east-1 2019 CA",
    "Amazon RDS eu-north-1 2019 CA",
    "Amazon RDS il-central-1 Root CA RSA2048 G1",
    "Amazon RDS ca-central-1 Root CA ECC384 G1",
    "Amazon RDS ap-southeast-4 Root CA RSA4096 G1",
    "Amazon RDS eu-west-1 Root CA RSA4096 G1",
    "Amazon RDS eu-west-3 2019 CA",
    "Amazon RDS us-east-1 Root CA RSA4096 G1",
    "Amazon RDS eu-south-1 Root CA ECC384 G1",
    "Amazon RDS ap-south-1 Root CA RSA4096 G1",
    "Amazon RDS ap-southeast-3 Root CA ECC384 G1",
    "Amazon RDS ca-west-1 Root CA RSA2048 G1",
    "Amazon RDS ap-south-2 Root CA RSA2048 G1",
    "Amazon RDS Root 2019 CA",
    "Amazon RDS ap-southeast-5 Root CA ECC384 G1",
    "Amazon RDS ap-northeast-2 Root CA RSA2048 G1",
    "Amazon RDS ap-east-1 Root CA RSA4096 G1",
    "Amazon RDS eu-central-1 Root CA RSA4096 G1",
    "Amazon RDS ap-south-1 2019 CA",
    "Amazon RDS il-central-1 Root CA ECC384 G1",
    "Amazon RDS eu-west-2 Root CA RSA4096 G1",
    "Amazon RDS us-west-2 Root CA RSA4096 G1",
    "Amazon RDS ca-central-1 Root CA RSA2048 G1",
    "Amazon RDS ca-central-1 Root CA RSA4096 G1",
    "Amazon RDS me-south-1 Root CA",
    "Amazon RDS eu-west-1 2019 CA",
    "Amazon RDS eu-west-1 Root CA RSA2048 G1",
    "Amazon RDS us-east-2 Root CA ECC384 G1",
    "Amazon RDS ap-southeast-5 Root CA RSA4096 G1",
    "Amazon RDS ap-northeast-1 Root CA RSA2048 G1",
    "Amazon RDS ap-southeast-2 Root CA ECC384 G1",
    "Amazon RDS ap-northeast-3 Root CA ECC384 G1",
    "Amazon RDS me-south-1 Root CA RSA4096 G1",
    "Amazon RDS ap-southeast-1 Root CA RSA2048 G1",
    "Amazon RDS ap-northeast-2 2019 CA",
    "Amazon RDS ca-west-1 Root CA RSA4096 G1",
    "Amazon RDS ap-northeast-1 2019 CA",
    "Amazon RDS me-central-1 Root CA RSA4096 G1",
    "Amazon RDS eu-south-1 Root CA RSA4096 G1",
    "Amazon RDS il-central-1 Root CA RSA4096 G1",
    "Amazon RDS eu-central-1 2019 CA",
    "Amazon RDS me-south-1 Root CA ECC384 G1",
    "Amazon RDS eu-south-2 Root CA ECC384 G1",
    "Amazon RDS us-west-1 Root CA ECC384 G1",
    "Amazon RDS Beta us-east-1 Root CA ECC384 G1",
    "Amazon RDS ap-northeast-3 Root CA RSA2048 G1",
    "Amazon RDS eu-north-1 Root CA RSA2048 G1",
    "Amazon RDS Preview us-east-2 Root CA RSA4096 G1",
    "Amazon RDS me-south-1 Root CA RSA2048 G1",
    "Amazon RDS us-east-2 2019 CA",
    "Amazon RDS ap-northeast-2 Root CA ECC384 G1",
    "Amazon RDS eu-west-1 Root CA ECC384 G1",
    "Amazon RDS ap-northeast-3 Root CA RSA4096 G1",
    "Amazon RDS ap-south-1 Root CA ECC384 G1",
    "Amazon RDS eu-south-2 Root CA RSA2048 G1",
    "Amazon RDS ca-west-1 Root CA ECC384 G1",
    "Amazon RDS ap-southeast-1 Root CA RSA4096 G1",
    "Amazon RDS ap-southeast-2 2019 CA",
    "Amazon RDS sa-east-1 2019 CA",
    "Amazon RDS Beta us-east-1 Root CA RSA4096 G1",
    "Amazon RDS us-east-1 2019 CA",
    "Amazon RDS Preview Root 2019 CA",
    "Amazon RDS Beta Root 2019 CA",
    "Amazon RDS us-west-2 2019 CA",
    "Amazon RDS ap-east-1 Root CA ECC384 G1",
    "Amazon RDS ap-southeast-2 Root CA RSA2048 G1",
    "Amazon RDS us-east-2 Root CA RSA4096 G1",
    "Amazon RDS sa-east-1 Root CA RSA2048 G1",
    "Amazon RDS ap-south-1 Root CA RSA2048 G1",
    "Amazon RDS us-west-1 Root CA RSA2048 G1",
    "Amazon RDS us-west-2 Root CA ECC384 G1",
    "Amazon RDS Preview us-east-2 Root CA ECC384 G1",
    "Amazon RDS me-central-1 Root CA ECC384 G1",
    "Amazon RDS af-south-1 Root CA ECC384 G1",
    "Amazon RDS us-east-2 Root CA RSA2048 G1",
    "Amazon RDS ap-southeast-2 Root CA RSA4096 G1",
    "Amazon RDS us-east-1 Root CA ECC384 G1",
    "Amazon RDS eu-west-2 2019 CA",
    "Amazon RDS ap-southeast-4 Root CA ECC384 G1",
    "Amazon RDS sa-east-1 Root CA RSA4096 G1",
    "Amazon RDS eu-west-3 Root CA ECC384 G1",
    "Amazon RDS me-south-1 CA",
    "Amazon RDS eu-west-3 Root CA RSA2048 G1",
    "Amazon RDS us-west-1 Root CA RSA4096 G1",
    "Amazon RDS eu-south-2 Root CA RSA4096 G1",
    "Amazon RDS eu-south-1 Root CA RSA2048 G1",
    "Amazon RDS af-south-1 Root CA RSA2048 G1",
    "Amazon RDS us-west-2 Root CA RSA2048 G1",
    "Amazon RDS ap-southeast-1 Root CA ECC384 G1",
    "Amazon RDS eu-north-1 Root CA ECC384 G1",
    "ACCVRAIZ1",
    "AC RAIZ FNMT-RCM SERVIDORES SEGUROS",
    "ANF Secure Server Root CA",
    "Actalis Authentication Root CA",
    "AffirmTrust Commercial",
    "AffirmTrust Networking",
    "AffirmTrust Premium",
    "AffirmTrust Premium ECC",
    "Amazon Root CA 1",
    "Amazon Root CA 2",
    "Amazon Root CA 3",
    "Amazon Root CA 4",
    "Atos TrustedRoot 2011",
    "Atos TrustedRoot Root CA ECC TLS 2021",
    "Atos TrustedRoot Root CA RSA TLS 2021",
    "Autoridad de Certificacion Firmaprofesional CIF A62634068",
    "BJCA Global Root CA1",
    "BJCA Global Root CA2",
    "Baltimore CyberTrust Root",
    "Buypass Class 2 Root CA",
    "Buypass Class 3 Root CA",
    "CA Disig Root R2",
    "CFCA EV ROOT",
    "COMODO Certification Authority",
    "COMODO ECC Certification Authority",
    "COMODO RSA Certification Authority",
    "Certainly Root E1",
    "Certainly Root R1",
    "Certigna",
    "Certigna Root CA",
    "Certum EC-384 CA",
    "Certum Trusted Network CA",
    "Certum Trusted Network CA 2",
    "Certum Trusted Root CA",
    "CommScope Public Trust ECC Root-01",
    "CommScope Public Trust ECC Root-02",
    "CommScope Public Trust RSA Root-01",
    "CommScope Public Trust RSA Root-02",
    "AAA Certificate Services",
    "D-TRUST BR Root CA 1 2020",
    "D-TRUST EV Root CA 1 2020",
    "D-TRUST Root Class 3 CA 2 2009",
    "D-TRUST Root Class 3 CA 2 EV 2009",
    "DigiCert Assured ID Root CA",
    "DigiCert Assured ID Root G2",
    "DigiCert Assured ID Root G3",
    "DigiCert Global Root CA",
    "DigiCert Global Root G2",
    "DigiCert Global Root G3",
    "DigiCert High Assurance EV Root CA",
    "DigiCert TLS ECC P384 Root G5",
    "DigiCert TLS RSA4096 Root G5",
    "DigiCert Trusted Root G4",
    "Entrust.net Certification Authority (2048)",
    "Entrust Root Certification Authority",
    "Entrust Root Certification Authority - EC1",
    "Entrust Root Certification Authority - G2",
    "Entrust Root Certification Authority - G4",
    "GDCA TrustAUTH R5 ROOT",
    "GLOBALTRUST 2020",
    "GTS Root R1",
    "GTS Root R2",
    "GTS Root R3",
    "GTS Root R4",
    "GlobalSign",
    "GlobalSign",
    "GlobalSign Root CA",
    "GlobalSign",
    "GlobalSign",
    "GlobalSign Root E46",
    "GlobalSign Root R46",
    "Go Daddy Root Certificate Authority - G2",
    "HARICA TLS ECC Root CA 2021",
    "HARICA TLS RSA Root CA 2021",
    "Hellenic Academic and Research Institutions ECC RootCA 2015",
    "Hellenic Academic and Research Institutions RootCA 2015",
    "HiPKI Root CA - G1",
    "Hongkong Post Root CA 3",
    "ISRG Root X1",
    "ISRG Root X2",
    "IdenTrust Commercial Root CA 1",
    "IdenTrust Public Sector Root CA 1",
    "Izenpe.com",
    "Microsec e-Szigno Root CA 2009",
    "Microsoft ECC Root Certificate Authority 2017",
    "Microsoft RSA Root Certificate Authority 2017",
    "NAVER Global Root Certification Authority",
    "NetLock Arany (Class Gold) Főtanúsítvány",
    "OISTE WISeKey Global Root GB CA",
    "OISTE WISeKey Global Root GC CA",
    "QuoVadis Root CA 1 G3",
    "QuoVadis Root CA 2",
    "QuoVadis Root CA 2 G3",
    "QuoVadis Root CA 3",
    "QuoVadis Root CA 3 G3",
    "SSL.com EV Root Certification Authority ECC",
    "SSL.com EV Root Certification Authority RSA R2",
    "SSL.com Root Certification Authority ECC",
    "SSL.com Root Certification Authority RSA",
    "SSL.com TLS ECC Root CA 2022",
    "SSL.com TLS RSA Root CA 2022",
    "SZAFIR ROOT CA2",
    "Sectigo Public Server Authentication Root E46",
    "Sectigo Public Server Authentication Root R46",
    "SecureSign RootCA11",
    "SecureTrust CA",
    "Secure Global CA",
    "Security Communication ECC RootCA1",
    "Security Communication RootCA3",
    "Starfield Root Certificate Authority - G2",
    "Starfield Services Root Certificate Authority - G2",
    "SwissSign Gold CA - G2",
    "SwissSign Silver CA - G2",
    "T-TeleSec GlobalRoot Class 2",
    "T-TeleSec GlobalRoot Class 3",
    "TUBITAK Kamu SM SSL Kok Sertifikasi - Surum 1",
    "TWCA Global Root CA",
    "TWCA Root Certification Authority",
    "TeliaSonera Root CA v1",
    "Telia Root CA v2",
    "TrustAsia Global Root CA G3",
    "TrustAsia Global Root CA G4",
    "Trustwave Global Certification Authority",
    "Trustwave Global ECC P256 Certification Authority",
    "Trustwave Global ECC P384 Certification Authority",
    "TunTrust Root CA",
    "UCA Extended Validation Root",
    "UCA Global G2 Root",
    "USERTrust ECC Certification Authority",
    "USERTrust RSA Certification Authority",
    "XRamp Global Certification Authority",
    "e-Szigno Root CA 2017",
    "emSign ECC Root CA - C3",
    "emSign ECC Root CA - G3",
    "emSign Root CA - C1",
    "emSign Root CA - G1",
    "vTrus ECC Root CA",
    "vTrus Root CA"
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment