Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DTLS support #2047

Merged
merged 49 commits into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
cd0ec9f
First draft
njsmith Jun 24, 2021
8c2fafa
smoke test passing!
njsmith Jun 25, 2021
66595f5
Move required SSL OP_* settings into the proper place
njsmith Jun 25, 2021
641494a
All logic implemented, I think (probably not all correct though)
njsmith Jun 25, 2021
d581e35
Run black
njsmith Jun 26, 2021
4903a61
Delay importing OpenSSL.SSL until a DTLS object is constructed
njsmith Jul 1, 2021
9304e38
Close test socket properly
njsmith Sep 3, 2021
cd7bf54
mark DTLS class as final
njsmith Sep 3, 2021
c44f29f
Refactor socket address resolution
njsmith Sep 3, 2021
d1866f6
Add randomized dtls handshake robustness test
njsmith Sep 5, 2021
7378ce7
run black
njsmith Sep 5, 2021
dcc5eae
Mark randomized test as slow
njsmith Sep 5, 2021
4a0bf1d
Make FakeNet private for now
njsmith Sep 5, 2021
c2cfb1c
make list of tests to write
njsmith Sep 5, 2021
5a224c1
Rename DTLSStream -> DTLSChannel
njsmith Sep 5, 2021
d94713a
more tests
njsmith Sep 5, 2021
def73ed
more tests
njsmith Sep 5, 2021
f260052
rename DTLS -> DTLSEndpoint
njsmith Sep 5, 2021
e694e8e
full duplex test (+ racing do_handshake)
njsmith Sep 5, 2021
17b5f90
testing testing
njsmith Sep 5, 2021
8a1e2cb
Switch DTLSChannel to follow '.statistics()' convention
njsmith Sep 5, 2021
db4b549
moar tests
njsmith Sep 5, 2021
57d75ad
Fixes + tests
njsmith Sep 6, 2021
f7250c3
Cleanup pass on names and cookie crypto
njsmith Sep 6, 2021
ca2c652
Take handshake out of connect() and make it sync
njsmith Sep 7, 2021
05c3f88
Cleanups and a few more tests
njsmith Sep 7, 2021
2fb2d0d
Don't let handshake implicitly overwrite user-specified mtu
njsmith Sep 7, 2021
78ecb67
More cleanup and test coverage
njsmith Sep 8, 2021
00e5caf
comment
njsmith Sep 8, 2021
0a2b055
A few more cleanups + add docs
njsmith Sep 8, 2021
419c962
Quote literal backslash in string
njsmith Sep 30, 2021
717e46f
Defer starting the DTLS receive task until we actually need to receive
njsmith Sep 30, 2021
08686f6
Work around bug in Ubuntu 18.04's OpenSSL
njsmith Nov 3, 2021
e5a4d0d
Clean up test
njsmith Nov 3, 2021
2ffd892
Temporarily switch branch to pull dev version of openssl, to let CI run
njsmith Nov 3, 2021
f335dce
blacken
njsmith Nov 3, 2021
acc0eac
Restore py36 compatibility
njsmith Nov 4, 2021
e3fb2d8
Maybe this will work?
njsmith Nov 4, 2021
7863498
Pacify flake8
njsmith Nov 4, 2021
6e3aca0
make mypy happy
njsmith Nov 4, 2021
1559b56
more py36
njsmith Nov 4, 2021
86ab14d
shut up mypy
njsmith Nov 4, 2021
1714e73
remove unneeded import
njsmith Jan 29, 2022
1fc7847
pyopenssl has released!
njsmith Jan 29, 2022
10f4506
Work around pypy gc quirks
njsmith Jan 29, 2022
284cf2d
Drop py36 support
njsmith Jan 29, 2022
082bc8d
Merge branch 'master' into dtls
gesslerpd Jun 22, 2022
c1d5d22
Merge branch 'master' into dtls
gesslerpd Jul 27, 2022
93851cf
Update _dtls.py
gesslerpd Jul 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def setup(app):
intersphinx_mapping = {
"python": ('https://docs.python.org/3', None),
"outcome": ('https://outcome.readthedocs.io/en/latest/', None),
"pyopenssl": ('https://www.pyopenssl.org/en/stable/', None),
}

autodoc_member_order = "bysource"
Expand Down
46 changes: 46 additions & 0 deletions docs/source/reference-io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,52 @@ you call them before the handshake completes:
.. autoexception:: NeedHandshakeError


Datagram TLS support
~~~~~~~~~~~~~~~~~~~~

Trio also has support for Datagram TLS (DTLS), which is like TLS but
for unreliable UDP connections. This can be useful for applications
where TCP's reliable in-order delivery is problematic, like
teleconferencing, latency-sensitive games, and VPNs.

Currently, using DTLS with Trio requires PyOpenSSL. We hope to
eventually allow the use of the stdlib `ssl` module as well, but
unfortunately that's not yet possible.

.. warning:: Note that PyOpenSSL is in many ways lower-level than the
`ssl` module – in particular, it currently **HAS NO BUILT-IN
MECHANISM TO VALIDATE CERTIFICATES**. We *strongly* recommend that
you use the `service-identity
<https://pypi.org/project/service-identity/>`__ library to validate
hostnames and certificates.

.. autoclass:: DTLSEndpoint

.. automethod:: connect

.. automethod:: serve

.. automethod:: close

.. autoclass:: DTLSChannel
:show-inheritance:

.. automethod:: do_handshake

.. automethod:: send

.. automethod:: receive

.. automethod:: close

.. automethod:: aclose

.. automethod:: set_ciphertext_mtu

.. automethod:: get_cleartext_mtu

.. automethod:: statistics

.. module:: trio.socket

Low-level networking with :mod:`trio.socket`
Expand Down
4 changes: 4 additions & 0 deletions newsfragments/2010.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Added support for `Datagram TLS
<https://en.wikipedia.org/wiki/Datagram_Transport_Layer_Security>`__,
for secure communication over UDP. Currently requires `PyOpenSSL
<https://pypi.org/p/pyopenssl>`__.
5 changes: 3 additions & 2 deletions test-requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ pytest >= 5.0 # for faulthandler in core
pytest-cov >= 2.6.0
# ipython 7.x is the last major version supporting Python 3.7
ipython < 7.32 # for the IPython traceback integration tests
pyOpenSSL # for the ssl tests
trustme # for the ssl tests
pyOpenSSL >= 22.0.0 # for the ssl + DTLS tests
trustme # for the ssl + DTLS tests
pylint # for pylint finding all symbols tests
jedi # for jedi code completion tests
cryptography>=36.0.0 # 35.0.0 is transitive but fails

# Tools
black; implementation_name == "cpython"
mypy; implementation_name == "cpython"
types-pyOpenSSL; implementation_name == "cpython"
flake8
astor # code generation

Expand Down
11 changes: 11 additions & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,21 @@ traitlets==5.3.0
# matplotlib-inline
trustme==0.9.0
# via -r test-requirements.in
types-cryptography==3.3.14
# via types-pyopenssl
types-enum34==1.1.8
# via types-cryptography
types-ipaddress==1.0.7
# via types-cryptography
types-pyopenssl==21.0.3 ; implementation_name == "cpython"
# via -r test-requirements.in
typing-extensions==4.3.0 ; implementation_name == "cpython"
# via
# -r test-requirements.in
# astroid
# black
# mypy
# pylint
wcwidth==0.2.5
# via prompt-toolkit
wrapt==1.14.1
Expand Down
2 changes: 2 additions & 0 deletions trio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@

from ._ssl import SSLStream, SSLListener, NeedHandshakeError

from ._dtls import DTLSEndpoint, DTLSChannel

from ._highlevel_serve_listeners import serve_listeners

from ._highlevel_open_tcp_stream import open_tcp_stream
Expand Down
Loading