Skip to content

Commit e3dc904

Browse files
Use cryptography to load the pyOpenSSL certificates (#670)
* Bump the dependencies group with 4 updates Bumps the dependencies group with 4 updates: [packaging](https://github.com/pypa/packaging), [types-setuptools](https://github.com/python/typeshed), [coverage[toml]](https://github.com/nedbat/coveragepy) and [pyopenssl](https://github.com/pyca/pyopenssl). Updates `packaging` from 24.1 to 24.2 - [Release notes](https://github.com/pypa/packaging/releases) - [Changelog](https://github.com/pypa/packaging/blob/main/CHANGELOG.rst) - [Commits](pypa/packaging@24.1...24.2) Updates `types-setuptools` from 75.2.0.20241025 to 75.6.0.20241126 - [Commits](https://github.com/python/typeshed/commits) Updates `coverage[toml]` from 7.6.4 to 7.6.8 - [Release notes](https://github.com/nedbat/coveragepy/releases) - [Changelog](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst) - [Commits](nedbat/coveragepy@7.6.4...7.6.8) Updates `pyopenssl` from 24.2.1 to 24.3.0 - [Changelog](https://github.com/pyca/pyopenssl/blob/main/CHANGELOG.rst) - [Commits](pyca/pyopenssl@24.2.1...24.3.0) --- updated-dependencies: - dependency-name: packaging dependency-type: indirect update-type: version-update:semver-minor dependency-group: dependencies - dependency-name: types-setuptools dependency-type: indirect update-type: version-update:semver-minor dependency-group: dependencies - dependency-name: coverage[toml] dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dependencies - dependency-name: pyopenssl dependency-type: direct:production update-type: version-update:semver-minor dependency-group: dependencies ... Signed-off-by: dependabot[bot] <[email protected]> * Switch to using cryptography privatekeys * Switch x509 too * Fix typings * Give up on typing --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: EXPLOSION <[email protected]>
1 parent 00a906d commit e3dc904

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

docs-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jinja2==3.1.2
2828
# via sphinx
2929
markupsafe==3.0.2
3030
# via jinja2
31-
packaging==24.1
31+
packaging==24.2
3232
# via sphinx
3333
pycparser==2.22
3434
# via cffi

lint-requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ mypy-extensions==1.0.0
2626
# via
2727
# black
2828
# mypy
29-
packaging==24.1
29+
packaging==24.2
3030
# via
3131
# black
3232
# pytest
@@ -44,7 +44,7 @@ types-cffi==1.16.0.20240331
4444
# via types-pyopenssl
4545
types-pyopenssl==24.1.0.20240722
4646
# via -r lint-requirements.in
47-
types-setuptools==75.2.0.20241025
47+
types-setuptools==75.6.0.20241126
4848
# via types-cffi
4949
typing-extensions==4.12.2
5050
# via mypy

src/trustme/__init__.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from contextlib import contextmanager
99
from enum import Enum
1010
from tempfile import NamedTemporaryFile
11-
from typing import TYPE_CHECKING, Generator, List, Optional, Union
11+
from typing import TYPE_CHECKING, Generator, List, Optional, Union, cast
1212

1313
import idna
1414
from cryptography import x509
@@ -545,15 +545,13 @@ def configure_cert(self, ctx: Union[ssl.SSLContext, OpenSSL.SSL.Context]) -> Non
545545
with self.private_key_and_cert_chain_pem.tempfile() as path:
546546
ctx.load_cert_chain(path)
547547
elif _smells_like_pyopenssl(ctx):
548-
from OpenSSL.crypto import FILETYPE_PEM, load_certificate, load_privatekey
549-
550-
key = load_privatekey(FILETYPE_PEM, self.private_key_pem.bytes())
551-
ctx.use_privatekey(key)
552-
cert = load_certificate(FILETYPE_PEM, self.cert_chain_pems[0].bytes())
553-
ctx.use_certificate(cert)
548+
key = load_pem_private_key(self.private_key_pem.bytes(), None)
549+
ctx.use_privatekey(key) # type: ignore[arg-type]
550+
cert = x509.load_pem_x509_certificate(self.cert_chain_pems[0].bytes())
551+
ctx.use_certificate(cert) # type: ignore[arg-type]
554552
for pem in self.cert_chain_pems[1:]:
555-
cert = load_certificate(FILETYPE_PEM, pem.bytes())
556-
ctx.add_extra_chain_cert(cert)
553+
cert = x509.load_pem_x509_certificate(pem.bytes())
554+
ctx.add_extra_chain_cert(cert) # type: ignore[arg-type]
557555
else:
558556
raise TypeError(
559557
"unrecognized context type {!r}".format(ctx.__class__.__name__)

test-requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ attrs==24.2.0
88
# via service-identity
99
cffi==1.17.1
1010
# via cryptography
11-
coverage[toml]==7.6.4
11+
coverage[toml]==7.6.8
1212
# via -r test-requirements.in
1313
cryptography==43.0.3
1414
# via
@@ -19,7 +19,7 @@ idna==3.10
1919
# via -r test-requirements.in
2020
iniconfig==2.0.0
2121
# via pytest
22-
packaging==24.1
22+
packaging==24.2
2323
# via pytest
2424
pluggy==1.5.0
2525
# via pytest
@@ -31,7 +31,7 @@ pyasn1-modules==0.4.1
3131
# via service-identity
3232
pycparser==2.22
3333
# via cffi
34-
pyopenssl==24.2.1
34+
pyopenssl==24.3.0
3535
# via -r test-requirements.in
3636
pytest==8.3.3
3737
# via -r test-requirements.in

0 commit comments

Comments
 (0)