OpenPDF icon indicating copy to clipboard operation
OpenPDF copied to clipboard

"Unknown encryption type R = 6" support AES256

Open ralfhauser opened this issue 4 years ago • 12 comments

It seems that the first AES256 encrypted pdf's are out in the wild

https://stackoverflow.com/questions/50822874/unknown-encryption-type-opening-pdf-file

I guess they should be supported

ralfhauser avatar May 28 '20 07:05 ralfhauser

I tried this once but failed and didn't have the time to investigate further. Seems not so easy...

Lonzak avatar May 28 '20 12:05 Lonzak

pwProtectedAES256_openPDFiss375.pdf

Here comes a test file

ralfhauser avatar May 29 '20 06:05 ralfhauser

Created with SettingsPwProtectedAES256_openPDFiss375

ralfhauser avatar May 29 '20 06:05 ralfhauser

Damn also had a document with this error now :-( Seems more and more docs are in the wild using this standard

Lonzak avatar Jan 22 '21 13:01 Lonzak

Here is an another example of the 256-bit AES encrypted file: https://pratiyogitaabhiyan.in/wp-content/uploads/2020/09/Indian-National-Movement-Phase-III-1935-1947-NotesMCQ-PDF-pratiyogitaabhiyan.in_.pdf

Qpdf output:

>qpdf --show-encryption Indian-National-Movement_1.pdf
WARNING: Indian-National-Movement_1.pdf: file is damaged
WARNING: Indian-National-Movement_1.pdf (offset 1116099): xref not found
WARNING: Indian-National-Movement_1.pdf: Attempting to reconstruct cross-reference table
R = 5
P = -1852
User password =
Supplied password is user password
extract for accessibility: not allowed
extract for any purpose: not allowed
print low resolution: allowed
print high resolution: allowed
modify document assembly: not allowed
modify forms: not allowed
modify annotations: not allowed
modify other: not allowed
modify anything: not allowed
stream encryption method: AESv3
string encryption method: AESv3
file encryption method: AESv3
qpdf: operation succeeded with warnings

mspnr avatar Mar 19 '21 21:03 mspnr

To fix the problem of opening files with 256-bit AES encryption this part from "itext7-dotnet" repository should be brought into this repository somewhere here:

https://github.com/LibrePDF/OpenPDF/blob/116b38cdbe30385161444976a2c418446fdaf0a5/openpdf/src/main/java/com/lowagie/text/pdf/PdfReader.java#L728-L737

mspnr avatar Mar 19 '21 21:03 mspnr

Pull requests welcome!

asturio avatar Mar 20 '21 12:03 asturio

To fix the problem of opening files with 256-bit AES encryption this part from "itext7-dotnet" repository should be brought into this repository somewhere here:

Beware not to really copy from there to here. While being inspired by it certainly is ok, a more or less verbatim copy of too much code might cause license issues.

mkl-public avatar Mar 22 '21 15:03 mkl-public

@mkl-public I get you point.

Actually I saved the link with AES256 implementation in iText because it is always nice to have a working code and you can always take a look into the alternative implementation, if you got stuck.

BTW here is the same part on Java, which is more useful for us, as long as OpenPDF is written on Java.

From the other side the encryption algorithm should be more or less the same, as long as we need to get the same result.

From the third side it looks like we still can copy the code from iText to OpenPDF:

mspnr avatar Mar 23 '21 00:03 mspnr

So this mean, that if you copy code from AGPL, into the LGPL project, the copied code still is AGPL. And OpenPDF would become AGPL too, which is not the intend of OpenPDF. It should remain LGPL, so it can still be used in closed source projects.

https://www.gnu.org/licenses/gpl-faq.en.html#UnreleasedModsAGPL

asturio avatar Mar 25 '21 20:03 asturio

See also PDFBox at https://issues.apache.org/jira/browse/PDFBOX-4413 and https://issues.apache.org/jira/browse/PDFBOX-1594

debuglevel avatar Nov 29 '21 22:11 debuglevel

Similar issues:

com.lowagie.text.exceptions.InvalidPdfException: Unknown encryption type R = 5
	at com.lowagie.text.pdf.PdfReader.readPdf(PdfReader.java:618)
	at com.lowagie.text.pdf.PdfReader.<init>(PdfReader.java:184)
	at com.lowagie.text.pdf.PdfReader.<init>(PdfReader.java:168)

h2cone avatar Apr 28 '22 02:04 h2cone

Did anybody try to implement it? Very interested in this as well!

@mkl-public , any chance for a PR maybe? :)

bsanchezb avatar Aug 31 '22 13:08 bsanchezb

Yes there is a working branch at least for R=6 (not the deprecated R=5) I did the quality test and it is running perfectly for me since quite a while.. @mkl-public wanted to add a PR here some time ago but maybe he's busy with some other things...

Lonzak avatar Aug 31 '22 13:08 Lonzak

@bsanchezb, @Lonzak,

ok ok, the PR is there, it's #802.

mkl-public avatar Sep 01 '22 14:09 mkl-public

Just to make sure the nature of the fix is correctly understood: It adds support for password based AES256 (ISO 32000-2) - R=6 - but not for the interim AES256 (ISO 32000-1 + Adobe Developer Extensions) - R=5 - which has been deprecated in ISO 32000-2. Thus, it solves the issue as originally posted by Ralf Hauser but it won't help with documents as referenced by mspnr (Indian-National-Movement_1.pdf) or as encountered by h2cone.

mkl-public avatar Sep 15 '22 12:09 mkl-public