Skip to content

Commit 96f6a82

Browse files
committed
add subjectAltName for valid certification in recent browser
1 parent b2bab64 commit 96f6a82

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

proxy2.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import time
1313
import json
1414
import re
15+
from string import Template
1516
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
1617
from SocketServer import ThreadingMixIn
1718
from cStringIO import StringIO
@@ -44,6 +45,7 @@ class ProxyRequestHandler(BaseHTTPRequestHandler):
4445
cacert = join_with_script_dir('ca.crt')
4546
certkey = join_with_script_dir('cert.key')
4647
certdir = join_with_script_dir('certs/')
48+
conf_template = Template("subjectAltName=DNS:${hostname}")
4749
timeout = 5
4850
lock = threading.Lock()
4951

@@ -69,13 +71,17 @@ def do_CONNECT(self):
6971
def connect_intercept(self):
7072
hostname = self.path.split(':')[0]
7173
certpath = "%s/%s.crt" % (self.certdir.rstrip('/'), hostname)
74+
confpath = "%s/%s.cnf" % (self.certdir.rstrip('/'), hostname)
7275

7376
with self.lock:
7477
if not os.path.isfile(certpath):
78+
with open(confpath, 'w') as fp:
79+
fp.write(self.conf_template.substitute(hostname=hostname))
7580
epoch = "%d" % (time.time() * 1000)
7681
p1 = Popen(["openssl", "req", "-new", "-key", self.certkey, "-subj", "/CN=%s" % hostname], stdout=PIPE)
77-
p2 = Popen(["openssl", "x509", "-req", "-days", "3650", "-CA", self.cacert, "-CAkey", self.cakey, "-set_serial", epoch, "-out", certpath], stdin=p1.stdout, stderr=PIPE)
82+
p2 = Popen(["openssl", "x509", "-req", "-extfile", confpath, "-days", "3650", "-CA", self.cacert, "-CAkey", self.cakey, "-set_serial", epoch, "-out", certpath], stdin=p1.stdout, stderr=PIPE)
7883
p2.communicate()
84+
os.unlink(confpath)
7985

8086
self.wfile.write("%s %d %s\r\n" % (self.protocol_version, 200, 'Connection Established'))
8187
self.end_headers()

0 commit comments

Comments
 (0)