Skip to content

Commit 4c62259

Browse files
committed
PoC for using capabilities from Rust
1 parent 9b8c497 commit 4c62259

File tree

3 files changed

+40
-73
lines changed

3 files changed

+40
-73
lines changed

.github/workflows/ci.yml

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ jobs:
1111
matrix:
1212
PYTHON:
1313
# Base builds
14-
- {VERSION: "3.7", TOXENV: "py37"}
15-
- {VERSION: "3.8", TOXENV: "py38"}
16-
- {VERSION: "3.9", TOXENV: "py39"}
17-
- {VERSION: "3.10", TOXENV: "py310"}
18-
- {VERSION: "3.11", TOXENV: "py311"}
19-
- {VERSION: "3.12", TOXENV: "py312"}
20-
- {VERSION: "3.13-dev", TOXENV: "py313"}
21-
- {VERSION: "pypy-3.9", TOXENV: "pypy3"}
22-
- {VERSION: "pypy-3.10", TOXENV: "pypy3"}
23-
- {VERSION: "3.11", TOXENV: "py311-useWheel", OS: "windows-2022" }
14+
# - {VERSION: "3.7", TOXENV: "py37"}
15+
# - {VERSION: "3.8", TOXENV: "py38"}
16+
# - {VERSION: "3.9", TOXENV: "py39"}
17+
# - {VERSION: "3.10", TOXENV: "py310"}
18+
# - {VERSION: "3.11", TOXENV: "py311"}
19+
# - {VERSION: "3.12", TOXENV: "py312"}
20+
# - {VERSION: "3.13-dev", TOXENV: "py313"}
21+
# - {VERSION: "pypy-3.9", TOXENV: "pypy3"}
22+
# - {VERSION: "pypy-3.10", TOXENV: "pypy3"}
23+
# - {VERSION: "3.11", TOXENV: "py311-useWheel", OS: "windows-2022" }
2424
# -cryptographyMain
2525
- {VERSION: "3.7", TOXENV: "py37-cryptographyMain"}
2626
- {VERSION: "3.8", TOXENV: "py38-cryptographyMain"}
@@ -32,24 +32,24 @@ jobs:
3232
- {VERSION: "pypy-3.9", TOXENV: "pypy3-cryptographyMain"}
3333
- {VERSION: "pypy-3.10", TOXENV: "pypy3-cryptographyMain"}
3434
# -cryptographyMinimum
35-
- {VERSION: "3.7", TOXENV: "py37-cryptographyMinimum"}
36-
- {VERSION: "3.8", TOXENV: "py38-cryptographyMinimum"}
37-
- {VERSION: "3.9", TOXENV: "py39-cryptographyMinimum"}
38-
- {VERSION: "3.10", TOXENV: "py310-cryptographyMinimum"}
39-
- {VERSION: "3.11", TOXENV: "py311-cryptographyMinimum"}
40-
- {VERSION: "3.12", TOXENV: "py312-cryptographyMinimum"}
41-
- {VERSION: "3.13-dev", TOXENV: "py313-cryptographyMinimum"}
42-
- {VERSION: "pypy-3.10", TOXENV: "pypy3-cryptographyMinimum"}
35+
# - {VERSION: "3.7", TOXENV: "py37-cryptographyMinimum"}
36+
# - {VERSION: "3.8", TOXENV: "py38-cryptographyMinimum"}
37+
# - {VERSION: "3.9", TOXENV: "py39-cryptographyMinimum"}
38+
# - {VERSION: "3.10", TOXENV: "py310-cryptographyMinimum"}
39+
# - {VERSION: "3.11", TOXENV: "py311-cryptographyMinimum"}
40+
# - {VERSION: "3.12", TOXENV: "py312-cryptographyMinimum"}
41+
# - {VERSION: "3.13-dev", TOXENV: "py313-cryptographyMinimum"}
42+
# - {VERSION: "pypy-3.10", TOXENV: "pypy3-cryptographyMinimum"}
4343
# Cryptography wheels
44-
- {VERSION: "3.9", TOXENV: "py39-cryptographyMinimum-useWheel"}
45-
- {VERSION: "3.9", TOXENV: "py39-useWheel"}
44+
# - {VERSION: "3.9", TOXENV: "py39-cryptographyMinimum-useWheel"}
45+
# - {VERSION: "3.9", TOXENV: "py39-useWheel"}
4646
# Random order
47-
- {VERSION: "3.9", TOXENV: "py39-randomorder"}
47+
# - {VERSION: "3.9", TOXENV: "py39-randomorder"}
4848
# Meta
4949
- {VERSION: "3.9", TOXENV: "check-manifest"}
5050
- {VERSION: "3.11", TOXENV: "lint"}
51-
- {VERSION: "3.11", TOXENV: "py311-mypy"}
52-
- {VERSION: "3.9", TOXENV: "docs"}
51+
# - {VERSION: "3.11", TOXENV: "py311-mypy"}
52+
# - {VERSION: "3.9", TOXENV: "docs"}
5353
name: "${{ matrix.PYTHON.TOXENV }}${{ matrix.PYTHON.OS && format(' on {0}', matrix.PYTHON.OS) || '' }}"
5454
steps:
5555
- uses: actions/checkout@v4
@@ -87,10 +87,10 @@ jobs:
8787
strategy:
8888
fail-fast: false
8989
matrix:
90-
DOWNSTREAM:
91-
- twisted
92-
- certbot
93-
- certbot-josepy
90+
DOWNSTREAM: []
91+
# - twisted
92+
# - certbot
93+
# - certbot-josepy
9494
PYTHON:
9595
- 3.12
9696
name: "Downstream tests for ${{ matrix.DOWNSTREAM }}"

src/OpenSSL/SSL.py

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from weakref import WeakValueDictionary
1414

1515
from cryptography import x509
16+
from cryptography.hazmat.bindings._rust import pyopenssl
1617
from cryptography.hazmat.primitives.asymmetric import ec
1718

1819
from OpenSSL._util import (
@@ -169,16 +170,16 @@
169170
SENT_SHUTDOWN = _lib.SSL_SENT_SHUTDOWN
170171
RECEIVED_SHUTDOWN = _lib.SSL_RECEIVED_SHUTDOWN
171172

172-
SSLv23_METHOD = 3
173-
TLSv1_METHOD = 4
174-
TLSv1_1_METHOD = 5
175-
TLSv1_2_METHOD = 6
176-
TLS_METHOD = 7
177-
TLS_SERVER_METHOD = 8
178-
TLS_CLIENT_METHOD = 9
179-
DTLS_METHOD = 10
180-
DTLS_SERVER_METHOD = 11
181-
DTLS_CLIENT_METHOD = 12
173+
SSLv23_METHOD = pyopenssl.SSLv23_METHOD
174+
TLSv1_METHOD = pyopenssl.TLSv1_METHOD
175+
TLSv1_1_METHOD = pyopenssl.TLSv1_1_METHOD
176+
TLSv1_2_METHOD = pyopenssl.TLSv1_2_METHOD
177+
TLS_METHOD = pyopenssl.TLS_METHOD
178+
TLS_SERVER_METHOD = pyopenssl.TLS_SERVER_METHOD
179+
TLS_CLIENT_METHOD = pyopenssl.TLS_CLIENT_METHOD
180+
DTLS_METHOD = pyopenssl.DTLS_METHOD
181+
DTLS_SERVER_METHOD = pyopenssl.DTLS_SERVER_METHOD
182+
DTLS_CLIENT_METHOD = pyopenssl.DTLS_CLIENT_METHOD
182183

183184
SSL3_VERSION: int = _lib.SSL3_VERSION
184185
TLS1_VERSION: int = _lib.TLS1_VERSION
@@ -827,7 +828,7 @@ class Session:
827828
_session: Any
828829

829830

830-
class Context:
831+
class Context(pyopenssl.Context):
831832
"""
832833
:class:`OpenSSL.SSL.Context` instances define the parameters for setting
833834
up new SSL connections.
@@ -838,38 +839,7 @@ class Context:
838839
not be used.
839840
"""
840841

841-
_methods: typing.ClassVar[
842-
dict[int, tuple[Callable[[], Any], int | None]]
843-
] = {
844-
SSLv23_METHOD: (_lib.TLS_method, None),
845-
TLSv1_METHOD: (_lib.TLS_method, TLS1_VERSION),
846-
TLSv1_1_METHOD: (_lib.TLS_method, TLS1_1_VERSION),
847-
TLSv1_2_METHOD: (_lib.TLS_method, TLS1_2_VERSION),
848-
TLS_METHOD: (_lib.TLS_method, None),
849-
TLS_SERVER_METHOD: (_lib.TLS_server_method, None),
850-
TLS_CLIENT_METHOD: (_lib.TLS_client_method, None),
851-
DTLS_METHOD: (_lib.DTLS_method, None),
852-
DTLS_SERVER_METHOD: (_lib.DTLS_server_method, None),
853-
DTLS_CLIENT_METHOD: (_lib.DTLS_client_method, None),
854-
}
855-
856842
def __init__(self, method: int) -> None:
857-
if not isinstance(method, int):
858-
raise TypeError("method must be an integer")
859-
860-
try:
861-
method_func, version = self._methods[method]
862-
except KeyError:
863-
raise ValueError("No such protocol")
864-
865-
method_obj = method_func()
866-
_openssl_assert(method_obj != _ffi.NULL)
867-
868-
context = _lib.SSL_CTX_new(method_obj)
869-
_openssl_assert(context != _ffi.NULL)
870-
context = _ffi.gc(context, _lib.SSL_CTX_free)
871-
872-
self._context = context
873843
self._passphrase_helper: _PassphraseHelper | None = None
874844
self._passphrase_callback: _PassphraseCallback[Any] | None = None
875845
self._passphrase_userdata: Any | None = None
@@ -894,9 +864,6 @@ def __init__(self, method: int) -> None:
894864
self._cookie_verify_helper: _CookieVerifyCallbackHelper | None = None
895865

896866
self.set_mode(_lib.SSL_MODE_ENABLE_PARTIAL_WRITE)
897-
if version is not None:
898-
self.set_min_proto_version(version)
899-
self.set_max_proto_version(version)
900867

901868
def set_min_proto_version(self, version: int) -> None:
902869
"""

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ setenv =
2727
PIP_NO_BINARY=cryptography
2828
useWheel: PIP_NO_BINARY=
2929
commands =
30-
cryptographyMain: pip install -U git+https://github.com/pyca/cryptography.git
30+
cryptographyMain: pip install -U git+https://github.com/alex/cryptography.git@openssl-horror-show
3131
openssl version
3232
coverage run --parallel -m OpenSSL.debug
3333
coverage run --parallel -m pytest -v {posargs}

0 commit comments

Comments
 (0)