]> xmof Git - DeDRM.git/commitdiff
Add UUID to adobekey DER file names
authorNoDRM <no_drm123@protonmail.com>
Mon, 15 Nov 2021 09:47:09 +0000 (10:47 +0100)
committerNoDRM <no_drm123@protonmail.com>
Mon, 15 Nov 2021 09:47:09 +0000 (10:47 +0100)
DeDRM_plugin/__init__.py
DeDRM_plugin/adobekey.py
DeDRM_plugin/wineutils.py

index 8af84b195ad670cb197fab8f1781e0c88858ed74..443786286e3e4e7a900889ed9d79075396250e54 100644 (file)
@@ -355,12 +355,12 @@ class DeDRM(FileTypePlugin):
                 if iswindows or isosx:
                     from calibre_plugins.dedrm.adobekey import adeptkeys
 
-                    defaultkeys = adeptkeys()
+                    defaultkeys, defaultnames = adeptkeys()
                 else: # linux
                     from .wineutils import WineGetKeys
 
                     scriptpath = os.path.join(self.alfdir,"adobekey.py")
-                    defaultkeys = WineGetKeys(scriptpath, ".der",dedrmprefs['adobewineprefix'])
+                    defaultkeys, defaultnames = WineGetKeys(scriptpath, ".der",dedrmprefs['adobewineprefix'])
 
                 self.default_key = defaultkeys[0]
             except:
@@ -369,9 +369,13 @@ class DeDRM(FileTypePlugin):
                 self.default_key = ""
 
             newkeys = []
+            newnames = []
+            idx = 0
             for keyvalue in defaultkeys:
                 if codecs.encode(keyvalue, 'hex').decode('ascii') not in dedrmprefs['adeptkeys'].values():
                     newkeys.append(keyvalue)
+                    newnames.append(defaultnames[idx])
+                idx += 1
 
             if len(newkeys) > 0:
                 try:
@@ -394,7 +398,7 @@ class DeDRM(FileTypePlugin):
                             # Store the new successful key in the defaults
                             print("{0} v{1}: Saving a new default key".format(PLUGIN_NAME, PLUGIN_VERSION))
                             try:
-                                dedrmprefs.addnamedvaluetoprefs('adeptkeys','default_key',codecs.encode(keyvalue, 'hex').decode('ascii'))
+                                dedrmprefs.addnamedvaluetoprefs('adeptkeys','default_key_uuid_' + newnames[i], codecs.encode(userkey, 'hex').decode('ascii'))
                                 dedrmprefs.writeprefs()
                                 print("{0} v{1}: Saved a new default key after {2:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,time.time()-self.starttime))
                             except:
@@ -458,12 +462,12 @@ class DeDRM(FileTypePlugin):
             if iswindows or isosx:
                 from calibre_plugins.dedrm.adobekey import adeptkeys
 
-                defaultkeys = adeptkeys()
+                defaultkeys, defaultnames = adeptkeys()
             else: # linux
                 from .wineutils import WineGetKeys
 
                 scriptpath = os.path.join(self.alfdir,"adobekey.py")
-                defaultkeys = WineGetKeys(scriptpath, ".der",dedrmprefs['adobewineprefix'])
+                defaultkeys, defaultnames = WineGetKeys(scriptpath, ".der",dedrmprefs['adobewineprefix'])
 
             self.default_key = defaultkeys[0]
         except:
@@ -472,9 +476,13 @@ class DeDRM(FileTypePlugin):
             self.default_key = ""
 
         newkeys = []
+        newnames = []
+        idx = 0
         for keyvalue in defaultkeys:
             if codecs.encode(keyvalue,'hex') not in dedrmprefs['adeptkeys'].values():
                 newkeys.append(keyvalue)
+                newnames.append(defaultnames[idx])
+            idx += 1
 
         if len(newkeys) > 0:
             try:
@@ -497,7 +505,7 @@ class DeDRM(FileTypePlugin):
                         # Store the new successful key in the defaults
                         print("{0} v{1}: Saving a new default key".format(PLUGIN_NAME, PLUGIN_VERSION))
                         try:
-                            dedrmprefs.addnamedvaluetoprefs('adeptkeys','default_key',codecs.encode(keyvalue,'hex'))
+                            dedrmprefs.addnamedvaluetoprefs('adeptkeys','default_key_uuid_' + newnames[i], codecs.encode(userkey,'hex').decode('ascii'))
                             dedrmprefs.writeprefs()
                             print("{0} v{1}: Saved a new default key after {2:.1f} seconds".format(PLUGIN_NAME, PLUGIN_VERSION,time.time()-self.starttime))
                         except:
index 489c59505f96fe394118f428fccb5eed9bcce197..5412b865aa5aca22ff9abd4a10827f4e6c3a20dd 100644 (file)
@@ -362,6 +362,7 @@ if iswindows:
         keykey = CryptUnprotectData(device, entropy)
         userkey = None
         keys = []
+        names = []
         try:
             plkroot = winreg.OpenKey(cuser, PRIVATE_LICENCE_KEY_PATH)
         except WindowsError:
@@ -374,12 +375,15 @@ if iswindows:
             ktype = winreg.QueryValueEx(plkparent, None)[0]
             if ktype != 'credentials':
                 continue
+            uuid_name = "Unknown"
             for j in range(0, 16):
                 try:
                     plkkey = winreg.OpenKey(plkparent, "%04d" % (j,))
                 except WindowsError:
                     break
                 ktype = winreg.QueryValueEx(plkkey, None)[0]
+                if ktype == 'user':
+                    uuid_name = winreg.QueryValueEx(plkkey, 'value')[0]
                 if ktype != 'privateLicenseKey':
                     continue
                 userkey = winreg.QueryValueEx(plkkey, 'value')[0]
@@ -387,12 +391,13 @@ if iswindows:
                 aes = AES(keykey)
                 userkey = aes.decrypt(userkey)
                 userkey = userkey[26:-ord(userkey[-1:])]
-                #print "found key:",userkey.encode('hex')
+                # print ("found " + uuid_name + " key: " + str(userkey))
                 keys.append(userkey)
+                names.append(uuid_name[9:])
         if len(keys) == 0:
             raise ADEPTError('Could not locate privateLicenseKey')
         print("Found {0:d} keys".format(len(keys)))
-        return keys
+        return keys, names
 
 
 elif isosx:
@@ -431,19 +436,25 @@ elif isosx:
         tree = etree.parse(actpath)
         adept = lambda tag: '{%s}%s' % (NSMAP['adept'], tag)
         expr = '//%s/%s' % (adept('credentials'), adept('privateLicenseKey'))
+        exprUUID = '//%s/%s' % (adept('credentials'), adept('user'))
         userkey = tree.findtext(expr)
+        userUUID = "Unknown"
+        try: 
+            userUUID = tree.findtext(exprUUID)
+        except: 
+            pass
         userkey = b64decode(userkey)
         userkey = userkey[26:]
-        return [userkey]
+        return [userkey], [userUUID[9:]]
 
 else:
     def adeptkeys():
         raise ADEPTError("This script only supports Windows and Mac OS X.")
-        return []
+        return [], []
 
 # interface for Python DeDRM
 def getkey(outpath):
-    keys = adeptkeys()
+    keys, names = adeptkeys()
     if len(keys) > 0:
         if not os.path.isdir(outpath):
             outfile = outpath
@@ -452,15 +463,17 @@ def getkey(outpath):
             print("Saved a key to {0}".format(outfile))
         else:
             keycount = 0
+            name_index = 0
             for key in keys:
                 while True:
                     keycount += 1
-                    outfile = os.path.join(outpath,"adobekey_{0:d}.der".format(keycount))
+                    outfile = os.path.join(outpath,"adobekey{0:d}_uuid_{1}.der".format(keycount, names[name_index]))
                     if not os.path.exists(outfile):
                         break
                 with open(outfile, 'wb') as keyfileout:
                     keyfileout.write(key)
                 print("Saved a key to {0}".format(outfile))
+                name_index += 1
         return True
     return False
 
@@ -506,7 +519,7 @@ def cli_main():
     # make sure the outpath is the
     outpath = os.path.realpath(os.path.normpath(outpath))
 
-    keys = adeptkeys()
+    keys, names = adeptkeys()
     if len(keys) > 0:
         if not os.path.isdir(outpath):
             outfile = outpath
@@ -515,15 +528,17 @@ def cli_main():
             print("Saved a key to {0}".format(outfile))
         else:
             keycount = 0
+            name_index = 0
             for key in keys:
                 while True:
                     keycount += 1
-                    outfile = os.path.join(outpath,"adobekey_{0:d}.der".format(keycount))
+                    outfile = os.path.join(outpath,"adobekey{0:d}_uuid_{1}.der".format(keycount, names[name_index]))
                     if not os.path.exists(outfile):
                         break
                 with open(outfile, 'wb') as keyfileout:
                     keyfileout.write(key)
                 print("Saved a key to {0}".format(outfile))
+                name_index += 1
     else:
         print("Could not retrieve Adobe Adept key.")
     return 0
@@ -556,12 +571,15 @@ def gui_main():
     progpath, progname = os.path.split(argv[0])
     success = False
     try:
-        keys = adeptkeys()
+        keys, names = adeptkeys()
+        print(keys)
+        print(names)
         keycount = 0
+        name_index = 0
         for key in keys:
             while True:
                 keycount += 1
-                outfile = os.path.join(progpath,"adobekey_{0:d}.der".format(keycount))
+                outfile = os.path.join(progpath,"adobekey{0:d}_uuid_{1}.der".format(keycount, names[name_index]))
                 if not os.path.exists(outfile):
                     break
 
@@ -569,6 +587,7 @@ def gui_main():
                 keyfileout.write(key)
             success = True
             tkinter.messagebox.showinfo(progname, "Key successfully retrieved to {0}".format(outfile))
+            name_index += 1
     except ADEPTError as e:
         tkinter.messagebox.showerror(progname, "Error: {0}".format(str(e)))
     except Exception:
index f48f4b190a65c32507224ee6f32da506e7b7cba5..071e0da12bbef6709aa32e4c2db103e84cab675f 100644 (file)
@@ -93,6 +93,7 @@ def WineGetKeys(scriptpath, extension, wineprefix=""):
 
     # try finding winekeys anyway, even if above code errored
     winekeys = []
+    winekey_names = []
     # get any files with extension in the output dir
     files = [f for f in os.listdir(outdirpath) if f.endswith(extension)]
     for filename in files:
@@ -104,9 +105,10 @@ def WineGetKeys(scriptpath, extension, wineprefix=""):
                 else:
                     new_key_value = keyfile.read()
             winekeys.append(new_key_value)
+            winekey_names.append(filename)
         except:
             print("{0} v{1}: Error loading file {2}".format(PLUGIN_NAME, PLUGIN_VERSION, filename))
             traceback.print_exc()
         os.remove(fpath)
     print("{0} v{1}: Found and decrypted {2} {3}".format(PLUGIN_NAME, PLUGIN_VERSION, len(winekeys), "key file" if len(winekeys) == 1 else "key files"))
-    return winekeys
+    return winekeys, winekey_names