Пример #1
0
 def test_all(self):
     certfile = get_cert("www.example.com")
     with open(os.path.join(self.dir, "www.example.com.pem"), "rb") as f:
         contents = f.read()
     file = tempfile.mkstemp()[1]
     with open(file, "wb") as f:
         f.write(contents)
         f.write(_CACERT)
     context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
     chain = context.load_cert_chain(file)
     os.remove(file)
Пример #2
0
    def do_CONNECT(self):
        self.wfile.write(b"HTTP/1.1 200 Connection Established\r\nProxy-Agent:"
                         b" Script Proxy 0.1\r\n\r\n")

        host, port = self.path.split(":")
        port = int(port)

        sock = ssl.wrap_socket(self.request, certfile=get_cert(host),
                               server_side=True)
        rfile = sock.makefile('rb')
        wfile = sock.makefile('wb')

        raw_first_line = rfile.readline()
        first_line = raw_first_line.decode("utf-8")[:-2]
        command, path, version = first_line.split(" ", 2)

        url = "https://" + host + ("" if port == 443 else ":" +
                                   str(port)) + path

        self.do_request(command, url, version, parse_headers(rfile), rfile,
                        wfile)