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: Further improvements Created Oct. 8, 2015, noon
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
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
22 from sitescripts.utils import get_config, get_template
23 from sitescripts.web import url_handler, request_path
24
25 @url_handler("/sitekey-frame")
26 def sitekey_frame(environ, start_response):
27 template_path, template_file = os.path.split(
28 get_config().get("testpages", "sitekeyFrameTemplate")
29 )
30 template = get_template(template_file, template_path=template_path)
31
32 key = M2Crypto.EVP.load_key(get_config().get("testpages", "sitekeyPath"))
33 key.sign_init()
34 key.sign_update("\0".join((
35 request_path(environ), environ["HTTP_HOST"], environ["HTTP_USER_AGENT"]
36 )))
37
38 public_key = base64.b64encode(key.as_der())
39 signature = base64.b64encode(key.final())
40
41 start_response("200 OK",
42 [("Content-Type", "text/html; charset=utf-8"),
43 ("X-Adblock-Key", "%s_%s" % (public_key, signature))])
44 return [template.render({"public_key": public_key,
45 "signature": signature}).encode("utf-8")]
OLDNEW
« no previous file with comments | « sitescripts/testpages/web/__init__.py ('k') | sitescripts/utils.py » ('j') | sitescripts/web.py » ('J')

Powered by Google App Engine
This is Rietveld