summaryrefslogtreecommitdiffstats
path: root/DeDRM_plugin/ignoblekeyAndroid.py
blob: e0b2f238e3ebaf4dcd94298d7f792072dadd8a3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'''
Extracts the user's ccHash from an .adobe-digital-editions folder
typically included in the Nook Android app's data folder.

Based on ignoblekeyWindowsStore.py, updated for Android by noDRM.
'''

import sys
import os
import base64
try: 
    from Cryptodome.Cipher import AES
except ImportError:
    from Crypto.Cipher import AES
import hashlib
from lxml import etree

def unpad(data, padding=16):
    if sys.version_info[0] == 2:
        pad_len = ord(data[-1])
    else:
        pad_len = data[-1]

    return data[:-pad_len]


PASS_HASH_SECRET = "9ca588496a1bc4394553d9e018d70b9e"


def dump_keys(path_to_adobe_folder):
    
    activation_path = os.path.join(path_to_adobe_folder, "activation.xml")
    device_path = os.path.join(path_to_adobe_folder, "device.xml")

    if not os.path.isfile(activation_path):
        print("Nook activation file is missing: %s\n" % activation_path)
        return []
    if not os.path.isfile(device_path):
        print("Nook device file is missing: %s\n" % device_path)
        return []

    # Load files:
    activation_xml = etree.parse(activation_path)
    device_xml = etree.parse(device_path)
    
    # Get fingerprint: 
    device_fingerprint = device_xml.findall(".//{http://ns.adobe.com/adept}fingerprint")[0].text
    device_fingerprint = base64.b64decode(device_fingerprint).hex()

    hash_key = hashlib.sha1(bytearray.fromhex(device_fingerprint + PASS_HASH_SECRET)).digest()[:16]

    hashes = []

    for pass_hash in activation_xml.findall(".//{http://ns.adobe.com/adept}passHash"):
        try: 
            encrypted_cc_hash = base64.b64decode(pass_hash.text)
            cc_hash = unpad(AES.new(hash_key, AES.MODE_CBC, encrypted_cc_hash[:16]).decrypt(encrypted_cc_hash[16:]))
            hashes.append(base64.b64encode(cc_hash).decode("ascii"))
            #print("Nook ccHash is %s" % (base64.b64encode(cc_hash).decode("ascii")))
        except:
            pass

    return hashes



if __name__ == "__main__":
    print("No standalone version available.")