From 776a6ced27fa0fe813871dda61b8eee869e8355d Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Fri, 7 Nov 2014 19:36:02 +0100 Subject: Rename MegaNz to MegaCoNz --- module/plugins/hoster/MegaCoNz.py | 140 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 module/plugins/hoster/MegaCoNz.py (limited to 'module/plugins/hoster/MegaCoNz.py') diff --git a/module/plugins/hoster/MegaCoNz.py b/module/plugins/hoster/MegaCoNz.py new file mode 100644 index 000000000..70688c26a --- /dev/null +++ b/module/plugins/hoster/MegaCoNz.py @@ -0,0 +1,140 @@ +# -*- coding: utf-8 -*- + +import random +import re + +from array import array +from base64 import standard_b64decode +from os import remove + +from Crypto.Cipher import AES +from Crypto.Util import Counter +from pycurl import SSL_CIPHER_LIST + +from module.common.json_layer import json_loads, json_dumps +from module.plugins.Hoster import Hoster + + +class MegaCoNz(Hoster): + __name__ = "MegaCoNz" + __type__ = "hoster" + __version__ = "0.16" + + __pattern__ = r'https?://(\w+\.)?mega\.co\.nz/#!([\w!-]+)' + + __description__ = """Mega.co.nz hoster plugin""" + __license__ = "GPLv3" + __authors__ = [("RaNaN", "ranan@pyload.org")] + + + API_URL = "https://g.api.mega.co.nz/cs?id=%d" + FILE_SUFFIX = ".crypted" + + + def b64_decode(self, data): + data = data.replace("-", "+").replace("_", "/") + return standard_b64decode(data + '=' * (-len(data) % 4)) + + + def getCipherKey(self, key): + """ Construct the cipher key from the given data """ + a = array("I", key) + key_array = array("I", [a[0] ^ a[4], a[1] ^ a[5], a[2] ^ a[6], a[3] ^ a[7]]) + return key_array + + + def callApi(self, **kwargs): + """ Dispatch a call to the api, see https://mega.co.nz/#developers """ + # generate a session id, no idea where to obtain elsewhere + uid = random.randint(10 << 9, 10 ** 10) + + resp = self.load(self.API_URL % uid, post=json_dumps([kwargs])) + self.logDebug("Api Response: " + resp) + return json_loads(resp) + + + def decryptAttr(self, data, key): + cbc = AES.new(self.getCipherKey(key), AES.MODE_CBC, "\0" * 16) + attr = cbc.decrypt(self.b64_decode(data)) + self.logDebug("Decrypted Attr: " + attr) + if not attr.startswith("MEGA"): + self.fail(_("Decryption failed")) + + # Data is padded, 0-bytes must be stripped + return json_loads(re.search(r'{.+?}', attr).group(0)) + + + def decryptFile(self, key): + """ Decrypts the file at lastDownload` """ + + # upper 64 bit of counter start + n = key[16:24] + + # convert counter to long and shift bytes + ctr = Counter.new(128, initial_value=long(n.encode("hex"), 16) << 64) + cipher = AES.new(self.getCipherKey(key), AES.MODE_CTR, counter=ctr) + + self.pyfile.setStatus("decrypting") + + file_crypted = self.lastDownload + file_decrypted = file_crypted.rsplit(self.FILE_SUFFIX)[0] + f = open(file_crypted, "rb") + df = open(file_decrypted, "wb") + + # TODO: calculate CBC-MAC for checksum + + size = 2 ** 15 # buffer size, 32k + while True: + buf = f.read(size) + if not buf: + break + + df.write(cipher.decrypt(buf)) + + f.close() + df.close() + remove(file_crypted) + + self.lastDownload = file_decrypted + + + def process(self, pyfile): + key = None + + # match is guaranteed because plugin was chosen to handle url + node = re.match(self.__pattern__, pyfile.url).group(2) + if "!" in node: + node, key = node.split("!") + + self.logDebug("File id: %s | Key: %s" % (node, key)) + + if not key: + self.fail(_("No file key provided in the URL")) + + # g is for requesting a download url + # this is similar to the calls in the mega js app, documentation is very bad + dl = self.callApi(a="g", g=1, p=node, ssl=1)[0] + + if "e" in dl: + e = dl['e'] + # ETEMPUNAVAIL (-18): Resource temporarily not available, please try again later + if e == -18: + self.retry() + else: + self.fail(_("Error code:") + e) + + # TODO: map other error codes, e.g + # EACCESS (-11): Access violation (e.g., trying to write to a read-only share) + + key = self.b64_decode(key) + attr = self.decryptAttr(dl['at'], key) + + pyfile.name = attr['n'] + self.FILE_SUFFIX + + self.req.http.c.setopt(SSL_CIPHER_LIST, "RC4-MD5:DEFAULT") + + self.download(dl['g']) + self.decryptFile(key) + + # Everything is finished and final name can be set + pyfile.name = attr['n'] -- cgit v1.2.3 From bd8259220ab4d56ab419b7b32045b08cc9b0a7c8 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 9 Nov 2014 03:08:19 +0100 Subject: Use with statement instead open method when accessing fod + handle i/o error --- module/plugins/hoster/MegaCoNz.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'module/plugins/hoster/MegaCoNz.py') diff --git a/module/plugins/hoster/MegaCoNz.py b/module/plugins/hoster/MegaCoNz.py index 70688c26a..9b120827c 100644 --- a/module/plugins/hoster/MegaCoNz.py +++ b/module/plugins/hoster/MegaCoNz.py @@ -48,9 +48,9 @@ class MegaCoNz(Hoster): # generate a session id, no idea where to obtain elsewhere uid = random.randint(10 << 9, 10 ** 10) - resp = self.load(self.API_URL % uid, post=json_dumps([kwargs])) - self.logDebug("Api Response: " + resp) - return json_loads(resp) + res = self.load(self.API_URL % uid, post=json_dumps([kwargs])) + self.logDebug("Api Response: " + res) + return json_loads(res) def decryptAttr(self, data, key): @@ -78,8 +78,12 @@ class MegaCoNz(Hoster): file_crypted = self.lastDownload file_decrypted = file_crypted.rsplit(self.FILE_SUFFIX)[0] - f = open(file_crypted, "rb") - df = open(file_decrypted, "wb") + + try: + f = open(file_crypted, "rb") + df = open(file_decrypted, "wb") + except IOError, e: + self.fail(str(e)) # TODO: calculate CBC-MAC for checksum -- cgit v1.2.3 From 59f72bfc5ed721c80c821bd0ca1bc8daf0d49880 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 9 Nov 2014 03:12:41 +0100 Subject: Code cosmetics --- module/plugins/hoster/MegaCoNz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'module/plugins/hoster/MegaCoNz.py') diff --git a/module/plugins/hoster/MegaCoNz.py b/module/plugins/hoster/MegaCoNz.py index 9b120827c..2129fbfc8 100644 --- a/module/plugins/hoster/MegaCoNz.py +++ b/module/plugins/hoster/MegaCoNz.py @@ -78,7 +78,7 @@ class MegaCoNz(Hoster): file_crypted = self.lastDownload file_decrypted = file_crypted.rsplit(self.FILE_SUFFIX)[0] - + try: f = open(file_crypted, "rb") df = open(file_decrypted, "wb") -- cgit v1.2.3 From f4db1a3ce2692b9f310dac1548c1966bcea319a2 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 6 Dec 2014 22:47:56 +0100 Subject: Plugin code cosmetics (2) --- module/plugins/hoster/MegaCoNz.py | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'module/plugins/hoster/MegaCoNz.py') diff --git a/module/plugins/hoster/MegaCoNz.py b/module/plugins/hoster/MegaCoNz.py index 2129fbfc8..385295d42 100644 --- a/module/plugins/hoster/MegaCoNz.py +++ b/module/plugins/hoster/MegaCoNz.py @@ -14,6 +14,34 @@ from pycurl import SSL_CIPHER_LIST from module.common.json_layer import json_loads, json_dumps from module.plugins.Hoster import Hoster +############################ General errors ################################### +# EINTERNAL (-1): An internal error has occurred. Please submit a bug report, detailing the exact circumstances in which this error occurred +# EARGS (-2): You have passed invalid arguments to this command +# EAGAIN (-3): (always at the request level) A temporary congestion or server malfunction prevented your request from being processed. No data was altered. Retry. Retries must be spaced with exponential backoff +# ERATELIMIT (-4): You have exceeded your command weight per time quota. Please wait a few seconds, then try again (this should never happen in sane real-life applications) +# +############################ Upload errors #################################### +# EFAILED (-5): The upload failed. Please restart it from scratch +# ETOOMANY (-6): Too many concurrent IP addresses are accessing this upload target URL +# ERANGE (-7): The upload file packet is out of range or not starting and ending on a chunk boundary +# EEXPIRED (-8): The upload target URL you are trying to access has expired. Please request a fresh one +# +############################ Stream/System errors ############################# +# ENOENT (-9): Object (typically, node or user) not found +# ECIRCULAR (-10): Circular linkage attempted +# EACCESS (-11): Access violation (e.g., trying to write to a read-only share) +# EEXIST (-12): Trying to create an object that already exists +# EINCOMPLETE (-13): Trying to access an incomplete resource +# EKEY (-14): A decryption operation failed (never returned by the API) +# ESID (-15): Invalid or expired user session, please relogin +# EBLOCKED (-16): User blocked +# EOVERQUOTA (-17): Request over quota +# ETEMPUNAVAIL (-18): Resource temporarily not available, please try again later +# ETOOMANYCONNECTIONS (-19): Too many connections on this resource +# EWRITE (-20): Write failed +# EREAD (-21): Read failed +# EAPPKEY (-22): Invalid application key; request not processed + class MegaCoNz(Hoster): __name__ = "MegaCoNz" @@ -26,8 +54,7 @@ class MegaCoNz(Hoster): __license__ = "GPLv3" __authors__ = [("RaNaN", "ranan@pyload.org")] - - API_URL = "https://g.api.mega.co.nz/cs?id=%d" + API_URL = "https://g.api.mega.co.nz/cs" FILE_SUFFIX = ".crypted" @@ -48,7 +75,7 @@ class MegaCoNz(Hoster): # generate a session id, no idea where to obtain elsewhere uid = random.randint(10 << 9, 10 ** 10) - res = self.load(self.API_URL % uid, post=json_dumps([kwargs])) + res = self.load(self.API_URL, get={'id': uid}, post=json_dumps([kwargs])) self.logDebug("Api Response: " + res) return json_loads(res) -- cgit v1.2.3 From 6325eda4e8c142edd11c747f7a9d4a3fa975c494 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sat, 20 Dec 2014 14:24:13 +0100 Subject: Fix password retrieving in some plugins --- module/plugins/hoster/MegaCoNz.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'module/plugins/hoster/MegaCoNz.py') diff --git a/module/plugins/hoster/MegaCoNz.py b/module/plugins/hoster/MegaCoNz.py index 385295d42..fc6724dc7 100644 --- a/module/plugins/hoster/MegaCoNz.py +++ b/module/plugins/hoster/MegaCoNz.py @@ -46,9 +46,9 @@ from module.plugins.Hoster import Hoster class MegaCoNz(Hoster): __name__ = "MegaCoNz" __type__ = "hoster" - __version__ = "0.16" + __version__ = "0.17" - __pattern__ = r'https?://(\w+\.)?mega\.co\.nz/#!([\w!-]+)' + __pattern__ = r'https?://(?:www\.)?mega\.co\.nz/#!(?P[\w!-]+)' __description__ = """Mega.co.nz hoster plugin""" __license__ = "GPLv3" @@ -133,11 +133,11 @@ class MegaCoNz(Hoster): key = None # match is guaranteed because plugin was chosen to handle url - node = re.match(self.__pattern__, pyfile.url).group(2) + node = re.match(self.__pattern__, pyfile.url).group('ID') if "!" in node: - node, key = node.split("!") + node, key = node.split("!", 1) - self.logDebug("File id: %s | Key: %s" % (node, key)) + self.logDebug("ID: %s | Key: %s" % (node, key)) if not key: self.fail(_("No file key provided in the URL")) -- cgit v1.2.3 From 4ef28917ae8be8a0c6f5374bac6116fd1c469bd3 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Sun, 28 Dec 2014 11:52:57 +0100 Subject: [MegaCoNz] Private file support --- module/plugins/hoster/MegaCoNz.py | 93 ++++++++++++++++++++++++--------------- 1 file changed, 57 insertions(+), 36 deletions(-) (limited to 'module/plugins/hoster/MegaCoNz.py') diff --git a/module/plugins/hoster/MegaCoNz.py b/module/plugins/hoster/MegaCoNz.py index fc6724dc7..db3f8d571 100644 --- a/module/plugins/hoster/MegaCoNz.py +++ b/module/plugins/hoster/MegaCoNz.py @@ -9,11 +9,12 @@ from os import remove from Crypto.Cipher import AES from Crypto.Util import Counter -from pycurl import SSL_CIPHER_LIST +# from pycurl import SSL_CIPHER_LIST from module.common.json_layer import json_loads, json_dumps from module.plugins.Hoster import Hoster + ############################ General errors ################################### # EINTERNAL (-1): An internal error has occurred. Please submit a bug report, detailing the exact circumstances in which this error occurred # EARGS (-2): You have passed invalid arguments to this command @@ -46,15 +47,17 @@ from module.plugins.Hoster import Hoster class MegaCoNz(Hoster): __name__ = "MegaCoNz" __type__ = "hoster" - __version__ = "0.17" + __version__ = "0.20" - __pattern__ = r'https?://(?:www\.)?mega\.co\.nz/#!(?P[\w!-]+)' + __pattern__ = r'https?://(?:www\.)?mega\.co\.nz/#(?PN|)!(?P[\w^_]+)!(?P[\w,\\-]+)' __description__ = """Mega.co.nz hoster plugin""" __license__ = "GPLv3" - __authors__ = [("RaNaN", "ranan@pyload.org")] + __authors__ = [("RaNaN", "ranan@pyload.org"), + ("Walter Purcaro", "vuolter@gmail.com")] + - API_URL = "https://g.api.mega.co.nz/cs" + API_URL = "https://eu.api.mega.co.nz/cs" FILE_SUFFIX = ".crypted" @@ -66,12 +69,17 @@ class MegaCoNz(Hoster): def getCipherKey(self, key): """ Construct the cipher key from the given data """ a = array("I", key) - key_array = array("I", [a[0] ^ a[4], a[1] ^ a[5], a[2] ^ a[6], a[3] ^ a[7]]) - return key_array + k = array("I", [a[0] ^ a[4], a[1] ^ a[5], a[2] ^ a[6], a[3] ^ a[7]]) + iv = a[4:6] + (0, 0) + meta_mac = a[6:8] + + return k, iv, meta_mac - def callApi(self, **kwargs): + + def api_response(self, **kwargs): """ Dispatch a call to the api, see https://mega.co.nz/#developers """ + # generate a session id, no idea where to obtain elsewhere uid = random.randint(10 << 9, 10 ** 10) @@ -81,8 +89,10 @@ class MegaCoNz(Hoster): def decryptAttr(self, data, key): - cbc = AES.new(self.getCipherKey(key), AES.MODE_CBC, "\0" * 16) - attr = cbc.decrypt(self.b64_decode(data)) + k, iv, meta_mac = getCipherKey(key) + cbc = AES.new(k, AES.MODE_CBC, "\0" * 16) + attr = cbc.decrypt(self.b64_decode(data)) + self.logDebug("Decrypted Attr: " + attr) if not attr.startswith("MEGA"): self.fail(_("Decryption failed")) @@ -98,34 +108,37 @@ class MegaCoNz(Hoster): n = key[16:24] # convert counter to long and shift bytes - ctr = Counter.new(128, initial_value=long(n.encode("hex"), 16) << 64) - cipher = AES.new(self.getCipherKey(key), AES.MODE_CTR, counter=ctr) + k, iv, meta_mac = getCipherKey(key) + ctr = Counter.new(128, initial_value=long(n.encode("hex"), 16) << 64) + cipher = AES.new(k, AES.MODE_CTR, counter=ctr) self.pyfile.setStatus("decrypting") - file_crypted = self.lastDownload + file_crypted = self.lastDownload file_decrypted = file_crypted.rsplit(self.FILE_SUFFIX)[0] try: - f = open(file_crypted, "rb") + f = open(file_crypted, "rb") df = open(file_decrypted, "wb") + except IOError, e: self.fail(str(e)) - # TODO: calculate CBC-MAC for checksum + chunk_size = 2 ** 15 # buffer size, 32k + # file_mac = [0, 0, 0, 0] # calculate CBC-MAC for checksum - size = 2 ** 15 # buffer size, 32k while True: - buf = f.read(size) + buf = f.read(chunk_size) if not buf: break - df.write(cipher.decrypt(buf)) + chunk = cipher.decrypt(buf) + df.write(chunk) f.close() df.close() - remove(file_crypted) + remove(file_crypted) self.lastDownload = file_decrypted @@ -133,38 +146,46 @@ class MegaCoNz(Hoster): key = None # match is guaranteed because plugin was chosen to handle url - node = re.match(self.__pattern__, pyfile.url).group('ID') - if "!" in node: - node, key = node.split("!", 1) + pattern = re.match(self.__pattern__, pyfile.url).groupdict() + node = pattern['ID'] + key = pattern['KEY'] + public = pattern['TYPE'] != 'N' - self.logDebug("ID: %s | Key: %s" % (node, key)) + self.logDebug("ID: %s" % node, "Key: %s" % key, "Type: %s" % ("public" if public else "node")) - if not key: - self.fail(_("No file key provided in the URL")) + key = self.b64_decode(key) # g is for requesting a download url # this is similar to the calls in the mega js app, documentation is very bad - dl = self.callApi(a="g", g=1, p=node, ssl=1)[0] + if public: + dl = self.api_response(a="g", g=1, p=node, ssl=1)[0] + else: + dl = self.api_response(a="g", g=1, n=node, ssl=1)[0] if "e" in dl: - e = dl['e'] - # ETEMPUNAVAIL (-18): Resource temporarily not available, please try again later - if e == -18: - self.retry() - else: - self.fail(_("Error code:") + e) + ecode = -dl['e'] - # TODO: map other error codes, e.g - # EACCESS (-11): Access violation (e.g., trying to write to a read-only share) + if ecode in (9, 16, 21): + self.offline() + + elif ecode in (3, 13, 17, 18, 19): + self.tempOffline() + + elif ecode in (1, 4, 6, 10, 15, 21): + self.retry(5, 30, _("Error code: [%s]") % -ecode) + + else: + self.fail(_("Error code: [%s]") % -ecode) - key = self.b64_decode(key) attr = self.decryptAttr(dl['at'], key) pyfile.name = attr['n'] + self.FILE_SUFFIX + pyfile.size = dl['s'] - self.req.http.c.setopt(SSL_CIPHER_LIST, "RC4-MD5:DEFAULT") + # self.req.http.c.setopt(SSL_CIPHER_LIST, "RC4-MD5:DEFAULT") self.download(dl['g']) + self.decryptFile(key) # Everything is finished and final name can be set -- cgit v1.2.3 From 85febdf6ce5666d5e29052eca93361656eb65ac8 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 30 Dec 2014 00:22:47 +0100 Subject: [MegaCoNz] Fixup --- module/plugins/hoster/MegaCoNz.py | 71 +++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 36 deletions(-) (limited to 'module/plugins/hoster/MegaCoNz.py') diff --git a/module/plugins/hoster/MegaCoNz.py b/module/plugins/hoster/MegaCoNz.py index db3f8d571..39eba4a40 100644 --- a/module/plugins/hoster/MegaCoNz.py +++ b/module/plugins/hoster/MegaCoNz.py @@ -47,9 +47,9 @@ from module.plugins.Hoster import Hoster class MegaCoNz(Hoster): __name__ = "MegaCoNz" __type__ = "hoster" - __version__ = "0.20" + __version__ = "0.21" - __pattern__ = r'https?://(?:www\.)?mega\.co\.nz/#(?PN|)!(?P[\w^_]+)!(?P[\w,\\-]+)' + __pattern__ = r'https?://(?:www\.)?mega\.co\.nz/#(?PN)?!(?P[\w^_]+)!(?P[\w,\\-]+)' __description__ = """Mega.co.nz hoster plugin""" __license__ = "GPLv3" @@ -68,11 +68,9 @@ class MegaCoNz(Hoster): def getCipherKey(self, key): """ Construct the cipher key from the given data """ - a = array("I", key) - - k = array("I", [a[0] ^ a[4], a[1] ^ a[5], a[2] ^ a[6], a[3] ^ a[7]]) - iv = a[4:6] + (0, 0) - meta_mac = a[6:8] + k = key[0] ^ key[4], key[1] ^ key[5], key[2] ^ key[6], key[3] ^ key[7] + iv = key[4:6] + (0, 0) + meta_mac = key[6:8] return k, iv, meta_mac @@ -89,7 +87,7 @@ class MegaCoNz(Hoster): def decryptAttr(self, data, key): - k, iv, meta_mac = getCipherKey(key) + k, iv, meta_mac = self.getCipherKey(self.b64_decode(key)) cbc = AES.new(k, AES.MODE_CBC, "\0" * 16) attr = cbc.decrypt(self.b64_decode(data)) @@ -104,11 +102,13 @@ class MegaCoNz(Hoster): def decryptFile(self, key): """ Decrypts the file at lastDownload` """ + key = self.b64_decode(key) + # upper 64 bit of counter start n = key[16:24] # convert counter to long and shift bytes - k, iv, meta_mac = getCipherKey(key) + k, iv, meta_mac = self.getCipherKey(key) ctr = Counter.new(128, initial_value=long(n.encode("hex"), 16) << 64) cipher = AES.new(k, AES.MODE_CTR, counter=ctr) @@ -142,49 +142,48 @@ class MegaCoNz(Hoster): self.lastDownload = file_decrypted - def process(self, pyfile): - key = None + def checkError(self, code): + ecode = abs(code) - # match is guaranteed because plugin was chosen to handle url - pattern = re.match(self.__pattern__, pyfile.url).groupdict() - node = pattern['ID'] - key = pattern['KEY'] - public = pattern['TYPE'] != 'N' + if ecode in (9, 16, 21): + self.offline() - self.logDebug("ID: %s" % node, "Key: %s" % key, "Type: %s" % ("public" if public else "node")) + elif ecode in (3, 13, 17, 18, 19): + self.tempOffline() - key = self.b64_decode(key) + elif ecode in (1, 4, 6, 10, 15, 21): + self.retry(5, 30, _("Error code: [%s]") % -ecode) - # g is for requesting a download url - # this is similar to the calls in the mega js app, documentation is very bad - if public: - dl = self.api_response(a="g", g=1, p=node, ssl=1)[0] else: - dl = self.api_response(a="g", g=1, n=node, ssl=1)[0] + self.fail(_("Error code: [%s]") % -ecode) - if "e" in dl: - ecode = -dl['e'] - if ecode in (9, 16, 21): - self.offline() + def process(self, pyfile): + pattern = re.match(self.__pattern__, pyfile.url).groupdict() + id = pattern['ID'] + key = pattern['KEY'] + public = 'TYPE' not in pattern - elif ecode in (3, 13, 17, 18, 19): - self.tempOffline() + self.logDebug("ID: %s" % id, "Key: %s" % key, "Type: %s" % ("public" if public else "node")) - elif ecode in (1, 4, 6, 10, 15, 21): - self.retry(5, 30, _("Error code: [%s]") % -ecode) + # g is for requesting a download url + # this is similar to the calls in the mega js app, documentation is very bad + if public: + mega = self.api_response(a="g", g=1, p=id, ssl=1)[0] + else: + mega = self.api_response(a="g", g=1, n=id, ssl=1)[0] - else: - self.fail(_("Error code: [%s]") % -ecode) + if "e" in mega: + self.checkError(mega['e']) - attr = self.decryptAttr(dl['at'], key) + attr = self.decryptAttr(mega['at'], key) pyfile.name = attr['n'] + self.FILE_SUFFIX - pyfile.size = dl['s'] + pyfile.size = mega['s'] # self.req.http.c.setopt(SSL_CIPHER_LIST, "RC4-MD5:DEFAULT") - self.download(dl['g']) + self.download(mega['g']) self.decryptFile(key) -- cgit v1.2.3 From fb7c5cf5845c22bb751c824679c856b45a1bb970 Mon Sep 17 00:00:00 2001 From: Walter Purcaro Date: Tue, 30 Dec 2014 00:32:18 +0100 Subject: [MegaCoNz] Fixup (2) --- module/plugins/hoster/MegaCoNz.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'module/plugins/hoster/MegaCoNz.py') diff --git a/module/plugins/hoster/MegaCoNz.py b/module/plugins/hoster/MegaCoNz.py index 39eba4a40..00f38ff06 100644 --- a/module/plugins/hoster/MegaCoNz.py +++ b/module/plugins/hoster/MegaCoNz.py @@ -68,6 +68,8 @@ class MegaCoNz(Hoster): def getCipherKey(self, key): """ Construct the cipher key from the given data """ + key = self.b64_decode(key) + k = key[0] ^ key[4], key[1] ^ key[5], key[2] ^ key[6], key[3] ^ key[7] iv = key[4:6] + (0, 0) meta_mac = key[6:8] @@ -87,7 +89,7 @@ class MegaCoNz(Hoster): def decryptAttr(self, data, key): - k, iv, meta_mac = self.getCipherKey(self.b64_decode(key)) + k, iv, meta_mac = self.getCipherKey(key) cbc = AES.new(k, AES.MODE_CBC, "\0" * 16) attr = cbc.decrypt(self.b64_decode(data)) @@ -102,10 +104,8 @@ class MegaCoNz(Hoster): def decryptFile(self, key): """ Decrypts the file at lastDownload` """ - key = self.b64_decode(key) - # upper 64 bit of counter start - n = key[16:24] + n = self.b64_decode(key)[16:24] # convert counter to long and shift bytes k, iv, meta_mac = self.getCipherKey(key) -- cgit v1.2.3