Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: sitescripts/testpages/web/sitekey_frame.py

Issue 29328589: Issue 3122 - Add testpages.web.sitekey_frame URL handler (Closed)
Patch Set: Removed unrelated commit that was accidentally uploaded previously Created Oct. 8, 2015, 11:26 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sitescripts/testpages/web/__init__.py ('k') | sitescripts/utils.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # coding: utf-8
2
3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2015 Eyeo GmbH
5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation.
9 #
10 # Adblock Plus is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
17
18 import base64
19 import M2Crypto
20 import os
21 import urllib
22
23 from sitescripts.utils import get_config, get_template
24 from sitescripts.web import url_handler
25
26 # https://www.python.org/dev/peps/pep-0333/#url-reconstruction
27 def request_path(environ):
28 path = urllib.quote(environ.get("SCRIPT_NAME", "") +
29 environ.get("PATH_INFO", ""))
30 query_string = environ.get("QUERY_STRING", "")
31 if query_string:
32 path += "?" + urllib.quote(query_string)
33 return path
34
35 @url_handler("/sitekey-frame")
36 def sitekey_frame(environ, start_response):
37 template_path, template_file = os.path.split(
38 get_config().get("testpages", "sitekeyFrameTemplate")
39 )
40 template = get_template(template_file, template_path=template_path)
41
42 key = M2Crypto.EVP.load_key(get_config().get("testpages", "sitekeyPath"))
43 key.sign_init()
44 key.sign_update(request_path(environ) + "\0")
45 key.sign_update(environ["HTTP_HOST"] + "\0")
46 key.sign_update(environ["HTTP_USER_AGENT"])
47
48 public_key = base64.b64encode(key.as_der())
49 signature = base64.b64encode(key.final())
50
51 start_response("200 OK",
52 [("Content-Type", "text/html; charset=utf-8"),
53 ("X-Adblock-Key", "%s_%s" % (public_key, signature))])
54 return [template.render({"public_key": public_key,
55 "signature": signature}).encode("utf-8")]
OLDNEW
« no previous file with comments | « sitescripts/testpages/web/__init__.py ('k') | sitescripts/utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld