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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sitescripts/testpages/web/sitekey_frame.py
diff --git a/sitescripts/testpages/web/sitekey_frame.py b/sitescripts/testpages/web/sitekey_frame.py
new file mode 100644
index 0000000000000000000000000000000000000000..b0b66b207982ff2a60d0966dedded2a39d767cf2
--- /dev/null
+++ b/sitescripts/testpages/web/sitekey_frame.py
@@ -0,0 +1,45 @@
+# coding: utf-8
+
+# This file is part of the Adblock Plus web scripts,
+# Copyright (C) 2006-2015 Eyeo GmbH
+#
+# Adblock Plus is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# Adblock Plus is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+
+import base64
+import M2Crypto
+import os
+
+from sitescripts.utils import get_config, get_template
+from sitescripts.web import url_handler
+
+@url_handler("/sitekey-frame")
+def sitekey_frame(environ, start_response):
+ template_path, template_file = os.path.split(
+ get_config().get("testpages", "sitekeyFrameTemplate")
+ )
+ template = get_template(template_file, template_path=template_path)
+
+ key = M2Crypto.EVP.load_key(get_config().get("testpages", "sitekeyPath"))
+ key.sign_init()
+ 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
+ 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
+ environ["HTTP_HOST"], environ["HTTP_USER_AGENT"]
+ )))
+ public_key = base64.b64encode(key.as_der())
+ signature = base64.b64encode(key.final())
+
+ start_response("200 OK",
+ [("Content-Type", "text/html"),
Sebastian Noack 2015/09/29 12:09:32 Charset is missing.
kzar 2015/10/07 16:08:44 Done.
+ ("X-Adblock-Key", "%s_%s" % (public_key, signature))])
+ return [template.render({"public_key": public_key,
+ "signature": signature}).encode("utf-8")]

Powered by Google App Engine
This is Rietveld