This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Add set_post_handshake_auth for TLS 1.3
Type: behavior Stage: resolved
Components: SSL Versions: Python 3.8, Python 3.7, Python 3.6, Python 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: christian.heimes Nosy List: benjamin.peterson, christian.heimes, miss-islington, ned.deily, njs, xnox
Priority: normal Keywords: patch

Created on 2018-09-14 00:16 by christian.heimes, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 9460 merged christian.heimes, 2018-09-20 19:32
PR 9505 merged christian.heimes, 2018-09-23 06:41
PR 9507 merged christian.heimes, 2018-09-23 07:00
Messages (8)
msg325314 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2018-09-14 00:16
TLS 1.3 removed renegotiation in favor of rekeying and post handshake authentication (PHA). With PHA, a server can request a client certificate from a client at some point after the handshake. The feature is commonly used by HTTP server for conditional and path specific TLS client auth. For example a server can decide to require a cert based on HTTP method and/or path. A client must announce support for PHA during the handshake

Apache mod_ssl uses PHA,

As of OpenSSL ticket, TLS 1.3 clients no longer send the PHA TLS extension by default. Nikos and I requested the change, because PHA breaks some assumptions of TLS 1.2 clients. For on-demand auth, PHA extension must be enabled with SSL_CTX_set_post_handshake_auth(), .

I propose to add a property on SSLContext to enable PHA and backport the change to Python 2.7, 3.6 and 3.7.

In order to test the feature, I'd also have to add some flags and a function for the server side: (SSL_VERIFY_CLIENT_ONCE, SSL_VERIFY_POST_HANDSHAKE, SSL_verify_client_post_handshake()).
msg325973 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2018-09-21 08:00
Please note that SSL_verify_client_post_handshake() doesn't perform any IO by itself.

A typical scenario for HTTP looks like this (actual flow may vary):

* client
  * send ``HTTP GET /path``
* server
  * recv
  * verify_client_post_handshake
  * send HTTP Connection Upgrade (emits CertRequest message)
* client
  * recv
  * send upgrade confirmation (emits Certificate, CertificateVerify, Finish message)
* server
  * recv
  * verify certificate
  * send payload or error (may emit TLS alert for unknown, invalid, or missing cert)
* client
  * recv (receive TLS alert or server response)
msg326138 - (view) Author: miss-islington (miss-islington) Date: 2018-09-23 06:32
New changeset 9fb051f032c36b9f6086b79086b4d6b7755a3d70 by Miss Islington (bot) (Christian Heimes) in branch 'master':
bpo-34670: Add TLS 1.3 post handshake auth (GH-9460)
msg326141 - (view) Author: miss-islington (miss-islington) Date: 2018-09-23 07:22
New changeset 2756ef31656399a120589b7aa19c32e2b91a4758 by Miss Islington (bot) (Christian Heimes) in branch '3.7':
[3.7] bpo-34670: Add TLS 1.3 post handshake auth (GH-9460) (GH-9505)
msg326142 - (view) Author: miss-islington (miss-islington) Date: 2018-09-23 07:23
New changeset 94812f717dde8b11a9ad9c0fd5be66ff9bd53f58 by Miss Islington (bot) (Christian Heimes) in branch '3.6':
[3.6] bpo-34670: Add TLS 1.3 post handshake auth (GH-9460) (GH-9507)
msg326458 - (view) Author: Dimitri John Ledkov (xnox) * Date: 2018-09-26 12:32
Will this be backported to the 2.7 branch as well? Pretty please =)
msg327932 - (view) Author: Nathaniel Smith (njs) * (Python committer) Date: 2018-10-18 04:23
FYI Christian, your "typical scenario for HTTP" doesn't make sense to me... you can't send HTTP Connection Upgrade in the middle of a regular request/response cycle. I feel like the typical scenario ought to be more like:

* client
  * send ``HTTP GET /path``
* server
  * recv
  * verify_client_post_handshake (maybe... via calling SSL_do_handshake again?)
* client
  * recv
  * send upgrade confirmation (emits Certificate, CertificateVerify, Finish message)
* server
  * recv
  * verify certificate
  * send either the requested response, or a 401 Unauthorized depending

But I don't really understand the underlying design here, either at the TLS 1.3 level or the openssl level, and haven't found very useful docs yet, so I could be wrong.
msg391394 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2021-04-19 19:53
I don't think is anything left to do here. PHA has been supported for a while and I haven't seen any problems.
Date User Action Args
2022-04-11 14:59:05adminsetgithub: 78851
2021-04-19 19:53:59christian.heimessetstatus: open -> closed
resolution: fixed
messages: + msg391394

stage: patch review -> resolved
2018-10-18 04:23:03njssetnosy: + njs
messages: + msg327932
2018-09-26 12:32:36xnoxsetnosy: + xnox
messages: + msg326458
2018-09-23 07:23:05miss-islingtonsetmessages: + msg326142
2018-09-23 07:22:56miss-islingtonsetmessages: + msg326141
2018-09-23 07:00:03christian.heimessetpull_requests: + pull_request8914
2018-09-23 06:41:45christian.heimessetpull_requests: + pull_request8912
2018-09-23 06:32:35miss-islingtonsetnosy: + miss-islington
messages: + msg326138
2018-09-21 08:00:36christian.heimessetmessages: + msg325973
2018-09-20 19:32:19christian.heimessetkeywords: + patch
stage: needs patch -> patch review
pull_requests: + pull_request8874
2018-09-14 00:16:08christian.heimescreate