From dbd9423f99fcde168b0483e4a37a094b93bb2ea0 Mon Sep 17 00:00:00 2001 From: RaNaN Date: Fri, 3 Sep 2010 18:12:36 +0200 Subject: new js engine for cnl --- module/web/cnl/views.py | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'module/web/cnl/views.py') diff --git a/module/web/cnl/views.py b/module/web/cnl/views.py index 7bc2ae6d4..46db5e76e 100644 --- a/module/web/cnl/views.py +++ b/module/web/cnl/views.py @@ -90,28 +90,38 @@ def addcrypted2(request): jk = request.POST["jk"] crypted = base64.standard_b64decode(unquote(crypted.replace(" ", "+"))) - try: import spidermonkey - except: - try: - jk = re.findall(r"return ('|\")(.+)('|\")", jk)[0][1] - except: - ## Test for some known js functions to decode - if jk.find("dec") > -1 and jk.find("org") > -1: - org = re.findall(r"var org = ('|\")([^\"']+)", jk)[0][1] - jk = list(org) - jk.reverse() - jk = "".join(jk) - else: - print "Could not decrypt key, please install py-spidermonkey" - else: rt = spidermonkey.Runtime() cx = rt.new_context() jk = cx.execute("%s f()" % jk) + except ImportError: + if settings.JS: + import subprocess + jk = jk.replace("'", '"') + cmd = settings.JS + ["-e", "%s ;print(f());" % jk ] + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1) + jk = p.stdout.read().strip() + + else: + try: + jk = re.findall(r"return ('|\")(.+)('|\")", jk)[0][1] + except: + ## Test for some known js functions to decode + if jk.find("dec") > -1 and jk.find("org") > -1: + org = re.findall(r"var org = ('|\")([^\"']+)", jk)[0][1] + jk = list(org) + jk.reverse() + jk = "".join(jk) + else: + print "Could not decrypt key, please install py-spidermonkey or other js engine" + try: + Key = binascii.unhexlify(jk) + except: + print "Could not decrypt key, please install py-spidermonkey or other js engine" + return JsonResponse("failed", request) - Key = binascii.unhexlify(jk) IV = Key obj = AES.new(Key, AES.MODE_CBC, IV) -- cgit v1.2.3