Merge pull request #9 from jlejeune/pull_request
Decrypt now shared folders/files that do not belong to us
This commit is contained in:
commit
236ffc673c
1 changed files with 56 additions and 15 deletions
71
mega/mega.py
71
mega/mega.py
|
@ -101,28 +101,69 @@ class Mega(object):
|
||||||
|
|
||||||
def process_file(self, file):
|
def process_file(self, file):
|
||||||
"""
|
"""
|
||||||
Process a file...
|
Process a file
|
||||||
"""
|
"""
|
||||||
if file['t'] == 0 or file['t'] == 1:
|
if file['t'] == 0 or file['t'] == 1:
|
||||||
key = file['k'][file['k'].index(':') + 1:]
|
|
||||||
#fix for shared folder key format {k: foo1:bar1/foo2:bar2 }
|
|
||||||
uid = file['u']
|
uid = file['u']
|
||||||
keys = file['k'].split('/')
|
keys = file['k'].split('/')
|
||||||
regex = re.compile('^%s:.*$' % uid)
|
regex = re.compile('^%s:.*$' % uid)
|
||||||
|
key = None
|
||||||
for keytmp in keys:
|
for keytmp in keys:
|
||||||
if regex.match(keytmp):
|
if regex.match(keytmp):
|
||||||
key = keytmp[keytmp.index(':') + 1:]
|
key = keytmp[keytmp.index(':') + 1:]
|
||||||
key = decrypt_key(base64_to_a32(key), self.master_key)
|
break
|
||||||
if file['t'] == 0:
|
|
||||||
k = (key[0] ^ key[4], key[1] ^ key[5], key[2] ^ key[6],
|
# my objects
|
||||||
key[3] ^ key[7])
|
if key:
|
||||||
file['iv'] = key[4:6] + (0, 0)
|
key = decrypt_key(base64_to_a32(key), self.master_key)
|
||||||
file['meta_mac'] = key[6:8]
|
# file
|
||||||
else:
|
if file['t'] == 0:
|
||||||
k = file['k'] = key
|
k = (key[0] ^ key[4], key[1] ^ key[5], key[2] ^ key[6],
|
||||||
attributes = base64_url_decode(file['a'])
|
key[3] ^ key[7])
|
||||||
attributes = decrypt_attr(attributes, k)
|
file['iv'] = key[4:6] + (0, 0)
|
||||||
file['a'] = attributes
|
file['meta_mac'] = key[6:8]
|
||||||
|
# folder
|
||||||
|
else:
|
||||||
|
k = key
|
||||||
|
attributes = base64_url_decode(file['a'])
|
||||||
|
attributes = decrypt_attr(attributes, k)
|
||||||
|
file['a'] = attributes
|
||||||
|
# shared folders
|
||||||
|
elif 'su' in file and 'sk' in file and ':' in file['k']:
|
||||||
|
user_key = decrypt_key(base64_to_a32(file['sk']),
|
||||||
|
self.master_key)
|
||||||
|
key = decrypt_key(base64_to_a32(file['k'].split(':')[1]),
|
||||||
|
user_key)
|
||||||
|
# save user_key to decrypt shared files
|
||||||
|
self.users_keys[file['su']] = user_key
|
||||||
|
if file['t'] == 0:
|
||||||
|
k = (key[0] ^ key[4], key[1] ^ key[5], key[2] ^ key[6],
|
||||||
|
key[3] ^ key[7])
|
||||||
|
file['iv'] = key[4:6] + (0, 0)
|
||||||
|
file['meta_mac'] = key[6:8]
|
||||||
|
else:
|
||||||
|
k = key
|
||||||
|
attributes = base64_url_decode(file['a'])
|
||||||
|
attributes = decrypt_attr(attributes, k)
|
||||||
|
file['a'] = attributes
|
||||||
|
# shared files
|
||||||
|
elif file['u'] and ':' in file['k']:
|
||||||
|
user_key = self.users_keys[file['u']]
|
||||||
|
key = decrypt_key(base64_to_a32(file['k'].split(':')[1]),
|
||||||
|
user_key)
|
||||||
|
if file['t'] == 0:
|
||||||
|
k = (key[0] ^ key[4], key[1] ^ key[5], key[2] ^ key[6],
|
||||||
|
key[3] ^ key[7])
|
||||||
|
file['iv'] = key[4:6] + (0, 0)
|
||||||
|
file['meta_mac'] = key[6:8]
|
||||||
|
else:
|
||||||
|
k = key
|
||||||
|
attributes = base64_url_decode(file['a'])
|
||||||
|
attributes = decrypt_attr(attributes, k)
|
||||||
|
file['a'] = attributes
|
||||||
|
# other => wrong object
|
||||||
|
elif file['k'] == '':
|
||||||
|
file['a'] = False
|
||||||
elif file['t'] == 2:
|
elif file['t'] == 2:
|
||||||
self.root_id = file['h']
|
self.root_id = file['h']
|
||||||
file['a'] = {'n': 'Cloud Drive'}
|
file['a'] = {'n': 'Cloud Drive'}
|
||||||
|
@ -451,4 +492,4 @@ class Mega(object):
|
||||||
'k': encrypted_key}]})
|
'k': encrypted_key}]})
|
||||||
#close input file and return API msg
|
#close input file and return API msg
|
||||||
input_file.close()
|
input_file.close()
|
||||||
return data
|
return data
|
||||||
|
|
Loading…
Reference in a new issue