cpython: 63df21e74c65 (original) (raw)

Mercurial > cpython

changeset 87422:63df21e74c65

Issue #19689: Add ssl.create_default_context() factory function. It creates a new SSLContext object with secure default settings. [#19689]

Christian Heimes christian@cheimes.de
date Sat, 23 Nov 2013 15:58:30 +0100
parents 9ee40eec0180
children 16dd19aa64c8
files Doc/library/ssl.rst Lib/ssl.py Lib/test/test_ssl.py Misc/NEWS
diffstat 4 files changed, 76 insertions(+), 0 deletions(-)[+] [-] Doc/library/ssl.rst 18 Lib/ssl.py 35 Lib/test/test_ssl.py 20 Misc/NEWS 3

line wrap: on

line diff

--- a/Doc/library/ssl.rst +++ b/Doc/library/ssl.rst @@ -346,6 +346,24 @@ Certificate handling .. versionchanged:: 3.3 This function is now IPv6-compatible. +.. function:: create_default_context(purpose=Purpose.SERVER_AUTH, cafile=None, capath=None, cadata=None) +

+

.. function:: DER_cert_to_PEM_cert(DER_cert_bytes) Given a certificate as a DER-encoded blob of bytes, returns a PEM-encoded

--- a/Lib/ssl.py +++ b/Lib/ssl.py @@ -165,6 +165,13 @@ else:

(OpenSSL's default setting is 'DEFAULT:!aNULL:!eNULL')

_DEFAULT_CIPHERS = 'DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2' +# restricted and more secure ciphers +# HIGH: high encryption cipher suites with key length >= 128 bits (no MD5) +# !aNULL: only authenticated cipher suites (no anonymous DH) +# !RC4: no RC4 streaming cipher, RC4 is broken +# !DSS: RSA is preferred over DSA +_RESTRICTED_CIPHERS = 'HIGH:!aNULL:!RC4:!DSS' + class CertificateError(ValueError): pass @@ -363,6 +370,34 @@ class SSLContext(_SSLContext): self.set_default_verify_paths() +def create_default_context(purpose=Purpose.SERVER_AUTH, *, cafile=None,

+

+ + class SSLSocket(socket): """This class implements a subtype of socket.socket that wraps the underlying OS socket in an SSL context when necessary, and

--- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -999,6 +999,26 @@ class ContextTests(unittest.TestCase): self.assertRaises(TypeError, ctx.load_default_certs, None) self.assertRaises(TypeError, ctx.load_default_certs, 'SERVER_AUTH')

+

+

+ + class SSLErrorTests(unittest.TestCase):

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -68,6 +68,9 @@ Core and Builtins Library ------- +- Issue #19689: Add ssl.create_default_context() factory function. It creates