summaryrefslogtreecommitdiff
path: root/source/pdf/pdf-crypt.c
AgeCommit message (Collapse)Author
2018-11-20fixprofxjcIru Cai
2018-11-20clean upIru Cai
2018-11-20move the profxjc things out of pdf_new_cryptIru Cai
2018-11-20free r_bufIru Cai
2018-11-20more cleaningIru Cai
2018-11-20use the original MT19937 codeIru Cai
2018-11-20final fix - it works!!Iru Cai
2018-11-20some fix - still not workIru Cai
2018-11-20the complete hashing, but not worksIru Cai
2018-11-20add mt19937 codeIru Cai
2018-11-20hash r_bufIru Cai
2018-11-20get id string and xmlIru Cai
2018-11-19hardcode an encryption key for test -- it worksIru Cai
2018-11-18support ProfXJCIru Cai
build with `make USE_SYSTEM_LIBS=yes build=debug -j5`
2018-04-24Remove need for namedump by using macros and preprocessor.Tor Andersson
Add a PDF_NAME(Foo) macro that evaluates to a pdf_obj for /Foo. Use the C preprocessor to create the enum values and string table from one include file instead of using a separate code generator tool.
2018-04-03Don't implicitly drop in fz_open_* chained filters.Tor Andersson
2018-03-22Fix 699085: Use at most 16 bytes from MD5 digests.Sebastian Rasmussen
Previously crypt->len / 8 could be 0..32. In the case of crypt->len == 256 this meant that when an 16 byte MD5 was computed, uninitalized key data would be accessed because 32 bytes of key data was accessed. Now crypt->len / 8 is limited to 0..16. So when the 16 byte MD5 is computed and later accessed only the initialized part of the key data is accessed. Because crypt->len / 8 is now limited to 0..16 the key data buffer can also be shrunk to 16 bytes without risking the code stepping over its boundaries.
2018-03-22Rearrange user password authentication code.Sebastian Rasmussen
pdf_authenticate_user_password() now looks similar to pdf_compute_user_password(), easing readability.
2018-02-27Don't use constants larger than will fit in a signed int in enum.Tor Andersson
2018-02-12Expose detailed PDF permissions.Tor Andersson
2018-02-08Bug 698996: Disallow "" as owner password unless user password also "".Robin Watts
2018-01-05Enable saving of encrypted PDF files.Robin Watts
We need both RC4 and AES encryption. RC4 is a straight reversable stream, and our AES library knows how to encrypt as well as decrypt, so it's "just" a matter of calling them correctly. We therefore expose a generic "encrypt this data" routine (and a matching "how long will the data be once encrypted" routine) within pdf-crypt.c. We then extend our our PDF object output routines to call these. This is enough to get encrypted data preserved over calls to mutool clean. Unfortunately the created files aren't readable, due to 2 further problems, also fixed here. Firstly, mutool clean does not preserve the Encrypt entry in the trailer. This is a simple fix. Secondly, we are required NOT to encrypt the Encrypt entry. This requires us to spot the crypt entry and to special case it.
2017-09-13Consistently drop filter chain upon error.Sebastian Rasmussen
2017-07-03Avoid leaking an fz_stream for every unknown crypt handler.Robin Watts
2017-04-27Include required system headers.Tor Andersson
2017-04-27Use namespace for AES crypto code.Tor Andersson
2017-03-22Rename fz_putc/puts/printf to fz_write_*.Tor Andersson
Rename fz_write to fz_write_data. Rename fz_write_buffer_* and fz_buffer_printf to fz_append_*. Be consistent in naming: fz_write_* calls write to fz_output. fz_append_* calls append to fz_buffer. Update documentation.
2017-02-23Improve return codes from pdf_authenticate_password.Robin Watts
Customer request to enable finer control based on which password authenticates.
2016-10-13crypt: Handle null pointer when dropping crypt object.Sebastian Rasmussen
Exposed by weird-jpx.pdf from bug 696885.
2016-07-06pdf: Drop generation number from public interfaces.Tor Andersson
The generation number is only needed for decryption, and is assumed to be zero or irrelevant for all other uses. Store the original object number and generation in the xref slot, so that we can decrypt them even when the objects have been renumbered, without needing to pass the original object number around through the stream loading APIs.
2016-06-17Use 'size_t' instead of int as appropriate.Robin Watts
This silences the many warnings we get when building for x64 in windows. This does not address any of the warnings we get in thirdparty libraries - in particular harfbuzz. These look (at a quick glance) harmless though.
2016-04-27Fix 696649: remove fz_rethrow_message calls.Tor Andersson
2016-04-22pdf: Handle implicit identity crypt filtersSebastian Rasmussen
Fixes http://bugs.ghostscript.com/show_bug.cgi?id=696687
2016-04-12Fix some warnings.Robin Watts
Remove some bonkers conditions arising (presumably) as a result of search and replace.
2016-03-29pdf-crypt: Crypt filer keys must be at least of length 40.Sebastian Rasmussen
This is stated in table 3.22 in PDF Reference 1.7. Fixes valgrind errors for SIGABRT-090214-045131-116.pdf from bug 695040.
2015-12-11Use fz_output instead of FILE* for most of our output needs.Tor Andersson
Use fz_output in debug printing functions. Use fz_output in pdfshow. Use fz_output in fz_trace_device instead of stdout. Use fz_output in pdf-write.c. Rename fz_new_output_to_filename to fz_new_output_with_path. Add seek and tell to fz_output. Remove unused functions like fz_fprintf. Fix typo in pdf_print_obj.
2015-09-28Bug 696182: Fix Revision 6 PDF encryption.Robin Watts
Take on 2 patches from Zeniko to solve problems with the latest version of PDF encryption. Many thanks.
2015-04-14Split fz_meta into separate querying functions.Tor Andersson
Add fz_has_permission function to fz_document. Add fz_lookup_metadata function to fz_document. Remove fz_meta function from fz_document.
2015-03-24Rework handling of PDF names for speed and memory.Robin Watts
Currently, every PDF name is allocated in a pdf_obj structure, and comparisons are done using strcmp. Given that we can predict most of the PDF names we'll use in a given file, this seems wasteful. The pdf_obj type is opaque outside the pdf-object.c file, so we can abuse it slightly without anyone outside knowing. We collect a sorted list of names used in PDF (resources/pdf/names.txt), and we add a utility (namedump) that preprocesses this into 2 header files. The first (include/mupdf/pdf/pdf-names-table.h, included as part of include/mupdf/pdf/object.h), defines a set of "PDF_NAME_xxxx" entries. These are pdf_obj *'s that callers can use to mean "A PDF object that means literal name 'xxxx'" The second (source/pdf/pdf-name-impl.h) is a C array of names. We therefore update the code so that rather than passing "xxxx" to functions (such as pdf_dict_gets(...)) we now pass PDF_NAME_xxxx (to pdf_dict_get(...)). This is a fairly natural (if widespread) change. The pdf_dict_getp (and sibling) functions that take a path (e.g. "foo/bar/baz") are therefore supplemented with equivalents that take a list (pdf_dict_getl(... , PDF_NAME_foo, PDF_NAME_bar, PDF_NAME_baz, NULL)). The actual implementation of this relies on the fact that small pointer values are never valid values. For a given pdf_obj *p, if NULL < (intptr_t)p < PDF_NAME__LIMIT then p is a literal entry in the name table. This enables us to do fast pointer compares and to skip expensive strcmps. Also, bring "null", "true" and "false" into the same style as PDF names. Rather than using full pdf_obj structures for null/true/false, use special pointer values just above the PDF_NAME_ table. This saves memory and makes comparisons easier.
2015-02-17Add ctx parameter and remove embedded contexts for API regularity.Tor Andersson
Purge several embedded contexts: Remove embedded context in fz_output. Remove embedded context in fz_stream. Remove embedded context in fz_device. Remove fz_rebind_stream (since it is no longer necessary). Remove embedded context in svg_device. Remove embedded context in XML parser. Add ctx argument to fz_document functions. Remove embedded context in fz_document. Remove embedded context in pdf_document. Remove embedded context in pdf_obj. Make fz_page independent of fz_document in the interface. We shouldn't need to pass the document to all functions handling a page. If a page is tied to the source document, it's redundant; otherwise it's just pointless. Fix reference counting oddity in fz_new_image_from_pixmap.
2015-02-17Rename fz_close_* and fz_free_* to fz_drop_*.Tor Andersson
Rename fz_close to fz_drop_stream. Rename fz_close_archive to fz_drop_archive. Rename fz_close_output to fz_drop_output. Rename fz_free_* to fz_drop_*. Rename pdf_free_* to pdf_drop_*. Rename xps_free_* to xps_drop_*.
2014-09-08Revert part of commit 5509a4ef7520bf0b5280ce7d6af8eb15b1b8b0f1Simon Bünzli
Even though the encryption key length isn't supposed to be taken from the encryption dictionary's /Length for crypt version 4, other readers such as Adobe's still use that value if a crypt filter's /Length is missing. See https://code.google.com/p/sumatrapdf/issues/detail?id=2710 for a document where this makes a difference (or simply remove /Length from the crypt filter in any document encrypted with crypt version 4 and an AESV2 crypt filter).
2014-05-15Fix 695101 and 694114: Use the correct numbers to validate the encryption ↵Tor Andersson
key length. This reverts commit b1ed116091b790223a976eca2381da2875341e10. The key length for V==2 must be 40 <= length <= 128. The key length for V==4 is not taken from the /Length entry.
2014-01-08sanitize crypt revision in pdf_new_cryptSimon Bünzli
(Second part of Simons patch - apologies for missing this the first time). This correctly enables the sanitization of the key length needed for 90db34f64037e2a8a5c3b6a518ba4153_asan_heap-oob_9b117e_1197_1802.pdf Thanks to Mateusz Jurczyk and Gynvael Coldwind of the Google Security Team for providing the example files.
2014-01-08sanitize crypt revision in pdf_new_cryptSimon Bünzli
This correctly enables the sanitization of the key length needed for 90db34f64037e2a8a5c3b6a518ba4153_asan_heap-oob_9b117e_1197_1802.pdf
2013-12-17Remove fz_context from pdf_cryptRobin Watts
Unused field. Also tweak some comments for clarity.
2013-11-27Bug 694114: Fix valgrind issue.Robin Watts
I believe the implementation for revision 3 is wrong. From pdf_reference17.pdf, step 5 of Algorithm 3.5 says: 5. Do the following 19 times: Take the output from the previous invocation of the RC4 function and pass it as input to a new invocation of the function; use an encryption key generated by taking each byte of the original encryption key (obtained in step 1) and performing an XOR (exclusive or) operation between that byte and the single-byte value of the iteration counter (from 1 to 19). "the original encryption key (obtained in step 1)" is pwbuf (32 bytes) not key. Even if it was key, it wouldn't be n bytes long, but only 16.
2013-09-13Fix various compile warnings spotted by the cluster.Robin Watts
2013-06-25Rid the world of "pdf_document *xref".Robin Watts
For historical reasons lots of the code uses "xref" when talking about a pdf document. Now pdf_xref is a separate type this has become confusing, so replace 'xref' with 'doc' for clarity.
2013-06-20Rearrange source files.Tor Andersson