Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign up[bpo-28414] Make all hostnames in SSL module IDN A-labels #5128
Conversation
tiran
requested review from
1st1 and
asvetlov
as
code owners
Jan 7, 2018
the-knights-who-say-ni
added
the
CLA signed
label
Jan 7, 2018
bedevere-bot
added
the
awaiting merge
label
Jan 7, 2018
tiran
referenced this pull request
Jan 7, 2018
Closed
[bpo-28414] In SSL module, store server_hostname as an A-label #3010
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
njsmith
Jan 10, 2018
Contributor
I did a quick skim and the code seems fine to me, but... I do think that for set_servername_callback
, instead of just breaking things we maybe we need to rename it and add a compatibility shim. Quoting from https://mail.python.org/pipermail/python-dev/2017-December/151527.html:
On the server, the obvious fix would be to start passing
A-label-encoded names to the servername_callback, instead of
U-label-encoded names. Unfortunately, this is a bit trickier, because
this has historically worked (AFAIK) for IDNA names, so long as they
didn't use one of the four magic characters who changed meaning
between IDNA 2003 and IDNA 2008. But we do still need to do something.
For example, right now, it's impossible to use the ssl module to
implement a web server at https://straße.de, because incoming
connections will use SNI to say that they expect a cert for
"xn--strae-oqa.de", and then the ssl module will freak out and throw
an exception instead of invoking the servername callback.It's ugly, but probably the simplest thing is to add a new function
likeset_servername_callback2
that uses the A-label, and then redefine
set_servername_callback
as a deprecated compatibility shim:def set_servername_callback(self, cb): def shim_cb(sslobj, servername, sslctx): if servername is not None: servername = servername.encode("ascii").decode("idna") return cb(sslobj, servername, sslctx) self.set_servername_callback2(shim_cb)We can bikeshed what the new name should be. Maybe
set_sni_callback
?
orset_server_hostname_callback
, since the corresponding client-mode
argument isserver_hostname
?
I did a quick skim and the code seems fine to me, but... I do think that for
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
tiran
Jan 13, 2018
Member
Meh! :(
Let's make it PEP 543 compatible and add sni_callback
property. The Python subclass can provide your shim cb. Thanks for proposing it!
Meh! :( Let's make it PEP 543 compatible and add |
tiran
referenced this pull request
Jan 19, 2018
Merged
bpo-32598: Use autoconf to detect usable OpenSSL #5242
tiran
added
the
DO-NOT-MERGE
label
Jan 26, 2018
njsmith
and others
added some commits
Aug 6, 2017
tiran
added
needs backport to 3.7
and removed
DO-NOT-MERGE
labels
Feb 22, 2018
tiran
changed the title from
[bpo-28414][WIP] Make all hostnames in SSL module IDN A-labels
to
[bpo-28414] Make all hostnames in SSL module IDN A-labels
Feb 22, 2018
tiran
requested a review
from
njsmith
Feb 22, 2018
njsmith
added some commits
Feb 23, 2018
njsmith
reviewed
Feb 23, 2018
I pushed some prose changes, and here are some comments on the code. Overall looks good, but there are a few small cleanups to consider, and a few points where I have questions.
@@ -355,13 +355,20 @@ def __new__(cls, protocol=PROTOCOL_TLS, *args, **kwargs): | ||
self = _SSLContext.__new__(cls, protocol) | ||
return self | ||
def __init__(self, protocol=PROTOCOL_TLS): | ||
self.protocol = protocol | ||
def _encode_hostname(self, hostname): |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
tiran
Feb 23, 2018
Member
I'd prefer to keep this a method. It makes it easier to modify the behavior in subclasses or in tests.
tiran
Feb 23, 2018
Member
I'd prefer to keep this a method. It makes it easier to modify the behavior in subclasses or in tests.
{"options", (getter) get_options, | ||
(setter) set_options, NULL}, | ||
{"protocol", (getter) get_protocol, | ||
NULL, NULL}, |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
njsmith
Feb 23, 2018
Contributor
Why is this new protocol
attribute in this PR? Should it be documented or anything?
njsmith
Feb 23, 2018
Contributor
Why is this new protocol
attribute in this PR? Should it be documented or anything?
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
tiran
Feb 23, 2018
Member
It's not new: https://docs.python.org/3/library/ssl.html#ssl.SSLContext.protocol
I just moved it from Python code into C code so I can access the value from C methods. The new setter for the callback uses the value to prevent setting a SNI callback for a client-only context.
tiran
Feb 23, 2018
Member
It's not new: https://docs.python.org/3/library/ssl.html#ssl.SSLContext.protocol
I just moved it from Python code into C code so I can access the value from C methods. The new setter for the callback uses the value to prevent setting a SNI callback for a client-only context.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
The context special handling is pining for the fjords. |
njsmith
merged commit 11a1493
into
python:master
Feb 24, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
miss-islington
commented
Feb 24, 2018
bedevere-bot
removed
the
awaiting merge
label
Feb 24, 2018
added a commit
to miss-islington/cpython
that referenced
this pull request
Feb 24, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
bedevere-bot
commented
Feb 24, 2018
GH-5843 is a backport of this pull request to the 3.7 branch. |
tiran commentedJan 7, 2018
•
edited by bedevere-bot
Alternative approach to PR #3010
https://bugs.python.org/issue28414