From 2f3d29e05bbab4cfb95322f5cccf6d2aec66428c Mon Sep 17 00:00:00 2001 From: Robert Xiao Date: Wed, 27 Nov 2024 17:43:49 +0800 Subject: [PATCH] Fix #7354 "AttributeError" from tlsconfig.py (#7355) * Fix 7354 "AttributeError" from tlsconfig.py CertStore was inserting raw x509.Certificate objects into default_chain_certs instead of Cert objects, which caused an error later in tlsconfig.py when the certs were used. * [autofix.ci] apply automated fixes * typing++, add CHANGELOG entry * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Maximilian Hils --- CHANGELOG.md | 2 ++ mitmproxy/certs.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a01599aa1..bd8f10b0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ - Stop sorting keys in JSON contentview ([#7346](https://github.com/mitmproxy/mitmproxy/pull/7346), @injust) +- Fix a bug where a custom CA would raise an error. + ([#7355](https://github.com/mitmproxy/mitmproxy/pull/7355), @nneonneo) ## 24 November 2024: mitmproxy 11.0.1 diff --git a/mitmproxy/certs.py b/mitmproxy/certs.py index a5a81ea1a..550164289 100644 --- a/mitmproxy/certs.py +++ b/mitmproxy/certs.py @@ -362,6 +362,11 @@ class CertStore: """ STORE_CAP = 100 + default_privatekey: rsa.RSAPrivateKey + default_ca: Cert + default_chain_file: Path | None + default_chain_certs: list[Cert] + dhparams: DHParams certs: dict[TCertId, CertStoreEntry] expire_queue: list[CertStoreEntry] @@ -376,7 +381,12 @@ class CertStore: self.default_ca = default_ca self.default_chain_file = default_chain_file self.default_chain_certs = ( - x509.load_pem_x509_certificates(self.default_chain_file.read_bytes()) + [ + Cert(c) + for c in x509.load_pem_x509_certificates( + self.default_chain_file.read_bytes() + ) + ] if self.default_chain_file else [default_ca] )