Skip to content

Commit 6b79947

Browse files
authored
Fix generated test X.509 certificates. (#917)
From RFC 5280, section 4.1.2.9: [Extensions] MUST only appear if the version is 3 (Section 4.1.2.1). If present, this field is a SEQUENCE of one or more certificate extensions. The format and content of certificate extensions in the Internet PKI are defined in Section 4.2. X509 objects default to v1, so the test certs need a set_version(2) call. (Note v3 is encoded as 2.)
1 parent 2dca7a7 commit 6b79947

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

tests/test_crypto.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,6 +1729,9 @@ def test_digest(self):
17291729

17301730
def _extcert(self, pkey, extensions):
17311731
cert = X509()
1732+
# Certificates with extensions must be X.509v3, which is encoded with a
1733+
# version of two.
1734+
cert.set_version(2)
17321735
cert.set_pubkey(pkey)
17331736
cert.get_subject().commonName = "Unit Tests"
17341737
cert.get_issuer().commonName = "Unit Tests"

tests/test_ssl.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ def _create_certificate_chain():
199199
cakey = PKey()
200200
cakey.generate_key(TYPE_RSA, 1024)
201201
cacert = X509()
202+
cacert.set_version(2)
202203
cacert.get_subject().commonName = "Authority Certificate"
203204
cacert.set_issuer(cacert.get_subject())
204205
cacert.set_pubkey(cakey)
@@ -212,6 +213,7 @@ def _create_certificate_chain():
212213
ikey = PKey()
213214
ikey.generate_key(TYPE_RSA, 1024)
214215
icert = X509()
216+
icert.set_version(2)
215217
icert.get_subject().commonName = "Intermediate Certificate"
216218
icert.set_issuer(cacert.get_subject())
217219
icert.set_pubkey(ikey)
@@ -225,6 +227,7 @@ def _create_certificate_chain():
225227
skey = PKey()
226228
skey.generate_key(TYPE_RSA, 1024)
227229
scert = X509()
230+
scert.set_version(2)
228231
scert.get_subject().commonName = "Server Certificate"
229232
scert.set_issuer(icert.get_subject())
230233
scert.set_pubkey(skey)

0 commit comments

Comments
 (0)