apprenticeharper / DeDRM_tools

DeDRM tools for ebooks
14.53k stars 1.51k forks source link

ADEPT_LICENSE not being found by ineptpdf #1780

Open BentonEdmondson opened 3 years ago

BentonEdmondson commented 3 years ago

I'm using ineptpdf to decrypt a PDF. I am getting this error:

Traceback (most recent call last):
  In <module>
    sys.exit(cli_main())
  In cli_main
    result = decryptBook(userkey, inpath, outpath)
  In decryptBook
    serializer = PDFSerializer(inf, userkey)
  In __init__
    doc.initialize(userkey)
  In initialize
    return self.initialize_ebx(password, docid, param)
  In initialize_ebx
    rights = codecs.decode(param.get('ADEPT_LICENSE'), 'base64')
TypeError: decoding with 'base64' codec failed (TypeError: expected bytes-like object, not NoneType)

At line 1425 the value of self.encryption is

{
  'Filter': /EBX#5fHANDLER,
  'EBX_TITLE': b'',
  'ADEPT_ID': b'urn:uuid:...',
  'V': 4,
  'EBX_AUTHOR': b'',
  'Length': 128
}

Of course the ADEPT_LICENSE is missing. I assume the 'V': 4 means that this is ADE v4 content making it undecryptable for now. Is this correct?

ElleKayEm commented 3 years ago

Some (many?) pdfs are not working with the Python 3 version, but can often be decrypted with the Python 2 version.

BentonEdmondson commented 3 years ago

Thanks for the suggestion. I tried the Python 2 version and got this:

Traceback (most recent call last):
  In <module>
    sys.exit(cli_main())
  In cli_main
    result = decryptBook(userkey, inpath, outpath)
  In decryptBook
    serializer = PDFSerializer(inf, userkey)
  In __init__
    doc.initialize(userkey)
  In initialize
    return self.initialize_ebx(password, docid, param)
  In initialize_ebx
    rights = zlib.decompress(rights, -15)
zlib.error: Error -5 while decompressing data: incomplete or truncated stream

It is essentially the same error, complaining that ADEPT_LICENSE is missing

j-howell commented 3 years ago

Of course the ADEPT_LICENSE is missing.

Where did this PDF come from?

In books downloaded using ADE 2.x the ADEPT_LICENSE field should be present. ADE inserts it into the file after it is downloaded. (I have seen it missing in some B&N PDF files, which can have this data stored in a separate database.)

I assume the 'V': 4 means that this is ADE v4 content making it undecryptable for now. Is this correct?

No. V=4 is the normal expected value.

BentonEdmondson commented 3 years ago

It came from libgourou (http://indefero.soutade.fr/p/libgourou/), which I realized doesn't support PDF (http://indefero.soutade.fr/p/libgourou/issues/17/) which explains it. I guess the client has to add in ADEPT_LICENSE once it receives the file from Adobe?

j-howell commented 3 years ago

I guess the client has to add in ADEPT_LICENSE once it receives the file from Adobe?

Yes.

BentonEdmondson commented 3 years ago

Ok. When downloading EPUBs does the client modify them upon receipt or does it just download the EPUB and call it good?

j-howell commented 3 years ago

When downloading EPUBs does the client modify them upon receipt or does it just download the EPUB and call it good?

EPUBs are modified by ADE in much the same way to add a rights.xml file.

BentonEdmondson commented 3 years ago

Alright. Thanks for the help

BentonEdmondson commented 2 years ago

I now have a pdf with ADEPT_LICENSE present and I'm still getting the issue. It's The Goodbye Summer (realized as summer.pdf) from the Adobe ADE sample library. ineptpdf.py gives me

    rights = zlib.decompress(rights, -15)
zlib.error: Error -5 while decompressing data: incomplete or truncated stream

Any idea what the problem is? Does the pre-decryption pdf itself look correct? I checked and it has ADEPT_LICENSE. Also I'm using the same keyfile.der that I use on epubs that works.

ElleKayEm commented 2 years ago

I don't know what that error is. But I was able to download the book with ADE 2.0.1 and then decrypt it with the DeDRM 7.2.1 plugin.

BentonEdmondson commented 2 years ago

@ElleKayEm alright. Can you verify that DeDRM works on the pdf I downloaded?: summer.pdf

j-howell commented 2 years ago

Each ADE download is locked to the downloading user's key. No one else is going to be able to decrypt a file you downloaded.

That said, I took a look at the file and the rights information is malformed in it. Are you still trying to use libgourou for the download?

BentonEdmondson commented 2 years ago

Ah I forgot about that. Yes I am using libgourou. I'll open an issue there.

BentonEdmondson commented 2 years ago

@j-howell actually, I should ask, how is it malformed?

j-howell commented 2 years ago

@j-howell actually, I should ask, how is it malformed?

It appears to be truncated, but it is hard to be certain.

j-howell commented 2 years ago

Ah I forgot about that. Yes I am using libgourou.

You may want to consider using the DeACSM plugin for calibre instead.