MCPcopy Create free account
hub / github.com/secdev/scapy / Cert

Class Cert

scapy/layers/tls/cert.py:943–1176  ·  view source on GitHub ↗

Wrapper for the X509_Cert from layers/x509.py. Use the 'x509Cert' attribute to access original object.

Source from the content-addressed store, hash-verified

941
942
943class Cert(metaclass=_CertMaker):
944 """
945 Wrapper for the X509_Cert from layers/x509.py.
946 Use the 'x509Cert' attribute to access original object.
947 """
948
949 def import_from_asn1pkt(self, cert):
950 error_msg = "Unable to import certificate"
951
952 self.x509Cert = cert
953
954 tbsCert = cert.tbsCertificate
955
956 if tbsCert.version:
957 self.version = tbsCert.version.val + 1
958 else:
959 self.version = 1
960 self.serial = tbsCert.serialNumber.val
961 self.sigAlg = tbsCert.signature.algorithm.oidname
962 self.issuer = tbsCert.get_issuer()
963 self.issuer_str = tbsCert.get_issuer_str()
964 self.issuer_hash = hash(self.issuer_str)
965 self.subject = tbsCert.get_subject()
966 self.subject_str = tbsCert.get_subject_str()
967 self.subject_hash = hash(self.subject_str)
968 self.authorityKeyID = None
969
970 self.notBefore_str = tbsCert.validity.not_before.pretty_time
971 try:
972 self.notBefore = tbsCert.validity.not_before.datetime.timetuple()
973 except ValueError:
974 raise Exception(error_msg)
975 self.notBefore_str_simple = time.strftime("%x", self.notBefore)
976
977 self.notAfter_str = tbsCert.validity.not_after.pretty_time
978 try:
979 self.notAfter = tbsCert.validity.not_after.datetime.timetuple()
980 except ValueError:
981 raise Exception(error_msg)
982 self.notAfter_str_simple = time.strftime("%x", self.notAfter)
983
984 self.pubkey = PubKey(bytes(tbsCert.subjectPublicKeyInfo))
985
986 if tbsCert.extensions:
987 for extn in tbsCert.extensions:
988 if extn.extnID.oidname == "basicConstraints":
989 self.cA = False
990 if extn.extnValue.cA:
991 self.cA = not (extn.extnValue.cA.val == 0)
992 elif extn.extnID.oidname == "keyUsage":
993 self.keyUsage = extn.extnValue.get_keyUsage()
994 elif extn.extnID.oidname == "extKeyUsage":
995 self.extKeyUsage = extn.extnValue.get_extendedKeyUsage()
996 elif extn.extnID.oidname == "authorityKeyIdentifier":
997 self.authorityKeyID = extn.extnValue.keyIdentifier.val
998
999 self.signatureValue = bytes(cert.signatureValue)
1000 self.signatureLen = len(self.signatureValue)

Callers 10

fromsslMethod · 0.90
__init__Method · 0.90
parse_argsMethod · 0.90
getfieldMethod · 0.90
getfieldMethod · 0.90
getfieldMethod · 0.90
gen_alike_chainMethod · 0.85
__init__Method · 0.85
verifyMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…