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