证书内容:
MIIDhDCCAmygAwIBAgIFAV0Imw0wDQYJKoZIhvcNAQELBQAwXDEnMCUGA1UEAwweczUwLTYyLTEzNS0xNS5zZWN1cmVzZXJ2ZXIubmV0MTEwLwYJKoZIhvcNAQkBFiJzc2xAczUwLTYyLTEzNS0xNS5zZWN1cmVzZXJ2ZXIubmV0MB4XDTE4MDQyMjA3NTE0MVoXDTE5MDQyMjA3NTE0MVowXDEnMCUGA1UEAwweczUwLTYyLTEzNS0xNS5zZWN1cmVzZXJ2ZXIubmV0MTEwLwYJKoZIhvcNAQkBFiJzc2xAczUwLTYyLTEzNS0xNS5zZWN1cmVzZXJ2ZXIubmV0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwOgVQHLrxZruiiMGHQyEmCWwPpDLoxlMZboD4XpMKScxfCWYMeHgygEImagDCNzQdGgJeQ
到https://www.sslshopper.com/certificate-decoder.html 去解码下:
可以看到结果为:
Certificate Information:
Common Name: s50-62-135-15.secureserver.net
Valid From: April 22, 2018
Valid To: April 22, 2019
Serial Number: 5855812365 (0x15d089b0d)
使用python完成同样的事情:
from asn1crypto import x509
import base64
if __name__ == "__main__":
st_cert64 = "MIIDhDCCAmygAwIBAgIFAV0Imw0wDQYJKoZIhvcNAQELBQAwXDEnMCUGA1UEAwweczUwLTYyLTEzNS0xNS5zZWN1cmVzZXJ2ZXIubmV0MTEwLwYJKoZIhvcNAQkBFiJzc2xAczUwLTYyLTEzNS0xNS5zZWN1cmVzZXJ2ZXIubmV0MB4XDTE4MDQyMjA3NTE0MVoXDTE5MDQyMjA3NTE0MVowXDEnMCUGA1UEAwweczUwLTYyLTEzNS0xNS5zZWN1cmVzZXJ2ZXIubmV0MTEwLwYJKoZIhvcNAQkBFiJzc2xAczUwLTYyLTEzNS0xNS5zZWN1cmVzZXJ2ZXIubmV0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwOgVQHLrxZruiiMGHQyEmCWwPpDLoxlMZboD4XpMKScxfCWYMeHgygEImagDCNzQdGgJeQ/CvUcS7/4ziYSlAbuNlQygfif+E3KdwsZ93QDZW8V0EsD64nU1lftu4svfCclg01PCjArn1ql5yP8A3ur+Gp0Fz9SdciJVy8N2nK2QU8r2GTlLJHRbuQ7jjgYUvVvt5ykTiqE2GFL2bf6kNZISm65U/wn8E3j9WXlTaakzdm5hDdmFdBuKdZYLZO33PJlJ39sekmt+eo32z9RFXKHCBqNN2AwXPhxITeir8PokjJyv0QHB9/L++dWWs1dCsGchTavwfcXLKnbNk0AtQwIDAQABo00wSzAdBgNVHQ4EFgQUyMRlELq4JmdTDH/3aINzdN0JCBEwHwYDVR0jBBgwFoAUyMRlELq4JmdTDH/3aINzdN0JCBEwCQYDVR0TBAIwADANBgkqhkiG9w0BAQsFAAOCAQEAgEz4bp2pqlazup3HqFntquyhSiuUyx3ad/Am9lsTKq31rwbriSL2F6I3I+5bB2I9/B82vKKcqsY5ZhblDgBvvqKgV7tP5xE3k8P2wu+IE5iBEdqUAv8C5V+D3zlI1M0OXjCi4/kphwYJVKn0WPI/imjQbN/6q03ItApG2tUmmm76x+VBDtwk7VSFngfGDyL90dkH1UgxrCPGGLMUX21GgbdEB0Md7vax+yAXxNg4joc67CsZ5B9XaFhZDKGKSPrM6oORnsYkdAXNw17CtbL2Trwd1IVsQOGymKqko9LEeWgyq8GpRsFCX+WMC4RqsNt8Pm8PwLd2OhgeaCbhfJkKyQ=="
st_cert=base64.b64decode(st_cert64) ;
cert = x509.Certificate.load(st_cert)
print(cert)
print(cert.subject)
print(cert.serial_number)
#print(dir(cert))