New submission from Dima Tisnek <dim...@gmail.com>:

It's quite easy to create new or modify existing ssl context:

ssl_context = ssl.create_default_context()
ssl_context.set_alpn_protocols(["h2"])

I'm writing a library where the context may be passed by the caller (useful if 
the caller wants to set custom CA path, or client cert auth, share TLS session 
tickets, etc.).

I'd love to be able to check that the context I get has correct ALPN and/or NPN 
protocols specified.

I'd love to be able to do something like this:

assert "h2" in ssl_context.alpn_protocols
or
assert "h2" in ssl_context.get_alpn_protocols()


There's sortof precedent for this, I use following code to set and check TLS 
version flags:

ssl_context.options |= ssl.OP_NO_TLSv1
assert ssl.OP_NO_TLSv1 in ssl_context.options

----------
components: Extension Modules
messages: 365300
nosy: Dima.Tisnek
priority: normal
severity: normal
status: open
title: Introspect ssl context: read ALPN and NPN protocols
versions: Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40111>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to