Skip to content

Commit fdb1971

Browse files
committed
enable X509_V_FLAG_TRUSTED_FIRST when possible (closes #23476)
1 parent 20f4bd4 commit fdb1971

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ Core and Builtins
1313
Library
1414
-------
1515

16+
- Issue #23476: In the ssl module, enable OpenSSL's X509_V_FLAG_TRUSTED_FIRST
17+
flag on certificate stores when it is available.
18+
1619
- Issue #23576: Avoid stalling in SSL reads when EOF has been reached in the
1720
SSL layer but the underlying connection hasn't been closed.
1821

Modules/_ssl.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,15 @@ context_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
20632063
sizeof(SID_CTX));
20642064
#undef SID_CTX
20652065

2066+
#ifdef X509_V_FLAG_TRUSTED_FIRST
2067+
{
2068+
/* Improve trust chain building when cross-signed intermediate
2069+
certificates are present. See https://bugs.python.org/issue23476. */
2070+
X509_STORE *store = SSL_CTX_get_cert_store(self->ctx);
2071+
X509_STORE_set_flags(store, X509_V_FLAG_TRUSTED_FIRST);
2072+
}
2073+
#endif
2074+
20662075
return (PyObject *)self;
20672076
}
20682077

0 commit comments

Comments
 (0)