noDRM / DeDRM_tools

DeDRM tools for ebooks
6.95k stars 305 forks source link

RSA key format is not supported #377

Open JPFrancoia opened 1 year ago

JPFrancoia commented 1 year ago

Question / bug report

I bought a book from a french vendor and I got a URLLink.acsm file. I've been trying to import this book into Calibre. Initially, I used Adobe ADE to import the book (through wine). At first I did an anonymous authentication. I can see the book in ADE, ADE generates a 7.5 MB epub file somewhere called "ePub made using QuarkXPress.epub". I tried opening this file with all the readers I could find, with no luck.

I then installed the DeACM plugin in Calibre. I got the account and key info. I imported all these settings into DeDRM. When I try to import my acsm file, the import doesn't work and I still can't open the book. I tried the stable and master versions of DeACM and DeDRM. It's always the same error. Here are the logs:

I believe the important line is:

ValueError: RSA key format is not supported

Could you please give me a hand? I'm willing to test and make PRs.

Which version of Calibre are you running?

6.23.0

Which version of the DeDRM plugin are you running?

v10.0.3 and master

If applicable, which version of the Kindle software are you running?

No response

Log output

DeDRM v10.0.3: Trying to decrypt ePub made using QuarkXPress.epub
DeDRM v10.0.3: Verifying zip archive integrity
DeDRM v10.0.3: ePub made using QuarkXPress.epub is a secure Adobe Adept ePub for UUID 04bcecb7-d2e7-42b8-8755-8e1ccc89d40a
DeDRM v10.0.3: Trying UUID-matched encryption key adobe_uuid_04bcecb7-d2e7-42b8-8755-8e1ccc89d40a
g7ikrsxi.epub is a secure Adobe Adept ePub.
Could not decrypt g7ikrsxi.epub because of an exception:
Traceback (most recent call last):
  File "/home/djipey/.config/calibre/plugins/DeDRM.zip/ineptepub.py", line 246, in decryptBook
    rsakey = RSA.importKey(userkey) # parses the ASN1 structure
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/Crypto/PublicKey/RSA.py", line 820, in import_key
    return _import_keyDER(extern_key, passphrase)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/Crypto/PublicKey/RSA.py", line 719, in _import_keyDER
    raise ValueError("RSA key format is not supported")
ValueError: RSA key format is not supported

DeDRM v10.0.3: Trying Encryption key adobe_uuid_04bcecb7-d2e7-42b8-8755-8e1ccc89d40a
g7ikrsxi.epub is a secure Adobe Adept ePub.
Could not decrypt g7ikrsxi.epub because of an exception:
Traceback (most recent call last):
  File "/home/djipey/.config/calibre/plugins/DeDRM.zip/ineptepub.py", line 246, in decryptBook
    rsakey = RSA.importKey(userkey) # parses the ASN1 structure
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/Crypto/PublicKey/RSA.py", line 820, in import_key
    return _import_keyDER(extern_key, passphrase)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/Crypto/PublicKey/RSA.py", line 719, 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 key adobe_uuid_04bcecb7-d2e7-42b8-8755-8e1ccc89d40a after 0.1 seconds
DeDRM v10.0.3: Looking for new default Adobe Digital Editions Keys after 0.1 seconds
007c:fixme:hid:handle_IRP_MN_QUERY_ID Unhandled type 00000005
ioctl (GFEATURE): Input/output error
ioctl (GFEATURE): Input/output error
ioctl (GFEATURE): Input/output error
ioctl (GFEATURE): Input/output error
ioctl (GFEATURE): Input/output error
ioctl (GFEATURE): Input/output error
007c:fixme:hid:handle_IRP_MN_QUERY_ID Unhandled type 00000005
007c:fixme:hid:handle_IRP_MN_QUERY_ID Unhandled type 00000005
007c:fixme:hid:handle_IRP_MN_QUERY_ID Unhandled type 00000005
Application could not be started, or no application associated with the specified file.
ShellExecuteEx failed: File not found.

DeDRM v10.0.3: wine py.exe -3 is not python3
Application could not be started, or no application associated with the specified file.
ShellExecuteEx failed: File not found.

DeDRM v10.0.3: wine python3.exe is not python3
Application could not be started, or no application associated with the specified file.
ShellExecuteEx failed: File not found.

DeDRM v10.0.3: wine python.exe is not python3
wine: failed to open "C:\\Python27\\python.exe": c0000135
DeDRM v10.0.3: wine C:\Python27\python.exe does not exist
DeDRM v10.0.3: Unable to find python3 executable in WINEPREFIX=""
DeDRM v10.0.3: Ultimately failed to decrypt after 2.1 seconds. Read the FAQs at noDRM's repository: https://github.com/noDRM/DeDRM_tools/blob/master/FAQs.md
Running file type plugin DeDRM failed with traceback:
Traceback (most recent call last):
  File "/usr/lib/calibre/calibre/customize/ui.py", line 187, in _run_filetype_plugins
    nfp = plugin.run(nfp) or nfp
          ^^^^^^^^^^^^^^^
  File "calibre_plugins.dedrm.__init__", line 1040, in run
    decrypted_ebook = self.ePubDecrypt(path_to_ebook)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "calibre_plugins.dedrm.__init__", line 638, 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.1 seconds. Read the FAQs at noDRM's repository: https://github.com/noDRM/DeDRM_tools/blob/master/FAQs.md
ElleKayEm commented 1 year ago

Since you originally downloaded the book with an anonymous authentication, the DRM will be tied to that installation of ADE. You can read the book there? I'd try installing Windows calibre with DeDRM where ADE is installed. You'll need older calibre 4.23 and DeDRM 6.8.1.

mathesst commented 1 month ago

Hi, got the same error. I have the newest versions of DeACM and DeDRM installed in calibre. And I am getting the same error. It dosen't matter if I import the ebub or the acsm file. As from the logs I assume that DeACM is working fine, but DeDRM runs into an error of unsupported RSA Key. In my wine environment I can open the files in Adobe just fine.


DeACSM v0.0.16: Trying to parse file Corey_Abaddon_s-Gate_9780748122981.acsm
DeACSM v0.0.16: Try to fulfill ...
Notifying server ...
Notifying server https://acs.pageplace.de/fulfillment/FulfillmentNotification
Fulfillment notification successful.
DeACSM v0.0.16: Downloading book ...
DeACSM v0.0.16: Loading book from http://cdp.pageplace.de/rcdp/files/adrm/9ab599ec-7499-4b89-9d76-ea79868e4849/DT0400.9780748122981_A25080631.epub
Download took 311 ms (HTTP 200)
That's a ZIP file -> EPUB
DeACSM v0.0.16: File successfully fulfilled ...
DeACSM v0.0.16: Executing plugin DeDRM ...
DeDRM v10.0.9: Trying to decrypt chzp3z_8.epub
DeDRM v10.0.9: Verifying zip archive integrity
DeDRM v10.0.9: chzp3z_8.epub is a secure Adobe Adept ePub for UUID 1a13b13f-7442-4a3f-8cf8-3eedd7149cb8
DeDRM v10.0.9: Trying UUID-matched encryption key DeACSM_uuid_1a13b13f-7442-4a3f-8cf8-3eedd7149cb8
g3rdzfwx.epub is a secure Adobe Adept ePub.
Could not decrypt g3rdzfwx.epub because of an exception:
Traceback (most recent call last):
  File "/home/mathes/.config/calibre/plugins/DeDRM.zip/ineptepub.py", line 253, in decryptBook
    rsakey = RSA.importKey(userkey) # parses the ASN1 structure
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/Crypto/PublicKey/RSA.py", line 851, in import_key
    return _import_keyDER(extern_key, passphrase)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/Crypto/PublicKey/RSA.py", line 750, in _import_keyDER
    raise ValueError("RSA key format is not supported")
ValueError: RSA key format is not supported

DeDRM v10.0.9: Trying Encryption key DeACSM_uuid_1a13b13f-7442-4a3f-8cf8-3eedd7149cb8
g3rdzfwx.epub is a secure Adobe Adept ePub.
Could not decrypt g3rdzfwx.epub because of an exception:
Traceback (most recent call last):
  File "/home/mathes/.config/calibre/plugins/DeDRM.zip/ineptepub.py", line 253, in decryptBook
    rsakey = RSA.importKey(userkey) # parses the ASN1 structure
             ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/Crypto/PublicKey/RSA.py", line 851, in import_key
    return _import_keyDER(extern_key, passphrase)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/site-packages/Crypto/PublicKey/RSA.py", line 750, in _import_keyDER
    raise ValueError("RSA key format is not supported")
ValueError: RSA key format is not supported

DeDRM v10.0.9: Failed to decrypt with key DeACSM_uuid_1a13b13f-7442-4a3f-8cf8-3eedd7149cb8 after 0.1 seconds
DeDRM v10.0.9: Looking for new default Adobe Digital Editions Keys after 0.1 seconds
No installed Python found!
0134:fixme:kernelbase:AppPolicyGetProcessTerminationMethod FFFFFFFA, 005BFEB8
Es konnte keine Anwendung gestartet werden, oder es ist keine Anwendung mit der angegebenen Datei verknüpft.
ShellExecuteEx fehlgeschlagen: Datei nicht gefunden.

DeDRM v10.0.9: wine python3.exe is not python3
Es konnte keine Anwendung gestartet werden, oder es ist keine Anwendung mit der angegebenen Datei verknüpft.
ShellExecuteEx fehlgeschlagen: Datei nicht gefunden.

DeDRM v10.0.9: wine python.exe is not python3
wine: failed to open "C:\\Python27\\python.exe": c0000135
DeDRM v10.0.9: wine C:\Python27\python.exe does not exist
DeDRM v10.0.9: Unable to find python3 executable in WINEPREFIX="/home/mathes/Games/Heroic/Prefixes/sideload"
DeDRM v10.0.9: Ultimately failed to decrypt after 0.8 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 1041, in run
    decrypted_ebook = self.ePubDecrypt(path_to_ebook)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "calibre_plugins.dedrm.__init__", line 639, 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.9: Ultimately failed to decrypt after 0.8 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
ElleKayEm commented 1 month ago

Are ADE and DeACSM set up with the same Adobe ID? If not, then they'd have different keys. That would explain DeACSM's key not working on ADE's epub. Maybe try saving the key from DeACSM and importing it into DeDRM's customization.

mathesst commented 1 month ago

It is the same, and the last try was importing the key in DEAcm from the ADE install in Wine, which was successful (the import of the key). But still get the RSA error.

ElleKayEm commented 1 month ago

I don't know. When I've seen that error before, it was when the books had been downloaded with ADE on a different machine than the one where calibre/DeDRM was installed. Once they installed calibre/DeDRM on the machine where the books were downloaded, it worked.

mathesst commented 1 month ago

today I installed calibre on Windows and it extracted the key from ADE automatically. This Key I exported and then imported in calibre in my Linux installation. With that key I was able to decrypt the ebooks even under Linux. So there seems to be an issue between the key retrival from wine.

BG Mathias

ElleKayEm commented 1 month ago

Yup, that what all this from the log is about:

DeDRM v10.0.9: Looking for new default Adobe Digital Editions Keys after 0.1 seconds No installed Python found! 0134:fixme:kernelbase:AppPolicyGetProcessTerminationMethod FFFFFFFA, 005BFEB8 Es konnte keine Anwendung gestartet werden, oder es ist keine Anwendung mit der angegebenen Datei verknüpft. ShellExecuteEx fehlgeschlagen: Datei nicht gefunden.

DeDRM v10.0.9: wine python3.exe is not python3 Es konnte keine Anwendung gestartet werden, oder es ist keine Anwendung mit der angegebenen Datei verknüpft. ShellExecuteEx fehlgeschlagen: Datei nicht gefunden.

DeDRM v10.0.9: wine python.exe is not python3 wine: failed to open "C:\Python27\python.exe": c0000135 DeDRM v10.0.9: wine C:\Python27\python.exe does not exist DeDRM v10.0.9: Unable to find python3 executable in WINEPREFIX="/home/mathes/Games/Heroic/Prefixes/sideload"

I don't know what all you need to have installed under wine to get the key scripts to run there and get the key from ADE. Some people are able to use DeACSM to avoid using ADE. I don't know why that didn't work for you. Once you have the key in the Linux installation of calibre, DeDRM is fine because the rest of the scripts are then able to use calibre's built-in Python. With Windows calibre, DeDRM is able to also use calibre's built-in Python to run the key retrieval scripts.