From: Benjamin Peterson Date: Thu, 5 Mar 2015 03:11:12 +0000 (-0500) Subject: enable X509_V_FLAG_TRUSTED_FIRST when possible (closes #23476) X-Git-Tag: v2.7.10rc1~145 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b1ebba5bd569ede9b6f9573d6618fb3a6abddae5;p=thirdparty%2FPython%2Fcpython.git enable X509_V_FLAG_TRUSTED_FIRST when possible (closes #23476) --- diff --git a/Misc/NEWS b/Misc/NEWS index c480033fcaa6..1999d844e84a 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -18,6 +18,9 @@ Core and Builtins Library ------- +- Issue #23476: In the ssl module, enable OpenSSL's X509_V_FLAG_TRUSTED_FIRST + flag on certificate stores when it is available. + - Issue #23576: Avoid stalling in SSL reads when EOF has been reached in the SSL layer but the underlying connection hasn't been closed. diff --git a/Modules/_ssl.c b/Modules/_ssl.c index f9d66a1dd9c9..309d00bf783c 100644 --- a/Modules/_ssl.c +++ b/Modules/_ssl.c @@ -2072,6 +2072,15 @@ context_new(PyTypeObject *type, PyObject *args, PyObject *kwds) sizeof(SID_CTX)); #undef SID_CTX +#ifdef X509_V_FLAG_TRUSTED_FIRST + { + /* Improve trust chain building when cross-signed intermediate + certificates are present. See https://bugs.python.org/issue23476. */ + X509_STORE *store = SSL_CTX_get_cert_store(self->ctx); + X509_STORE_set_flags(store, X509_V_FLAG_TRUSTED_FIRST); + } +#endif + return (PyObject *)self; }