From 53e106fa738a8680a69fef7b5b879b6dd6b3f581 Mon Sep 17 00:00:00 2001 From: Florian Bach Date: Sat, 14 May 2022 10:26:11 +0200 Subject: [PATCH] Display error message if pkcs12 can't be decrypted --- calibre-plugin/__init__.py | 16 +++++++++++++--- calibre-plugin/config.py | 4 ++++ calibre-plugin/libadobeFulfill.py | 22 +++++++++++++++++++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/calibre-plugin/__init__.py b/calibre-plugin/__init__.py index c4e7818..9c1607b 100644 --- a/calibre-plugin/__init__.py +++ b/calibre-plugin/__init__.py @@ -189,7 +189,7 @@ class DeACSM(FileTypePlugin): from libadobe import createDeviceKeyFile, update_account_path, sendHTTPRequest from libadobeAccount import createDeviceFile, createUser, signIn, activateDevice - from libadobeFulfill import buildRights, fulfill + from libadobeFulfill import buildRights, fulfill, getDecryptedCert import calibre_plugins.deacsm.prefs as prefs # type: ignore @@ -215,25 +215,35 @@ class DeACSM(FileTypePlugin): import calibre_plugins.deacsm.prefs as prefs # type: ignore deacsmprefs = prefs.DeACSM_Prefs() - activation_xml_path = os.path.join(deacsmprefs["path_to_account_data"], "activation.xml") + from libadobe import get_activation_xml_path + from libadobeFulfill import getDecryptedCert container = None try: - container = etree.parse(activation_xml_path) + container = etree.parse(get_activation_xml_path()) except: + print("ADE sanity check: Can't parse activation container") return False try: adeptNS = lambda tag: '{%s}%s' % ('http://ns.adobe.com/adept', tag) if container.find(adeptNS("activationToken")) == None: + print("ADE sanity check: activationToken missing") return False if container.find(adeptNS("credentials")).find(adeptNS("pkcs12")) == None: + print("ADE sanity check: pkcs12 missing") + return False + + if getDecryptedCert() is None: + print("ADE sanity check: Can't decrypt pkcs12") return False return True except: + print("ADE sanity check: Exception") + traceback.print_exc() return False def download(self, replyData): diff --git a/calibre-plugin/config.py b/calibre-plugin/config.py index 45a87a6..481c2a0 100644 --- a/calibre-plugin/config.py +++ b/calibre-plugin/config.py @@ -511,6 +511,7 @@ class ConfigWidget(QWidget): try: from libadobe import VAR_VER_SUPP_CONFIG_NAMES, VAR_VER_HOBBES_VERSIONS + from libadobeFulfill import getDecryptedCert except: print("{0} v{1}: Error while importing Account stuff".format(PLUGIN_NAME, PLUGIN_VERSION)) traceback.print_exc() @@ -564,6 +565,9 @@ class ConfigWidget(QWidget): if container.find(adeptNS("credentials")).find(adeptNS("pkcs12")) == None: return "ADE authorization seems to be corrupted (pkcs12 missing)", False, None + if getDecryptedCert() is None: + return "ADE authorization seems to be corrupted (failed to decrypt pkcs12)", False, None + if not anon: return "Authorized with ADE ID ("+ade_type+") " + ade_mail + "\non device " + ade_device_name + ", emulating " + ADE_version + ".", True, ade_mail else: diff --git a/calibre-plugin/libadobeFulfill.py b/calibre-plugin/libadobeFulfill.py index 0ff2c0b..40c2f01 100644 --- a/calibre-plugin/libadobeFulfill.py +++ b/calibre-plugin/libadobeFulfill.py @@ -137,8 +137,8 @@ def buildInitLicenseServiceRequest(authURL): return "\n" + etree.tostring(req_xml, encoding="utf-8", pretty_print=True, xml_declaration=False).decode("utf-8") -def buildAuthRequest(): +def getDecryptedCert(): activationxml = etree.parse(get_activation_xml_path()) adNS = lambda tag: '{%s}%s' % ('http://ns.adobe.com/adept', tag) @@ -155,9 +155,21 @@ def buildAuthRequest(): f = open(get_devkey_path(), "rb") devkey_bytes = f.read() f.close() - - my_cert = get_cert_from_pkcs12(user_pkcs12, base64.b64encode(devkey_bytes)) + try: + return get_cert_from_pkcs12(user_pkcs12, base64.b64encode(devkey_bytes)) + except: + return None + +def buildAuthRequest(): + + activationxml = etree.parse(get_activation_xml_path()) + adNS = lambda tag: '{%s}%s' % ('http://ns.adobe.com/adept', tag) + + my_cert = getDecryptedCert() + if my_cert is None: + print("Can't decrypt pkcs12 with devkey!") + return None ret = "\n" @@ -177,6 +189,10 @@ def doOperatorAuth(operatorURL): auth_req = buildAuthRequest() + if auth_req is None: + return "Failed to create auth request" + + authURL = operatorURL if authURL.endswith("Fulfill"): authURL = authURL.replace("/Fulfill", "")