MCPcopy Index your code
hub / github.com/mitmproxy/mitmproxy / create_proxy_server_context

Function create_proxy_server_context

mitmproxy/net/tls.py:192–237  ·  view source on GitHub ↗
(
    *,
    method: Method,
    min_version: Version,
    max_version: Version,
    cipher_list: tuple[str, ...] | None,
    ecdh_curve: EllipticCurve | None,
    verify: Verify,
    ca_path: str | None,
    ca_pemfile: str | None,
    client_cert: str | None,
    legacy_server_connect: bool,
)

Source from the content-addressed store, hash-verified

190
191@lru_cache(256)
192def create_proxy_server_context(
193 *,
194 method: Method,
195 min_version: Version,
196 max_version: Version,
197 cipher_list: tuple[str, ...] | None,
198 ecdh_curve: EllipticCurve | None,
199 verify: Verify,
200 ca_path: str | None,
201 ca_pemfile: str | None,
202 client_cert: str | None,
203 legacy_server_connect: bool,
204) -> SSL.Context:
205 context: SSL.Context = _create_ssl_context(
206 method=method,
207 min_version=min_version,
208 max_version=max_version,
209 cipher_list=cipher_list,
210 ecdh_curve=ecdh_curve,
211 )
212 context.set_verify(verify.value, None)
213
214 if ca_path is None and ca_pemfile is None:
215 ca_pemfile = certifi.where()
216 try:
217 context.load_verify_locations(ca_pemfile, ca_path)
218 except SSL.Error as e:
219 raise RuntimeError(
220 f"Cannot load trusted certificates ({ca_pemfile=}, {ca_path=})."
221 ) from e
222
223 # Client Certs
224 if client_cert:
225 try:
226 context.use_privatekey_file(client_cert)
227 context.use_certificate_chain_file(client_cert)
228 except SSL.Error as e:
229 raise RuntimeError(f"Cannot load TLS client certificate: {e}") from e
230
231 # https://github.com/mitmproxy/mitmproxy/discussions/7550
232 SSL._lib.SSL_CTX_set_post_handshake_auth(context._context, 1) # type: ignore
233
234 if legacy_server_connect:
235 context.set_options(OP_LEGACY_SERVER_CONNECT)
236
237 return context
238
239
240@lru_cache(256)

Callers

nothing calls this directly

Calls 1

_create_ssl_contextFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…