Fix for Kobo Desktop 3.17

This commit is contained in:
apprenticeharper 2015-09-03 07:49:09 +01:00
parent 3c322f3695
commit d54dc38c2d
5 changed files with 69 additions and 21 deletions

Binary file not shown.

View File

@ -19,7 +19,7 @@ except NameError:
PLUGIN_NAME = 'Obok DeDRM' PLUGIN_NAME = 'Obok DeDRM'
PLUGIN_SAFE_NAME = PLUGIN_NAME.strip().lower().replace(' ', '_') PLUGIN_SAFE_NAME = PLUGIN_NAME.strip().lower().replace(' ', '_')
PLUGIN_DESCRIPTION = _('Removes DRM from Kobo kepubs and adds them to the library.') PLUGIN_DESCRIPTION = _('Removes DRM from Kobo kepubs and adds them to the library.')
PLUGIN_VERSION_TUPLE = (3, 1, 3) PLUGIN_VERSION_TUPLE = (3, 1, 4)
PLUGIN_VERSION = '.'.join([str(x) for x in PLUGIN_VERSION_TUPLE]) PLUGIN_VERSION = '.'.join([str(x) for x in PLUGIN_VERSION_TUPLE])
HELPFILE_NAME = PLUGIN_SAFE_NAME + '_Help.htm' HELPFILE_NAME = PLUGIN_SAFE_NAME + '_Help.htm'
PLUGIN_AUTHORS = 'Anon' PLUGIN_AUTHORS = 'Anon'

View File

@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import os, zipfile import os, traceback, zipfile
try: try:
from PyQt5.Qt import QToolButton, QUrl from PyQt5.Qt import QToolButton, QUrl
@ -98,6 +98,7 @@ class InterfacePluginAction(InterfaceAction):
candidate_keys = self.library.userkeys candidate_keys = self.library.userkeys
except: except:
print (_('Trouble retrieving keys with newer obok method.')) print (_('Trouble retrieving keys with newer obok method.'))
traceback.print_exc()
else: else:
if len(candidate_keys): if len(candidate_keys):
self.userkeys.extend(candidate_keys) self.userkeys.extend(candidate_keys)

View File

@ -1,6 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Version 3.1.4 September 2015
# Updated for version 3.17 of the Windows Desktop app.
#
# Version 3.1.3 August 2015 # Version 3.1.3 August 2015
# Add translations for Portuguese and Arabic # Add translations for Portuguese and Arabic
# #
@ -220,7 +223,7 @@ class KoboLibrary(object):
of books, their titles, and the user's encryption key(s).""" of books, their titles, and the user's encryption key(s)."""
def __init__ (self): def __init__ (self):
print u"Obok v{0}\nCopyright © 2012-2014 Physisticated et al.".format(__version__) print u"Obok v{0}\nCopyright © 2012-2015 Physisticated et al.".format(__version__)
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
if sys.getwindowsversion().major > 5: if sys.getwindowsversion().major > 5:
self.kobodir = os.environ['LOCALAPPDATA'] self.kobodir = os.environ['LOCALAPPDATA']
@ -249,9 +252,8 @@ class KoboLibrary(object):
""" """
if len(self._userkeys) != 0: if len(self._userkeys) != 0:
return self._userkeys return self._userkeys
userid = self.__getuserid()
for macaddr in self.__getmacaddrs(): for macaddr in self.__getmacaddrs():
self._userkeys.append(self.__getuserkey(macaddr, userid)) self._userkeys.extend(self.__getuserkeys(macaddr))
return self._userkeys return self._userkeys
@property @property
@ -297,13 +299,33 @@ class KoboLibrary(object):
macaddrs.append(m[0].upper()) macaddrs.append(m[0].upper())
return macaddrs return macaddrs
def __getuserid (self): def __getuserids (self):
return self.__cursor.execute('SELECT UserID FROM user WHERE HasMadePurchase = "true"').fetchone()[0] userids = []
cursor = self.__cursor.execute('SELECT UserID FROM user WHERE HasMadePurchase = "true"')
def __getuserkey (self, macaddr, userid): row = cursor.fetchone()
while row is not None:
try:
userid = row[0]
userids.append(userid)
except:
pass
row = cursor.fetchone()
return userids
def __getuserkeys (self, macaddr):
userids = self.__getuserids()
userkeys = []
# This version is used for versions before 3.17.0.
deviceid = hashlib.sha256('NoCanLook' + macaddr).hexdigest() deviceid = hashlib.sha256('NoCanLook' + macaddr).hexdigest()
userkey = hashlib.sha256(deviceid + userid).hexdigest() for userid in userids:
return binascii.a2b_hex(userkey[32:]) userkey = hashlib.sha256(deviceid + userid).hexdigest()
userkeys.append(binascii.a2b_hex(userkey[32:]))
# This version is used for 3.17.0 and later.
deviceid = hashlib.sha256('XzUhGYdFp' + macaddr).hexdigest()
for userid in userids:
userkey = hashlib.sha256(deviceid + userid).hexdigest()
userkeys.append(binascii.a2b_hex(userkey[32:]))
return userkeys
class KoboBook(object): class KoboBook(object):
"""A Kobo book. """A Kobo book.

View File

@ -1,6 +1,12 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Version 3.1.4 September 2015
# Updated for version 3.17 of the Windows Desktop app.
#
# Version 3.1.3 August 2015
# Add translations for Portuguese and Arabic
#
# Version 3.1.2 January 2015 # Version 3.1.2 January 2015
# Add coding, version number and version announcement # Add coding, version number and version announcement
# #
@ -109,7 +115,7 @@
# #
"""Manage all Kobo books, either encrypted or DRM-free.""" """Manage all Kobo books, either encrypted or DRM-free."""
__version__ = '3.1.1' __version__ = '3.1.3'
import sys import sys
import os import os
@ -217,7 +223,7 @@ class KoboLibrary(object):
of books, their titles, and the user's encryption key(s).""" of books, their titles, and the user's encryption key(s)."""
def __init__ (self): def __init__ (self):
print u"Obok v{0}\nCopyright © 2012-2014 Physisticated et al.".format(__version__) print u"Obok v{0}\nCopyright © 2012-2015 Physisticated et al.".format(__version__)
if sys.platform.startswith('win'): if sys.platform.startswith('win'):
if sys.getwindowsversion().major > 5: if sys.getwindowsversion().major > 5:
self.kobodir = os.environ['LOCALAPPDATA'] self.kobodir = os.environ['LOCALAPPDATA']
@ -246,9 +252,8 @@ class KoboLibrary(object):
""" """
if len(self._userkeys) != 0: if len(self._userkeys) != 0:
return self._userkeys return self._userkeys
userid = self.__getuserid()
for macaddr in self.__getmacaddrs(): for macaddr in self.__getmacaddrs():
self._userkeys.append(self.__getuserkey(macaddr, userid)) self._userkeys.extend(self.__getuserkeys(macaddr))
return self._userkeys return self._userkeys
@property @property
@ -294,13 +299,33 @@ class KoboLibrary(object):
macaddrs.append(m[0].upper()) macaddrs.append(m[0].upper())
return macaddrs return macaddrs
def __getuserid (self): def __getuserids (self):
return self.__cursor.execute('SELECT UserID FROM user WHERE HasMadePurchase = "true"').fetchone()[0] userids = []
cursor = self.__cursor.execute('SELECT UserID FROM user WHERE HasMadePurchase = "true"')
def __getuserkey (self, macaddr, userid): row = cursor.fetchone()
while row is not None:
try:
userid = row[0]
userids.append(userid)
except:
pass
row = cursor.fetchone()
return userids
def __getuserkeys (self, macaddr):
userids = self.__getuserids()
userkeys = []
# This version is used for versions before 3.17.0.
deviceid = hashlib.sha256('NoCanLook' + macaddr).hexdigest() deviceid = hashlib.sha256('NoCanLook' + macaddr).hexdigest()
userkey = hashlib.sha256(deviceid + userid).hexdigest() for userid in userids:
return binascii.a2b_hex(userkey[32:]) userkey = hashlib.sha256(deviceid + userid).hexdigest()
userkeys.append(binascii.a2b_hex(userkey[32:]))
# This version is used for 3.17.0 and later.
deviceid = hashlib.sha256('XzUhGYdFp' + macaddr).hexdigest()
for userid in userids:
userkey = hashlib.sha256(deviceid + userid).hexdigest()
userkeys.append(binascii.a2b_hex(userkey[32:]))
return userkeys
class KoboBook(object): class KoboBook(object):
"""A Kobo book. """A Kobo book.