From ac77fde89217ac31f5a74dc07dd6de30df247138 Mon Sep 17 00:00:00 2001 From: Salad Dais Date: Tue, 9 Jan 2024 09:17:05 +0000 Subject: [PATCH] Update mitmproxy, change required Python to 3.10 --- .github/workflows/pypi_publish.yml | 2 +- README.md | 2 +- hippolyzer/lib/proxy/http_proxy.py | 19 +++++++++++++++---- setup.py | 7 +++---- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pypi_publish.yml b/.github/workflows/pypi_publish.yml index 8f8d16b..1ca6fa0 100644 --- a/.github/workflows/pypi_publish.yml +++ b/.github/workflows/pypi_publish.yml @@ -19,7 +19,7 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: - python-version: 3.9 + python-version: 3.10 - name: Install dependencies run: | diff --git a/README.md b/README.md index 46850f6..fe84e62 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ with low-level SL details. See the [Local Animation addon example](https://githu ### From Source -* Python 3.8 or above is **required**. If you're unable to upgrade your system Python package due to +* Python 3.10 or above is **required**. If you're unable to upgrade your system Python package due to being on a stable distro, you can use [pyenv](https://github.com/pyenv/pyenv) to create a self-contained Python install with the appropriate version. * [Create a clean Python 3 virtualenv](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment) diff --git a/hippolyzer/lib/proxy/http_proxy.py b/hippolyzer/lib/proxy/http_proxy.py index c7aa511..b056b45 100644 --- a/hippolyzer/lib/proxy/http_proxy.py +++ b/hippolyzer/lib/proxy/http_proxy.py @@ -8,6 +8,7 @@ import queue import typing import uuid import weakref +from typing import Iterable import mitmproxy.certs import mitmproxy.ctx @@ -15,7 +16,10 @@ import mitmproxy.log import mitmproxy.master import mitmproxy.options import mitmproxy.proxy +from cryptography import x509 +from cryptography.x509 import GeneralNames from mitmproxy.addons import core, clientplayback, proxyserver, next_layer, disable_h2c +from mitmproxy.certs import CertStoreEntry from mitmproxy.http import HTTPFlow from mitmproxy.proxy.layers import tls import OpenSSL @@ -26,9 +30,16 @@ from hippolyzer.lib.proxy.caps import SerializedCapData class SLCertStore(mitmproxy.certs.CertStore): - def get_cert(self, commonname: typing.Optional[str], sans: typing.List[str], *args, **kwargs): + def get_cert( + self, + commonname: str | None, + sans: Iterable[x509.GeneralName], + organization: str | None = None, + *args, + **kwargs + ) -> CertStoreEntry: entry = super().get_cert(commonname, sans, *args, **kwargs) - cert, privkey, chain = entry.cert, entry.privatekey, entry.chain_file + cert, privkey, chain, chain_certs = entry.cert, entry.privatekey, entry.chain_file, entry.chain_certs x509 = cert.to_pyopenssl() # The cert must have a subject key ID or the viewer will reject it. for i in range(0, x509.get_extension_count()): @@ -48,10 +59,10 @@ class SLCertStore(mitmproxy.certs.CertStore): ]) x509.sign(OpenSSL.crypto.PKey.from_cryptography_key(privkey), "sha256") # type: ignore new_entry = mitmproxy.certs.CertStoreEntry( - mitmproxy.certs.Cert.from_pyopenssl(x509), privkey, chain + mitmproxy.certs.Cert.from_pyopenssl(x509), privkey, chain, chain_certs, ) # Replace the cert that was created in the base `get_cert()` with our modified cert - self.certs[(commonname, tuple(sans))] = new_entry + self.certs[(commonname, GeneralNames(sans))] = new_entry self.expire_queue.pop(-1) self.expire(new_entry) return new_entry diff --git a/setup.py b/setup.py index 1e5197b..2361cb7 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,6 @@ setup( "Operating System :: POSIX", "Operating System :: Microsoft :: Windows", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: Implementation :: CPython", @@ -79,7 +78,7 @@ setup( } }, zip_safe=False, - python_requires='>=3.9', + python_requires='>=3.10', install_requires=[ 'llsd<1.1.0', 'defusedxml', @@ -100,8 +99,8 @@ setup( # Proxy-specific stuff 'outleap<1.0', 'arpeggio', - # 10.x will be a major change. - 'mitmproxy>=9.0.0,<10', + # 11.x will be a major change. + 'mitmproxy>=10.0.0,<11', 'Werkzeug<3.0', # For REPLs 'ptpython<4.0',