[python] M2Crypto를 사용하여 X.509 인증서의 키 사용 용도를 확인하는 방법은 어떻게 되나요?

먼저, M2Crypto 모듈을 설치합니다.

pip install M2Crypto

다음으로, 아래의 Python 코드를 사용하여 X.509 인증서의 키 사용 용도를 확인할 수 있습니다.

from M2Crypto import X509

def check_key_usage(cert_file):
    cert = X509.load_cert(cert_file)
    ext = cert.get_ext('keyUsage')
    if ext:
        print(f"Key Usage: {ext.get_value()}")
    else:
        print("Key Usage extension not found")

check_key_usage('path_to_cert_file.pem')

위의 코드를 사용하면 주어진 X.509 인증서에서 키 사용 용도를 확인할 수 있습니다. 코드를 실행하면 인증서의 키 사용 용도에 대한 정보가 출력됩니다.

참고 문헌: M2Crypto 라이브러리 문서: https://gitlab.com/m2crypto/m2crypto/-/wikis/Documents