summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIru Cai <mytbk920423@gmail.com>2018-11-20 21:16:18 +0800
committerIru Cai <mytbk920423@gmail.com>2018-11-20 21:18:29 +0800
commit02e13877f413064b587bf238fed15140f7f8e5e7 (patch)
tree3b70e8526d5dc61e5690d6834b100ac3fe4e53ef
parent3fb6738a8e47756fb898a4f7e461706193860893 (diff)
downloadmupdf-profxjc.tar.xz
-rw-r--r--source/pdf/pdf-crypt.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/source/pdf/pdf-crypt.c b/source/pdf/pdf-crypt.c
index c623d6c4..af805469 100644
--- a/source/pdf/pdf-crypt.c
+++ b/source/pdf/pdf-crypt.c
@@ -170,11 +170,10 @@ struct pdf_crypt_s
static void pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, pdf_crypt *crypt, pdf_obj *name);
static pdf_crypt *
-pdf_new_profxjc_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id)
+pdf_set_profxjc_crypt(pdf_crypt *crypt, fz_context *ctx, pdf_obj *dict, pdf_obj *id)
{
fz_sha256 sha256;
fz_sha256 xml_hash;
- fz_sha256 final_hash;
unsigned char xml_hash_sum[32];
unsigned char *r_buf = NULL;
size_t r_size = 0;
@@ -182,11 +181,23 @@ pdf_new_profxjc_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id)
unsigned char crypt_bytes[4] = { 3, 0, 0, 0 }; /* AESV3 */
unsigned char len_bytes[4] = { 0, 0, 0, 0 };
unsigned char idstr[32];
+ pdf_obj *obj;
+
+ crypt->xjc = 1;
obj = pdf_dict_get(ctx, dict, PDF_NAME(Length));
if (pdf_is_int(ctx, obj))
crypt->length = pdf_to_int(ctx, obj);
+ obj = pdf_dict_get(ctx, dict, PDF_NAME(P));
+ if (pdf_is_int(ctx, obj))
+ crypt->p = pdf_to_int(ctx, obj);
+ else
+ {
+ fz_warn(ctx, "encryption dictionary missing permissions");
+ crypt->p = 0xfffffffc;
+ }
+
crypt->stmf.method = PDF_CRYPT_AESV3;
crypt->stmf.length = crypt->length;
crypt->strf.method = PDF_CRYPT_AESV3;
@@ -274,9 +285,9 @@ pdf_new_profxjc_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id)
fz_sha256_final(&sha256, crypt->key);
for (int i = 0; i < 43; i++) {
- fz_sha256_init(&final_hash);
- fz_sha256_update(&final_hash, crypt->key, 32);
- fz_sha256_final(&final_hash, crypt->key);
+ fz_sha256_init(&sha256);
+ fz_sha256_update(&sha256, crypt->key, 32);
+ fz_sha256_final(&sha256, crypt->key);
}
fz_free(ctx, r_buf);
return crypt;
@@ -306,8 +317,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id)
crypt->xjc = 0;
if (!strcmp("ProfXJC", pdf_to_name(ctx, obj)))
{
- crypt->xjc = 1;
- return pdf_new_profxjc_crypt(ctx, dict, id);
+ return pdf_set_profxjc_crypt(crypt, ctx, dict, id);
}
if (!pdf_name_eq(ctx, PDF_NAME(Standard), obj))
{