From 4dfa2194b8398c0bd64ef35765574955b55f52a9 Mon Sep 17 00:00:00 2001 From: Florian Bach Date: Wed, 5 Jan 2022 21:39:29 +0100 Subject: [PATCH] Small ADE version differences --- calibre-plugin/config.py | 5 ++++- calibre-plugin/libadobe.py | 6 ++++++ calibre-plugin/libadobeAccount.py | 4 ++++ calibre-plugin/libadobeFulfill.py | 30 ++++++++++++++++++++++++++++-- 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/calibre-plugin/config.py b/calibre-plugin/config.py index 5531cb9..0f3fa31 100644 --- a/calibre-plugin/config.py +++ b/calibre-plugin/config.py @@ -498,7 +498,10 @@ class ConfigWidget(QWidget): except: pass if ade_mail is None: - self.button_convert_anon_to_account.setEnabled(False) + try: + self.button_convert_anon_to_account.setEnabled(False) + except: + pass self.button_export_activation.setEnabled(False) self.button_export_key.setEnabled(False) self.lblAccInfo.setText("Authorization deleted.\nClose and re-open this window to add a new authorization.") diff --git a/calibre-plugin/libadobe.py b/calibre-plugin/libadobe.py index ade078d..7ae29e5 100644 --- a/calibre-plugin/libadobe.py +++ b/calibre-plugin/libadobe.py @@ -51,6 +51,7 @@ VAR_VER_OS_IDENTIFIERS = [ "Windows Vista", "Windows Vista", "Windows 8", "Windo # "Missing" versions: # 1.7.1, 2.0, 3.0, 4.0, 4.0.1, 4.0.2, 4.5 to 4.5.9 +# 4.5.7.179634 # This is a list of ALL versions we know (and can potentially use if present in a config file). # Must have the same length / size as the four lists above. @@ -67,6 +68,11 @@ VAR_VER_ALLOWED_BUILD_IDS_SWITCH_TO = [ 1131, 78765, 91394, 123281, 187303 ] # According to changelogs, this is implemented as of ADE 4.0.1 - no idea what build ID that is. VAR_VER_NEED_HTTPS_BUILD_ID_LIMIT = 123281 +# Versions >= this are using a different order for the XML elements in a FulfillmentNotification. +# This doesn't matter for fulfillment at all, but I want to emulate ADE as accurately as possible. +# Implemented as of ADE 4.0.0, no idea what exact build number that is. +VAR_VER_USE_DIFFERENT_NOTIFICATION_XML_ORDER = 123281 + # Default build ID to use - ADE 2.0.1 VAR_VER_DEFAULT_BUILD_ID = 78765 diff --git a/calibre-plugin/libadobeAccount.py b/calibre-plugin/libadobeAccount.py index ae201b4..81dd6c6 100644 --- a/calibre-plugin/libadobeAccount.py +++ b/calibre-plugin/libadobeAccount.py @@ -711,6 +711,10 @@ def buildActivateReq(useVersionIndex: int = 0): ret += "%s" % (devicexml.find("./%s" % (adNS("fingerprint"))).text) + # TODO: Here's where multiple s, each with a user and a device, + # TODO: would show up if the client was already activated and just adds an additional activation. + # TODO: Not sure if I want to replicate this, or if I'd rather replicate independant installations ... + ret += "" ret += addNonce() diff --git a/calibre-plugin/libadobeFulfill.py b/calibre-plugin/libadobeFulfill.py index a1fbd7c..893e736 100644 --- a/calibre-plugin/libadobeFulfill.py +++ b/calibre-plugin/libadobeFulfill.py @@ -5,10 +5,12 @@ try: from libadobe import addNonce, sign_node, get_cert_from_pkcs12, sendRequestDocu, sendRequestDocuRC, sendHTTPRequest from libadobe import get_devkey_path, get_device_path, get_activation_xml_path from libadobe import VAR_VER_SUPP_VERSIONS, VAR_VER_SUPP_CONFIG_NAMES, VAR_VER_HOBBES_VERSIONS + from libadobe import VAR_VER_BUILD_IDS, VAR_VER_USE_DIFFERENT_NOTIFICATION_XML_ORDER except: from calibre_plugins.deacsm.libadobe import addNonce, sign_node, get_cert_from_pkcs12, sendRequestDocu, sendRequestDocuRC, sendHTTPRequest from calibre_plugins.deacsm.libadobe import get_devkey_path, get_device_path, get_activation_xml_path from calibre_plugins.deacsm.libadobe import VAR_VER_SUPP_VERSIONS, VAR_VER_SUPP_CONFIG_NAMES, VAR_VER_HOBBES_VERSIONS + from calibre_plugins.deacsm.libadobe import VAR_VER_BUILD_IDS, VAR_VER_USE_DIFFERENT_NOTIFICATION_XML_ORDER def buildFulfillRequest(acsm): @@ -658,8 +660,32 @@ def performFulfillmentNotification(fulfillmentResultToken, forceOptional = False full_text = "" full_text += "%s" % user full_text += "%s" % device - full_text += etree.tostring(body, encoding="utf-8", pretty_print=True, xml_declaration=False).decode("utf-8") - full_text += addNonce() + + + # ADE 4.0 apparently changed the order of these two elements. + # I still don't know exactly how this order is determined, but in most cases + # ADE 4+ has the body first, then the nonce, while ADE 3 and lower usually has nonce first, then body. + # It probably doesn't matter, but still, we want to behave exactly like ADE, so check the version number: + + devicexml = etree.parse(get_device_path()) + for f in devicexml.findall("./%s" % (adNS("version"))): + if f.get("name") == "hobbes": + version = f.get("value") + + try: + v_idx = VAR_VER_HOBBES_VERSIONS.index(version) + clientVersion = VAR_VER_BUILD_IDS[v_idx] + except: + clientVersion = 0 + + if (clientVersion >= VAR_VER_USE_DIFFERENT_NOTIFICATION_XML_ORDER): + full_text += etree.tostring(body, encoding="utf-8", pretty_print=True, xml_declaration=False).decode("utf-8") + full_text += addNonce() + else: + full_text += addNonce() + full_text += etree.tostring(body, encoding="utf-8", pretty_print=True, xml_declaration=False).decode("utf-8") + + full_text += ""