| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 # coding: utf-8 | 1 # coding: utf-8 |
| 2 | 2 |
| 3 # This file is part of the Adblock Plus web scripts, | 3 # This file is part of the Adblock Plus web scripts, |
| 4 # Copyright (C) 2006-2015 Eyeo GmbH | 4 # Copyright (C) 2006-2015 Eyeo GmbH |
| 5 # | 5 # |
| 6 # Adblock Plus is free software: you can redistribute it and/or modify | 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 | 7 # it under the terms of the GNU General Public License version 3 as |
| 8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. |
| 9 # | 9 # |
| 10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, |
| 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 # GNU General Public License for more details. | 13 # GNU General Public License for more details. |
| 14 # | 14 # |
| 15 # You should have received a copy of the GNU General Public License | 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/>. | 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 17 | 17 |
| 18 import base64 | 18 import base64 |
| 19 import M2Crypto | 19 import M2Crypto |
| 20 import os | 20 import os |
| 21 | 21 |
| 22 from sitescripts.utils import get_config, get_template | 22 from sitescripts.utils import get_config, get_template |
| 23 from sitescripts.web import url_handler | 23 from sitescripts.web import url_handler, request_path |
| 24 | 24 |
| 25 @url_handler("/sitekey-frame") | 25 @url_handler("/sitekey-frame") |
| 26 def sitekey_frame(environ, start_response): | 26 def sitekey_frame(environ, start_response): |
| 27 template_path, template_file = os.path.split( | 27 template_path, template_file = os.path.split( |
| 28 get_config().get("testpages", "sitekeyFrameTemplate") | 28 get_config().get("testpages", "sitekeyFrameTemplate") |
| 29 ) | 29 ) |
| 30 template = get_template(template_file, template_path=template_path) | 30 template = get_template(template_file, template_path=template_path) |
| 31 | 31 |
| 32 key = M2Crypto.EVP.load_key(get_config().get("testpages", "sitekeyPath")) | 32 key = M2Crypto.EVP.load_key(get_config().get("testpages", "sitekeyPath")) |
| 33 key.sign_init() | 33 key.sign_init() |
| 34 key.sign_update("\0".join(( | 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")), | 35 request_path(environ), environ["HTTP_HOST"], environ["HTTP_USER_AGENT"] |
|
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 ))) | 36 ))) |
| 37 | |
| 38 public_key = base64.b64encode(key.as_der()) | 38 public_key = base64.b64encode(key.as_der()) |
| 39 signature = base64.b64encode(key.final()) | 39 signature = base64.b64encode(key.final()) |
| 40 | 40 |
| 41 start_response("200 OK", | 41 start_response("200 OK", |
| 42 [("Content-Type", "text/html"), | 42 [("Content-Type", "text/html; charset=utf-8"), |
|
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))]) | 43 ("X-Adblock-Key", "%s_%s" % (public_key, signature))]) |
| 44 return [template.render({"public_key": public_key, | 44 return [template.render({"public_key": public_key, |
| 45 "signature": signature}).encode("utf-8")] | 45 "signature": signature}).encode("utf-8")] |
| LEFT | RIGHT |