apprenticeharper / DeDRM_tools

DeDRM tools for ebooks
14.55k stars 1.52k forks source link

MacCatalina/Kindle 1.30 unable to remove DRM from AZW3 file #1795

Open JeNeSuisPasDave opened 3 years ago

JeNeSuisPasDave commented 3 years ago

I forced Kindle 1.30 to download an AZW3 file instead of KFX file. But the decryption/DRM-removal fails.

The key is claimed to be discovered but there is an error decrypting the AZW3 file. Here's the log from Calibre 5.24. I'm not sure what the 4 keys are that it claims to have tried before decrypting the key from the .kinf2018 file. I can't tell from these log messages what the problem might be. (various ID strings have been changed in these log messages)

Successfully initialized third party plugins: DeDRM (7, 2, 1) devicePixelRatio: 2.0 logicalDpi: 72.0 x 72.0 physicalDpi: 113.00000169708973 x 113.50000170459899 Using calibre Qt style: True [0.00] Starting up... [0.02] Showing splash screen... [0.24] splash screen shown [0.24] Initializing db... [0.41] db initialized [0.41] Constructing main UI... [1.17] main UI initialized... [1.17] Hiding splash screen Starting QuickView DeDRM v7.2.1: Trying to decrypt XYZZYXYZZY_EBOK.azw Using Library AlfCrypto Python Using Library AlfCrypto Python MobiDeDrm v1.0. Copyright © 2008-2020 The Dark Reverser, Apprentice Harper et al. Decrypting Kindle Format 8 ebook: Ike's Mystery Man Found 4 keys to try after 0.1 seconds Crypto Type is: 2 DeDRM v7.2.1: Failed to decrypt with error: No key found in 4 PIDs tried. DeDRM v7.2.1: Looking for new default Kindle Key after 0.1 seconds Found k4Mac kinf2018 file: /Users/someuser/Library/Application Support/Kindle/storage/.kinf2018 trying username b'someuser' on file /Users/someuser/Library/Application Support/Kindle/storage/.kinf2018 trying IDString: b'7723acbd045a' Decrypted key file using IDString '7723acbd045a' and UserName 'someuser' DeDRM v7.2.1: Found 1 new key MobiDeDrm v1.0. Copyright © 2008-2020 The Dark Reverser, Apprentice Harper et al. Decrypting Kindle Format 8 ebook: The Noisy Book Got SerialNumber from database default_key_1 Got UsernameHash from database default_key_1 Found 4 keys to try after 0.5 seconds Crypto Type is: 2 DeDRM v7.2.1: Ultimately failed to decrypt after 0.5 seconds. Read the FAQs at Harper's repository: https://github.com/apprenticeharper/DeDRM_tools/blob/master/FAQs.md Running file type plugin DeDRM failed with traceback: Traceback (most recent call last): File "calibre_plugins.dedrm.init", line 540, in KindleMobiDecrypt book = k4mobidedrm.GetDecryptedBook(path_to_ebook,kindleDatabases,androidFiles,serials,pids,self.starttime) File "calibre_plugins.dedrm.k4mobidedrm", line 238, in GetDecryptedBook mb.processBook(totalpids) File "calibre_plugins.dedrm.mobidedrm", line 484, in processBook raise DrmException("No key found in {0:d} PIDs tried.".format(len(goodpids))) calibre_plugins.dedrm.mobidedrm.DrmException: No key found in 4 PIDs tried.

JeNeSuisPasDave commented 3 years ago

I was able to run kindlekey.py and it decrypted the .kinf2018 file and produced a kindlekey1.k4i keyfile. I added that to the plugin and tried again. This time it said it had 8 keys to try; none worked, so it found my .kinf2018 file again and pulled keys from that and tried and that failed as well. Very similar to the above log.

c00lt commented 3 years ago

I had the same error and tried the same thing. I was able to fix this issue by reverting to Calibre 4.23 and tools 6.8.1 as proposed here

hmoffatt commented 3 years ago

I cannot get the latest plugin to work with Calibre 5.12 on linux either (the previous generation worked ok). It appears to work in the latest Calibre on Windows though, with the same AWZ3 files.

ElleKayEm commented 3 years ago

Each app installation/device has a unique key. So book and key need to be from the same.

hmoffatt commented 3 years ago

I'm downloading for my Kindle Paperwhite.

ElleKayEm commented 3 years ago

Then make sure you have that Kindle's serial number entered correctly into DeDRM's customization and be sure that was the device chosen when you downloaded that copy of the book.

hmoffatt commented 3 years ago

Yes I have - I had it set up with Calibre 4 and the older plugin and the same serial numbers are still there. Also, it works when I set it up fresh on Windows with the latest versions. It just doesn't work on linux.

I had Calibre 5.12 and just upgraded to 5.29, no change.

ElleKayEm commented 3 years ago

No idea why it would be any different on Linux for E-ink Kindle AZW3 format. Dealing with books from Kindle for PC, on the other hand, can be tricky on Linux, usually much easier on Windows. What about saving the e-ink Kindle keys from the working Windows calibre DeDRM and importing them into the Linux setup?

hmoffatt commented 3 years ago

I tried a fresh setup on linux with Calibre 5.29 and DeDRM 7.2.1 and there was no change. I have AZW3 files downloaded from amazon.com for my Paperwhite with the serial number entered in the plugin settings. The exact same config works on Windows, and it worked on Linux with Calibre 4.

Is there any debugging I can turn on to get more info?

ElleKayEm commented 3 years ago

Let's see a debug log of adding a book.

hmoffatt commented 3 years ago

How do I enable debug logging?

ElleKayEm commented 3 years ago

Preferences > Restart in debug mode

hmoffatt commented 3 years ago

Ah:

DeDRM v7.2.1: Trying to decrypt <book>.azw3
Using Library AlfCrypto DLL/DYLIB/SO
Using Library AlfCrypto DLL/DYLIB/SO
Running file type plugin DeDRM failed with traceback:
Traceback (most recent call last):
  File "calibre_plugins.dedrm.kfxdedrm", line 18, in <module>
    from ion import DrmIon, DrmIonVoucher
  File "/tmp/calibre_5.29.0_tmp_jpm_s6s6/98ngpgz2plugin_unzip/ion.py", line 33, in <module>
    from Crypto.Cipher import AES
ModuleNotFoundError: No module named 'Crypto'
ElleKayEm commented 3 years ago

Hmm, that part is for kfx format which obviously this isn't. What does the successful log in Windows look like?

hmoffatt commented 3 years ago

On Windows, where it works:

DeDRM v7.2.1: Trying to decrypt Mawson.azw3
Using Library AlfCrypto DLL/DYLIB/SO
Using Library AlfCrypto DLL/DYLIB/SO
MobiDeDrm v1.0.
Copyright © 2008-2020 The Dark Reverser, Apprentice Harper et al.
Decrypting Kindle Format 8 ebook: Mawson
Found 2 keys to try after 0.3 seconds
Crypto Type is: 2
File is encoded with PID /3eeYXOtZU.
Decrypting. Please wait . . . . . . . . done
Decryption succeeded after 0.3 seconds
DeDRM v7.2.1: Finished after 0.3 seconds
hmoffatt commented 3 years ago

So it looks like the root cause of my problem is that the python-crypto library has been removed in the latest Debian release. It is apparently no longer maintained and has been replaced by the Cryptodome library.

j-howell commented 3 years ago

So it looks like the root cause of my problem is that the python-crypto library has been removed in the latest Debian release. It is apparently no longer maintained and has been replaced by the Cryptodome library.

Are you using the version of calibre provided by your Linux distribution?

If so you may want to consider installing the official Linux version of calibre instead.