mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 02:49:00 +00:00
Modernize encryption API for more granularity
Setting encryption permissions for R >= 3 set permission bits in groups corresponding to menu options in Acrobat 5. The new API allows the bits to be set individually.
This commit is contained in:
parent
4630377731
commit
6ec22f117d
@ -16,6 +16,15 @@
|
||||
|
||||
2019-01-14 Jay Berkenbilt <ejb@ql.org>
|
||||
|
||||
* Add new versions of
|
||||
QPDFWriter::setR{3,4,5,6}EncryptionParameters that allow
|
||||
individual setting of the various permission bits. The old
|
||||
interfaces are retained for backward compatibility. In the "C"
|
||||
API, add qpdf_set_r{3,4,5,6}_encryption_parameters2. The new
|
||||
interfaces use separate booleans for various permissions instead
|
||||
of the qpdf_r3_modify_e enumerated type, which set permission bits
|
||||
in predefined groups.
|
||||
|
||||
* Add versions of utf8 to single-byte character transcoders that
|
||||
return a success code.
|
||||
|
||||
|
@ -80,13 +80,18 @@ enum qpdf_r3_print_e
|
||||
qpdf_r3p_low, /* allow only low-resolution printing */
|
||||
qpdf_r3p_none /* allow no printing */
|
||||
};
|
||||
|
||||
/* qpdf_r3_modify_e doesn't allow the full flexibility of the spec. It
|
||||
* corresponds to options in Acrobat 5's menus. The new interface in
|
||||
* QPDFWriter offers more granularity and no longer uses this type.
|
||||
*/
|
||||
enum qpdf_r3_modify_e /* Allowed changes: */
|
||||
{
|
||||
qpdf_r3m_all = 0, /* General editing, comments, forms */
|
||||
qpdf_r3m_annotate, /* Comments, form field fill-in, and signing */
|
||||
qpdf_r3m_form, /* form field fill-in and signing */
|
||||
qpdf_r3m_assembly, /* only document assembly */
|
||||
qpdf_r3m_none /* no modifications */
|
||||
qpdf_r3m_all = 0, /* All editing */
|
||||
qpdf_r3m_annotate, /* Comments, fill forms, signing, assembly */
|
||||
qpdf_r3m_form, /* Fill forms, signing, assembly */
|
||||
qpdf_r3m_assembly, /* Only document assembly */
|
||||
qpdf_r3m_none /* No modifications */
|
||||
};
|
||||
|
||||
/* Form field flags from the PDF spec */
|
||||
|
@ -344,6 +344,39 @@ class QPDFWriter
|
||||
// AES is used, 1.6, and setting R5 or R6 parameters pushes the
|
||||
// version to at least 1.7 with extension level 3.
|
||||
QPDF_DLL
|
||||
void setR3EncryptionParameters(
|
||||
char const* user_password, char const* owner_password,
|
||||
bool allow_accessibility, bool allow_extract,
|
||||
bool allow_assemble, bool allow_annotate_and_form,
|
||||
bool allow_form_filling, bool allow_modify_other,
|
||||
qpdf_r3_print_e print);
|
||||
QPDF_DLL
|
||||
void setR4EncryptionParameters(
|
||||
char const* user_password, char const* owner_password,
|
||||
bool allow_accessibility, bool allow_extract,
|
||||
bool allow_assemble, bool allow_annotate_and_form,
|
||||
bool allow_form_filling, bool allow_modify_other,
|
||||
qpdf_r3_print_e print, bool encrypt_metadata, bool use_aes);
|
||||
// R5 is deprecated. Do not use it for production use. Writing
|
||||
// R5 is supported by qpdf primarily to generate test files for
|
||||
// applications that may need to test R5 support.
|
||||
QPDF_DLL
|
||||
void setR5EncryptionParameters(
|
||||
char const* user_password, char const* owner_password,
|
||||
bool allow_accessibility, bool allow_extract,
|
||||
bool allow_assemble, bool allow_annotate_and_form,
|
||||
bool allow_form_filling, bool allow_modify_other,
|
||||
qpdf_r3_print_e print, bool encrypt_metadata);
|
||||
QPDF_DLL
|
||||
void setR6EncryptionParameters(
|
||||
char const* user_password, char const* owner_password,
|
||||
bool allow_accessibility, bool allow_extract,
|
||||
bool allow_assemble, bool allow_annotate_and_form,
|
||||
bool allow_form_filling, bool allow_modify_other,
|
||||
qpdf_r3_print_e print, bool encrypt_metadata_aes);
|
||||
|
||||
// Pre qpdf 8.4.0 API
|
||||
QPDF_DLL
|
||||
void setR2EncryptionParameters(
|
||||
char const* user_password, char const* owner_password,
|
||||
bool allow_print, bool allow_modify,
|
||||
@ -359,9 +392,6 @@ class QPDFWriter
|
||||
bool allow_accessibility, bool allow_extract,
|
||||
qpdf_r3_print_e print, qpdf_r3_modify_e modify,
|
||||
bool encrypt_metadata, bool use_aes);
|
||||
// R5 is deprecated. Do not use it for production use. Writing
|
||||
// R5 is supported by qpdf primarily to generate test files for
|
||||
// applications that may need to test R5 support.
|
||||
QPDF_DLL
|
||||
void setR5EncryptionParameters(
|
||||
char const* user_password, char const* owner_password,
|
||||
@ -459,6 +489,8 @@ class QPDFWriter
|
||||
std::set<int>& bits_to_clear,
|
||||
char const* user_password, char const* owner_password,
|
||||
bool allow_accessibility, bool allow_extract,
|
||||
bool allow_assemble, bool allow_annotate_and_form,
|
||||
bool allow_form_filling, bool allow_modify_other,
|
||||
qpdf_r3_print_e print, qpdf_r3_modify_e modify);
|
||||
void disableIncompatibleEncryption(int major, int minor,
|
||||
int extension_level);
|
||||
|
@ -389,6 +389,40 @@ extern "C" {
|
||||
QPDF_BOOL allow_print, QPDF_BOOL allow_modify,
|
||||
QPDF_BOOL allow_extract, QPDF_BOOL allow_annotate);
|
||||
|
||||
QPDF_DLL
|
||||
void qpdf_set_r3_encryption_parameters2(
|
||||
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
||||
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
|
||||
QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
|
||||
QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
|
||||
enum qpdf_r3_print_e print);
|
||||
|
||||
QPDF_DLL
|
||||
void qpdf_set_r4_encryption_parameters2(
|
||||
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
||||
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
|
||||
QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
|
||||
QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
|
||||
enum qpdf_r3_print_e print,
|
||||
QPDF_BOOL encrypt_metadata, QPDF_BOOL use_aes);
|
||||
|
||||
QPDF_DLL
|
||||
void qpdf_set_r5_encryption_parameters2(
|
||||
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
||||
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
|
||||
QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
|
||||
QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
|
||||
enum qpdf_r3_print_e print, QPDF_BOOL encrypt_metadata);
|
||||
|
||||
QPDF_DLL
|
||||
void qpdf_set_r6_encryption_parameters2(
|
||||
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
||||
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
|
||||
QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
|
||||
QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
|
||||
enum qpdf_r3_print_e print, QPDF_BOOL encrypt_metadata);
|
||||
|
||||
/* Pre 8.4.0 encryption API */
|
||||
QPDF_DLL
|
||||
void qpdf_set_r3_encryption_parameters(
|
||||
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
||||
|
@ -409,7 +409,26 @@ QPDFWriter::setR3EncryptionParameters(
|
||||
std::set<int> clear;
|
||||
interpretR3EncryptionParameters(
|
||||
clear, user_password, owner_password,
|
||||
allow_accessibility, allow_extract, print, modify);
|
||||
allow_accessibility, allow_extract,
|
||||
true, true, true, true, print, modify);
|
||||
setEncryptionParameters(user_password, owner_password, 2, 3, 16, clear);
|
||||
}
|
||||
|
||||
void
|
||||
QPDFWriter::setR3EncryptionParameters(
|
||||
char const* user_password, char const* owner_password,
|
||||
bool allow_accessibility, bool allow_extract,
|
||||
bool allow_assemble, bool allow_annotate_and_form,
|
||||
bool allow_form_filling, bool allow_modify_other,
|
||||
qpdf_r3_print_e print)
|
||||
{
|
||||
std::set<int> clear;
|
||||
interpretR3EncryptionParameters(
|
||||
clear, user_password, owner_password,
|
||||
allow_accessibility, allow_extract,
|
||||
allow_assemble, allow_annotate_and_form,
|
||||
allow_form_filling, allow_modify_other,
|
||||
print, qpdf_r3m_all);
|
||||
setEncryptionParameters(user_password, owner_password, 2, 3, 16, clear);
|
||||
}
|
||||
|
||||
@ -423,7 +442,29 @@ QPDFWriter::setR4EncryptionParameters(
|
||||
std::set<int> clear;
|
||||
interpretR3EncryptionParameters(
|
||||
clear, user_password, owner_password,
|
||||
allow_accessibility, allow_extract, print, modify);
|
||||
allow_accessibility, allow_extract,
|
||||
true, true, true, true, print, modify);
|
||||
this->m->encrypt_use_aes = use_aes;
|
||||
this->m->encrypt_metadata = encrypt_metadata;
|
||||
setEncryptionParameters(user_password, owner_password, 4, 4, 16, clear);
|
||||
}
|
||||
|
||||
void
|
||||
QPDFWriter::setR4EncryptionParameters(
|
||||
char const* user_password, char const* owner_password,
|
||||
bool allow_accessibility, bool allow_extract,
|
||||
bool allow_assemble, bool allow_annotate_and_form,
|
||||
bool allow_form_filling, bool allow_modify_other,
|
||||
qpdf_r3_print_e print,
|
||||
bool encrypt_metadata, bool use_aes)
|
||||
{
|
||||
std::set<int> clear;
|
||||
interpretR3EncryptionParameters(
|
||||
clear, user_password, owner_password,
|
||||
allow_accessibility, allow_extract,
|
||||
allow_assemble, allow_annotate_and_form,
|
||||
allow_form_filling, allow_modify_other,
|
||||
print, qpdf_r3m_all);
|
||||
this->m->encrypt_use_aes = use_aes;
|
||||
this->m->encrypt_metadata = encrypt_metadata;
|
||||
setEncryptionParameters(user_password, owner_password, 4, 4, 16, clear);
|
||||
@ -439,7 +480,29 @@ QPDFWriter::setR5EncryptionParameters(
|
||||
std::set<int> clear;
|
||||
interpretR3EncryptionParameters(
|
||||
clear, user_password, owner_password,
|
||||
allow_accessibility, allow_extract, print, modify);
|
||||
allow_accessibility, allow_extract,
|
||||
true, true, true, true, print, modify);
|
||||
this->m->encrypt_use_aes = true;
|
||||
this->m->encrypt_metadata = encrypt_metadata;
|
||||
setEncryptionParameters(user_password, owner_password, 5, 5, 32, clear);
|
||||
}
|
||||
|
||||
void
|
||||
QPDFWriter::setR5EncryptionParameters(
|
||||
char const* user_password, char const* owner_password,
|
||||
bool allow_accessibility, bool allow_extract,
|
||||
bool allow_assemble, bool allow_annotate_and_form,
|
||||
bool allow_form_filling, bool allow_modify_other,
|
||||
qpdf_r3_print_e print,
|
||||
bool encrypt_metadata)
|
||||
{
|
||||
std::set<int> clear;
|
||||
interpretR3EncryptionParameters(
|
||||
clear, user_password, owner_password,
|
||||
allow_accessibility, allow_extract,
|
||||
allow_assemble, allow_annotate_and_form,
|
||||
allow_form_filling, allow_modify_other,
|
||||
print, qpdf_r3m_all);
|
||||
this->m->encrypt_use_aes = true;
|
||||
this->m->encrypt_metadata = encrypt_metadata;
|
||||
setEncryptionParameters(user_password, owner_password, 5, 5, 32, clear);
|
||||
@ -455,7 +518,29 @@ QPDFWriter::setR6EncryptionParameters(
|
||||
std::set<int> clear;
|
||||
interpretR3EncryptionParameters(
|
||||
clear, user_password, owner_password,
|
||||
allow_accessibility, allow_extract, print, modify);
|
||||
allow_accessibility, allow_extract,
|
||||
true, true, true, true, print, modify);
|
||||
this->m->encrypt_use_aes = true;
|
||||
this->m->encrypt_metadata = encrypt_metadata;
|
||||
setEncryptionParameters(user_password, owner_password, 5, 6, 32, clear);
|
||||
}
|
||||
|
||||
void
|
||||
QPDFWriter::setR6EncryptionParameters(
|
||||
char const* user_password, char const* owner_password,
|
||||
bool allow_accessibility, bool allow_extract,
|
||||
bool allow_assemble, bool allow_annotate_and_form,
|
||||
bool allow_form_filling, bool allow_modify_other,
|
||||
qpdf_r3_print_e print,
|
||||
bool encrypt_metadata)
|
||||
{
|
||||
std::set<int> clear;
|
||||
interpretR3EncryptionParameters(
|
||||
clear, user_password, owner_password,
|
||||
allow_accessibility, allow_extract,
|
||||
allow_assemble, allow_annotate_and_form,
|
||||
allow_form_filling, allow_modify_other,
|
||||
print, qpdf_r3m_all);
|
||||
this->m->encrypt_use_aes = true;
|
||||
this->m->encrypt_metadata = encrypt_metadata;
|
||||
setEncryptionParameters(user_password, owner_password, 5, 6, 32, clear);
|
||||
@ -466,6 +551,8 @@ QPDFWriter::interpretR3EncryptionParameters(
|
||||
std::set<int>& clear,
|
||||
char const* user_password, char const* owner_password,
|
||||
bool allow_accessibility, bool allow_extract,
|
||||
bool allow_assemble, bool allow_annotate_and_form,
|
||||
bool allow_form_filling, bool allow_modify_other,
|
||||
qpdf_r3_print_e print, qpdf_r3_modify_e modify)
|
||||
{
|
||||
// Acrobat 5 security options:
|
||||
@ -486,8 +573,21 @@ QPDFWriter::interpretR3EncryptionParameters(
|
||||
// Low Resolution
|
||||
// Full printing
|
||||
|
||||
// Meanings of bits in P when R >= 3
|
||||
//
|
||||
// 3: low-resolution printing
|
||||
// 4: document modification except as controlled by 6, 9, and 11
|
||||
// 5: extraction
|
||||
// 6: add/modify annotations (comment), fill in forms
|
||||
// if 4+6 are set, also allows modification of form fields
|
||||
// 9: fill in forms even if 6 is clear
|
||||
// 10: accessibility; ignored by readers, should always be set
|
||||
// 11: document assembly even if 4 is clear
|
||||
// 12: high-resolution printing
|
||||
|
||||
if (! allow_accessibility)
|
||||
{
|
||||
// setEncryptionParameters sets this if R > 3
|
||||
clear.insert(10);
|
||||
}
|
||||
if (! allow_extract)
|
||||
@ -511,6 +611,13 @@ QPDFWriter::interpretR3EncryptionParameters(
|
||||
// no default so gcc warns for missing cases
|
||||
}
|
||||
|
||||
// Modify options. The qpdf_r3_modify_e options control groups of
|
||||
// bits and lack the full flexibility of the spec. This is
|
||||
// unfortunate, but it's been in the API for ages, and we're stuck
|
||||
// with it. See also allow checks below to control the bits
|
||||
// individually.
|
||||
|
||||
// NOT EXERCISED IN TEST SUITE
|
||||
switch (modify)
|
||||
{
|
||||
case qpdf_r3m_none:
|
||||
@ -530,6 +637,24 @@ QPDFWriter::interpretR3EncryptionParameters(
|
||||
|
||||
// no default so gcc warns for missing cases
|
||||
}
|
||||
// END NOT EXERCISED IN TEST SUITE
|
||||
|
||||
if (! allow_assemble)
|
||||
{
|
||||
clear.insert(11);
|
||||
}
|
||||
if (! allow_annotate_and_form)
|
||||
{
|
||||
clear.insert(6);
|
||||
}
|
||||
if (! allow_form_filling)
|
||||
{
|
||||
clear.insert(9);
|
||||
}
|
||||
if (! allow_modify_other)
|
||||
{
|
||||
clear.insert(4);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -603,12 +603,77 @@ void qpdf_set_r2_encryption_parameters(
|
||||
allow_print, allow_modify, allow_extract, allow_annotate);
|
||||
}
|
||||
|
||||
void qpdf_set_r3_encryption_parameters2(
|
||||
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
||||
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
|
||||
QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
|
||||
QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
|
||||
enum qpdf_r3_print_e print)
|
||||
{
|
||||
QTC::TC("qpdf", "qpdf-c called qpdf_set_r3_encryption_parameters");
|
||||
qpdf->qpdf_writer->setR3EncryptionParameters(
|
||||
user_password, owner_password,
|
||||
allow_accessibility, allow_extract,
|
||||
allow_assemble, allow_annotate_and_form,
|
||||
allow_form_filling, allow_modify_other,
|
||||
print);
|
||||
}
|
||||
|
||||
void qpdf_set_r4_encryption_parameters2(
|
||||
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
||||
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
|
||||
QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
|
||||
QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
|
||||
enum qpdf_r3_print_e print,
|
||||
QPDF_BOOL encrypt_metadata, QPDF_BOOL use_aes)
|
||||
{
|
||||
QTC::TC("qpdf", "qpdf-c called qpdf_set_r4_encryption_parameters");
|
||||
qpdf->qpdf_writer->setR4EncryptionParameters(
|
||||
user_password, owner_password,
|
||||
allow_accessibility, allow_extract,
|
||||
allow_assemble, allow_annotate_and_form,
|
||||
allow_form_filling, allow_modify_other,
|
||||
print, encrypt_metadata, use_aes);
|
||||
}
|
||||
|
||||
|
||||
void qpdf_set_r5_encryption_parameters2(
|
||||
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
||||
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
|
||||
QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
|
||||
QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
|
||||
enum qpdf_r3_print_e print, QPDF_BOOL encrypt_metadata)
|
||||
{
|
||||
QTC::TC("qpdf", "qpdf-c called qpdf_set_r5_encryption_parameters");
|
||||
qpdf->qpdf_writer->setR5EncryptionParameters(
|
||||
user_password, owner_password,
|
||||
allow_accessibility, allow_extract,
|
||||
allow_assemble, allow_annotate_and_form,
|
||||
allow_form_filling, allow_modify_other,
|
||||
print, encrypt_metadata);
|
||||
}
|
||||
|
||||
void qpdf_set_r6_encryption_parameters2(
|
||||
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
||||
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
|
||||
QPDF_BOOL allow_assemble, QPDF_BOOL allow_annotate_and_form,
|
||||
QPDF_BOOL allow_form_filling, QPDF_BOOL allow_modify_other,
|
||||
enum qpdf_r3_print_e print, QPDF_BOOL encrypt_metadata)
|
||||
{
|
||||
QTC::TC("qpdf", "qpdf-c called qpdf_set_r6_encryption_parameters");
|
||||
qpdf->qpdf_writer->setR6EncryptionParameters(
|
||||
user_password, owner_password,
|
||||
allow_accessibility, allow_extract,
|
||||
allow_assemble, allow_annotate_and_form,
|
||||
allow_form_filling, allow_modify_other,
|
||||
print, encrypt_metadata);
|
||||
}
|
||||
|
||||
void qpdf_set_r3_encryption_parameters(
|
||||
qpdf_data qpdf, char const* user_password, char const* owner_password,
|
||||
QPDF_BOOL allow_accessibility, QPDF_BOOL allow_extract,
|
||||
qpdf_r3_print_e print, qpdf_r3_modify_e modify)
|
||||
{
|
||||
QTC::TC("qpdf", "qpdf-c called qpdf_set_r3_encryption_parameters");
|
||||
qpdf->qpdf_writer->setR3EncryptionParameters(
|
||||
user_password, owner_password,
|
||||
allow_accessibility, allow_extract, print, modify);
|
||||
@ -620,7 +685,6 @@ void qpdf_set_r4_encryption_parameters(
|
||||
qpdf_r3_print_e print, qpdf_r3_modify_e modify,
|
||||
QPDF_BOOL encrypt_metadata, QPDF_BOOL use_aes)
|
||||
{
|
||||
QTC::TC("qpdf", "qpdf-c called qpdf_set_r4_encryption_parameters");
|
||||
qpdf->qpdf_writer->setR4EncryptionParameters(
|
||||
user_password, owner_password,
|
||||
allow_accessibility, allow_extract, print, modify,
|
||||
@ -633,7 +697,6 @@ void qpdf_set_r5_encryption_parameters(
|
||||
qpdf_r3_print_e print, qpdf_r3_modify_e modify,
|
||||
QPDF_BOOL encrypt_metadata)
|
||||
{
|
||||
QTC::TC("qpdf", "qpdf-c called qpdf_set_r5_encryption_parameters");
|
||||
qpdf->qpdf_writer->setR5EncryptionParameters(
|
||||
user_password, owner_password,
|
||||
allow_accessibility, allow_extract, print, modify,
|
||||
@ -646,7 +709,6 @@ void qpdf_set_r6_encryption_parameters(
|
||||
qpdf_r3_print_e print, qpdf_r3_modify_e modify,
|
||||
QPDF_BOOL encrypt_metadata)
|
||||
{
|
||||
QTC::TC("qpdf", "qpdf-c called qpdf_set_r6_encryption_parameters");
|
||||
qpdf->qpdf_writer->setR6EncryptionParameters(
|
||||
user_password, owner_password,
|
||||
allow_accessibility, allow_extract, print, modify,
|
||||
|
@ -303,9 +303,10 @@ static void test12(char const* infile,
|
||||
qpdf_read(qpdf, infile, password);
|
||||
qpdf_init_write(qpdf, outfile);
|
||||
qpdf_set_static_ID(qpdf, QPDF_TRUE);
|
||||
qpdf_set_r3_encryption_parameters(
|
||||
qpdf_set_r3_encryption_parameters2(
|
||||
qpdf, "user2", "owner2", QPDF_TRUE, QPDF_TRUE,
|
||||
qpdf_r3p_low, qpdf_r3m_all);
|
||||
QPDF_TRUE, QPDF_TRUE, QPDF_TRUE, QPDF_TRUE,
|
||||
qpdf_r3p_low);
|
||||
qpdf_write(qpdf);
|
||||
report_errors();
|
||||
}
|
||||
@ -350,9 +351,10 @@ static void test15(char const* infile,
|
||||
qpdf_init_write(qpdf, outfile);
|
||||
qpdf_set_static_ID(qpdf, QPDF_TRUE);
|
||||
qpdf_set_static_aes_IV(qpdf, QPDF_TRUE);
|
||||
qpdf_set_r4_encryption_parameters(
|
||||
qpdf_set_r4_encryption_parameters2(
|
||||
qpdf, "user2", "owner2", QPDF_TRUE, QPDF_TRUE,
|
||||
qpdf_r3p_low, qpdf_r3m_all, QPDF_TRUE, QPDF_TRUE);
|
||||
QPDF_TRUE, QPDF_TRUE, QPDF_TRUE, QPDF_TRUE,
|
||||
qpdf_r3p_low, QPDF_TRUE, QPDF_TRUE);
|
||||
qpdf_write(qpdf);
|
||||
report_errors();
|
||||
}
|
||||
@ -405,9 +407,10 @@ static void test17(char const* infile,
|
||||
qpdf_init_write(qpdf, outfile);
|
||||
qpdf_set_static_ID(qpdf, QPDF_TRUE);
|
||||
qpdf_set_static_aes_IV(qpdf, QPDF_TRUE);
|
||||
qpdf_set_r5_encryption_parameters(
|
||||
qpdf_set_r5_encryption_parameters2(
|
||||
qpdf, "user3", "owner3", QPDF_TRUE, QPDF_TRUE,
|
||||
qpdf_r3p_low, qpdf_r3m_all, QPDF_TRUE);
|
||||
QPDF_TRUE, QPDF_TRUE, QPDF_TRUE, QPDF_TRUE,
|
||||
qpdf_r3p_low, QPDF_TRUE);
|
||||
qpdf_write(qpdf);
|
||||
report_errors();
|
||||
}
|
||||
@ -421,9 +424,10 @@ static void test18(char const* infile,
|
||||
qpdf_init_write(qpdf, outfile);
|
||||
qpdf_set_static_ID(qpdf, QPDF_TRUE);
|
||||
qpdf_set_static_aes_IV(qpdf, QPDF_TRUE);
|
||||
qpdf_set_r6_encryption_parameters(
|
||||
qpdf_set_r6_encryption_parameters2(
|
||||
qpdf, "user4", "owner4", QPDF_TRUE, QPDF_TRUE,
|
||||
qpdf_r3p_low, qpdf_r3m_all, QPDF_TRUE);
|
||||
QPDF_TRUE, QPDF_TRUE, QPDF_TRUE, QPDF_TRUE,
|
||||
qpdf_r3p_low, QPDF_TRUE);
|
||||
qpdf_write(qpdf);
|
||||
report_errors();
|
||||
}
|
||||
|
58
qpdf/qpdf.cc
58
qpdf/qpdf.cc
@ -80,8 +80,11 @@ struct Options
|
||||
r2_annotate(true),
|
||||
r3_accessibility(true),
|
||||
r3_extract(true),
|
||||
r3_assemble(true),
|
||||
r3_annotate_and_form(true),
|
||||
r3_form_filling(true),
|
||||
r3_modify_other(true),
|
||||
r3_print(qpdf_r3p_full),
|
||||
r3_modify(qpdf_r3m_all),
|
||||
force_V4(false),
|
||||
force_R5(false),
|
||||
cleartext_metadata(false),
|
||||
@ -160,8 +163,11 @@ struct Options
|
||||
bool r2_annotate;
|
||||
bool r3_accessibility;
|
||||
bool r3_extract;
|
||||
bool r3_assemble;
|
||||
bool r3_annotate_and_form;
|
||||
bool r3_form_filling;
|
||||
bool r3_modify_other;
|
||||
qpdf_r3_print_e r3_print;
|
||||
qpdf_r3_modify_e r3_modify;
|
||||
bool force_V4;
|
||||
bool force_R5;
|
||||
bool cleartext_metadata;
|
||||
@ -1863,23 +1869,38 @@ ArgParser::arg128Modify(char* parameter)
|
||||
{
|
||||
if (strcmp(parameter, "all") == 0)
|
||||
{
|
||||
o.r3_modify = qpdf_r3m_all;
|
||||
o.r3_assemble = true;
|
||||
o.r3_annotate_and_form = true;
|
||||
o.r3_form_filling = true;
|
||||
o.r3_modify_other = true;
|
||||
}
|
||||
else if (strcmp(parameter, "annotate") == 0)
|
||||
{
|
||||
o.r3_modify = qpdf_r3m_annotate;
|
||||
o.r3_assemble = true;
|
||||
o.r3_annotate_and_form = true;
|
||||
o.r3_form_filling = true;
|
||||
o.r3_modify_other = false;
|
||||
}
|
||||
else if (strcmp(parameter, "form") == 0)
|
||||
{
|
||||
o.r3_modify = qpdf_r3m_form;
|
||||
o.r3_assemble = true;
|
||||
o.r3_annotate_and_form = false;
|
||||
o.r3_form_filling = true;
|
||||
o.r3_modify_other = false;
|
||||
}
|
||||
else if (strcmp(parameter, "assembly") == 0)
|
||||
{
|
||||
o.r3_modify = qpdf_r3m_assembly;
|
||||
o.r3_assemble = true;
|
||||
o.r3_annotate_and_form = false;
|
||||
o.r3_form_filling = false;
|
||||
o.r3_modify_other = false;
|
||||
}
|
||||
else if (strcmp(parameter, "none") == 0)
|
||||
{
|
||||
o.r3_modify = qpdf_r3m_none;
|
||||
o.r3_assemble = false;
|
||||
o.r3_annotate_and_form = false;
|
||||
o.r3_form_filling = false;
|
||||
o.r3_modify_other = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -4030,25 +4051,34 @@ static void set_encryption_options(QPDF& pdf, Options& o, QPDFWriter& w)
|
||||
case 3:
|
||||
w.setR3EncryptionParameters(
|
||||
o.user_password.c_str(), o.owner_password.c_str(),
|
||||
o.r3_accessibility, o.r3_extract, o.r3_print, o.r3_modify);
|
||||
o.r3_accessibility, o.r3_extract,
|
||||
o.r3_assemble, o.r3_annotate_and_form,
|
||||
o.r3_form_filling, o.r3_modify_other,
|
||||
o.r3_print);
|
||||
break;
|
||||
case 4:
|
||||
w.setR4EncryptionParameters(
|
||||
o.user_password.c_str(), o.owner_password.c_str(),
|
||||
o.r3_accessibility, o.r3_extract, o.r3_print, o.r3_modify,
|
||||
!o.cleartext_metadata, o.use_aes);
|
||||
o.r3_accessibility, o.r3_extract,
|
||||
o.r3_assemble, o.r3_annotate_and_form,
|
||||
o.r3_form_filling, o.r3_modify_other,
|
||||
o.r3_print, !o.cleartext_metadata, o.use_aes);
|
||||
break;
|
||||
case 5:
|
||||
w.setR5EncryptionParameters(
|
||||
o.user_password.c_str(), o.owner_password.c_str(),
|
||||
o.r3_accessibility, o.r3_extract, o.r3_print, o.r3_modify,
|
||||
!o.cleartext_metadata);
|
||||
o.r3_accessibility, o.r3_extract,
|
||||
o.r3_assemble, o.r3_annotate_and_form,
|
||||
o.r3_form_filling, o.r3_modify_other,
|
||||
o.r3_print, !o.cleartext_metadata);
|
||||
break;
|
||||
case 6:
|
||||
w.setR6EncryptionParameters(
|
||||
o.user_password.c_str(), o.owner_password.c_str(),
|
||||
o.r3_accessibility, o.r3_extract, o.r3_print, o.r3_modify,
|
||||
!o.cleartext_metadata);
|
||||
o.r3_accessibility, o.r3_extract,
|
||||
o.r3_assemble, o.r3_annotate_and_form,
|
||||
o.r3_form_filling, o.r3_modify_other,
|
||||
o.r3_print, !o.cleartext_metadata);
|
||||
break;
|
||||
default:
|
||||
throw std::logic_error("bad encryption R value");
|
||||
|
Loading…
Reference in New Issue
Block a user