f8bb41
From c9ed53c284a6747f17366eab71ba8922e33910e2 Mon Sep 17 00:00:00 2001
f8bb41
From: Lumir Balhar <lbalhar@redhat.com>
f8bb41
Date: Wed, 28 Aug 2019 14:55:26 +0200
f8bb41
Subject: [PATCH] Backported patch from:
f8bb41
 https://github.com/urllib3/urllib3/commit/6a626be4ff623c25270e20db9002705bf4504e4e
f8bb41
f8bb41
Enable TLS 1.3 post-handshake authentication
f8bb41
---
f8bb41
 src/urllib3/util/ssl_.py |  7 +++++++
f8bb41
 test/test_ssl.py         | 15 +++++++++++++++
f8bb41
 2 files changed, 22 insertions(+)
f8bb41
f8bb41
diff --git a/src/urllib3/util/ssl_.py b/src/urllib3/util/ssl_.py
f8bb41
index 5ae4358..7dc4a5a 100644
f8bb41
--- a/src/urllib3/util/ssl_.py
f8bb41
+++ b/src/urllib3/util/ssl_.py
f8bb41
@@ -280,6 +280,13 @@ def create_urllib3_context(ssl_version=None, cert_reqs=None,
f8bb41
 
f8bb41
     context.options |= options
f8bb41
 
f8bb41
+    # Enable post-handshake authentication for TLS 1.3, see GH #1634. PHA is
f8bb41
+    # necessary for conditional client cert authentication with TLS 1.3.
f8bb41
+    # The attribute is None for OpenSSL <= 1.1.0 or does not exist in older
f8bb41
+    # versions of Python.
f8bb41
+    if getattr(context, "post_handshake_auth", None) is not None:
f8bb41
+        context.post_handshake_auth = True
f8bb41
+
f8bb41
     context.verify_mode = cert_reqs
f8bb41
     if getattr(context, 'check_hostname', None) is not None:  # Platform-specific: Python 3.2
f8bb41
         # We do our own verification, including fingerprints and alternative
f8bb41
diff --git a/test/test_ssl.py b/test/test_ssl.py
f8bb41
index 6a46b4f..3a99522 100644
f8bb41
--- a/test/test_ssl.py
f8bb41
+++ b/test/test_ssl.py
f8bb41
@@ -125,3 +125,18 @@ def test_wrap_socket_default_loads_default_certs(monkeypatch):
f8bb41
     ssl_.ssl_wrap_socket(sock)
f8bb41
 
f8bb41
     context.load_default_certs.assert_called_with()
f8bb41
+
f8bb41
+
f8bb41
+@pytest.mark.parametrize(
f8bb41
+    ["pha", "expected_pha"], [(None, None), (False, True), (True, True)]
f8bb41
+)
f8bb41
+def test_create_urllib3_context_pha(monkeypatch, pha, expected_pha):
f8bb41
+    context = mock.create_autospec(ssl_.SSLContext)
f8bb41
+    context.set_ciphers = mock.Mock()
f8bb41
+    context.options = 0
f8bb41
+    context.post_handshake_auth = pha
f8bb41
+    monkeypatch.setattr(ssl_, "SSLContext", lambda *_, **__: context)
f8bb41
+
f8bb41
+    assert ssl_.create_urllib3_context() is context
f8bb41
+
f8bb41
+    assert context.post_handshake_auth == expected_pha
f8bb41
-- 
f8bb41
2.21.0
f8bb41