Skip to content

Commit

Permalink
Display error message if pkcs12 can't be decrypted
Browse files Browse the repository at this point in the history
  • Loading branch information
Leseratte10 committed May 14, 2022
1 parent dd10466 commit 53e106f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
16 changes: 13 additions & 3 deletions calibre-plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def initialize(self):

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
Expand All @@ -215,25 +215,35 @@ def ADE_sanity_check(self):
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):
Expand Down
4 changes: 4 additions & 0 deletions calibre-plugin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ def get_account_info(self):

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()
Expand Down Expand Up @@ -564,6 +565,9 @@ def get_account_info(self):
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:
Expand Down
22 changes: 19 additions & 3 deletions calibre-plugin/libadobeFulfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ def buildInitLicenseServiceRequest(authURL):

return "<?xml version=\"1.0\"?>\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)

Expand All @@ -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 = "<?xml version=\"1.0\"?>\n"
Expand All @@ -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", "")
Expand Down

0 comments on commit 53e106f

Please sign in to comment.