summaryrefslogtreecommitdiffstats
path: root/Tools/ssl/get-remote-certificate.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-10-28 08:38:30 (GMT)
committerGeorg Brandl <georg@python.org>2010-10-28 08:38:30 (GMT)
commitcbb9421347c97b5a443b260118931962783d4efc (patch)
treea6d94ef733b52e8d7dbed9af04047ffbd25bb319 /Tools/ssl/get-remote-certificate.py
parent4d540885993b0c8336f20fd52ee3972f0de44c25 (diff)
downloadcpython-cbb9421347c97b5a443b260118931962783d4efc.zip
cpython-cbb9421347c97b5a443b260118931962783d4efc.tar.gz
cpython-cbb9421347c97b5a443b260118931962783d4efc.tar.bz2
Fix bytes/str issues in get-remote-certificate.py.
Diffstat (limited to 'Tools/ssl/get-remote-certificate.py')
-rw-r--r--Tools/ssl/get-remote-certificate.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/Tools/ssl/get-remote-certificate.py b/Tools/ssl/get-remote-certificate.py
index 67491c1..02f1c8a 100644
--- a/Tools/ssl/get-remote-certificate.py
+++ b/Tools/ssl/get-remote-certificate.py
@@ -6,11 +6,14 @@
#
# By Bill Janssen.
+import re
+import os
+import ssl
import sys
+import tempfile
-def fetch_server_certificate (host, port):
- import re, tempfile, os, ssl
+def fetch_server_certificate (host, port):
def subproc(cmd):
from subprocess import Popen, PIPE, STDOUT
@@ -20,15 +23,15 @@ def fetch_server_certificate (host, port):
return status, output
def strip_to_x509_cert(certfile_contents, outfile=None):
- m = re.search(r"^([-]+BEGIN CERTIFICATE[-]+[\r]*\n"
- r".*[\r]*^[-]+END CERTIFICATE[-]+)$",
+ m = re.search(br"^([-]+BEGIN CERTIFICATE[-]+[\r]*\n"
+ br".*[\r]*^[-]+END CERTIFICATE[-]+)$",
certfile_contents, re.MULTILINE | re.DOTALL)
if not m:
return None
else:
tn = tempfile.mktemp()
- fp = open(tn, "w")
- fp.write(m.group(1) + "\n")
+ fp = open(tn, "wb")
+ fp.write(m.group(1) + b"\n")
fp.close()
try:
tn2 = (outfile or tempfile.mktemp())
@@ -67,6 +70,7 @@ def fetch_server_certificate (host, port):
(host, port))
return certtext
+
if __name__ == "__main__":
if len(sys.argv) < 2:
sys.stderr.write(
@@ -75,5 +79,5 @@ if __name__ == "__main__":
sys.exit(1)
for arg in sys.argv[1:]:
host, port = arg.split(":")
- sys.stdout.write(fetch_server_certificate(host, int(port)))
+ sys.stdout.buffer.write(fetch_server_certificate(host, int(port)))
sys.exit(0)