Example #1
0
 def test_with_ca(self):
     with tutils.tmpdir() as d:
         cacert = os.path.join(d, "cacert")
         assert certutils.dummy_ca(cacert)
         p = os.path.join(d, "foo")
         certutils.dummy_cert(file(p, "w"), cacert, "foo.com",
                              ["one.com", "two.com", "*.three.com"])
         assert file(p).read()
Example #2
0
    def test_with_ca(self):
        with tutils.tmpdir() as d:
            ca = certutils.CertStore.from_store(d, "test")
            r = certutils.dummy_cert(ca.default_privatekey, ca.default_ca,
                                     b"foo.com",
                                     [b"one.com", b"two.com", b"*.three.com"])
            assert r.cn == b"foo.com"

            r = certutils.dummy_cert(ca.default_privatekey, ca.default_ca,
                                     None, [])
            assert r.cn is None
Example #3
0
 def test_with_ca(self):
     with tutils.tmpdir() as d:
         cacert = os.path.join(d, "cacert")
         assert certutils.dummy_ca(cacert)
         p = os.path.join(d, "foo")
         certutils.dummy_cert(
             file(p, "w"),
             cacert,
             "foo.com",
             ["one.com", "two.com", "*.three.com"]
         )
         assert file(p).read()
Example #4
0
 def test_with_ca(self):
     with tutils.tmpdir() as d:
         ca = certutils.CertStore.from_store(d, "test")
         r = certutils.dummy_cert(
             ca.default_privatekey, ca.default_ca, b"foo.com", [b"one.com", b"two.com", b"*.three.com"]
         )
         assert r.cn == b"foo.com"
Example #5
0
 def test_no_ca(self):
     with tutils.tmpdir() as d:
         p = certutils.dummy_cert(
             d,
             None,
             "foo.com",
             []
         )
         assert os.path.exists(p)
Example #6
0
    def test_with_ca(self):
        with tutils.tmpdir() as d:
            cacert = os.path.join(d, "foo/cert.cnf")
            assert certutils.dummy_ca(cacert)
            p = certutils.dummy_cert(
                os.path.join(d, "foo"),
                cacert,
                "foo.com",
                ["one.com", "two.com", "*.three.com"]
            )
            assert os.path.exists(p)

            # Short-circuit
            assert certutils.dummy_cert(
                os.path.join(d, "foo"),
                cacert,
                "foo.com",
                []
            )
Example #7
0
 def test_with_ca(self):
     with tutils.tmpdir() as d:
         cacert = os.path.join(d, "cacert")
         assert certutils.dummy_ca(cacert)
         r = certutils.dummy_cert(
             cacert,
             "foo.com",
             ["one.com", "two.com", "*.three.com"]
         )
         assert r.cn == "foo.com"
Example #8
0
 def test_with_ca(self):
     with tutils.tmpdir() as d:
         ca = certutils.CertStore.from_store(d, "test")
         r = certutils.dummy_cert(
             ca.privkey,
             ca.cacert,
             "foo.com",
             ["one.com", "two.com", "*.three.com"]
         )
         assert r.cn == "foo.com"
Example #9
0
 def find_cert(self, host, port, sni):
     if self.config.certfile:
         return self.config.certfile
     else:
         sans = []
         if self.config.upstream_cert:
             cert = certutils.get_remote_cert(host, port, sni)
             sans = cert.altnames
             host = cert.cn
         ret = certutils.dummy_cert(self.config.certdir, self.config.cacert, host, sans)
         time.sleep(self.config.cert_wait_time)
         if not ret:
             raise ProxyError(502, "mitmproxy: Unable to generate dummy cert.")
         return ret
Example #10
0
 def find_cert(self, host, port, sni):
     if self.config.certfile:
         return self.config.certfile
     else:
         sans = []
         if not self.config.no_upstream_cert:
             try:
                 cert = certutils.get_remote_cert(host, port, sni)
             except tcp.NetLibError, v:
                 raise ProxyError(502, "Unable to get remote cert: %s"%str(v))
             sans = cert.altnames
             host = cert.cn.decode("utf8").encode("idna")
         ret = certutils.dummy_cert(self.config.certdir, self.config.cacert, host, sans)
         time.sleep(self.config.cert_wait_time)
         if not ret:
             raise ProxyError(502, "mitmproxy: Unable to generate dummy cert.")
         return ret
Example #11
0
 def find_cert(self, host, port, sni):
     if self.config.certfile:
         return self.config.certfile
     else:
         sans = []
         if not self.config.no_upstream_cert:
             try:
                 cert = certutils.get_remote_cert(host, port, sni)
             except tcp.NetLibError, v:
                 raise ProxyError(502, "Unable to get remote cert: %s"%str(v))
             sans = cert.altnames
             host = cert.cn.decode("utf8").encode("idna")
         ret = certutils.dummy_cert(self.config.certdir, self.config.cacert, host, sans)
         time.sleep(self.config.cert_wait_time)
         if not ret:
             raise ProxyError(502, "mitmproxy: Unable to generate dummy cert.")
         return ret