Commit 3101955ac0f7f3818dca53d285f5ccd60ccdddea
1 parent
68447bb5
Add V5 parameters to EncryptionData
Showing
4 changed files
with
62 additions
and
4 deletions
include/qpdf/QPDF.hh
| @@ -230,6 +230,8 @@ class QPDF | @@ -230,6 +230,8 @@ class QPDF | ||
| 230 | // This class holds data read from the encryption dictionary. | 230 | // This class holds data read from the encryption dictionary. |
| 231 | EncryptionData(int V, int R, int Length_bytes, int P, | 231 | EncryptionData(int V, int R, int Length_bytes, int P, |
| 232 | std::string const& O, std::string const& U, | 232 | std::string const& O, std::string const& U, |
| 233 | + std::string const& OE, std::string const& UE, | ||
| 234 | + std::string const& Perms, | ||
| 233 | std::string const& id1, bool encrypt_metadata) : | 235 | std::string const& id1, bool encrypt_metadata) : |
| 234 | V(V), | 236 | V(V), |
| 235 | R(R), | 237 | R(R), |
| @@ -237,6 +239,9 @@ class QPDF | @@ -237,6 +239,9 @@ class QPDF | ||
| 237 | P(P), | 239 | P(P), |
| 238 | O(O), | 240 | O(O), |
| 239 | U(U), | 241 | U(U), |
| 242 | + OE(OE), | ||
| 243 | + UE(UE), | ||
| 244 | + Perms(Perms), | ||
| 240 | id1(id1), | 245 | id1(id1), |
| 241 | encrypt_metadata(encrypt_metadata) | 246 | encrypt_metadata(encrypt_metadata) |
| 242 | { | 247 | { |
| @@ -248,11 +253,19 @@ class QPDF | @@ -248,11 +253,19 @@ class QPDF | ||
| 248 | int getP() const; | 253 | int getP() const; |
| 249 | std::string const& getO() const; | 254 | std::string const& getO() const; |
| 250 | std::string const& getU() const; | 255 | std::string const& getU() const; |
| 256 | + std::string const& getOE() const; | ||
| 257 | + std::string const& getUE() const; | ||
| 258 | + std::string const& getPerms() const; | ||
| 251 | std::string const& getId1() const; | 259 | std::string const& getId1() const; |
| 252 | bool getEncryptMetadata() const; | 260 | bool getEncryptMetadata() const; |
| 253 | 261 | ||
| 254 | void setO(std::string const&); | 262 | void setO(std::string const&); |
| 255 | void setU(std::string const&); | 263 | void setU(std::string const&); |
| 264 | + void setV5EncryptionParameters(std::string const& O, | ||
| 265 | + std::string const& OE, | ||
| 266 | + std::string const& U, | ||
| 267 | + std::string const& UE, | ||
| 268 | + std::string const& Perms); | ||
| 256 | 269 | ||
| 257 | private: | 270 | private: |
| 258 | EncryptionData(EncryptionData const&); | 271 | EncryptionData(EncryptionData const&); |
| @@ -264,6 +277,9 @@ class QPDF | @@ -264,6 +277,9 @@ class QPDF | ||
| 264 | int P; | 277 | int P; |
| 265 | std::string O; | 278 | std::string O; |
| 266 | std::string U; | 279 | std::string U; |
| 280 | + std::string OE; | ||
| 281 | + std::string UE; | ||
| 282 | + std::string Perms; | ||
| 267 | std::string id1; | 283 | std::string id1; |
| 268 | bool encrypt_metadata; | 284 | bool encrypt_metadata; |
| 269 | }; | 285 | }; |
include/qpdf/QPDFWriter.hh
| @@ -295,6 +295,7 @@ class QPDFWriter | @@ -295,6 +295,7 @@ class QPDFWriter | ||
| 295 | void setEncryptionParametersInternal( | 295 | void setEncryptionParametersInternal( |
| 296 | int V, int R, int key_len, long P, | 296 | int V, int R, int key_len, long P, |
| 297 | std::string const& O, std::string const& U, | 297 | std::string const& O, std::string const& U, |
| 298 | + std::string const& OE, std::string const& UE, std::string const& Perms, | ||
| 298 | std::string const& id1, std::string const& user_password); | 299 | std::string const& id1, std::string const& user_password); |
| 299 | void setDataKey(int objid); | 300 | void setDataKey(int objid); |
| 300 | int openObject(int objid = 0); | 301 | int openObject(int objid = 0); |
libqpdf/QPDFWriter.cc
| @@ -406,7 +406,7 @@ QPDFWriter::setEncryptionParameters( | @@ -406,7 +406,7 @@ QPDFWriter::setEncryptionParameters( | ||
| 406 | user_password, owner_password, V, R, key_len, P, | 406 | user_password, owner_password, V, R, key_len, P, |
| 407 | this->encrypt_metadata, this->id1, O, U); | 407 | this->encrypt_metadata, this->id1, O, U); |
| 408 | setEncryptionParametersInternal( | 408 | setEncryptionParametersInternal( |
| 409 | - V, R, key_len, P, O, U, this->id1, user_password); | 409 | + V, R, key_len, P, O, U, "", "", "", this->id1, user_password); |
| 410 | } | 410 | } |
| 411 | 411 | ||
| 412 | void | 412 | void |
| @@ -467,6 +467,9 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf) | @@ -467,6 +467,9 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf) | ||
| 467 | encrypt.getKey("/P").getIntValue(), | 467 | encrypt.getKey("/P").getIntValue(), |
| 468 | encrypt.getKey("/O").getStringValue(), | 468 | encrypt.getKey("/O").getStringValue(), |
| 469 | encrypt.getKey("/U").getStringValue(), | 469 | encrypt.getKey("/U").getStringValue(), |
| 470 | + "", // XXXX OE | ||
| 471 | + "", // XXXX UE | ||
| 472 | + "", // XXXX Perms | ||
| 470 | this->id1, // this->id1 == the other file's id1 | 473 | this->id1, // this->id1 == the other file's id1 |
| 471 | qpdf.getPaddedUserPassword()); | 474 | qpdf.getPaddedUserPassword()); |
| 472 | } | 475 | } |
| @@ -569,8 +572,11 @@ void | @@ -569,8 +572,11 @@ void | ||
| 569 | QPDFWriter::setEncryptionParametersInternal( | 572 | QPDFWriter::setEncryptionParametersInternal( |
| 570 | int V, int R, int key_len, long P, | 573 | int V, int R, int key_len, long P, |
| 571 | std::string const& O, std::string const& U, | 574 | std::string const& O, std::string const& U, |
| 575 | + std::string const& OE, std::string const& UE, std::string const& Perms, | ||
| 572 | std::string const& id1, std::string const& user_password) | 576 | std::string const& id1, std::string const& user_password) |
| 573 | { | 577 | { |
| 578 | + // XXXX OE, UE, Perms, V=5 | ||
| 579 | + | ||
| 574 | encryption_dictionary["/Filter"] = "/Standard"; | 580 | encryption_dictionary["/Filter"] = "/Standard"; |
| 575 | encryption_dictionary["/V"] = QUtil::int_to_string(V); | 581 | encryption_dictionary["/V"] = QUtil::int_to_string(V); |
| 576 | encryption_dictionary["/Length"] = QUtil::int_to_string(key_len * 8); | 582 | encryption_dictionary["/Length"] = QUtil::int_to_string(key_len * 8); |
| @@ -606,7 +612,7 @@ QPDFWriter::setEncryptionParametersInternal( | @@ -606,7 +612,7 @@ QPDFWriter::setEncryptionParametersInternal( | ||
| 606 | 612 | ||
| 607 | this->encrypted = true; | 613 | this->encrypted = true; |
| 608 | QPDF::EncryptionData encryption_data( | 614 | QPDF::EncryptionData encryption_data( |
| 609 | - V, R, key_len, P, O, U, id1, this->encrypt_metadata); | 615 | + V, R, key_len, P, O, U, OE, UE, Perms, id1, this->encrypt_metadata); |
| 610 | this->encryption_key = QPDF::compute_encryption_key( | 616 | this->encryption_key = QPDF::compute_encryption_key( |
| 611 | user_password, encryption_data); | 617 | user_password, encryption_data); |
| 612 | } | 618 | } |
libqpdf/QPDF_encryption.cc
| @@ -63,6 +63,24 @@ QPDF::EncryptionData::getU() const | @@ -63,6 +63,24 @@ QPDF::EncryptionData::getU() const | ||
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | std::string const& | 65 | std::string const& |
| 66 | +QPDF::EncryptionData::getOE() const | ||
| 67 | +{ | ||
| 68 | + return this->OE; | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | +std::string const& | ||
| 72 | +QPDF::EncryptionData::getUE() const | ||
| 73 | +{ | ||
| 74 | + return this->UE; | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +std::string const& | ||
| 78 | +QPDF::EncryptionData::getPerms() const | ||
| 79 | +{ | ||
| 80 | + return this->Perms; | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +std::string const& | ||
| 66 | QPDF::EncryptionData::getId1() const | 84 | QPDF::EncryptionData::getId1() const |
| 67 | { | 85 | { |
| 68 | return this->id1; | 86 | return this->id1; |
| @@ -86,6 +104,21 @@ QPDF::EncryptionData::setU(std::string const& U) | @@ -86,6 +104,21 @@ QPDF::EncryptionData::setU(std::string const& U) | ||
| 86 | this->U = U; | 104 | this->U = U; |
| 87 | } | 105 | } |
| 88 | 106 | ||
| 107 | +void | ||
| 108 | +QPDF::EncryptionData::setV5EncryptionParameters( | ||
| 109 | + std::string const& O, | ||
| 110 | + std::string const& OE, | ||
| 111 | + std::string const& U, | ||
| 112 | + std::string const& UE, | ||
| 113 | + std::string const& Perms) | ||
| 114 | +{ | ||
| 115 | + this->O = O; | ||
| 116 | + this->OE = OE; | ||
| 117 | + this->U = U; | ||
| 118 | + this->UE = UE; | ||
| 119 | + this->Perms = Perms; | ||
| 120 | +} | ||
| 121 | + | ||
| 89 | static void | 122 | static void |
| 90 | pad_or_truncate_password(std::string const& password, char k1[key_bytes]) | 123 | pad_or_truncate_password(std::string const& password, char k1[key_bytes]) |
| 91 | { | 124 | { |
| @@ -557,7 +590,8 @@ QPDF::initializeEncryption() | @@ -557,7 +590,8 @@ QPDF::initializeEncryption() | ||
| 557 | " a bug report that includes this file."); | 590 | " a bug report that includes this file."); |
| 558 | } | 591 | } |
| 559 | } | 592 | } |
| 560 | - EncryptionData data(V, R, Length / 8, P, O, U, id1, this->encrypt_metadata); | 593 | + EncryptionData data(V, R, Length / 8, P, O, U, "", "", "", |
| 594 | + id1, this->encrypt_metadata); | ||
| 561 | if (check_owner_password( | 595 | if (check_owner_password( |
| 562 | this->user_password, this->provided_password, data)) | 596 | this->user_password, this->provided_password, data)) |
| 563 | { | 597 | { |
| @@ -779,7 +813,8 @@ QPDF::compute_encryption_O_U( | @@ -779,7 +813,8 @@ QPDF::compute_encryption_O_U( | ||
| 779 | int V, int R, int key_len, int P, bool encrypt_metadata, | 813 | int V, int R, int key_len, int P, bool encrypt_metadata, |
| 780 | std::string const& id1, std::string& O, std::string& U) | 814 | std::string const& id1, std::string& O, std::string& U) |
| 781 | { | 815 | { |
| 782 | - EncryptionData data(V, R, key_len, P, "", "", id1, encrypt_metadata); | 816 | + EncryptionData data(V, R, key_len, P, "", "", "", "", "", |
| 817 | + id1, encrypt_metadata); | ||
| 783 | data.setO(compute_O_value(user_password, owner_password, data)); | 818 | data.setO(compute_O_value(user_password, owner_password, data)); |
| 784 | O = data.getO(); | 819 | O = data.getO(); |
| 785 | data.setU(compute_U_value(user_password, data)); | 820 | data.setU(compute_U_value(user_password, data)); |