aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2013-06-16 00:28:21 +0200
committerMaximilian Hils <git@maximilianhils.com>2013-06-16 00:28:21 +0200
commitc9ab1c60b5d43f0b4d645c751350b16e9e562b55 (patch)
tree9e73c400b2c7e940d42b8e6e4b111a8b903e8dbc
parentd698ee50a74ac33730ce19cf5eeb36935bd3643d (diff)
downloadmitmproxy-c9ab1c60b5d43f0b4d645c751350b16e9e562b55.tar.gz
mitmproxy-c9ab1c60b5d43f0b4d645c751350b16e9e562b55.tar.bz2
mitmproxy-c9ab1c60b5d43f0b4d645c751350b16e9e562b55.zip
always read files in binary mode
-rw-r--r--netlib/certutils.py12
-rw-r--r--test/test_certutils.py12
2 files changed, 12 insertions, 12 deletions
diff --git a/netlib/certutils.py b/netlib/certutils.py
index f18318f6..4c06eb8f 100644
--- a/netlib/certutils.py
+++ b/netlib/certutils.py
@@ -48,23 +48,23 @@ def dummy_ca(path):
key, ca = create_ca()
# Dump the CA plus private key
- f = open(path, "w")
+ f = open(path, "wb")
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 = open(os.path.join(dirname, basename + "-cert.pem"), "wb")
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 = open(os.path.join(dirname, basename + "-cert.cer"), "wb")
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")
+ f = open(os.path.join(dirname, basename + "-cert.p12"), "wb")
p12 = OpenSSL.crypto.PKCS12()
p12.set_certificate(ca)
p12.set_privatekey(key)
@@ -88,7 +88,7 @@ def dummy_cert(fp, ca, commonname, sans):
ss.append("DNS: %s"%i)
ss = ", ".join(ss)
- raw = file(ca, "r").read()
+ raw = file(ca, "rb").read()
ca = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, raw)
key = OpenSSL.crypto.load_privatekey(OpenSSL.crypto.FILETYPE_PEM, raw)
@@ -165,7 +165,7 @@ class CertStore:
if os.path.exists(certpath):
return certpath
elif cacert:
- f = open(certpath, "w")
+ f = open(certpath, "wb")
dummy_cert(f, cacert, commonname, sans)
return certpath
diff --git a/test/test_certutils.py b/test/test_certutils.py
index 334a6be4..89b6ff50 100644
--- a/test/test_certutils.py
+++ b/test/test_certutils.py
@@ -53,22 +53,22 @@ class TestDummyCert:
assert certutils.dummy_ca(cacert)
p = os.path.join(d, "foo")
certutils.dummy_cert(
- file(p, "w"),
+ file(p, "wb"),
cacert,
"foo.com",
["one.com", "two.com", "*.three.com"]
)
- assert file(p).read()
+ assert file(p,"rb").read()
class TestSSLCert:
def test_simple(self):
- c = certutils.SSLCert.from_pem(file(tutils.test_data.path("data/text_cert"), "r").read())
+ c = certutils.SSLCert.from_pem(file(tutils.test_data.path("data/text_cert"), "rb").read())
assert c.cn == "google.com"
assert len(c.altnames) == 436
- c = certutils.SSLCert.from_pem(file(tutils.test_data.path("data/text_cert_2"), "r").read())
+ c = certutils.SSLCert.from_pem(file(tutils.test_data.path("data/text_cert_2"), "rb").read())
assert c.cn == "www.inode.co.nz"
assert len(c.altnames) == 2
assert c.digest("sha1")
@@ -82,11 +82,11 @@ class TestSSLCert:
c.has_expired
def test_err_broken_sans(self):
- c = certutils.SSLCert.from_pem(file(tutils.test_data.path("data/text_cert_weird1"), "r").read())
+ c = certutils.SSLCert.from_pem(file(tutils.test_data.path("data/text_cert_weird1"), "rb").read())
# This breaks unless we ignore a decoding error.
c.altnames
def test_der(self):
- d = file(tutils.test_data.path("data/dercert")).read()
+ d = file(tutils.test_data.path("data/dercert"),"rb").read()
s = certutils.SSLCert.from_der(d)
assert s.cn