Skip to content

Commit 5fa9c85

Browse files
committed
bpo-18369: Add certificate and private key types
Signed-off-by: Christian Heimes <christian@python.org>
1 parent bd5c7d2 commit 5fa9c85

File tree

12 files changed

+1850
-25
lines changed

12 files changed

+1850
-25
lines changed

Lib/ssl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
import _ssl # if we can't import it, let the error propagate
101101

102102
from _ssl import OPENSSL_VERSION_NUMBER, OPENSSL_VERSION_INFO, OPENSSL_VERSION
103-
from _ssl import _SSLContext, MemoryBIO, SSLSession
103+
from _ssl import _SSLContext, MemoryBIO, SSLSession, Certificate, PrivateKey
104104
from _ssl import (
105105
SSLError, SSLZeroReturnError, SSLWantReadError, SSLWantWriteError,
106106
SSLSyscallError, SSLEOFError, SSLCertVerificationError

Lib/test/test_ssl.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,24 @@ def getpass(self):
10921092
# Make sure the password function isn't called if it isn't needed
10931093
ctx.load_cert_chain(CERTFILE, password=getpass_exception)
10941094

1095+
def test_load_cert_privkey(self):
1096+
chain = ssl.Certificate.chain_from_file(ONLYCERT)
1097+
self.assertEqual(len(chain), 1)
1098+
cas = ssl.Certificate.bundle_from_file(SIGNING_CA)
1099+
self.assertEqual(len(cas), 1)
1100+
pkey = ssl.PrivateKey.from_file(ONLYKEY)
1101+
1102+
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
1103+
ctx.load_cert_chain(chain, pkey)
1104+
ctx.load_verify_locations(cadata=cas)
1105+
self.assertEqual(len(ctx.get_ca_certs()), 1)
1106+
1107+
pkey = ssl.PrivateKey.from_file(
1108+
ONLYKEY_PROTECTED, password=KEY_PASSWORD
1109+
)
1110+
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
1111+
ctx.load_cert_chain(chain, pkey)
1112+
10951113
def test_load_verify_locations(self):
10961114
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
10971115
ctx.load_verify_locations(CERTFILE)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Certificate and PrivateKey classes were added to the ssl module.
2+
Certificates and keys can now be loaded from memory buffer, too.

0 commit comments

Comments
 (0)