From 569d74d36ba287b6951687ee1bdea45ae19091f8 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sun, 14 Jan 2018 10:17:17 -0500 Subject: Allow raw encryption key to be specified Add options to enable the raw encryption key to be directly shown or specified. Thanks to Didier Stevens for the idea and contribution of one implementation of this idea. --- libqpdf/QPDF.cc | 7 +++++++ libqpdf/QPDF_encryption.cc | 14 +++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'libqpdf') diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 33847a45..51a87d66 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -75,6 +75,7 @@ QPDF::QPDFVersion() } QPDF::Members::Members() : + provided_password_is_hex_key(false), encrypted(false), encryption_initialized(false), ignore_xref_streams(false), @@ -171,6 +172,12 @@ QPDF::processInputSource(PointerHolder source, parse(password); } +void +QPDF::setPasswordIsHexKey(bool val) +{ + this->m->provided_password_is_hex_key = val; +} + void QPDF::emptyPDF() { diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc index a2445b61..fd717c35 100644 --- a/libqpdf/QPDF_encryption.cc +++ b/libqpdf/QPDF_encryption.cc @@ -1007,8 +1007,12 @@ QPDF::initializeEncryption() EncryptionData data(V, R, Length / 8, P, O, U, OE, UE, Perms, id1, this->m->encrypt_metadata); - if (check_owner_password( - this->m->user_password, this->m->provided_password, data)) + if (this->m->provided_password_is_hex_key) + { + // ignore passwords in file + } + else if (check_owner_password( + this->m->user_password, this->m->provided_password, data)) { // password supplied was owner password; user_password has // been initialized for V < 5 @@ -1023,7 +1027,11 @@ QPDF::initializeEncryption() "", 0, "invalid password"); } - if (V < 5) + if (this->m->provided_password_is_hex_key) + { + this->m->encryption_key = QUtil::hex_decode(this->m->provided_password); + } + else if (V < 5) { // For V < 5, the user password is encrypted with the owner // password, and the user password is always used for -- cgit v1.2.3-54-g00ecf