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: Created Sept. 24, 2015, 3:45 p.m.
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
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((
Sebastian Noack 2015/09/29 12:09:32 Can't you just call sign_update() for each substri
kzar 2015/10/07 16:08:44 Done.
Sebastian Noack 2015/10/07 16:17:07 Well, know you use both, string concatenation and
kzar 2015/10/08 12:06:37 Yea, you're right. I tried a few different approac
35 environ.get("REQUEST_URI", environ.get("PATH_INFO")),
Sebastian Noack 2015/09/29 12:09:32 I think wsgiref.util.request_uri() is what you wan
kzar 2015/10/07 16:08:44 I ended up taking part of that function's logic, a
36 environ["HTTP_HOST"], environ["HTTP_USER_AGENT"]
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"),
Sebastian Noack 2015/09/29 12:09:32 Charset is missing.
kzar 2015/10/07 16:08:44 Done.
43 ("X-Adblock-Key", "%s_%s" % (public_key, signature))])
44 return [template.render({"public_key": public_key,
45 "signature": signature}).encode("utf-8")]
OLDNEW

Powered by Google App Engine
This is Rietveld