Skip to content

Commit bcb6663

Browse files
authored
Merge pull request #2047 from njsmith/dtls
DTLS support
2 parents 585a783 + 93851cf commit bcb6663

File tree

12 files changed

+2761
-98
lines changed

12 files changed

+2761
-98
lines changed

docs/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def setup(app):
8787
intersphinx_mapping = {
8888
"python": ('https://docs.python.org/3', None),
8989
"outcome": ('https://outcome.readthedocs.io/en/latest/', None),
90+
"pyopenssl": ('https://www.pyopenssl.org/en/stable/', None),
9091
}
9192

9293
autodoc_member_order = "bysource"

docs/source/reference-io.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,52 @@ you call them before the handshake completes:
258258
.. autoexception:: NeedHandshakeError
259259

260260

261+
Datagram TLS support
262+
~~~~~~~~~~~~~~~~~~~~
263+
264+
Trio also has support for Datagram TLS (DTLS), which is like TLS but
265+
for unreliable UDP connections. This can be useful for applications
266+
where TCP's reliable in-order delivery is problematic, like
267+
teleconferencing, latency-sensitive games, and VPNs.
268+
269+
Currently, using DTLS with Trio requires PyOpenSSL. We hope to
270+
eventually allow the use of the stdlib `ssl` module as well, but
271+
unfortunately that's not yet possible.
272+
273+
.. warning:: Note that PyOpenSSL is in many ways lower-level than the
274+
`ssl` module – in particular, it currently **HAS NO BUILT-IN
275+
MECHANISM TO VALIDATE CERTIFICATES**. We *strongly* recommend that
276+
you use the `service-identity
277+
<https://pypi.org/project/service-identity/>`__ library to validate
278+
hostnames and certificates.
279+
280+
.. autoclass:: DTLSEndpoint
281+
282+
.. automethod:: connect
283+
284+
.. automethod:: serve
285+
286+
.. automethod:: close
287+
288+
.. autoclass:: DTLSChannel
289+
:show-inheritance:
290+
291+
.. automethod:: do_handshake
292+
293+
.. automethod:: send
294+
295+
.. automethod:: receive
296+
297+
.. automethod:: close
298+
299+
.. automethod:: aclose
300+
301+
.. automethod:: set_ciphertext_mtu
302+
303+
.. automethod:: get_cleartext_mtu
304+
305+
.. automethod:: statistics
306+
261307
.. module:: trio.socket
262308

263309
Low-level networking with :mod:`trio.socket`

newsfragments/2010.feature.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Added support for `Datagram TLS
2+
<https://en.wikipedia.org/wiki/Datagram_Transport_Layer_Security>`__,
3+
for secure communication over UDP. Currently requires `PyOpenSSL
4+
<https://pypi.org/p/pyopenssl>`__.

test-requirements.in

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ pytest >= 5.0 # for faulthandler in core
33
pytest-cov >= 2.6.0
44
# ipython 7.x is the last major version supporting Python 3.7
55
ipython < 7.32 # for the IPython traceback integration tests
6-
pyOpenSSL # for the ssl tests
7-
trustme # for the ssl tests
6+
pyOpenSSL >= 22.0.0 # for the ssl + DTLS tests
7+
trustme # for the ssl + DTLS tests
88
pylint # for pylint finding all symbols tests
99
jedi # for jedi code completion tests
1010
cryptography>=36.0.0 # 35.0.0 is transitive but fails
1111

1212
# Tools
1313
black; implementation_name == "cpython"
1414
mypy; implementation_name == "cpython"
15+
types-pyOpenSSL; implementation_name == "cpython"
1516
flake8
1617
astor # code generation
1718

test-requirements.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,21 @@ traitlets==5.3.0
134134
# matplotlib-inline
135135
trustme==0.9.0
136136
# via -r test-requirements.in
137+
types-cryptography==3.3.14
138+
# via types-pyopenssl
139+
types-enum34==1.1.8
140+
# via types-cryptography
141+
types-ipaddress==1.0.7
142+
# via types-cryptography
143+
types-pyopenssl==21.0.3 ; implementation_name == "cpython"
144+
# via -r test-requirements.in
137145
typing-extensions==4.3.0 ; implementation_name == "cpython"
138146
# via
139147
# -r test-requirements.in
148+
# astroid
149+
# black
140150
# mypy
151+
# pylint
141152
wcwidth==0.2.5
142153
# via prompt-toolkit
143154
wrapt==1.14.1

trio/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474

7575
from ._ssl import SSLStream, SSLListener, NeedHandshakeError
7676

77+
from ._dtls import DTLSEndpoint, DTLSChannel
78+
7779
from ._highlevel_serve_listeners import serve_listeners
7880

7981
from ._highlevel_open_tcp_stream import open_tcp_stream

0 commit comments

Comments
 (0)