abustany/lcp-decrypt

Exception when decrypting fonts

Closed this issue · 6 comments

When decrypting lcp file from library, I got this exception:

2024/11/27 12:59:52 Processing file OEBPS/Babel-epub-45.xhtml...
2024/11/27 12:59:52 Processing file OEBPS/Babel-epub-46.xhtml...
2024/11/27 12:59:52 Processing file OEBPS/Babel-epub-47.xhtml...
2024/11/27 12:59:52 Processing file OEBPS/Babel-epub-48.xhtml...
2024/11/27 12:59:52 Processing file OEBPS/toc.ncx...
2024/11/27 12:59:52 Processing file META-INF/container.xml...
2024/11/27 12:59:52 Processing file OEBPS/css/Babel_idstyles.css...
2024/11/27 12:59:52 Processing file OEBPS/font/BemboBookMTPro-Bold.otf...
panic: crypto/cipher: input not full blocks

goroutine 1 [running]:
crypto/cipher.(*cbcDecrypter).CryptBlocks(0xc1d5e0?, {0xc000310b00?, 0xc000310580?, 0x10?}, {0xc000310590?, 0xc000310900?, 0xc000094000?})
        C:/Program Files/Go/src/crypto/cipher/cbc.go:145 +0x40b
main.decipher({0xc000310580, 0x537, 0x580}, {0xc0000bb2c0?, 0xc00016c101?, 0xc00008c080?})
        C:/dev/go-dedrm/lcp-decrypt/main.go:263 +0x14b
main.decryptFile({0xc1cd98, 0xc00010fa40}, {0x2a7ee1eb088?, 0xc00010fa90?}, {0xc0000bb2c0, 0x20, 0x30})
        C:/dev/go-dedrm/lcp-decrypt/main.go:281 +0x9b
main.run()
        C:/dev/go-dedrm/lcp-decrypt/main.go:137 +0x1248
main.main()
        C:/dev/go-dedrm/lcp-decrypt/main.go:21 +0x13

Thanks for the report! This seems to be this panic, which means that the length of the input we're trying to decipher is not a multiple of the block size... The AES block size is 16, so somehow the "content key" size is not a multiple of 16, as we expect it to be. And the content key is stored encrypted in the epub file, we decrypt it using the user key (bear with me, I haven't touched this code in ages 😅). I wonder if this is the same issue as #4 ?

I pushed the changes from devvythelopper to master, can you give it a try and let me know if the problem goes away?

Unfortunately, it's the same as before. I tried pasting devvythelopper's code before, but to no avail. :(
I don't know enough go to debug this myself and I would like to strip that DRM to be able to read library books on my KIndle :)

Anyhow, thanks for your efforts

I’m happy to take a look if you can share the file and the key with me, but I of course understand it’s sensitive material… You can reach out at adrien AT bustany DOT org .

Alright, the font issue was "fixed" in 3c6b32e (we just ignore obfuscated font files, and things seem to work). There was also a very silly path decoding issue fixed in 3588181 that should fix decoding for files that still looked like garbage after decryption. The latest version is deployed on https://abustany.github.io/lcp-decrypt/ (does the same as the command line tool, but easier to use), let me know if it works for you!

Great, issue is fixed. Works both online and as command tool