Ejemplo n.º 1
0
    def __init__(self, parent=None):
        QDialog.__init__(self, parent)
        self.parent = parent
        self.setWindowTitle(u"{0} {1}: Getting Default Adobe Digital Editions Key".format(PLUGIN_NAME, PLUGIN_VERSION))
        layout = QVBoxLayout(self)
        self.setLayout(layout)

        try:
            if iswindows or isosx:
                from calibre_plugins.dedrm.adobekey import adeptkeys

                defaultkeys = adeptkeys()
            else:  # linux
                from wineutils import WineGetKeys

                scriptpath = os.path.join(parent.parent.alfdir, u"adobekey.py")
                defaultkeys = WineGetKeys(scriptpath, u".der", parent.getwineprefix())

            self.default_key = defaultkeys[0]
        except:
            traceback.print_exc()
            self.default_key = u""

        self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)

        if len(self.default_key) > 0:
            data_group_box = QGroupBox(u"", self)
            layout.addWidget(data_group_box)
            data_group_box_layout = QVBoxLayout()
            data_group_box.setLayout(data_group_box_layout)

            key_group = QHBoxLayout()
            data_group_box_layout.addLayout(key_group)
            key_group.addWidget(QLabel(u"Unique Key Name:", self))
            self.key_ledit = QLineEdit(u"default_key", self)
            self.key_ledit.setToolTip(
                u"<p>Enter an identifying name for the current default Adobe Digital Editions key."
            )
            key_group.addWidget(self.key_ledit)

            self.button_box.accepted.connect(self.accept)
        else:
            default_key_error = QLabel(
                u"The default encryption key for Adobe Digital Editions could not be found.", self
            )
            default_key_error.setAlignment(Qt.AlignHCenter)
            layout.addWidget(default_key_error)
            # if no default, bot buttons do the same
            self.button_box.accepted.connect(self.reject)

        self.button_box.rejected.connect(self.reject)
        layout.addWidget(self.button_box)

        self.resize(self.sizeHint())
Ejemplo n.º 2
0
    def __init__(self, parent=None,):
        QDialog.__init__(self, parent)
        self.parent = parent
        self.setWindowTitle(u"{0} {1}: Getting Default Adobe Digital Editions Key".format(PLUGIN_NAME, PLUGIN_VERSION))
        layout = QVBoxLayout(self)
        self.setLayout(layout)

        try:
            if iswindows or isosx:
                from calibre_plugins.dedrm.adobekey import adeptkeys

                defaultkeys = adeptkeys()
            else:  # linux
                from wineutils import WineGetKeys

                scriptpath = os.path.join(parent.parent.alfdir,u"adobekey.py")
                defaultkeys = WineGetKeys(scriptpath, u".der",parent.getwineprefix())

            self.default_key = defaultkeys[0]
        except:
            traceback.print_exc()
            self.default_key = u""

        self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)

        if len(self.default_key)>0:
            data_group_box = QGroupBox(u"", self)
            layout.addWidget(data_group_box)
            data_group_box_layout = QVBoxLayout()
            data_group_box.setLayout(data_group_box_layout)

            key_group = QHBoxLayout()
            data_group_box_layout.addLayout(key_group)
            key_group.addWidget(QLabel(u"Unique Key Name:", self))
            self.key_ledit = QLineEdit(u"default_key", self)
            self.key_ledit.setToolTip(u"<p>Enter an identifying name for the current default Adobe Digital Editions key.")
            key_group.addWidget(self.key_ledit)
            key_label = QLabel(_(''), self)
            key_label.setAlignment(Qt.AlignHCenter)
            data_group_box_layout.addWidget(key_label)
            self.button_box.accepted.connect(self.accept)
        else:
            default_key_error = QLabel(u"The default encryption key for Adobe Digital Editions could not be found.", self)
            default_key_error.setAlignment(Qt.AlignHCenter)
            layout.addWidget(default_key_error)
            # if no default, bot buttons do the same
            self.button_box.accepted.connect(self.reject)

        self.button_box.rejected.connect(self.reject)
        layout.addWidget(self.button_box)

        self.resize(self.sizeHint())
Ejemplo n.º 3
0
    def PDFDecrypt(self, path_to_ebook):
        import calibre_plugins.dedrm.prefs as prefs
        import calibre_plugins.dedrm.ineptpdf

        dedrmprefs = prefs.DeDRM_Prefs()
        # Attempt to decrypt epub with each encryption key (generated or provided).
        print("{0} v{1}: {2} is a PDF ebook".format(
            PLUGIN_NAME, PLUGIN_VERSION, os.path.basename(path_to_ebook)))
        for keyname, userkeyhex in dedrmprefs['adeptkeys'].items():
            userkey = codecs.decode(userkeyhex, 'hex')
            print("{0} v{1}: Trying Encryption key {2:s}".format(
                PLUGIN_NAME, PLUGIN_VERSION, keyname))
            of = self.temporary_file(".pdf")

            # Give the user key, ebook and TemporaryPersistent file to the decryption function.
            try:
                result = ineptpdf.decryptBook(userkey, path_to_ebook, of.name)
            except:
                print(
                    "{0} v{1}: Exception when decrypting after {2:.1f} seconds"
                    .format(PLUGIN_NAME, PLUGIN_VERSION,
                            time.time() - self.starttime))
                traceback.print_exc()
                result = 1

            of.close()

            if result == 0:
                # Decryption was successful.
                # Return the modified PersistentTemporary file to calibre.
                return of.name

            print(
                "{0} v{1}: Failed to decrypt with key {2:s} after {3:.1f} seconds"
                .format(PLUGIN_NAME, PLUGIN_VERSION, keyname,
                        time.time() - self.starttime))

        # perhaps we need to get a new default ADE key
        print(
            "{0} v{1}: Looking for new default Adobe Digital Editions Keys after {2:.1f} seconds"
            .format(PLUGIN_NAME, PLUGIN_VERSION,
                    time.time() - self.starttime))

        # get the default Adobe keys
        defaultkeys = []

        try:
            if iswindows or isosx:
                from calibre_plugins.dedrm.adobekey import adeptkeys

                defaultkeys = adeptkeys()
            else:  # linux
                from .wineutils import WineGetKeys

                scriptpath = os.path.join(self.alfdir, "adobekey.py")
                defaultkeys = WineGetKeys(scriptpath, ".der",
                                          dedrmprefs['adobewineprefix'])

            self.default_key = defaultkeys[0]
        except:
            print(
                "{0} v{1}: Exception when getting default Adobe Key after {2:.1f} seconds"
                .format(PLUGIN_NAME, PLUGIN_VERSION,
                        time.time() - self.starttime))
            traceback.print_exc()
            self.default_key = ""

        newkeys = []
        for keyvalue in defaultkeys:
            if codecs.encode(keyvalue,
                             'hex') not in dedrmprefs['adeptkeys'].values():
                newkeys.append(keyvalue)

        if len(newkeys) > 0:
            try:
                for i, userkey in enumerate(newkeys):
                    print("{0} v{1}: Trying a new default key".format(
                        PLUGIN_NAME, PLUGIN_VERSION))
                    of = self.temporary_file(".pdf")

                    # Give the user key, ebook and TemporaryPersistent file to the decryption function.
                    try:
                        result = ineptpdf.decryptBook(userkey, path_to_ebook,
                                                      of.name)
                    except:
                        print(
                            "{0} v{1}: Exception when decrypting after {2:.1f} seconds"
                            .format(PLUGIN_NAME, PLUGIN_VERSION,
                                    time.time() - self.starttime))
                        traceback.print_exc()
                        result = 1

                    of.close()

                    if result == 0:
                        # Decryption was a success
                        # 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.writeprefs()
                            print(
                                "{0} v{1}: Saved a new default key after {2:.1f} seconds"
                                .format(PLUGIN_NAME, PLUGIN_VERSION,
                                        time.time() - self.starttime))
                        except:
                            print(
                                "{0} v{1}: Exception when saving a new default key after {2:.1f} seconds"
                                .format(PLUGIN_NAME, PLUGIN_VERSION,
                                        time.time() - self.starttime))
                            traceback.print_exc()
                        # Return the modified PersistentTemporary file to calibre.
                        return of.name

                    print(
                        "{0} v{1}: Failed to decrypt with new default key after {2:.1f} seconds"
                        .format(PLUGIN_NAME, PLUGIN_VERSION,
                                time.time() - self.starttime))
            except Exception as e:
                pass

        # Something went wrong with decryption.
        print(
            "{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md"
            .format(PLUGIN_NAME, PLUGIN_VERSION,
                    time.time() - self.starttime))
        raise DeDRMError(
            "{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md"
            .format(PLUGIN_NAME, PLUGIN_VERSION,
                    time.time() - self.starttime))
Ejemplo n.º 4
0
    def ePubDecrypt(self, path_to_ebook):
        # Create a TemporaryPersistent file to work with.
        # Check original epub archive for zip errors.
        import calibre_plugins.dedrm.zipfix

        inf = self.temporary_file(".epub")
        try:
            print("{0} v{1}: Verifying zip archive integrity".format(
                PLUGIN_NAME, PLUGIN_VERSION))
            fr = zipfix.fixZip(path_to_ebook, inf.name)
            fr.fix()
        except Exception as e:
            print("{0} v{1}: Error \'{2}\' when checking zip archive".format(
                PLUGIN_NAME, PLUGIN_VERSION, e.args[0]))
            raise Exception(e)

        # import the decryption keys
        import calibre_plugins.dedrm.prefs as prefs
        dedrmprefs = prefs.DeDRM_Prefs()

        # import the Barnes & Noble ePub handler
        import calibre_plugins.dedrm.ignobleepub as ignobleepub

        #check the book
        if ignobleepub.ignobleBook(inf.name):
            print("{0} v{1}: “{2}” is a secure Barnes & Noble ePub".format(
                PLUGIN_NAME, PLUGIN_VERSION, os.path.basename(path_to_ebook)))

            # Attempt to decrypt epub with each encryption key (generated or provided).
            for keyname, userkey in dedrmprefs['bandnkeys'].items():
                keyname_masked = "".join(
                    ("X" if (x.isdigit()) else x) for x in keyname)
                print("{0} v{1}: Trying Encryption key {2:s}".format(
                    PLUGIN_NAME, PLUGIN_VERSION, keyname_masked))
                of = self.temporary_file(".epub")

                # Give the user key, ebook and TemporaryPersistent file to the decryption function.
                try:
                    result = ignobleepub.decryptBook(userkey, inf.name,
                                                     of.name)
                except:
                    print(
                        "{0} v{1}: Exception when trying to decrypt after {2:.1f} seconds"
                        .format(PLUGIN_NAME, PLUGIN_VERSION,
                                time.time() - self.starttime))
                    traceback.print_exc()
                    result = 1

                of.close()

                if result == 0:
                    # Decryption was successful.
                    # Return the modified PersistentTemporary file to calibre.
                    return of.name

                print(
                    "{0} v{1}: Failed to decrypt with key {2:s} after {3:.1f} seconds"
                    .format(PLUGIN_NAME, PLUGIN_VERSION, keyname_masked,
                            time.time() - self.starttime))

            # perhaps we should see if we can get a key from a log file
            print(
                "{0} v{1}: Looking for new NOOK Study Keys after {2:.1f} seconds"
                .format(PLUGIN_NAME, PLUGIN_VERSION,
                        time.time() - self.starttime))

            # get the default NOOK Study keys
            defaultkeys = []

            try:
                if iswindows or isosx:
                    from calibre_plugins.dedrm.ignoblekey import nookkeys

                    defaultkeys = nookkeys()
                else:  # linux
                    from .wineutils import WineGetKeys

                    scriptpath = os.path.join(self.alfdir, "ignoblekey.py")
                    defaultkeys = WineGetKeys(scriptpath, ".b64",
                                              dedrmprefs['adobewineprefix'])

            except:
                print(
                    "{0} v{1}: Exception when getting default NOOK Study Key after {2:.1f} seconds"
                    .format(PLUGIN_NAME, PLUGIN_VERSION,
                            time.time() - self.starttime))
                traceback.print_exc()

            newkeys = []
            for keyvalue in defaultkeys:
                if keyvalue not in dedrmprefs['bandnkeys'].values():
                    newkeys.append(keyvalue)

            if len(newkeys) > 0:
                try:
                    for i, userkey in enumerate(newkeys):
                        print("{0} v{1}: Trying a new default key".format(
                            PLUGIN_NAME, PLUGIN_VERSION))

                        of = self.temporary_file(".epub")

                        # Give the user key, ebook and TemporaryPersistent file to the decryption function.
                        try:
                            result = ignobleepub.decryptBook(
                                userkey, inf.name, of.name)
                        except:
                            print(
                                "{0} v{1}: Exception when trying to decrypt after {2:.1f} seconds"
                                .format(PLUGIN_NAME, PLUGIN_VERSION,
                                        time.time() - self.starttime))
                            traceback.print_exc()
                            result = 1

                        of.close()

                        if result == 0:
                            # Decryption was a success
                            # 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(
                                    'bandnkeys', 'nook_Study_key', keyvalue)
                                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:
                                print(
                                    "{0} v{1}: Exception saving a new default key after {2:.1f} seconds"
                                    .format(PLUGIN_NAME, PLUGIN_VERSION,
                                            time.time() - self.starttime))
                                traceback.print_exc()
                            # Return the modified PersistentTemporary file to calibre.
                            return of.name

                        print(
                            "{0} v{1}: Failed to decrypt with new default key after {2:.1f} seconds"
                            .format(PLUGIN_NAME, PLUGIN_VERSION,
                                    time.time() - self.starttime))
                except Exception as e:
                    pass

            print(
                "{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md"
                .format(PLUGIN_NAME, PLUGIN_VERSION,
                        time.time() - self.starttime))
            raise DeDRMError(
                "{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md"
                .format(PLUGIN_NAME, PLUGIN_VERSION,
                        time.time() - self.starttime))

        # import the Adobe Adept ePub handler
        import calibre_plugins.dedrm.ineptepub as ineptepub

        if ineptepub.adeptBook(inf.name):
            print("{0} v{1}: {2} is a secure Adobe Adept ePub".format(
                PLUGIN_NAME, PLUGIN_VERSION, os.path.basename(path_to_ebook)))

            # Attempt to decrypt epub with each encryption key (generated or provided).
            for keyname, userkeyhex in dedrmprefs['adeptkeys'].items():
                userkey = codecs.decode(userkeyhex, 'hex')
                print("{0} v{1}: Trying Encryption key {2:s}".format(
                    PLUGIN_NAME, PLUGIN_VERSION, keyname))
                of = self.temporary_file(".epub")

                # Give the user key, ebook and TemporaryPersistent file to the decryption function.
                try:
                    result = ineptepub.decryptBook(userkey, inf.name, of.name)
                except:
                    print(
                        "{0} v{1}: Exception when decrypting after {2:.1f} seconds"
                        .format(PLUGIN_NAME, PLUGIN_VERSION,
                                time.time() - self.starttime))
                    traceback.print_exc()
                    result = 1

                try:
                    of.close()
                except:
                    print(
                        "{0} v{1}: Exception closing temporary file after {2:.1f} seconds. Ignored."
                        .format(PLUGIN_NAME, PLUGIN_VERSION,
                                time.time() - self.starttime))

                if result == 0:
                    # Decryption was successful.
                    # Return the modified PersistentTemporary file to calibre.
                    print(
                        "{0} v{1}: Decrypted with key {2:s} after {3:.1f} seconds"
                        .format(PLUGIN_NAME, PLUGIN_VERSION, keyname,
                                time.time() - self.starttime))
                    return of.name

                print(
                    "{0} v{1}: Failed to decrypt with key {2:s} after {3:.1f} seconds"
                    .format(PLUGIN_NAME, PLUGIN_VERSION, keyname,
                            time.time() - self.starttime))

            # perhaps we need to get a new default ADE key
            print(
                "{0} v{1}: Looking for new default Adobe Digital Editions Keys after {2:.1f} seconds"
                .format(PLUGIN_NAME, PLUGIN_VERSION,
                        time.time() - self.starttime))

            # get the default Adobe keys
            defaultkeys = []

            try:
                if iswindows or isosx:
                    from calibre_plugins.dedrm.adobekey import adeptkeys

                    defaultkeys = adeptkeys()
                else:  # linux
                    from .wineutils import WineGetKeys

                    scriptpath = os.path.join(self.alfdir, "adobekey.py")
                    defaultkeys = WineGetKeys(scriptpath, ".der",
                                              dedrmprefs['adobewineprefix'])

                self.default_key = defaultkeys[0]
            except:
                print(
                    "{0} v{1}: Exception when getting default Adobe Key after {2:.1f} seconds"
                    .format(PLUGIN_NAME, PLUGIN_VERSION,
                            time.time() - self.starttime))
                traceback.print_exc()
                self.default_key = ""

            newkeys = []
            for keyvalue in defaultkeys:
                if codecs.encode(keyvalue, 'hex').decode(
                        'ascii') not in dedrmprefs['adeptkeys'].values():
                    newkeys.append(keyvalue)

            if len(newkeys) > 0:
                try:
                    for i, userkey in enumerate(newkeys):
                        print("{0} v{1}: Trying a new default key".format(
                            PLUGIN_NAME, PLUGIN_VERSION))
                        of = self.temporary_file(".epub")

                        # Give the user key, ebook and TemporaryPersistent file to the decryption function.
                        try:
                            result = ineptepub.decryptBook(
                                userkey, inf.name, of.name)
                        except:
                            print(
                                "{0} v{1}: Exception when decrypting after {2:.1f} seconds"
                                .format(PLUGIN_NAME, PLUGIN_VERSION,
                                        time.time() - self.starttime))
                            traceback.print_exc()
                            result = 1

                        of.close()

                        if result == 0:
                            # Decryption was a success
                            # 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.writeprefs()
                                print(
                                    "{0} v{1}: Saved a new default key after {2:.1f} seconds"
                                    .format(PLUGIN_NAME, PLUGIN_VERSION,
                                            time.time() - self.starttime))
                            except:
                                print(
                                    "{0} v{1}: Exception when saving a new default key after {2:.1f} seconds"
                                    .format(PLUGIN_NAME, PLUGIN_VERSION,
                                            time.time() - self.starttime))
                                traceback.print_exc()
                            print(
                                "{0} v{1}: Decrypted with new default key after {2:.1f} seconds"
                                .format(PLUGIN_NAME, PLUGIN_VERSION,
                                        time.time() - self.starttime))
                            # Return the modified PersistentTemporary file to calibre.
                            return of.name

                        print(
                            "{0} v{1}: Failed to decrypt with new default key after {2:.1f} seconds"
                            .format(PLUGIN_NAME, PLUGIN_VERSION,
                                    time.time() - self.starttime))
                except Exception as e:
                    print(
                        "{0} v{1}: Unexpected Exception trying a new default key after {2:.1f} seconds"
                        .format(PLUGIN_NAME, PLUGIN_VERSION,
                                time.time() - self.starttime))
                    traceback.print_exc()
                    pass

            # Something went wrong with decryption.
            print(
                "{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md"
                .format(PLUGIN_NAME, PLUGIN_VERSION,
                        time.time() - self.starttime))
            raise DeDRMError(
                "{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md"
                .format(PLUGIN_NAME, PLUGIN_VERSION,
                        time.time() - self.starttime))

        # Not a Barnes & Noble nor an Adobe Adept
        # Import the fixed epub.
        print(
            "{0} v{1}: “{2}” is neither an Adobe Adept nor a Barnes & Noble encrypted ePub"
            .format(PLUGIN_NAME, PLUGIN_VERSION,
                    os.path.basename(path_to_ebook)))
        raise DeDRMError(
            "{0} v{1}: Couldn't decrypt after {2:.1f} seconds. DRM free perhaps?"
            .format(PLUGIN_NAME, PLUGIN_VERSION,
                    time.time() - self.starttime))
Ejemplo n.º 5
0
    def PDFDecrypt(self, path_to_ebook):
        import calibre_plugins.dedrm.prefs as prefs
        import calibre_plugins.dedrm.ineptpdf

        dedrmprefs = prefs.DeDRM_Prefs()
        # Attempt to decrypt epub with each encryption key (generated or provided).
        print u"{0} v{1}: {2} is a PDF ebook".format(
            PLUGIN_NAME, PLUGIN_VERSION, os.path.basename(path_to_ebook))
        for keyname, userkeyhex in dedrmprefs['adeptkeys'].items():
            userkey = userkeyhex.decode('hex')
            print u"{0} v{1}: Trying Encryption key {2:s}".format(
                PLUGIN_NAME, PLUGIN_VERSION, keyname)
            of = self.temporary_file(u".pdf")

            # Give the user key, ebook and TemporaryPersistent file to the decryption function.
            try:
                result = ineptpdf.decryptBook(userkey, path_to_ebook, of.name)
            except:
                result = 1

            of.close()

            if result == 0:
                # Decryption was successful.
                # Return the modified PersistentTemporary file to calibre.
                return of.name

            # perhaps we need to get a new default ADE key
            print u"{0} v{1}: Looking for new default Adobe Digital Editions Keys after {2:.1f} seconds".format(
                PLUGIN_NAME, PLUGIN_VERSION,
                time.time() - self.starttime)

            # get the default Adobe keys
            defaultkeys = []

            if iswindows or isosx:
                import calibre_plugins.dedrm.adobekey as adobe

                try:
                    defaultkeys = adobe.adeptkeys()
                except:
                    pass
            else:
                # linux
                try:
                    from wineutils import WineGetKeys

                    scriptpath = os.join(self.alfdir, u"adobekey.py")
                    defaultkeys = self.WineGetKeys(
                        scriptpath, u".der", dedrmprefs['adobewineprefix'])
                except:
                    pass

            newkeys = []
            for keyvalue in defaultkeys:
                if keyvalue.encode(
                        'hex') not in dedrmprefs['adeptkeys'].values():
                    newkeys.append(keyvalue)

            if len(newkeys) > 0:
                try:
                    for i, userkey in enumerate(newkeys):
                        print u"{0} v{1}: Trying a new default key".format(
                            PLUGIN_NAME, PLUGIN_VERSION)
                        of = self.temporary_file(u".pdf")

                        # Give the user key, ebook and TemporaryPersistent file to the decryption function.
                        try:
                            result = ineptepdf.decryptBook(
                                userkey, inf.name, of.name)
                        except:
                            result = 1

                        of.close()

                        if result == 0:
                            # Decryption was a success
                            # Store the new successful key in the defaults
                            print u"{0} v{1}: Saving a new default key".format(
                                PLUGIN_NAME, PLUGIN_VERSION)
                            try:
                                dedrmprefs.addnamedvaluetoprefs(
                                    'adeptkeys', 'default_key',
                                    keyvalue.encode('hex'))
                                dedrmprefs.writeprefs()
                            except:
                                traceback.print_exc()
                            # Return the modified PersistentTemporary file to calibre.
                            return of.name

                        print u"{0} v{1}: Failed to decrypt with new default key after {2:.1f} seconds".format(
                            PLUGIN_NAME, PLUGIN_VERSION,
                            time.time() - self.starttime)
                except Exception, e:
                    pass
Ejemplo n.º 6
0
                    PLUGIN_NAME, PLUGIN_VERSION, keyname,
                    time.time() - self.starttime)

            # perhaps we need to get a new default ADE key
            print u"{0} v{1}: Looking for new default Adobe Digital Editions Keys after {2:.1f} seconds".format(
                PLUGIN_NAME, PLUGIN_VERSION,
                time.time() - self.starttime)

            # get the default Adobe keys
            defaultkeys = []

            try:
                if iswindows or isosx:
                    from calibre_plugins.dedrm.adobekey import adeptkeys

                    defaultkeys = adeptkeys()
                else:  # linux
                    from wineutils import WineGetKeys

                    scriptpath = os.join(self.alfdir, u"adobekey.py")
                    defaultkeys = WineGetKeys(scriptpath, u".der",
                                              dedrmprefs['adobewineprefix'])

                self.default_key = default_keys[0]
            except:
                traceback.print_exc()
                self.default_key = u""

            newkeys = []
            for keyvalue in defaultkeys:
                if keyvalue.encode(
Ejemplo n.º 7
0
    def PDFDecrypt(self, path_to_ebook):
        import calibre_plugins.dedrm.prefs as prefs
        import calibre_plugins.dedrm.ineptpdf

        dedrmprefs = prefs.DeDRM_Prefs()
        # Attempt to decrypt epub with each encryption key (generated or provided).
        print u"{0} v{1}: {2} is a PDF ebook".format(PLUGIN_NAME, PLUGIN_VERSION, os.path.basename(path_to_ebook))
        for keyname, userkeyhex in dedrmprefs["adeptkeys"].items():
            userkey = userkeyhex.decode("hex")
            print u"{0} v{1}: Trying Encryption key {2:s}".format(PLUGIN_NAME, PLUGIN_VERSION, keyname)
            of = self.temporary_file(u".pdf")

            # Give the user key, ebook and TemporaryPersistent file to the decryption function.
            try:
                result = ineptpdf.decryptBook(userkey, path_to_ebook, of.name)
            except:
                result = 1

            of.close()

            if result == 0:
                # Decryption was successful.
                # Return the modified PersistentTemporary file to calibre.
                return of.name

            # perhaps we need to get a new default ADE key
            print u"{0} v{1}: Looking for new default Adobe Digital Editions Keys after {2:.1f} seconds".format(
                PLUGIN_NAME, PLUGIN_VERSION, time.time() - self.starttime
            )

            # get the default Adobe keys
            defaultkeys = []

            if iswindows or isosx:
                import calibre_plugins.dedrm.adobekey as adobe

                try:
                    defaultkeys = adobe.adeptkeys()
                except:
                    pass
            else:
                # linux
                try:
                    from wineutils import WineGetKeys

                    scriptpath = os.path.join(self.alfdir, u"adobekey.py")
                    defaultkeys = WineGetKeys(scriptpath, u".der", dedrmprefs["adobewineprefix"])
                except:
                    pass

            newkeys = []
            for keyvalue in defaultkeys:
                if keyvalue.encode("hex") not in dedrmprefs["adeptkeys"].values():
                    newkeys.append(keyvalue)

            if len(newkeys) > 0:
                try:
                    for i, userkey in enumerate(newkeys):
                        print u"{0} v{1}: Trying a new default key".format(PLUGIN_NAME, PLUGIN_VERSION)
                        of = self.temporary_file(u".pdf")

                        # Give the user key, ebook and TemporaryPersistent file to the decryption function.
                        try:
                            result = ineptepdf.decryptBook(userkey, inf.name, of.name)
                        except:
                            result = 1

                        of.close()

                        if result == 0:
                            # Decryption was a success
                            # Store the new successful key in the defaults
                            print u"{0} v{1}: Saving a new default key".format(PLUGIN_NAME, PLUGIN_VERSION)
                            try:
                                dedrmprefs.addnamedvaluetoprefs("adeptkeys", "default_key", keyvalue.encode("hex"))
                                dedrmprefs.writeprefs()
                            except:
                                traceback.print_exc()
                            # Return the modified PersistentTemporary file to calibre.
                            return of.name

                        print u"{0} v{1}: Failed to decrypt with new default key after {2:.1f} seconds".format(
                            PLUGIN_NAME, PLUGIN_VERSION, time.time() - self.starttime
                        )
                except Exception, e:
                    pass
Ejemplo n.º 8
0
                    PLUGIN_NAME, PLUGIN_VERSION, keyname, time.time() - self.starttime
                )

            # perhaps we need to get a new default ADE key
            print u"{0} v{1}: Looking for new default Adobe Digital Editions Keys after {2:.1f} seconds".format(
                PLUGIN_NAME, PLUGIN_VERSION, time.time() - self.starttime
            )

            # get the default Adobe keys
            defaultkeys = []

            try:
                if iswindows or isosx:
                    from calibre_plugins.dedrm.adobekey import adeptkeys

                    defaultkeys = adeptkeys()
                else:  # linux
                    from wineutils import WineGetKeys

                    scriptpath = os.path.join(self.alfdir, u"adobekey.py")
                    defaultkeys = WineGetKeys(scriptpath, u".der", dedrmprefs["adobewineprefix"])

                self.default_key = defaultkeys[0]
            except:
                traceback.print_exc()
                self.default_key = u""

            newkeys = []
            for keyvalue in defaultkeys:
                if keyvalue.encode("hex") not in dedrmprefs["adeptkeys"].values():
                    newkeys.append(keyvalue)