def fetch_server_certificate (host, port):
def subproc(cmd):
- from subprocess import Popen, PIPE, STDOUT
- proc = Popen(cmd, stdout=PIPE, stderr=STDOUT, shell=True)
+ from subprocess import Popen, PIPE, STDOUT, DEVNULL
+ proc = Popen(cmd, stdout=PIPE, stderr=STDOUT, stdin=DEVNULL)
status = proc.wait()
output = proc.stdout.read()
return status, output
fp.write(m.group(1) + b"\n")
try:
tn2 = (outfile or tempfile.mktemp())
- status, output = subproc(r'openssl x509 -in "%s" -out "%s"' %
- (tn, tn2))
+ cmd = ['openssl', 'x509', '-in', tn, '-out', tn2]
+ status, output = subproc(cmd)
if status != 0:
raise RuntimeError('OpenSSL x509 failed with status %s and '
'output: %r' % (status, output))
finally:
os.unlink(tn)
- if sys.platform.startswith("win"):
- tfile = tempfile.mktemp()
- with open(tfile, "w") as fp:
- fp.write("quit\n")
- try:
- status, output = subproc(
- 'openssl s_client -connect "%s:%s" -showcerts < "%s"' %
- (host, port, tfile))
- finally:
- os.unlink(tfile)
- else:
- status, output = subproc(
- 'openssl s_client -connect "%s:%s" -showcerts < /dev/null' %
- (host, port))
+ cmd = ['openssl', 's_client', '-connect', '%s:%s' % (host, port), '-showcerts']
+ status, output = subproc(cmd)
+
if status != 0:
raise RuntimeError('OpenSSL connect failed with status %s and '
'output: %r' % (status, output))