2

I want to print SSL public key type:

certificate = ssl.get_server_certificate(serverAddress)
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, certificate)
pk = x509.get_pubkey()
print("Certificate public key type : " + keyTypeToStr(pk.type()))
def keyTypeToStr(keyType):
    if keyType == OpenSSL.crypto.TYPE_RSA:
        return "RSA"
    elif keyType == OpenSSL.crypto.TYPE_DSA:
        return "DSA"
    #elif keyType == OpenSSL.crypto.TYPE_ECDSA: # this enum doesn't exist
    #   return "ECDSA"

    return "UNKNOW(" + str(keyType) + ")"

Problem, it is a number... For example, I would like to print "secp256r1". How can I do it?

tripleee
  • 139,311
  • 24
  • 207
  • 268
ipStack
  • 61
  • 5
  • The EC `namedCurve` field is not present in the key type. For that you have to parse the ECDSA key data, not sure how to do that in Python+OpenSSL. – Robert Apr 20 '21 at 12:47

0 Answers0