home blog tags about

Remove DRM from ebooks

written by Robin Schubert on 2022-03-05 | Tags: miscellaneous, free-software

It has been ridiculously hard and I was about to pull my hair out at several points on this ordeal, but I finally managed to remove this stupid (revised to modest language here) DRM from my epub file. I took many side roads that lead me nowhere and spent quite some hours to find a working solution, so I'm writing this down in case I (or someone else) may need it again.

Why removing DRM from an ebook

First of all: I'm not saying you should do anything illegal (I'm also not saying that you shouldn't); however, a friend bought me an ebook as a gift. I told him about this book and that it was on top of my to-read pile, I just didn't buy it yet. So he purchased and gifted to me a digital copy and asked if I would lend it to him when done reading. Sure thing. Except that I couldn't. Bummer!

What I downloaded from the store was an acsm (for Adobe Content Server Message) file, which is needed to communicate with the Adobe Servers. It verifies that I'm authorized to download the (DRM protected) book, and to view the content on different devices that also use my Adobe ID.

A quick internet search...

revealed the following path that lay before me:

So far that sounded perfectly doable. Then I learned that Adobe Digital Editions is available for Windows, MacOS, Android ... of course there's no Linux app. I don't have a Windows or Apple machine, and I hate fiddling around with the phone, so wine it is.

However, on my main machine I also don't have wine - or rather I don't want to, because I hate to activate the multilib repositories. Wine is still all lib32. So I used another Ubuntu laptop that I keep for the dirty work of that kind.

Unfortunately (for my mental health) my Ubuntu distribution offers a calibre version 4.9x, while the latest DeDRM plugin requires calibre 5.x. Fine!, I think, I just use the latest DeDRM release that plays along with my calibre 4.9. Well, of course not! That would require calibre running on Python 2; mine runs on Python 3. There, I loose my hair.

So I end up installing the latest version from calibre-ebook.com. Should you have to do this, make sure to pick the "isolated" install, that does not require root.

This worked for me

We start with a fresh wine prefix to install our ADE:

export WINEPREFIX=~/.adewine
winetricks -q adobe_diged4

Evoking winecfg will initialize the new prefix. Make sure to pick Windows 10 here - I'll tell you why in a bit.

When I started ADE and tried to open the acsm directly, it crashed. So I had to first manually authorize the laptop via the Help menu. An Adobe ID is required, create one if you don't have it already. Then we can load the acsm and get the DRM protected ebook. I could find the epub files in a new ADE sub-folder in my ~/Documents, but you can also save them to a different location in ADE.

To use calibre's DeDRM plugin to remove the protection, we need to extract the Adobe ID key from ADE, so make sure to have both installed. The DeDRM plugin is nice enough to offer a field for our wine prefix. However, this also means that a wine Python is going to be necessary. This is what you need to pick Windows 10 for in winecfg: Python 3.9 or 3.10 can easily be downloaded from https://www.python.org/, but installers only work on Windows 8.1 or higher (and nobody wants to use 8.1). Remember to pick the 32 bit version; it's still meant for the wine environment.

So we install Python 3.10 and the necessary dependencies to make the scripts work:

export WINEPREFIX=~/.adewine
wine ~/Downloads/python-3.10.2[...].exe

wine python -m pip install --upgrade pip
wine python -m pip install pyopenssl

Set the check on "Add Python to Path" during the installation of Python, to spare you some headaches

The scripts also require an OpenSSL distribution in your wine environment (I failed to install PyCrypto, the other viable option. Don't ask me why, because I don't know.). I did find a working package here. Make sure to pick version 1.1; this is what the DeDRM scripts use (and again choose the 32 bit variant, of course).

Having this set up, you should be able to add your Adobe ID key to the DeDRM plugin in the plugin's preferences dialog.

I actually didn't know that I would need all this, but after enough cursing I finally remembered to start calibre with calibre-debug -g, to actually learn why that stupid (kidding, it's great) script failed. Actually in the end I just located the python script to extract the ADE keys and ran it manually:

cd ~/.config/calibre/plugins/DeDRM/libraryfiles/
wine python adobekey.py

And this is where you have deserved a bottle of well chilled beer. Whether you managed to import the key to the DeDRM plugin directly, or manually extracted them with running adobekey.py for later file import; Now your plugin should be armed and ready to have your book(s) added to calibre, and DRM protection should be removed on import.

I also tried...

a tool called knock that promised to remove DRM protection, with neither wine nor Adobe Digital Editions (ADE) required. I saw very positive comments so I assume it can work somehow, but apparently I was too dumb to use it. It probably would have been easier to install via nix, but that's completely unknown territory for me, so I tried to install all dependencies manually in a virtual environment, and as with many click apps, it was a pain to use it in any way that differs the original intention.

The binary packaged release also failed for me, but maybe you are smarter than I was.

Creative Commons License