aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-03-12 11:25:50 +1300
committerAldo Cortesi <aldo@nullcube.com>2012-03-12 11:25:50 +1300
commitfa6305ee9826db26bfa4ed8d95a1dc41293daf13 (patch)
tree5496ec179a985fce7b1db6c187da1ddcbd205fdc
parentfdffb2398935f7a4e44b0535a9692a87f26e03d2 (diff)
downloadmitmproxy-fa6305ee9826db26bfa4ed8d95a1dc41293daf13.tar.gz
mitmproxy-fa6305ee9826db26bfa4ed8d95a1dc41293daf13.tar.bz2
mitmproxy-fa6305ee9826db26bfa4ed8d95a1dc41293daf13.zip
Cleanliness fixes.
- Remove unused code during previous commit. - Code coverage fixes.
-rw-r--r--libmproxy/certutils.py97
-rw-r--r--test/test_utils.py1
2 files changed, 3 insertions, 95 deletions
diff --git a/libmproxy/certutils.py b/libmproxy/certutils.py
index 6650486b..ddf17f2e 100644
--- a/libmproxy/certutils.py
+++ b/libmproxy/certutils.py
@@ -119,101 +119,6 @@ def dummy_cert(certdir, ca, commonname, sans):
return certpath
-def dummy_cert_(certdir, ca, commonname, sans):
- """
- certdir: Certificate directory.
- ca: Path to the certificate authority file, or None.
- commonname: Common name for the generated certificate.
-
- Returns cert path if operation succeeded, None if not.
- """
- namehash = hashlib.sha256(commonname).hexdigest()
- certpath = os.path.join(certdir, namehash + ".pem")
- if os.path.exists(certpath):
- return certpath
-
- confpath = os.path.join(certdir, namehash + ".cnf")
- reqpath = os.path.join(certdir, namehash + ".req")
-
- template = open(utils.pkg_data.path("resources/cert.cnf")).read()
-
- ss = []
- for i, v in enumerate(sans):
- ss.append("DNS.%s = %s"%(i+1, v))
- ss = "\n".join(ss)
-
- f = open(confpath, "w")
- f.write(
- template%(
- dict(
- commonname=commonname,
- sans=ss,
- altnames="subjectAltName = @alt_names" if ss else ""
- )
- )
- )
- f.close()
-
- if ca:
- # Create a dummy signed certificate. Uses same key as the signing CA
- cmd = [
- "openssl",
- "req",
- "-new",
- "-config", confpath,
- "-out", reqpath,
- "-key", ca,
- ]
- ret = subprocess.call(
- cmd,
- stderr=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stdin=subprocess.PIPE
- )
- if ret: return None
- cmd = [
- "openssl",
- "x509",
- "-req",
- "-in", reqpath,
- "-days", CERT_EXPIRY,
- "-out", certpath,
- "-CA", ca,
- "-CAcreateserial",
- "-extfile", confpath,
- "-extensions", "v3_cert_req",
- ]
- ret = subprocess.call(
- cmd,
- stderr=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stdin=subprocess.PIPE
- )
- if ret: return None
- else:
- # Create a new selfsigned certificate + key
- cmd = [
- "openssl",
- "req",
- "-new",
- "-x509",
- "-config", confpath,
- "-nodes",
- "-days", CERT_EXPIRY,
- "-out", certpath,
- "-newkey", "rsa:1024",
- "-keyout", certpath,
- ]
- ret = subprocess.call(
- cmd,
- stderr=subprocess.PIPE,
- stdout=subprocess.PIPE,
- stdin=subprocess.PIPE
- )
- if ret: return None
- return certpath
-
-
class _GeneralName(univ.Choice):
# We are only interested in dNSNames. We use a default handler to ignore
# other types.
@@ -258,9 +163,11 @@ class SSLCert:
return altnames
+# begin nocover
def get_remote_cert(host, port):
addr = socket.gethostbyname(host)
s = ssl.get_server_certificate((addr, port))
return SSLCert(s)
+# end nocover
diff --git a/test/test_utils.py b/test/test_utils.py
index 9ab6d7b9..9f07c706 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -54,6 +54,7 @@ class upretty_size(libpry.AutoTree):
class uData(libpry.AutoTree):
def test_nonexistent(self):
+ assert utils.pkg_data.path("console")
libpry.raises("does not exist", utils.pkg_data.path, "nonexistent")