codekingpro/portable-devtools
114k
1from __future__ import annotations2 3from dataclasses import dataclass4from dataclasses import field5from ssl import VerifyMode6 7from aioquic.tls import CipherSuite8from cryptography import x5099from cryptography.hazmat.primitives.asymmetric import dsa10from cryptography.hazmat.primitives.asymmetric import ec11from cryptography.hazmat.primitives.asymmetric import rsa12 13from mitmproxy.proxy import commands14from mitmproxy.tls import TlsData15 16 17@dataclass18class QuicTlsSettings:19 """20 Settings necessary to establish QUIC's TLS context.21 """22 23 alpn_protocols: list[str] | None = None24 """A list of supported ALPN protocols."""25 certificate: x509.Certificate | None = None26 """The certificate to use for the connection."""27 certificate_chain: list[x509.Certificate] = field(default_factory=list)28 """A list of additional certificates to send to the peer."""29 certificate_private_key: (30 dsa.DSAPrivateKey | ec.EllipticCurvePrivateKey | rsa.RSAPrivateKey | None31 ) = None32 """The certificate's private key."""33 cipher_suites: list[CipherSuite] | None = None34 """An optional list of allowed/advertised cipher suites."""35 ca_path: str | None = None36 """An optional path to a directory that contains the necessary information to verify the peer certificate."""37 ca_file: str | None = None38 """An optional path to a PEM file that will be used to verify the peer certificate."""39 verify_mode: VerifyMode | None = None40 """An optional flag that specifies how/if the peer's certificate should be validated."""41 42 43@dataclass44class QuicTlsData(TlsData):45 """46 Event data for `quic_start_client` and `quic_start_server` event hooks.47 """48 49 settings: QuicTlsSettings | None = None50 """51 The associated `QuicTlsSettings` object.52 This will be set by an addon in the `quic_start_*` event hooks.53 """54 55 56@dataclass57class QuicStartClientHook(commands.StartHook):58 """59 TLS negotiation between mitmproxy and a client over QUIC is about to start.60 61 An addon is expected to initialize data.settings.62 (by default, this is done by `mitmproxy.addons.tlsconfig`)63 """64 65 data: QuicTlsData66 67 68@dataclass69class QuicStartServerHook(commands.StartHook):70 """71 TLS negotiation between mitmproxy and a server over QUIC is about to start.72 73 An addon is expected to initialize data.settings.74 (by default, this is done by `mitmproxy.addons.tlsconfig`)75 """76 77 data: QuicTlsData78 