From 35ee0c098f1a9c492ddec34bf03f4f6741ac6d41 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 27 Jun 2012 16:43:33 +1200 Subject: [PATCH] Remove certutils from mitmproxy. --- libmproxy/certutils.py | 219 ----------------------------------------- libmproxy/flow.py | 4 +- libmproxy/proxy.py | 4 +- test/data/text_cert | 145 --------------------------- test/data/text_cert_2 | 39 -------- test/test_certutils.py | 72 -------------- 6 files changed, 4 insertions(+), 479 deletions(-) delete mode 100644 libmproxy/certutils.py delete mode 100644 test/data/text_cert delete mode 100644 test/data/text_cert_2 delete mode 100644 test/test_certutils.py diff --git a/libmproxy/certutils.py b/libmproxy/certutils.py deleted file mode 100644 index 31b1fa08b..000000000 --- a/libmproxy/certutils.py +++ /dev/null @@ -1,219 +0,0 @@ -import os, ssl, hashlib, socket, time, datetime -from pyasn1.type import univ, constraint, char, namedtype, tag -from pyasn1.codec.der.decoder import decode -import OpenSSL - -CERT_SLEEP_TIME = 1 -CERT_EXPIRY = str(365 * 3) - - -def create_ca(): - key = OpenSSL.crypto.PKey() - key.generate_key(OpenSSL.crypto.TYPE_RSA, 1024) - ca = OpenSSL.crypto.X509() - ca.set_serial_number(int(time.time()*10000)) - ca.set_version(2) - ca.get_subject().CN = "mitmproxy" - ca.get_subject().O = "mitmproxy" - ca.gmtime_adj_notBefore(0) - ca.gmtime_adj_notAfter(24 * 60 * 60 * 720) - ca.set_issuer(ca.get_subject()) - ca.set_pubkey(key) - ca.add_extensions([ - OpenSSL.crypto.X509Extension("basicConstraints", True, - "CA:TRUE"), - OpenSSL.crypto.X509Extension("nsCertType", True, - "sslCA"), - OpenSSL.crypto.X509Extension("extendedKeyUsage", True, - "serverAuth,clientAuth,emailProtection,timeStamping,msCodeInd,msCodeCom,msCTLSign,msSGC,msEFS,nsSGC" - ), - OpenSSL.crypto.X509Extension("keyUsage", False, - "keyCertSign, cRLSign"), - OpenSSL.crypto.X509Extension("subjectKeyIdentifier", False, "hash", - subject=ca), - ]) - ca.sign(key, "sha1") - return key, ca - - -def dummy_ca(path): - dirname = os.path.dirname(path) - if not os.path.exists(dirname): - os.makedirs(dirname) - if path.endswith(".pem"): - basename, _ = os.path.splitext(path) - else: - basename = path - - key, ca = create_ca() - - # Dump the CA plus private key - f = open(path, "w") - f.write(OpenSSL.crypto.dump_privatekey(OpenSSL.crypto.FILETYPE_PEM, key)) - f.write(OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, ca)) - f.close() - - # Dump the certificate in PEM format - f = open(os.path.join(dirname, basename + "-cert.pem"), "w") - f.write(OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, ca)) - f.close() - - # Create a .cer file with the same contents for Android - f = open(os.path.join(dirname, basename + "-cert.cer"), "w") - f.write(OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, ca)) - f.close() - - # Dump the certificate in PKCS12 format for Windows devices - f = open(os.path.join(dirname, basename + "-cert.p12"), "w") - p12 = OpenSSL.crypto.PKCS12() - p12.set_certificate(ca) - p12.set_privatekey(key) - f.write(p12.export()) - f.close() - return True - - -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 - - ss = [] - for i in sans: - ss.append("DNS: %s"%i) - ss = ", ".join(ss) - - if ca: - raw = file(ca, "r").read() - ca = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, raw) - key = OpenSSL.crypto.load_privatekey(OpenSSL.crypto.FILETYPE_PEM, raw) - else: - key, ca = create_ca() - - req = OpenSSL.crypto.X509Req() - subj = req.get_subject() - subj.CN = commonname - req.set_pubkey(ca.get_pubkey()) - req.sign(key, "sha1") - if ss: - req.add_extensions([OpenSSL.crypto.X509Extension("subjectAltName", True, ss)]) - - cert = OpenSSL.crypto.X509() - cert.gmtime_adj_notBefore(0) - cert.gmtime_adj_notAfter(60 * 60 * 24 * 30) - cert.set_issuer(ca.get_subject()) - cert.set_subject(req.get_subject()) - cert.set_serial_number(int(time.time()*10000)) - if ss: - cert.add_extensions([OpenSSL.crypto.X509Extension("subjectAltName", True, ss)]) - cert.set_pubkey(req.get_pubkey()) - cert.sign(key, "sha1") - - f = open(certpath, "w") - f.write(OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, cert)) - f.close() - - return certpath - - -class _GeneralName(univ.Choice): - # We are only interested in dNSNames. We use a default handler to ignore - # other types. - componentType = namedtype.NamedTypes( - namedtype.NamedType('dNSName', char.IA5String().subtype( - implicitTag=tag.Tag(tag.tagClassContext, tag.tagFormatSimple, 2) - ) - ), - ) - - -class _GeneralNames(univ.SequenceOf): - componentType = _GeneralName() - sizeSpec = univ.SequenceOf.sizeSpec + constraint.ValueSizeConstraint(1, 1024) - - -class SSLCert: - def __init__(self, pemtxt): - """ - Returns a (common name, [subject alternative names]) tuple. - """ - self.cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, pemtxt) - - @classmethod - def from_der(klass, der): - pem = ssl.DER_cert_to_PEM_cert(der) - return klass(pem) - - def digest(self, name): - return self.cert.digest(name) - - @property - def issuer(self): - return self.cert.get_issuer().get_components() - - @property - def notbefore(self): - t = self.cert.get_notBefore() - return datetime.datetime.strptime(t, "%Y%m%d%H%M%SZ") - - @property - def notafter(self): - t = self.cert.get_notAfter() - return datetime.datetime.strptime(t, "%Y%m%d%H%M%SZ") - - @property - def has_expired(self): - return self.cert.has_expired() - - @property - def subject(self): - return self.cert.get_subject().get_components() - - @property - def serial(self): - return self.cert.get_serial_number() - - @property - def keyinfo(self): - pk = self.cert.get_pubkey() - types = { - OpenSSL.crypto.TYPE_RSA: "RSA", - OpenSSL.crypto.TYPE_DSA: "DSA", - } - return ( - types.get(pk.type(), "UNKNOWN"), - pk.bits() - ) - - @property - def cn(self): - cn = None - for i in self.subject: - if i[0] == "CN": - cn = i[1] - return cn - - @property - def altnames(self): - altnames = [] - for i in range(self.cert.get_extension_count()): - ext = self.cert.get_extension(i) - if ext.get_short_name() == "subjectAltName": - dec = decode(ext.get_data(), asn1Spec=_GeneralNames()) - for i in dec[0]: - altnames.append(i[0].asOctets()) - return altnames - - -def get_remote_cert(host, port): # pragma: no cover - addr = socket.gethostbyname(host) - s = ssl.get_server_certificate((addr, port)) - return SSLCert(s) diff --git a/libmproxy/flow.py b/libmproxy/flow.py index 0620ab185..06300784f 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -21,8 +21,8 @@ import hashlib, Cookie, cookielib, copy, re, urlparse import time import tnetstring, filt, script, utils, encoding, proxy from email.utils import parsedate_tz, formatdate, mktime_tz -from netlib import odict, http -import controller, version, certutils +from netlib import odict, http, certutils +import controller, version HDR_FORM_URLENCODED = "application/x-www-form-urlencoded" CONTENT_MISSING = 0 diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index bbccb713d..0f68fe258 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -16,8 +16,8 @@ import sys, os, string, socket, time import shutil, tempfile, threading import optparse, SocketServer from OpenSSL import SSL -from netlib import odict, tcp, http, wsgi -import utils, flow, certutils, version, platform +from netlib import odict, tcp, http, wsgi, certutils +import utils, flow, version, platform class ProxyError(Exception): diff --git a/test/data/text_cert b/test/data/text_cert deleted file mode 100644 index 36ca33b94..000000000 --- a/test/data/text_cert +++ /dev/null @@ -1,145 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIadTCCGd6gAwIBAgIGR09PUAFtMA0GCSqGSIb3DQEBBQUAMEYxCzAJBgNVBAYT -AlVTMRMwEQYDVQQKEwpHb29nbGUgSW5jMSIwIAYDVQQDExlHb29nbGUgSW50ZXJu -ZXQgQXV0aG9yaXR5MB4XDTEyMDExNzEyNTUwNFoXDTEzMDExNzEyNTUwNFowTDEL -MAkGA1UE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Wdvb2dsZS50bIIJZ29vZ2xl -LnRtgglnb29nbGUudG6CCWdvb2dsZS50b4IJZ29vZ2xlLnRwgglnb29nbGUudHSC -CWdvb2dsZS51c4IJZ29vZ2xlLnV6gglnb29nbGUudmeCCWdvb2dsZS52dYIJZ29v -Z2xlLndzMA0GCSqGSIb3DQEBBQUAA4GBAJmZ9RyqpUzrP0UcJnHXoLu/AjIEsIvZ -Y9hq/9bLry8InfmvERYHr4hNetkOYlW0FeDZtCpWxdPUgJjmWgKAK6j0goOFavTV -GptkL8gha4p1QUsdLkd36/cvBXeBYSle787veo46N1k4V6Uv2gaDVkre786CNsHv -Q6MYZ5ClQ+kS ------END CERTIFICATE----- - diff --git a/test/data/text_cert_2 b/test/data/text_cert_2 deleted file mode 100644 index ffe8faaea..000000000 --- a/test/data/text_cert_2 +++ /dev/null @@ -1,39 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIGujCCBaKgAwIBAgIDAQlEMA0GCSqGSIb3DQEBBQUAMIGMMQswCQYDVQQGEwJJ -TDEWMBQGA1UEChMNU3RhcnRDb20gTHRkLjErMCkGA1UECxMiU2VjdXJlIERpZ2l0 -YWwgQ2VydGlmaWNhdGUgU2lnbmluZzE4MDYGA1UEAxMvU3RhcnRDb20gQ2xhc3Mg -MSBQcmltYXJ5IEludGVybWVkaWF0ZSBTZXJ2ZXIgQ0EwHhcNMTAwMTExMTkyNzM2 -WhcNMTEwMTEyMDkxNDU1WjCBtDEgMB4GA1UEDRMXMTI2ODMyLU1DeExzWTZUbjFn -bTdvOTAxCzAJBgNVBAYTAk5aMR4wHAYDVQQKExVQZXJzb25hIE5vdCBWYWxpZGF0 -ZWQxKTAnBgNVBAsTIFN0YXJ0Q29tIEZyZWUgQ2VydGlmaWNhdGUgTWVtYmVyMRgw -FgYDVQQDEw93d3cuaW5vZGUuY28ubnoxHjAcBgkqhkiG9w0BCQEWD2ppbUBpbm9k -ZS5jby5uejCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCgg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y5z -dGFydHNzbC5jb20vY3J0MS1jcmwuY3JsMCqgKKAmhiRodHRwOi8vY3JsLnN0YXJ0 -c3NsLmNvbS9jcnQxLWNybC5jcmwwgY4GCCsGAQUFBwEBBIGBMH8wOQYIKwYBBQUH -MAGGLWh0dHA6Ly9vY3NwLnN0YXJ0c3NsLmNvbS9zdWIvY2xhc3MxL3NlcnZlci9j -YTBCBggrBgEFBQcwAoY2aHR0cDovL3d3dy5zdGFydHNzbC5jb20vY2VydHMvc3Vi -LmNsYXNzMS5zZXJ2ZXIuY2EuY3J0MCMGA1UdEgQcMBqGGGh0dHA6Ly93d3cuc3Rh -cnRzc2wuY29tLzANBgkqhkiG9w0BAQUFAAOCAQEAivWID0KT8q1EzWzy+BecsFry -hQhuLFfAsPkHqpNd9OfkRStGBuJlLX+9DQ9TzjqutdY2buNBuDn71buZK+Y5fmjr -28rAT6+WMd+KnCl5WLT5IOS6Z9s3cec5TFQbmOGlepSS9Q6Ts9KsXOHHQvDkQeDq -OV2UqdgXIAyFm5efSL9JXPXntRausNu2s8F2B2rRJe4jPfnUy2LvY8OW1YvjUA++ -vpdWRdfUbJQp55mRfaYMPRnyUm30lAI27QaxgQPFOqDeZUm5llb5eFG/B3f87uhg -+Y1oEykbEvZrIFN4hithioQ0tb+57FKkkG2sW3uemNiQw2qrEo/GAMb1cI50Rg== ------END CERTIFICATE----- - diff --git a/test/test_certutils.py b/test/test_certutils.py deleted file mode 100644 index 1fd6cbb20..000000000 --- a/test/test_certutils.py +++ /dev/null @@ -1,72 +0,0 @@ -import os -from libmproxy import certutils -import tutils - - -def test_dummy_ca(): - with tutils.tmpdir() as d: - path = os.path.join(d, "foo/cert.cnf") - assert certutils.dummy_ca(path) - assert os.path.exists(path) - - path = os.path.join(d, "foo/cert2.pem") - assert certutils.dummy_ca(path) - assert os.path.exists(path) - assert os.path.exists(os.path.join(d, "foo/cert2-cert.pem")) - assert os.path.exists(os.path.join(d, "foo/cert2-cert.p12")) - - -class TestDummyCert: - 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", - [] - ) - - def test_no_ca(self): - with tutils.tmpdir() as d: - p = certutils.dummy_cert( - d, - None, - "foo.com", - [] - ) - assert os.path.exists(p) - - -class TestSSLCert: - def test_simple(self): - c = certutils.SSLCert(file(tutils.test_data.path("data/text_cert"), "r").read()) - assert c.cn == "google.com" - assert len(c.altnames) == 436 - - c = certutils.SSLCert(file(tutils.test_data.path("data/text_cert_2"), "r").read()) - assert c.cn == "www.inode.co.nz" - assert len(c.altnames) == 2 - assert c.digest("sha1") - assert c.notbefore - assert c.notafter - assert c.subject - assert c.keyinfo == ("RSA", 2048) - assert c.serial - assert c.issuer - c.has_expired - - def test_der(self): - d = file(tutils.test_data.path("data/dercert")).read() - s = certutils.SSLCert.from_der(d) - assert s.cn