rtls 2026.3.26__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rtls-2026.3.26/LICENSE +21 -0
- rtls-2026.3.26/NOTICE +106 -0
- rtls-2026.3.26/PKG-INFO +142 -0
- rtls-2026.3.26/README.md +109 -0
- rtls-2026.3.26/pyproject.toml +97 -0
- rtls-2026.3.26/rust/Cargo.lock +942 -0
- rtls-2026.3.26/rust/Cargo.toml +32 -0
- rtls-2026.3.26/rust/build.rs +35 -0
- rtls-2026.3.26/rust/src/cert.rs +304 -0
- rtls-2026.3.26/rust/src/config.rs +657 -0
- rtls-2026.3.26/rust/src/connection.rs +549 -0
- rtls-2026.3.26/rust/src/error.rs +51 -0
- rtls-2026.3.26/rust/src/lib.rs +56 -0
- rtls-2026.3.26/rust/src/verify.rs +305 -0
- rtls-2026.3.26/src/rtls/__init__.py +265 -0
- rtls-2026.3.26/src/rtls/_bio.py +69 -0
- rtls-2026.3.26/src/rtls/_certificate.py +66 -0
- rtls-2026.3.26/src/rtls/_ciphers.py +228 -0
- rtls-2026.3.26/src/rtls/_constants.py +276 -0
- rtls-2026.3.26/src/rtls/_context.py +528 -0
- rtls-2026.3.26/src/rtls/_exceptions.py +67 -0
- rtls-2026.3.26/src/rtls/_object.py +420 -0
- rtls-2026.3.26/src/rtls/_rustls.pyi +83 -0
- rtls-2026.3.26/src/rtls/_socket.py +433 -0
- rtls-2026.3.26/src/rtls/_utils.py +222 -0
- rtls-2026.3.26/tests/certdata/allsans.pem +167 -0
- rtls-2026.3.26/tests/certdata/badcert.pem +36 -0
- rtls-2026.3.26/tests/certdata/badkey.pem +40 -0
- rtls-2026.3.26/tests/certdata/capath/4e1295a3.0 +14 -0
- rtls-2026.3.26/tests/certdata/capath/5ed36f99.0 +41 -0
- rtls-2026.3.26/tests/certdata/capath/6e88d7b8.0 +14 -0
- rtls-2026.3.26/tests/certdata/capath/99d0fa06.0 +41 -0
- rtls-2026.3.26/tests/certdata/capath/b1930218.0 +27 -0
- rtls-2026.3.26/tests/certdata/capath/ceff1710.0 +27 -0
- rtls-2026.3.26/tests/certdata/cert3.pem +34 -0
- rtls-2026.3.26/tests/certdata/idnsans.pem +166 -0
- rtls-2026.3.26/tests/certdata/intermediate_cert.pem +19 -0
- rtls-2026.3.26/tests/certdata/intermediate_cert.srl +1 -0
- rtls-2026.3.26/tests/certdata/intermediate_csr.pem +15 -0
- rtls-2026.3.26/tests/certdata/intermediate_key.pem +28 -0
- rtls-2026.3.26/tests/certdata/keycert.passwd.pem +69 -0
- rtls-2026.3.26/tests/certdata/keycert.pem +67 -0
- rtls-2026.3.26/tests/certdata/keycert.pem.reference +13 -0
- rtls-2026.3.26/tests/certdata/keycert3.pem +161 -0
- rtls-2026.3.26/tests/certdata/keycert3.pem.reference +15 -0
- rtls-2026.3.26/tests/certdata/keycert4.pem +161 -0
- rtls-2026.3.26/tests/certdata/keycert_leaf.pem +48 -0
- rtls-2026.3.26/tests/certdata/keycertecc.pem +103 -0
- rtls-2026.3.26/tests/certdata/leaf-missing-aki.ca.pem +13 -0
- rtls-2026.3.26/tests/certdata/leaf-missing-aki.keycert.pem +18 -0
- rtls-2026.3.26/tests/certdata/leaf_cert.pem +20 -0
- rtls-2026.3.26/tests/certdata/leaf_chain.pem +39 -0
- rtls-2026.3.26/tests/certdata/leaf_csr.pem +15 -0
- rtls-2026.3.26/tests/certdata/leaf_key.pem +28 -0
- rtls-2026.3.26/tests/certdata/nokia.pem +31 -0
- rtls-2026.3.26/tests/certdata/nosan.pem +137 -0
- rtls-2026.3.26/tests/certdata/nullbytecert.pem +90 -0
- rtls-2026.3.26/tests/certdata/nullcert.pem +0 -0
- rtls-2026.3.26/tests/certdata/pycacert.pem +102 -0
- rtls-2026.3.26/tests/certdata/pycakey.pem +40 -0
- rtls-2026.3.26/tests/certdata/revocation.crl +14 -0
- rtls-2026.3.26/tests/certdata/root_cert.pem +19 -0
- rtls-2026.3.26/tests/certdata/root_cert.srl +1 -0
- rtls-2026.3.26/tests/certdata/root_key.pem +28 -0
- rtls-2026.3.26/tests/certdata/ssl_cert.pem +27 -0
- rtls-2026.3.26/tests/certdata/ssl_key.passwd.pem +42 -0
- rtls-2026.3.26/tests/certdata/ssl_key.pem +40 -0
- rtls-2026.3.26/tests/certdata/talos-2019-0758.pem +22 -0
- rtls-2026.3.26/tests/test_cpython_ssl.py +1673 -0
- rtls-2026.3.26/tests/test_rtls.py +3385 -0
rtls-2026.3.26/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TAHRI Ahmed R.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
rtls-2026.3.26/NOTICE
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
NOTICE
|
|
2
|
+
======
|
|
3
|
+
|
|
4
|
+
This project contains code that is derived from, or inspired by, CPython's
|
|
5
|
+
``ssl`` module and its associated C extension ``_ssl``. The original CPython
|
|
6
|
+
source is licensed under the Python Software Foundation License Version 2,
|
|
7
|
+
reproduced below.
|
|
8
|
+
|
|
9
|
+
This project links against rustls, a modern TLS library written in Rust.
|
|
10
|
+
rustls is Copyright (c) 2016 Joseph Birr-Pixton and licensed under
|
|
11
|
+
Apache-2.0, MIT, or ISC (at your option). The rustls MIT license is
|
|
12
|
+
reproduced below.
|
|
13
|
+
|
|
14
|
+
Summary of changes made to Python
|
|
15
|
+
----------------------------------
|
|
16
|
+
|
|
17
|
+
rtls does not embed or modify CPython source code directly. Instead, it
|
|
18
|
+
re-implements the ``ssl`` module's public API (SSLContext, SSLSocket,
|
|
19
|
+
SSLObject, MemoryBIO, exceptions, constants, and utility functions) on top
|
|
20
|
+
of the rustls TLS library via PyO3. The API surface - class names, method
|
|
21
|
+
signatures, property semantics, constant values, exception hierarchy, and
|
|
22
|
+
``getpeercert()`` dict structure - is modelled after CPython 3.12+ to
|
|
23
|
+
achieve drop-in compatibility.
|
|
24
|
+
|
|
25
|
+
No CPython C code is included in this project.
|
|
26
|
+
|
|
27
|
+
------------------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
|
|
30
|
+
--------------------------------------------
|
|
31
|
+
|
|
32
|
+
1. This LICENSE AGREEMENT is between the Python Software Foundation
|
|
33
|
+
("PSF"), and the Individual or Organization ("Licensee") accessing and
|
|
34
|
+
otherwise using this software ("Python") in source or binary form and
|
|
35
|
+
its associated documentation.
|
|
36
|
+
|
|
37
|
+
2. Subject to the terms and conditions of this License Agreement, PSF hereby
|
|
38
|
+
grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
|
|
39
|
+
analyze, test, perform and/or display publicly, prepare derivative works,
|
|
40
|
+
distribute, and otherwise use Python alone or in any derivative version,
|
|
41
|
+
provided, however, that PSF's License Agreement and PSF's notice of copyright,
|
|
42
|
+
i.e., "Copyright (c) 2001-2025 Python Software Foundation; All Rights
|
|
43
|
+
Reserved" are retained in Python alone or in any derivative version prepared by
|
|
44
|
+
Licensee.
|
|
45
|
+
|
|
46
|
+
3. In the event Licensee prepares a derivative work that is based on
|
|
47
|
+
or incorporates Python or any part thereof, and wants to make
|
|
48
|
+
the derivative work available to others as provided herein, then
|
|
49
|
+
Licensee hereby agrees to include in any such work a brief summary of
|
|
50
|
+
the changes made to Python.
|
|
51
|
+
|
|
52
|
+
4. PSF is making Python available to Licensee on an "AS IS"
|
|
53
|
+
basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
|
|
54
|
+
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
|
|
55
|
+
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
|
|
56
|
+
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
|
|
57
|
+
INFRINGE ANY THIRD PARTY RIGHTS.
|
|
58
|
+
|
|
59
|
+
5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
|
|
60
|
+
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
|
|
61
|
+
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
|
|
62
|
+
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
|
|
63
|
+
|
|
64
|
+
6. This License Agreement will automatically terminate upon a material
|
|
65
|
+
breach of its terms and conditions.
|
|
66
|
+
|
|
67
|
+
7. Nothing in this License Agreement shall be deemed to create any
|
|
68
|
+
relationship of agency, partnership, or joint venture between PSF and
|
|
69
|
+
Licensee. This License Agreement does not grant permission to use PSF
|
|
70
|
+
trademarks or trade name in a trademark sense to endorse or promote
|
|
71
|
+
products or services of Licensee, or any third party.
|
|
72
|
+
|
|
73
|
+
8. By copying, installing or otherwise using Python, Licensee
|
|
74
|
+
agrees to be bound by the terms and conditions of this License
|
|
75
|
+
Agreement.
|
|
76
|
+
|
|
77
|
+
------------------------------------------------------------------------
|
|
78
|
+
|
|
79
|
+
RUSTLS LICENSE (MIT)
|
|
80
|
+
--------------------
|
|
81
|
+
|
|
82
|
+
Copyright (c) 2016 Joseph Birr-Pixton <jpixton@gmail.com>
|
|
83
|
+
|
|
84
|
+
Permission is hereby granted, free of charge, to any
|
|
85
|
+
person obtaining a copy of this software and associated
|
|
86
|
+
documentation files (the "Software"), to deal in the
|
|
87
|
+
Software without restriction, including without
|
|
88
|
+
limitation the rights to use, copy, modify, merge,
|
|
89
|
+
publish, distribute, sublicense, and/or sell copies of
|
|
90
|
+
the Software, and to permit persons to whom the Software
|
|
91
|
+
is furnished to do so, subject to the following
|
|
92
|
+
conditions:
|
|
93
|
+
|
|
94
|
+
The above copyright notice and this permission notice
|
|
95
|
+
shall be included in all copies or substantial portions
|
|
96
|
+
of the Software.
|
|
97
|
+
|
|
98
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
99
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
100
|
+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
101
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
|
102
|
+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
103
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
104
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
105
|
+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
106
|
+
DEALINGS IN THE SOFTWARE.
|
rtls-2026.3.26/PKG-INFO
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rtls
|
|
3
|
+
Version: 2026.3.26
|
|
4
|
+
Classifier: Development Status :: 4 - Beta
|
|
5
|
+
Classifier: Environment :: Web Environment
|
|
6
|
+
Classifier: Intended Audience :: Developers
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Programming Language :: Rust
|
|
9
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
10
|
+
Classifier: Programming Language :: Python
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
21
|
+
Classifier: Programming Language :: Python :: Free Threading :: 4 - Resilient
|
|
22
|
+
Requires-Dist: wassima>=1,<3
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
License-File: NOTICE
|
|
25
|
+
Summary: A drop-in replacement for Python's ssl module, backed by rustls
|
|
26
|
+
Home-Page: https://github.com/jawah/rtls
|
|
27
|
+
Author-email: "Ahmed R. TAHRI" <tahri.ahmed@proton.me>
|
|
28
|
+
Maintainer-email: "Ahmed R. TAHRI" <tahri.ahmed@proton.me>
|
|
29
|
+
Requires-Python: >=3.7
|
|
30
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
31
|
+
Project-URL: homepage, https://github.com/jawah/rtls
|
|
32
|
+
|
|
33
|
+
Rustls-backed TLS for CPython
|
|
34
|
+
-----------------------------
|
|
35
|
+
|
|
36
|
+
Ever dreamed of getting rid of OpenSSL within CPython without creating a custom build of CPython for this?
|
|
37
|
+
Tired of waiting half a decade for a solid and up-to-date TLS experience, shipping Post-quantum, and ECH support by default?
|
|
38
|
+
|
|
39
|
+
Then `rtls` is made for you.
|
|
40
|
+
|
|
41
|
+
It's a drop-in replacement for the `ssl` stdlib!
|
|
42
|
+
Support CPython 3.7 onward. Including freethreaded.
|
|
43
|
+
|
|
44
|
+
### Getting Started
|
|
45
|
+
|
|
46
|
+
Install from source (requires a Rust toolchain and maturin):
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
pip install rtls
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Then swap `ssl` for `rtls` anywhere in your code:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
import rtls as ssl
|
|
56
|
+
|
|
57
|
+
ctx = ssl.create_default_context()
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Or use it alongside the stdlib:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from rtls import SSLContext, PROTOCOL_TLS_CLIENT
|
|
64
|
+
|
|
65
|
+
ctx = SSLContext(PROTOCOL_TLS_CLIENT)
|
|
66
|
+
ctx.load_default_certs()
|
|
67
|
+
|
|
68
|
+
import socket
|
|
69
|
+
sock = socket.create_connection(("example.com", 443))
|
|
70
|
+
ssock = ctx.wrap_socket(sock, server_hostname="example.com")
|
|
71
|
+
ssock.sendall(b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
|
|
72
|
+
print(ssock.recv(4096).decode())
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
It works with asyncio out of the box:
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
import asyncio
|
|
79
|
+
import rtls as ssl
|
|
80
|
+
|
|
81
|
+
async def main():
|
|
82
|
+
ctx = ssl.create_default_context()
|
|
83
|
+
reader, writer = await asyncio.open_connection("example.com", 443, ssl=ctx)
|
|
84
|
+
writer.write(b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
|
|
85
|
+
await writer.drain()
|
|
86
|
+
print((await reader.read(4096)).decode())
|
|
87
|
+
writer.close()
|
|
88
|
+
|
|
89
|
+
asyncio.run(main())
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Feature Parity with stdlib
|
|
93
|
+
|
|
94
|
+
rtls re-exports **93 public names** matching the `ssl` module API. The table below summarizes
|
|
95
|
+
coverage across the main areas.
|
|
96
|
+
|
|
97
|
+
**What's different from `ssl`:**
|
|
98
|
+
|
|
99
|
+
- TLS 1.2 is the minimum version. SSLv2, SSLv3, TLS 1.0 and TLS 1.1 are not available.
|
|
100
|
+
- Hostname verification uses SAN only, never the Common Name.
|
|
101
|
+
- `compression()` always returns `None` (TLS compression is disabled, as it should be).
|
|
102
|
+
- `security_level` is always 2. rustls defaults are strong by design.
|
|
103
|
+
- `load_cert_chain` natively accepts **in-memory PEM bytes** as `certfile`/`keyfile`, not just file paths.
|
|
104
|
+
|
|
105
|
+
### Disclaimer
|
|
106
|
+
|
|
107
|
+
This project is in an early stage. The public API is stable, we do not plan to diverge from stdlib.
|
|
108
|
+
It's not pure Python, so you'll have either a pre-built wheel compatible with your platform or build
|
|
109
|
+
from the sources by yourself.
|
|
110
|
+
|
|
111
|
+
A notice is present to acknowledge CPython rights on the ssl Python codebase. The project itself is licensed
|
|
112
|
+
under MIT as we always do. Rustls is also permissively licensed.
|
|
113
|
+
|
|
114
|
+
Right now we deliberately focus on the client side. PRs are accepted to help us finalize/improve the server side.
|
|
115
|
+
|
|
116
|
+
- We are not inclined to enable FIPS mode via aws-lc-rs for the moment, however, it's on our roadmap.
|
|
117
|
+
- Do not open issue about "JA fingerprint", "Browser impersonator" or alike, we'll most likely close them on the spot. We are not interested in pursing this.
|
|
118
|
+
- PyPy is not going to be supported, unfortunately.
|
|
119
|
+
|
|
120
|
+
It's not faster than the stdlib. Expect roughly 5 to 10% slower. For example, a quick benchmark reveal that ssl stdlib can reach 456 MB/s raw throughput on my modest laptop while our
|
|
121
|
+
implementation reached 410 MB/s. Why? We heavily pay for crossing the boundary between Rust and CPython. We could implement the Buffer protocol (avoid needless memcpy each time), but that
|
|
122
|
+
would cost us our high CPython (i.e. 3.7+) compatibility. That trade off is quickly hided by the fact that you will run a memory safe TLS implementation. No longer in C shall we do TLS!
|
|
123
|
+
|
|
124
|
+
Contributions, bug reports, and feedback are welcome.
|
|
125
|
+
|
|
126
|
+
### Versioning
|
|
127
|
+
|
|
128
|
+
This project is based on calver (YYYY-0M-0D), it does not need semver as it aims to be a drop-in replacement for stdlib `ssl`.
|
|
129
|
+
You do not need to constraint the upper bound version.
|
|
130
|
+
|
|
131
|
+
### Prior art
|
|
132
|
+
|
|
133
|
+
I saw https://github.com/djc/pyrtls a couple of months ago, and it inspired me to write this alternative.
|
|
134
|
+
Why? As you are aware, we are maintaining a fork of urllib3 and requests, and having to handwrite a support for a non ssl
|
|
135
|
+
compatible lib is going to be a nightmare. We just can't ask the maintainer to rewrite everything for our
|
|
136
|
+
own needs.
|
|
137
|
+
|
|
138
|
+
### Documentation
|
|
139
|
+
|
|
140
|
+
See https://docs.python.org/3/library/ssl.html as it's fairly detailed and spotless.
|
|
141
|
+
We would host our own version later having unsupported feature removed. Amongst import naming, etc(...).
|
|
142
|
+
|
rtls-2026.3.26/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Rustls-backed TLS for CPython
|
|
2
|
+
-----------------------------
|
|
3
|
+
|
|
4
|
+
Ever dreamed of getting rid of OpenSSL within CPython without creating a custom build of CPython for this?
|
|
5
|
+
Tired of waiting half a decade for a solid and up-to-date TLS experience, shipping Post-quantum, and ECH support by default?
|
|
6
|
+
|
|
7
|
+
Then `rtls` is made for you.
|
|
8
|
+
|
|
9
|
+
It's a drop-in replacement for the `ssl` stdlib!
|
|
10
|
+
Support CPython 3.7 onward. Including freethreaded.
|
|
11
|
+
|
|
12
|
+
### Getting Started
|
|
13
|
+
|
|
14
|
+
Install from source (requires a Rust toolchain and maturin):
|
|
15
|
+
|
|
16
|
+
```
|
|
17
|
+
pip install rtls
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Then swap `ssl` for `rtls` anywhere in your code:
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
import rtls as ssl
|
|
24
|
+
|
|
25
|
+
ctx = ssl.create_default_context()
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Or use it alongside the stdlib:
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from rtls import SSLContext, PROTOCOL_TLS_CLIENT
|
|
32
|
+
|
|
33
|
+
ctx = SSLContext(PROTOCOL_TLS_CLIENT)
|
|
34
|
+
ctx.load_default_certs()
|
|
35
|
+
|
|
36
|
+
import socket
|
|
37
|
+
sock = socket.create_connection(("example.com", 443))
|
|
38
|
+
ssock = ctx.wrap_socket(sock, server_hostname="example.com")
|
|
39
|
+
ssock.sendall(b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
|
|
40
|
+
print(ssock.recv(4096).decode())
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
It works with asyncio out of the box:
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
import asyncio
|
|
47
|
+
import rtls as ssl
|
|
48
|
+
|
|
49
|
+
async def main():
|
|
50
|
+
ctx = ssl.create_default_context()
|
|
51
|
+
reader, writer = await asyncio.open_connection("example.com", 443, ssl=ctx)
|
|
52
|
+
writer.write(b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n")
|
|
53
|
+
await writer.drain()
|
|
54
|
+
print((await reader.read(4096)).decode())
|
|
55
|
+
writer.close()
|
|
56
|
+
|
|
57
|
+
asyncio.run(main())
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Feature Parity with stdlib
|
|
61
|
+
|
|
62
|
+
rtls re-exports **93 public names** matching the `ssl` module API. The table below summarizes
|
|
63
|
+
coverage across the main areas.
|
|
64
|
+
|
|
65
|
+
**What's different from `ssl`:**
|
|
66
|
+
|
|
67
|
+
- TLS 1.2 is the minimum version. SSLv2, SSLv3, TLS 1.0 and TLS 1.1 are not available.
|
|
68
|
+
- Hostname verification uses SAN only, never the Common Name.
|
|
69
|
+
- `compression()` always returns `None` (TLS compression is disabled, as it should be).
|
|
70
|
+
- `security_level` is always 2. rustls defaults are strong by design.
|
|
71
|
+
- `load_cert_chain` natively accepts **in-memory PEM bytes** as `certfile`/`keyfile`, not just file paths.
|
|
72
|
+
|
|
73
|
+
### Disclaimer
|
|
74
|
+
|
|
75
|
+
This project is in an early stage. The public API is stable, we do not plan to diverge from stdlib.
|
|
76
|
+
It's not pure Python, so you'll have either a pre-built wheel compatible with your platform or build
|
|
77
|
+
from the sources by yourself.
|
|
78
|
+
|
|
79
|
+
A notice is present to acknowledge CPython rights on the ssl Python codebase. The project itself is licensed
|
|
80
|
+
under MIT as we always do. Rustls is also permissively licensed.
|
|
81
|
+
|
|
82
|
+
Right now we deliberately focus on the client side. PRs are accepted to help us finalize/improve the server side.
|
|
83
|
+
|
|
84
|
+
- We are not inclined to enable FIPS mode via aws-lc-rs for the moment, however, it's on our roadmap.
|
|
85
|
+
- Do not open issue about "JA fingerprint", "Browser impersonator" or alike, we'll most likely close them on the spot. We are not interested in pursing this.
|
|
86
|
+
- PyPy is not going to be supported, unfortunately.
|
|
87
|
+
|
|
88
|
+
It's not faster than the stdlib. Expect roughly 5 to 10% slower. For example, a quick benchmark reveal that ssl stdlib can reach 456 MB/s raw throughput on my modest laptop while our
|
|
89
|
+
implementation reached 410 MB/s. Why? We heavily pay for crossing the boundary between Rust and CPython. We could implement the Buffer protocol (avoid needless memcpy each time), but that
|
|
90
|
+
would cost us our high CPython (i.e. 3.7+) compatibility. That trade off is quickly hided by the fact that you will run a memory safe TLS implementation. No longer in C shall we do TLS!
|
|
91
|
+
|
|
92
|
+
Contributions, bug reports, and feedback are welcome.
|
|
93
|
+
|
|
94
|
+
### Versioning
|
|
95
|
+
|
|
96
|
+
This project is based on calver (YYYY-0M-0D), it does not need semver as it aims to be a drop-in replacement for stdlib `ssl`.
|
|
97
|
+
You do not need to constraint the upper bound version.
|
|
98
|
+
|
|
99
|
+
### Prior art
|
|
100
|
+
|
|
101
|
+
I saw https://github.com/djc/pyrtls a couple of months ago, and it inspired me to write this alternative.
|
|
102
|
+
Why? As you are aware, we are maintaining a fork of urllib3 and requests, and having to handwrite a support for a non ssl
|
|
103
|
+
compatible lib is going to be a nightmare. We just can't ask the maintainer to rewrite everything for our
|
|
104
|
+
own needs.
|
|
105
|
+
|
|
106
|
+
### Documentation
|
|
107
|
+
|
|
108
|
+
See https://docs.python.org/3/library/ssl.html as it's fairly detailed and spotless.
|
|
109
|
+
We would host our own version later having unsupported feature removed. Amongst import naming, etc(...).
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["maturin>=1.2,<2.0"]
|
|
3
|
+
build-backend = "maturin"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "rtls"
|
|
7
|
+
description = "A drop-in replacement for Python's ssl module, backed by rustls"
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
requires-python = ">=3.7"
|
|
10
|
+
license = { file = "LICENSE" }
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "Ahmed R. TAHRI", email="tahri.ahmed@proton.me"},
|
|
13
|
+
]
|
|
14
|
+
maintainers = [
|
|
15
|
+
{name = "Ahmed R. TAHRI", email="tahri.ahmed@proton.me"},
|
|
16
|
+
]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 4 - Beta",
|
|
19
|
+
"Environment :: Web Environment",
|
|
20
|
+
"Intended Audience :: Developers",
|
|
21
|
+
"License :: OSI Approved :: MIT License",
|
|
22
|
+
"Programming Language :: Rust",
|
|
23
|
+
"Programming Language :: Python :: Implementation :: CPython",
|
|
24
|
+
"Programming Language :: Python",
|
|
25
|
+
"Programming Language :: Python :: 3",
|
|
26
|
+
"Programming Language :: Python :: 3.7",
|
|
27
|
+
"Programming Language :: Python :: 3.8",
|
|
28
|
+
"Programming Language :: Python :: 3.9",
|
|
29
|
+
"Programming Language :: Python :: 3.10",
|
|
30
|
+
"Programming Language :: Python :: 3.11",
|
|
31
|
+
"Programming Language :: Python :: 3.12",
|
|
32
|
+
"Programming Language :: Python :: 3.13",
|
|
33
|
+
"Programming Language :: Python :: 3.14",
|
|
34
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
35
|
+
"Programming Language :: Python :: Free Threading :: 4 - Resilient",
|
|
36
|
+
]
|
|
37
|
+
dynamic = [
|
|
38
|
+
'version'
|
|
39
|
+
]
|
|
40
|
+
dependencies = [
|
|
41
|
+
"wassima>=1,<3",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[tool.maturin]
|
|
45
|
+
include = [
|
|
46
|
+
{ path = "NOTICE", format = "sdist" },
|
|
47
|
+
{ path = "tests/**/*", format = "sdist" },
|
|
48
|
+
]
|
|
49
|
+
exclude = [
|
|
50
|
+
{ path = "**/__pycache__/**", format = "sdist" },
|
|
51
|
+
]
|
|
52
|
+
features = ["pyo3/extension-module", "pyo3/abi3-py37", "pyo3/generate-import-lib"]
|
|
53
|
+
module-name = "rtls._rustls"
|
|
54
|
+
python-source = "src"
|
|
55
|
+
manifest-path = "rust/Cargo.toml"
|
|
56
|
+
|
|
57
|
+
[tool.maturin.sbom]
|
|
58
|
+
# Generate a CycloneDX SBOM for the Rust dependency tree.
|
|
59
|
+
# Defaults to true when the sbom feature is enabled.
|
|
60
|
+
rust = true
|
|
61
|
+
# Generate a CycloneDX SBOM for external shared libraries grafted during
|
|
62
|
+
# auditwheel repair. Defaults to true when repair copies libraries.
|
|
63
|
+
auditwheel = true
|
|
64
|
+
|
|
65
|
+
[project.urls]
|
|
66
|
+
homepage = "https://github.com/jawah/rtls"
|
|
67
|
+
|
|
68
|
+
[tool.pytest.ini_options]
|
|
69
|
+
xfail_strict = true
|
|
70
|
+
log_level = "DEBUG"
|
|
71
|
+
filterwarnings = [
|
|
72
|
+
"error",
|
|
73
|
+
'''ignore:Exception ignored in:pytest.PytestUnraisableExceptionWarning''',
|
|
74
|
+
'''ignore:Exception in thread:pytest.PytestUnhandledThreadExceptionWarning''',
|
|
75
|
+
'''ignore:Unverified HTTPS request is being made to host:urllib3.exceptions.InsecureRequestWarning''',
|
|
76
|
+
'''ignore:Exception ignored while finalizing socket:pytest.PytestUnraisableExceptionWarning''',
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
[tool.mypy]
|
|
80
|
+
disallow_untyped_calls = true
|
|
81
|
+
disallow_untyped_decorators = true
|
|
82
|
+
ignore_missing_imports = true
|
|
83
|
+
strict_optional = false
|
|
84
|
+
warn_redundant_casts = true
|
|
85
|
+
warn_unused_ignores = true
|
|
86
|
+
|
|
87
|
+
[tool.ruff.lint]
|
|
88
|
+
select = [
|
|
89
|
+
"E", # pycodestyle
|
|
90
|
+
"F", # Pyflakes
|
|
91
|
+
"W", # pycodestyle
|
|
92
|
+
"I", # isort
|
|
93
|
+
"U", # pyupgrade
|
|
94
|
+
]
|
|
95
|
+
|
|
96
|
+
[tool.ruff.lint.isort]
|
|
97
|
+
required-imports = ["from __future__ import annotations"]
|