MCPcopy Create free account
hub / github.com/masterking32/MasterHttpRelayVPN / _serve_ca_cert

Method _serve_ca_cert

src/proxy/proxy_server.py:430–453  ·  view source on GitHub ↗

Serve the MITM CA certificate so LAN devices can install it.

(self, writer: asyncio.StreamWriter)

Source from the content-addressed store, hash-verified

428 # ── client handler ────────────────────────────────────────────
429
430 async def _serve_ca_cert(self, writer: asyncio.StreamWriter) -> None:
431 """Serve the MITM CA certificate so LAN devices can install it."""
432 import os as _os
433 ca_path = getattr(self, "_ca_cert_file", None)
434 if not ca_path or not _os.path.exists(ca_path):
435 writer.write(
436 b"HTTP/1.1 404 Not Found\r\n"
437 b"Content-Length: 0\r\n"
438 b"Connection: close\r\n\r\n"
439 )
440 await writer.drain()
441 return
442 with open(ca_path, "rb") as f:
443 cert_data = f.read()
444 headers = (
445 b"HTTP/1.1 200 OK\r\n"
446 b"Content-Type: application/x-x509-ca-cert\r\n"
447 b"Content-Disposition: attachment; filename=\"ca.crt\"\r\n"
448 + b"Content-Length: " + str(len(cert_data)).encode() + b"\r\n"
449 + b"Connection: close\r\n\r\n"
450 )
451 writer.write(headers + cert_data)
452 await writer.drain()
453 log.info("Served CA certificate to LAN device")
454
455 async def _on_client(self, reader: asyncio.StreamReader, writer: asyncio.StreamWriter):
456 addr = writer.get_extra_info("peername")

Callers 1

_on_clientMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected