2014-03-10 21:36:47 +00:00
|
|
|
from __future__ import absolute_import
|
2014-09-03 14:57:56 +00:00
|
|
|
import os
|
2014-12-27 10:06:51 +00:00
|
|
|
import tornado.web
|
|
|
|
import tornado.wsgi
|
|
|
|
import tornado.template
|
|
|
|
|
|
|
|
from .. import utils
|
2014-09-09 23:34:58 +00:00
|
|
|
from ..proxy import config
|
2013-03-24 20:20:26 +00:00
|
|
|
|
2014-12-27 10:06:51 +00:00
|
|
|
|
|
|
|
loader = tornado.template.Loader(utils.pkg_data.path("onboarding/templates"))
|
|
|
|
|
|
|
|
|
|
|
|
class Adapter(tornado.wsgi.WSGIAdapter):
|
|
|
|
# Tornado doesn't make the WSGI environment available to pages, so this
|
|
|
|
# hideous monkey patch is the easiest way to get to the mitmproxy.master
|
|
|
|
# variable.
|
2016-01-27 09:12:18 +00:00
|
|
|
|
2014-12-27 10:06:51 +00:00
|
|
|
def __init__(self, application):
|
|
|
|
self._application = application
|
|
|
|
|
|
|
|
def application(self, request):
|
|
|
|
request.master = self.environ["mitmproxy.master"]
|
|
|
|
return self._application(request)
|
|
|
|
|
|
|
|
def __call__(self, environ, start_response):
|
|
|
|
self.environ = environ
|
|
|
|
return tornado.wsgi.WSGIAdapter.__call__(
|
|
|
|
self,
|
|
|
|
environ,
|
|
|
|
start_response
|
|
|
|
)
|
2013-07-22 22:28:35 +00:00
|
|
|
|
2014-02-07 01:36:39 +00:00
|
|
|
|
2014-12-27 10:06:51 +00:00
|
|
|
class Index(tornado.web.RequestHandler):
|
2016-01-27 09:12:18 +00:00
|
|
|
|
2014-12-27 10:06:51 +00:00
|
|
|
def get(self):
|
|
|
|
t = loader.load("index.html")
|
|
|
|
self.write(t.generate())
|
2013-03-24 20:20:26 +00:00
|
|
|
|
2014-02-07 01:36:39 +00:00
|
|
|
|
2014-12-27 10:06:51 +00:00
|
|
|
class PEM(tornado.web.RequestHandler):
|
2016-01-27 09:12:18 +00:00
|
|
|
|
2015-03-19 15:17:44 +00:00
|
|
|
@property
|
|
|
|
def filename(self):
|
|
|
|
return config.CONF_BASENAME + "-ca-cert.pem"
|
|
|
|
|
2014-12-27 10:06:51 +00:00
|
|
|
def get(self):
|
2015-03-19 15:17:44 +00:00
|
|
|
p = os.path.join(self.request.master.server.config.cadir, self.filename)
|
|
|
|
self.set_header("Content-Type", "application/x-x509-ca-cert")
|
2015-05-30 00:03:28 +00:00
|
|
|
self.set_header(
|
|
|
|
"Content-Disposition",
|
|
|
|
"inline; filename={}".format(
|
|
|
|
self.filename))
|
2015-03-19 15:17:44 +00:00
|
|
|
|
|
|
|
with open(p, "rb") as f:
|
|
|
|
self.write(f.read())
|
2013-07-22 22:28:35 +00:00
|
|
|
|
|
|
|
|
2014-12-27 10:06:51 +00:00
|
|
|
class P12(tornado.web.RequestHandler):
|
2016-01-27 09:12:18 +00:00
|
|
|
|
2015-03-19 15:17:44 +00:00
|
|
|
@property
|
|
|
|
def filename(self):
|
|
|
|
return config.CONF_BASENAME + "-ca-cert.p12"
|
|
|
|
|
2014-12-27 10:06:51 +00:00
|
|
|
def get(self):
|
2015-03-19 15:17:44 +00:00
|
|
|
p = os.path.join(self.request.master.server.config.cadir, self.filename)
|
|
|
|
self.set_header("Content-Type", "application/x-pkcs12")
|
2015-05-30 00:03:28 +00:00
|
|
|
self.set_header(
|
|
|
|
"Content-Disposition",
|
|
|
|
"inline; filename={}".format(
|
|
|
|
self.filename))
|
2015-03-19 15:17:44 +00:00
|
|
|
|
|
|
|
with open(p, "rb") as f:
|
|
|
|
self.write(f.read())
|
2014-01-05 03:59:27 +00:00
|
|
|
|
|
|
|
|
2014-12-27 10:06:51 +00:00
|
|
|
application = tornado.web.Application(
|
|
|
|
[
|
|
|
|
(r"/", Index),
|
|
|
|
(r"/cert/pem", PEM),
|
|
|
|
(r"/cert/p12", P12),
|
|
|
|
(
|
|
|
|
r"/static/(.*)",
|
|
|
|
tornado.web.StaticFileHandler,
|
|
|
|
{
|
|
|
|
"path": utils.pkg_data.path("onboarding/static")
|
|
|
|
}
|
|
|
|
),
|
|
|
|
],
|
2015-05-30 00:03:28 +00:00
|
|
|
# debug=True
|
2014-12-27 10:06:51 +00:00
|
|
|
)
|
|
|
|
mapp = Adapter(application)
|