noDRM / DeDRM_tools

DeDRM tools for ebooks
7.15k stars 321 forks source link

WIKI, HOWTO, K4PC 1.17 installation, remove DRM settings, Linux, Playonlinux #182

Open promeneur opened 2 years ago

promeneur commented 2 years ago
  1. Presentation

This is the result of 3 days working to find why suddenly the 1.17 connection to amazon fails.

This is a tutorial for:

I assume you get the background knowledge for using Linux, PlayOnLinux, Calibre 6.6.1, DeDRM 10.0.3, wine config

  1. Install k4PC with Playonlinux (POL)

download https://keybase.pub/koumaza/Archive/kindle-for-pc-1-17-44183.exe

Launch the K4PC installation procedure.

Choose wine 5.0

During installation, K4PC is launched, quit the regitration windows, go to the settings, go to "General", uncheck "automatic update"

Do not forget to click on "register" button after unchecking "automatic update"

Quit K4PC

Continue until the end of the installation.

Warning : there is no updating problem with 1.17, so there is nothing to do to forbid the update, just uncheck "automatic update"

  1. Install python 3.9.6

download https://www.python.org/ftp/python/3.9.6/python-3.9.6.exe

With Calibre 6.6.1 and the new DeDRM plugin (10.0.3) you need python 3 installed with K4PC.

With POL select K4PC then go to its settings then the "wine" tab

click on "configure wine"

Change "windows 7" to "windows 8.1" (python 3.9.6 requires "windows 8.1") then "OK".

With POL select K4PC then go to its settings then the "miscellaneous" tab.

Click on "run an exe in this virtual disk".

The following steps are the same as for any app installation.

  1. Install "cryptodome" module in python 3.9.6

needed for DeDRM 10.0.3 to find book encryption key

With POL select K4PC then go to its settings then the "miscellaneous" tab.

Click on "open terminal"

run the command

wine py -m pip install pycryptodome

warning :don't forget to change "windwows 8.1" by "windows 7" in wine config

if not, you can't open the book in K4PC.

  1. Install a recent K4PC authentication certificate

In K4PC, to connect to the amazon server, you need an authentication certificate whose validity date has not expired.

The authentication certificate installed during the installation of K4PC 1.17 has an expired validity date.

Consequences of an obsolete certificate:

See explanations here

https://bugs.winehq.org/show_bug.cgi?id=50471

create a text file named b204d74a.0

copy in the following text

-----BEGIN CERTIFICATE----- MIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhki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QUHAQwEYTBfoV2gWzBZMFcwVRYJaW1hZ2UvZ2lmMCEwHzAH BgUrDgMCGgQUj+XTGoasjY5rw8+AatRIGCx7GS4wJRYjaHR0cDovL2xvZ28udmVy aXNpZ24uY29tL3ZzbG9nby5naWYwHQYDVR0OBBYEFH/TZafC3ey78DAJ80M5+gKv MzEzMA0GCSqGSIb3DQEBBQUAA4IBAQCTJEowX2LP2BqYLz3q3JktvXf2pXkiOOzE p6B4Eq1iDkVwZMXnl2YtmAl+X6/WzChl8gGqCBpH3vn5fJJaCGkgDdk+bW48DW7Y 5gaRQBi5+MHt39tBquCWIMnNZBU4gcmU7qKEKQsTb47bDN0lAtukixlE0kF6BWlK WE9gyn6CagsCqiUXObXbf+eEZSqVir2G3l6BFoMtEMze/aiCKm0oHw0LxOXnGiYZ 4fQRbxC1lfznQgUy286dUV4otp6F01vvpX1FQHKOtw5rDgb7MzVIcbidJ4vEZV8N hnacRHr2lVz2XTIIM6RUthg/aFzyQkqFOFSDX9HoLPKsEdao7WNq -----END CERTIFICATE-----

attention from here, the following steps are only valid for openSUSE

As administrator

put b204d74a.0 file in /usr/share/pki/trust/anchors/

run the command to add the certificate in the OS

update-ca-certificates

then the command to check the certificate is added

trust list

the last certificate in the list is certificate b204d74a.0

pkcs11:id=%7F%D3%65%A7%C2%DD%EC%BB%F0%30%09%F3%43%39%FA%02%AF%33%31%33;type=cert type: certificate label: VeriSign Class 3 Public Primary Certification Authority - G5 trust: anchor category: authority

  1. Setting up the DeDRM plugin in Calibre

launch Calibre

go to plugin management

look for the DeDRM plugin and select it

click on "Customize an extension"

click on "Kindle For Mac/PC ebooks"

in the WINEPREFIX field indicate the path to K4PC in Playonlinux

/home/your_user_name/.PlayOnLinux/wineprefix/name_of_the_kindle_virtual_disk/

for example

/home/toto/.PlayOnLinux/wineprefix/kindle/

then click "+", after a while you see that a file containing the decryption key is added

close the window then "OK" then "apply"

  1. Have fun
ElleKayEm commented 2 years ago

I'm surprised to hear that you have no problem with Kindle for PC 1.17 trying to update. In my experience on Windows, the check box is ignored. You have to replace the updates folder with a txt file of the same name with no extension. Then it still asks everytime it's opened if you want to update, but gives an option to skip the update.

promeneur commented 2 years ago

I use 1.17 since 2015 with different openSUSE versions, with different Playonlinux versions, with different wine versions. It was never updated.

Another mystery !

Is there any Linux user using 1.17, having updates ?

promeneur commented 2 years ago

An hypothesis :

the update fails silently because wine is not perfectly compliant with 1.17.

promeneur commented 2 years ago

An interesting thing

For 1.17

"Cache", "storage", "updates" folders are in

/home/user_name/.PlayOnLinux/wineprefix/kindle_virtual_disk/drive_c/users/user_name/Local Settings/Application Data/Amazon/Kindle/

promeneur commented 2 years ago

Perhaps a solution for Windows users about upgrade problem : install Playonlinux on MS Windows

Perhaps It is possible with MS WSL 2 (Windows Subsystem for Linux).

Once Playonlinux installed, you can use this tutorial (see above)

Playonlinux is a tool to easily install a Windows app. Each app is installed in a separate MS Windows or the same Windows. This is your choice.

https://learn.microsoft.com/en-us/tr...tem-for-linux/ https://www.playonlinux.com/

ElleKayEm commented 2 years ago

The solution I mentioned above works well.

promeneur commented 2 years ago

Another suggestion for MS Windows users.

Manage the ACL of the file KindleForPC-installer.exe to forbid its execution.

ElleKayEm commented 2 years ago

The solution I gave prevents the update from downloading.

cmc302a commented 1 year ago

Finally, after 4 days of tinkering and battling with different versions of Python, pycrypto, pycryptodome, etc, etc.. I managed to obtain the keys for kindle!! The post covers it mostly, but the steps are mixed, and the language is not clear at parts... But thanks for this post!!! I may post the steps I followed to help linux users like me...

wegotourselvesareader commented 1 year ago

Thank you, thank you, thank you very much to the OP for this useful information. I was accustomed to DeDRM "just working" when using Windows, so it was a bit of a shock to find that it wasn't quite so straightforward under Linux.

As noted by another respondent, some of the steps and language aren't as clear as they could be, so I have taken the liberty of touching up the OP's work for legibility. The OP assumes that the reader knows how to find, install, and use software such as PlayOnLinux, Calibre, DeDRM, as well as any dependencies they may have, and so shall I.

For the avoidance of doubt, the OP's work belongs to the OP. I am not taking any credit for such a superb piece of research; this is just an edit for readability. Some of the software versions have been upgraded since the OP wrote the original entry; I was able to get this process to work on Ubuntu 22.10 using Calibre 6.10 and Python 3.9.13.

Contents

Introduction

  1. Install a recent K4PC authentication certificate
  2. Install Kindle 4 PC (K4PC) on PlayOnLinux (POL)
  3. Install Python3
  4. Install PyCryptodome module in Python
  5. Configure DeDRM in Calibre
  6. Have fun

Introduction

This is the result of 3 days spent working out why suddenly the K4PC 1.17 connection to Amazon fails.

This is a tutorial for:

-----BEGIN CERTIFICATE-----
MIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCB
yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL
ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJp
U2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxW
ZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0
aG9yaXR5IC0gRzUwHhcNMDYxMTA4MDAwMDAwWhcNMzYwNzE2MjM1OTU5WjCByjEL
MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZW
ZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJpU2ln
biwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJp
U2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9y
aXR5IC0gRzUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCvJAgIKXo1
nmAMqudLO07cfLw8RRy7K+D+KQL5VwijZIUVJ/XxrcgxiV0i6CqqpkKzj/i5Vbex
t0uz/o9+B1fs70PbZmIVYc9gDaTY3vjgw2IIPVQT60nKWVSFJuUrjxuf6/WhkcIz
SdhDY2pSS9KP6HBRTdGJaXvHcPaz3BJ023tdS1bTlr8Vd6Gw9KIl8q8ckmcY5fQG
BO+QueQA5N06tRn/Arr0PO7gi+s3i+z016zy9vA9r911kTMZHRxAy3QkGSGT2RT+
rCpSx4/VBEnkjWNHiDxpg8v+R70rfk/Fla4OndTRQ8Bnc+MUCH7lP59zuDMKz10/
NIeWiu5T6CUVAgMBAAGjgbIwga8wDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8E
BAMCAQYwbQYIKwYBBQUHAQwEYTBfoV2gWzBZMFcwVRYJaW1hZ2UvZ2lmMCEwHzAH
BgUrDgMCGgQUj+XTGoasjY5rw8+AatRIGCx7GS4wJRYjaHR0cDovL2xvZ28udmVy
aXNpZ24uY29tL3ZzbG9nby5naWYwHQYDVR0OBBYEFH/TZafC3ey78DAJ80M5+gKv
MzEzMA0GCSqGSIb3DQEBBQUAA4IBAQCTJEowX2LP2BqYLz3q3JktvXf2pXkiOOzE
p6B4Eq1iDkVwZMXnl2YtmAl+X6/WzChl8gGqCBpH3vn5fJJaCGkgDdk+bW48DW7Y
5gaRQBi5+MHt39tBquCWIMnNZBU4gcmU7qKEKQsTb47bDN0lAtukixlE0kF6BWlK
WE9gyn6CagsCqiUXObXbf+eEZSqVir2G3l6BFoMtEMze/aiCKm0oHw0LxOXnGiYZ
4fQRbxC1lfznQgUy286dUV4otp6F01vvpX1FQHKOtw5rDgb7MzVIcbidJ4vEZV8N
hnacRHr2lVz2XTIIM6RUthg/aFzyQkqFOFSDX9HoLPKsEdao7WNq
-----END CERTIFICATE-----

Attention: from here, the following steps are only valid for openSUSE. (Editor's note: if you, like me, are using Ubuntu, you may find suitable instructions here: https://askubuntu.com/a/1352999).

With admin/root privileges, put the file "b204d74a.0" in /usr/share/pki/trust/anchors/

Issue this command to add the certificate to the operating system: update-ca-certificates

Then issue this command to double-check that the certificate was added successfully: trust list

The last certificate in the list should be the certificate "b204d74a.0":

pkcs11:id=%7F%D3%65%A7%C2%DD%EC%BB%F0%30%09%F3%43%39%FA%02%AF%33%31%33;type=cert
type: certificate
label: VeriSign Class 3 Public Primary Certification Authority - G5
trust: anchor
category: authority

2. Install Kindle 4 PC (K4PC) on PlayOnLinux (POL)

Download K4PC from https://keybase.pub/koumaza/Archive/kindle-for-pc-1-17-44183.exe

Within POL, install a non-listed program in a new virtual drive, with the name "kindle" (you may choose a different name if you wish; remember that whatever name you choose is case-sensitive). In the "What would you like to do before installation" dialog, leave the boxes unchecked. Choose "32 bits windows installation." When prompted, browse for the K4PC installer you downloaded.

During the installation, K4PC will launch automatically. Close the "Register Kindle" window, go to Tools -> Options -> General, and uncheck "Automatically install updates [...]". Click on "Save".

Still in the Options dialog, go to Registration, click on "Register", and sign in with your usual Amazon credentials.

Once you have successfully registered K4PC with your Amazon account, quit K4PC. The POL installation wizard will continue and prompt you to create a shortcut for K4PC if you wish.

Warning : there is no updating problem with 1.17, so there is nothing to do to forbid the update, just uncheck "Automatically install updates [...]"

2.1 (Optional, added by editor) Prevent K4PC from applying updates even though you unchecked the automatic update box.

Unlike the OP, I found that K4PC 1.17 would frequently attempt to upgrade to 1.30 even if automatic updates were disabled. I had to put an empty placeholder file where the K4PC application would attempt to download its update. If you do not experience this problem, then this step may be considered optional.

_Open a Terminal window, and navigate to $HOME/.PlayOnLinux/wineprefix/kindle/drive_c/users/$USERNAME/AppData/Local/Amazon/Kindle. If you chose a different name for your K4PC virtual drive in POL, replace "kindle" with the name of your chosen virtual drive (remembering that the name you chose is case-sensitive)._

Issue the command touch updates followed by chmod -w updates. If this fails, then K4PC may have already attempted to update itself. You may verify this by checking for the presence of a subdirectory called "updates". If that subdirectory does already exist, then issue the command rm -rf updates, followed by touch updates followed by chmod -w updates.

3. Install Python3

Python3 is required with Calibre 6.10 and DeDRM 10.0.3. This step will walk you through installing Python3 into the POL virtual drive used for K4PC.

Download https://www.python.org/ftp/python/3.9.13/python-3.9.13.exe

Within POL, select your K4PC installation and click on "Configure". The PlayOnLinux configuration dialog will launch.

Go to the Wine tab and click on "Configure Wine". The Wine configuration dialog will launch.

In the Wine configuration dialog, on the Applications tab, change the "Windows Version" from "Windows 7" to "Windows 8.1". Click on "OK".

Still in the PlayOnLinux configuration dialog, go to the Miscellaneous tab and click on "Run a Windows Executable (.exe) file in this virtual drive". (Editor's note: depending on your screen settings, you may have to expand or maximise the PlayOnLinux configuration dialog to see the "Run a Windows Executable [...]" button.)

Browse to and select the Python3 installer you downloaded earlier. Click on "Install Now" to install Python3 with the default settings. Once the Python3 installation is complete, stay on the Miscellaneous tab and do not close the PlayOnLinux configuration dialog; you'll still need it for the next step.

4. Install PyCryptodome module in Python

This is required for DeDRM 10.0.3 to find the book encryption key in your K4PC installation.

Still in the PlayOnLinux configuration dialog from the previous step, click on "Open a Shell". This will spawn a Terminal window inside POL.

Issue the command wine py -m pip install pycryptodome. Ignore any prompts to upgrade pip.

5. Configure DeDRM in Calibre

Launch Calibre.

Go to Preferences -> Plug-ins and find and select the DeDRM plugin. At the time of writing it sits in the "File type" section.

Click on "Customize plug-in".

Click on "Kindle For Mac/PC ebooks".

In the "WINEPREFIX:" field, add the path to your installation of K4PC in PlayOnLinux: /home/your_user_name/.PlayOnLinux/wineprefix/name_of_the_kindle_virtual_disk/

For example:

/home/toto/.PlayOnLinux/wineprefix/kindle/

Do not omit the trailing '/' character. If you chose a different name for your K4PC virtual drive in POL, replace "kindle" with the name of your chosen virtual drive (remembering that the name you chose is case-sensitive).

Then click on "+".

If the plugin is able to detect the K4PC key, you will see a dialog box titled "DeDRM 10.0.3: Getting Default Kindle for Mac/PC Key", with a "Unique Key Name" populated. Click on "OK" to save it.

If, instead, you see a dialog box with the text "The default encryption key for Kindle for Mac/PC could not be found", then double-check that you have followed every step. (Editor's note: in the course of attempting this, I made several mistakes and omissions; it took several tries before I got it working.)

Click on "Close", then "OK", then "Apply", then "Close" to exit Calibre's Preferences and return to the main application.

6. Have fun