Skip to content

Commit dfa734b

Browse files
committed
Python: Export the TBSCertificate
Add a method to export the TBSCertificate part of the certificate. In RFC6962-bis, the signature in the SCT for X.509 certs does not cover the entire certificate, but the TBSCertificate and the issuer key hash. To implement issuance of V2 SCTs, access to the TBSCertificate is necessary.
1 parent d6b35b7 commit dfa734b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

python/ct/crypto/cert.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ def get_extensions(self):
221221
"""
222222
return self._asn1_cert["tbsCertificate"]["extensions"] or []
223223

224+
def tbscertificate(self):
225+
"""Returns the underlying tbsCertificate
226+
227+
Returns:
228+
An x509.TBSCertificate instance.
229+
"""
230+
return self._asn1_cert["tbsCertificate"]
231+
224232
def version(self):
225233
"""Get the version.
226234

python/ct/crypto/cert_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
from ct.crypto import cert
88
from ct.crypto import error
99
from ct.crypto.asn1 import oid
10+
from ct.crypto.asn1 import x509_common
1011
from ct.crypto.asn1 import x509_extension as x509_ext
1112
from ct.crypto.asn1 import x509_name
13+
from ct.crypto.asn1 import x509
1214
from ct.test import test_config
1315

1416
class CertificateTest(unittest.TestCase):
@@ -724,6 +726,14 @@ def test_get_extensions(self):
724726
oid.ID_CE_CRL_DISTRIBUTION_POINTS),
725727
extensions_oids)
726728

729+
def test_tbscertificate(self):
730+
c = self.cert_from_pem_file(self._PEM_FILE)
731+
tbs = c.tbscertificate()
732+
self.assertTrue(isinstance(tbs, x509.TBSCertificate))
733+
self.assertEqual(
734+
x509_common.CertificateSerialNumber(454887626504608315115709L),
735+
tbs["serialNumber"])
736+
727737
def test_indefinite_encoding(self):
728738
self.assertRaises(error.ASN1Error, self.cert_from_pem_file,
729739
self._PEM_INDEFINITE_LENGTH)

0 commit comments

Comments
 (0)