/usr/lib/python3/dist-packages/tlslite/x509certchain.py is in python3-tlslite-ng 0.5.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | # Author: Trevor Perrin
# See the LICENSE file for legal information regarding use of this file.
"""Class representing an X.509 certificate chain."""
from .utils import cryptomath
from .utils.tackwrapper import *
from .utils.pem import *
from .x509 import X509
class X509CertChain(object):
"""This class represents a chain of X.509 certificates.
@type x509List: list
@ivar x509List: A list of L{tlslite.x509.X509} instances,
starting with the end-entity certificate and with every
subsequent certificate certifying the previous.
"""
def __init__(self, x509List=None):
"""Create a new X509CertChain.
@type x509List: list
@param x509List: A list of L{tlslite.x509.X509} instances,
starting with the end-entity certificate and with every
subsequent certificate certifying the previous.
"""
if x509List:
self.x509List = x509List
else:
self.x509List = []
def parsePemList(self, s):
"""Parse a string containing a sequence of PEM certs.
Raise a SyntaxError if input is malformed.
"""
x509List = []
bList = dePemList(s, "CERTIFICATE")
for b in bList:
x509 = X509()
x509.parseBinary(b)
x509List.append(x509)
self.x509List = x509List
def getNumCerts(self):
"""Get the number of certificates in this chain.
@rtype: int
"""
return len(self.x509List)
def getEndEntityPublicKey(self):
"""Get the public key from the end-entity certificate.
@rtype: L{tlslite.utils.rsakey.RSAKey}
"""
if self.getNumCerts() == 0:
raise AssertionError()
return self.x509List[0].publicKey
def getFingerprint(self):
"""Get the hex-encoded fingerprint of the end-entity certificate.
@rtype: str
@return: A hex-encoded fingerprint.
"""
if self.getNumCerts() == 0:
raise AssertionError()
return self.x509List[0].getFingerprint()
def checkTack(self, tack):
if self.x509List:
tlsCert = TlsCertificate(self.x509List[0].bytes)
if tlsCert.matches(tack):
return True
return False
def getTackExt(self):
"""Get the TACK and/or Break Sigs from a TACK Cert in the chain."""
tackExt = None
# Search list in backwards order
for x509 in self.x509List[::-1]:
tlsCert = TlsCertificate(x509.bytes)
if tlsCert.tackExt:
if tackExt:
raise SyntaxError("Multiple TACK Extensions")
else:
tackExt = tlsCert.tackExt
return tackExt
|