Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add subjectAltName for valid certification in recent browser #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion proxy2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import time
import json
import re
from string import Template
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from SocketServer import ThreadingMixIn
from cStringIO import StringIO
Expand Down Expand Up @@ -44,6 +45,7 @@ class ProxyRequestHandler(BaseHTTPRequestHandler):
cacert = join_with_script_dir('ca.crt')
certkey = join_with_script_dir('cert.key')
certdir = join_with_script_dir('certs/')
conf_template = Template("subjectAltName=${category}:${hostname}")
timeout = 5
lock = threading.Lock()

Expand All @@ -68,14 +70,25 @@ def do_CONNECT(self):

def connect_intercept(self):
hostname = self.path.split(':')[0]
ippat = re.compile("^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
if ippat.match(hostname):
cert_category = "IP"
else:
cert_category = "DNS"


certpath = "%s/%s.crt" % (self.certdir.rstrip('/'), hostname)
confpath = "%s/%s.cnf" % (self.certdir.rstrip('/'), hostname)

with self.lock:
if not os.path.isfile(certpath):
with open(confpath, 'w') as fp:
fp.write(self.conf_template.substitute(category = cert_category, hostname = hostname))
epoch = "%d" % (time.time() * 1000)
p1 = Popen(["openssl", "req", "-new", "-key", self.certkey, "-subj", "/CN=%s" % hostname], stdout=PIPE)
p2 = Popen(["openssl", "x509", "-req", "-days", "3650", "-CA", self.cacert, "-CAkey", self.cakey, "-set_serial", epoch, "-out", certpath], stdin=p1.stdout, stderr=PIPE)
p2 = Popen(["openssl", "x509", "-req", "-extfile", confpath, "-days", "3650", "-CA", self.cacert, "-CAkey", self.cakey, "-set_serial", epoch, "-sha512", "-out", certpath], stdin=p1.stdout, stderr=PIPE)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

H

p2.communicate()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wyd

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.unlink(confpath)

self.wfile.write("%s %d %s\r\n" % (self.protocol_version, 200, 'Connection Established'))
self.end_headers()
Expand Down
2 changes: 1 addition & 1 deletion setup_https_intercept.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh

openssl genrsa -out ca.key 2048
openssl req -new -x509 -days 3650 -key ca.key -out ca.crt -subj "/CN=proxy2 CA"
openssl req -new -x509 -days 3650 -key ca.key -sha512 -out ca.crt -subj "/CN=proxy2 CA"
openssl genrsa -out cert.key 2048
mkdir certs/