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

Class CertList

scapy/layers/tls/cert.py:1452–1535  ·  view source on GitHub ↗

An object that can store a list of Cert objects, load them and export them into DER/PEM format.

Source from the content-addressed store, hash-verified

1450
1451
1452class CertList(list):
1453 """
1454 An object that can store a list of Cert objects, load them and export them
1455 into DER/PEM format.
1456 """
1457
1458 def __init__(
1459 self,
1460 certList: Union[Self, List[Cert], List[CSR], Cert, str],
1461 ):
1462 """
1463 Construct a list of certificates/CRLs to be used as list of ROOT certificates.
1464 """
1465 # Parse the certificate list / CA
1466 if isinstance(certList, str):
1467 # It's a path. First get the _PKIObj
1468 obj = _PKIObjMaker.__call__(
1469 CertList, certList, _MAX_CERT_SIZE, "CERTIFICATE"
1470 )
1471
1472 # Then parse the der until there's nothing left
1473 certList = []
1474 payload = obj._der
1475 while payload:
1476 cert = X509_Cert(payload)
1477 if conf.raw_layer in cert.payload:
1478 payload = cert.payload.load
1479 else:
1480 payload = None
1481 cert.remove_payload()
1482 certList.append(Cert(cert))
1483
1484 self.frmt = obj.frmt
1485 elif isinstance(certList, Cert):
1486 certList = [certList]
1487 self.frmt = "PEM"
1488 else:
1489 self.frmt = "PEM"
1490
1491 super(CertList, self).__init__(certList)
1492
1493 def findCertBySid(self, sid):
1494 """
1495 Find a certificate in the list by SubjectIDentifier.
1496 """
1497 for cert in self:
1498 if isinstance(cert, Cert) and isinstance(sid, CMS_IssuerAndSerialNumber):
1499 if cert.issuer == sid.get_issuer():
1500 return cert
1501 elif isinstance(cert, CSR) and isinstance(sid, CMS_SubjectKeyIdentifier):
1502 if cert.sid == sid.sid:
1503 return cert
1504 raise KeyError("Certificate not found !")
1505
1506 def export(self, filename, fmt=None):
1507 """
1508 Export a list of certificates 'fmt' format (DER or PEM) to file 'filename'
1509 """

Callers 2

__init__Method · 0.90
__init__Method · 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…