Debugging for encyption/permissions

This commit is contained in:
John Whitington 2014-10-24 17:24:29 +01:00
parent 898776ee73
commit f689fa8f20
1 changed files with 30 additions and 15 deletions

View File

@ -326,6 +326,7 @@ type args =
mutable no_assemble : bool;
mutable no_hq_print : bool;
mutable debug : bool;
mutable debugcrypt : bool;
mutable boxes : bool;
mutable encrypt_metadata : bool;
mutable retain_numbering : bool;
@ -406,6 +407,7 @@ let args =
no_assemble = false;
no_hq_print = false;
debug = false;
debugcrypt = false;
boxes = false;
encrypt_metadata = true;
retain_numbering = false;
@ -481,6 +483,7 @@ let reset_arguments () =
args.no_assemble <- false;
args.no_hq_print <- false;
args.debug <- false;
args.debugcrypt <- false;
args.boxes <- false;
args.encrypt_metadata <- true;
args.retain_numbering <- false;
@ -539,19 +542,20 @@ let operation_allowed banlist op =
| Some op -> not (banned banlist op)
let rec decrypt_if_necessary (_, _, _, user_pw, owner_pw) op pdf =
begin match op with
None -> flprint "decrypt_if_necessary: op = None\n"
| Some x -> Printf.printf "decrypt_if_necessary: op = %s\n" (string_of_op x)
end;
if args.debugcrypt then
begin match op with
None -> flprint "decrypt_if_necessary: op = None\n"
| Some x -> Printf.printf "decrypt_if_necessary: op = %s\n" (string_of_op x)
end;
if not (Pdfcrypt.is_encrypted pdf) then pdf else
match Pdfcrypt.decrypt_pdf_owner owner_pw pdf with
| Some pdf ->
Printf.printf "Managed to decrypt with owner password"; pdf
if args.debugcrypt then Printf.printf "Managed to decrypt with owner password\n"; pdf
| _ ->
Printf.printf "Couldn't decrypt with owner password %s\n" owner_pw;
if args.debugcrypt then Printf.printf "Couldn't decrypt with owner password %s\n" owner_pw;
match Pdfcrypt.decrypt_pdf user_pw pdf with
| Some pdf, permissions ->
Printf.printf "Managed to decrypt with user password\n";
if args.debugcrypt then Printf.printf "Managed to decrypt with user password\n";
if operation_allowed permissions op
then pdf
else soft_error "User password cannot give permission for this operation"
@ -1057,6 +1061,9 @@ let setdebug () =
set Pdfcrypt.crypt_debug;
args.debug <- true
let setdebugcrypt () =
args.debugcrypt <- true
let setboxes () =
args.boxes <- true
@ -1792,6 +1799,7 @@ and specs =
("-flat-kids", Arg.Unit setflatkids, "");
("-gs", Arg.String setgspath, "");
("-debug", Arg.Unit setdebug, "");
("-debug-crypt", Arg.Unit setdebugcrypt, "");
("-fix-prince", Arg.Unit (setop RemoveUnusedResources), "");
("-extract-text", Arg.Unit (setop ExtractText), "")]
@ -1888,14 +1896,21 @@ let really_write_pdf ?(encryption = None) mk_id pdf outname =
then Filename.temp_file "cpdflin" ".pdf"
else outname
in
begin if args.recrypt && args.was_encrypted then
Pdfwrite.pdf_to_file_recrypting
(get_single_pdf_nodecrypt false) pdf args.user outname'
else
Pdfwrite.pdf_to_file_options
~preserve_objstm:args.preserve_objstm
~generate_objstm:args.create_objstm
false encryption mk_id pdf outname'
begin
if args.recrypt && args.was_encrypted then
begin
if args.debugcrypt then Printf.printf "Recrypting in really_write_pdf\n";
Pdfwrite.pdf_to_file_recrypting
(get_single_pdf_nodecrypt false) pdf args.user outname'
end
else
begin
if args.debugcrypt then Printf.printf "Pdf to file in really_write_pdf\n";
Pdfwrite.pdf_to_file_options
~preserve_objstm:args.preserve_objstm
~generate_objstm:args.create_objstm
false encryption mk_id pdf outname'
end
end;
begin
if args.linearize then