Leseratte10 / acsm-calibre-plugin

Calibre plugin for ACSM->EPUB and ACSM->PDF conversion.
https://www.mobileread.com/forums/showthread.php?t=341975
GNU General Public License v3.0
652 stars 23 forks source link

Encryption key export broken? #45

Closed TPolzer closed 1 year ago

TPolzer commented 1 year ago

Bug description

I'm trying to import an ADE book with Calibre. I successfully logged in to my Adobe account with your plugin and I can download the epub from the ACSM.

But then Calibre fails the decryption:

DeDRM v10.0.3: Found new key 'DeACSM_uuid_44c825f8-2faf-4521-b803-d997eab0e949' in DeACSM plugin
DeDRM v10.0.3: Trying a new default key
s_3mohg7.epub is a secure Adobe Adept ePub.
Could not decrypt s_3mohg7.epub because of an exception:
Traceback (most recent call last):
  File "/home/tobias/.config/calibre/plugins/DeDRM.zip/ineptepub.py", line 305, in decryptBook
    rsakey = RSA.import_key(userkey) # parses the ASN1 structure
  File "/usr/lib/python3/dist-packages/Cryptodome/PublicKey/RSA.py", line 786, in import_key
    return _import_keyDER(extern_key, passphrase)
  File "/usr/lib/python3/dist-packages/Cryptodome/PublicKey/RSA.py", line 685, in _import_keyDER
    raise ValueError("RSA key format is not supported")
ValueError: RSA key format is not supported

DeDRM v10.0.3: Failed to decrypt with new default key after 2.4 seconds
DeDRM v10.0.3: Ultimately failed to decrypt after 2.4 seconds. Read the FAQs at noDRM's repository: https://github.com/noDRM/DeDRM_tools/blob/master/FAQs.md
DeACSM v0.0.16: Running file type plugin failed with traceback:
Traceback (most recent call last):
  File "calibre_plugins.deacsm.__init__", line 486, in run
    plugin_ret = plugin.run(rpl)
  File "calibre_plugins.dedrm.__init__", line 1067, in run
    decrypted_ebook = self.ePubDecrypt(path_to_ebook)
  File "calibre_plugins.dedrm.__init__", line 665, in ePubDecrypt
    raise DeDRMError("{0} v{1}: Ultimately failed to decrypt after {2:.1f} seconds. Read the FAQs at noDRM's repository: https://github.com/noDRM/DeDRM_tools/blob/master/FAQs.md".format(PLUGIN_NAME, PLUGIN_VERSION,time.time()-self.starttime))
calibre_plugins.dedrm.DeDRMError: DeDRM v10.0.3: Ultimately failed to decrypt after 2.4 seconds. Read the FAQs at noDRM's repository: https://github.com/noDRM/DeDRM_tools/blob/master/FAQs.md
DeACSM v0.0.16: Plugin returned nothing - skipping

I then tried to export the key from DeACSM into DeDRM manually, that didn't work either.

I tried to inspect the exported .der key manually, and it seems it's broken? At least openssl thinks so (replaced long hex sequences with [...]):

$ openssl asn1parse -inform DER -in adobe_uuid_44c825f8-2faf-4521-b803-d997eab0e949.der
    0:d=0  hl=4 l= 606 cons: SEQUENCE          
    4:d=1  hl=2 l=   1 prim: INTEGER           :00
    7:d=1  hl=3 l= 129 prim: INTEGER           :[...]
  139:d=1  hl=2 l=   3 prim: INTEGER           :010001
  144:d=1  hl=3 l= 129 prim: INTEGER           :[...]
  276:d=1  hl=2 l=  65 prim: INTEGER           :[...]
  343:d=1  hl=2 l=  65 prim: INTEGER           :[...]
  410:d=1  hl=2 l=  65 prim: INTEGER           :[...]
  477:d=1  hl=2 l=  65 prim: INTEGER           :[...]
  544:d=1  hl=2 l=  64 prim: INTEGER           :[...]
Error in encoding
80D2EB137B7F0000:error:0680009B:asn1 encoding routines:ASN1_get_object:too long:../crypto/asn1/asn1_lib.c:95:

Operating system

Linux

Which version of Calibre are you running?

6.8.0

Which version of the ACSM Input plugin are you running?

v0.0.16

Further information

No response

Leseratte10 commented 1 year ago

Interesting, I have never seen that happen before.

Would you be willing to send me a copy of your whole authorization so I can take a closer look? If so please export the whole authentication (using the "Export account activation data" button) and send the ZIP to email removed

Did you authorize the plugin by entering your credentials or by generating a new anonymous authorization, or did you import an existing one from ADE?

Leseratte10 commented 1 year ago

No response to my question(s), closing this issue. If this still occurs please re-open this issue.

PDunham113 commented 6 months ago

I may not have experienced quite the same issue - but I did get the same error message. I was ultimately able to resolve it.

My initial steps (that resulted in the above issue - DeDRM failing to decrypt):

This would consistently result in the above error when importing ascm files into Calibre. I was able to resolve it by:

No way to tell if this is the same class of issue the OP encountered - but based on my experience, this smells like an issue w/ ADE generating malformed keys and not DeASCM. If, like me, someone shows up here after frantically googling - maybe consider authorizing directly through DeASCM?