Commit 3101955ac0f7f3818dca53d285f5ccd60ccdddea

Authored by Jay Berkenbilt
1 parent 68447bb5

Add V5 parameters to EncryptionData

include/qpdf/QPDF.hh
... ... @@ -230,6 +230,8 @@ class QPDF
230 230 // This class holds data read from the encryption dictionary.
231 231 EncryptionData(int V, int R, int Length_bytes, int P,
232 232 std::string const& O, std::string const& U,
  233 + std::string const& OE, std::string const& UE,
  234 + std::string const& Perms,
233 235 std::string const& id1, bool encrypt_metadata) :
234 236 V(V),
235 237 R(R),
... ... @@ -237,6 +239,9 @@ class QPDF
237 239 P(P),
238 240 O(O),
239 241 U(U),
  242 + OE(OE),
  243 + UE(UE),
  244 + Perms(Perms),
240 245 id1(id1),
241 246 encrypt_metadata(encrypt_metadata)
242 247 {
... ... @@ -248,11 +253,19 @@ class QPDF
248 253 int getP() const;
249 254 std::string const& getO() const;
250 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 259 std::string const& getId1() const;
252 260 bool getEncryptMetadata() const;
253 261  
254 262 void setO(std::string const&);
255 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 270 private:
258 271 EncryptionData(EncryptionData const&);
... ... @@ -264,6 +277,9 @@ class QPDF
264 277 int P;
265 278 std::string O;
266 279 std::string U;
  280 + std::string OE;
  281 + std::string UE;
  282 + std::string Perms;
267 283 std::string id1;
268 284 bool encrypt_metadata;
269 285 };
... ...
include/qpdf/QPDFWriter.hh
... ... @@ -295,6 +295,7 @@ class QPDFWriter
295 295 void setEncryptionParametersInternal(
296 296 int V, int R, int key_len, long P,
297 297 std::string const& O, std::string const& U,
  298 + std::string const& OE, std::string const& UE, std::string const& Perms,
298 299 std::string const& id1, std::string const& user_password);
299 300 void setDataKey(int objid);
300 301 int openObject(int objid = 0);
... ...
libqpdf/QPDFWriter.cc
... ... @@ -406,7 +406,7 @@ QPDFWriter::setEncryptionParameters(
406 406 user_password, owner_password, V, R, key_len, P,
407 407 this->encrypt_metadata, this->id1, O, U);
408 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 412 void
... ... @@ -467,6 +467,9 @@ QPDFWriter::copyEncryptionParameters(QPDF& qpdf)
467 467 encrypt.getKey("/P").getIntValue(),
468 468 encrypt.getKey("/O").getStringValue(),
469 469 encrypt.getKey("/U").getStringValue(),
  470 + "", // XXXX OE
  471 + "", // XXXX UE
  472 + "", // XXXX Perms
470 473 this->id1, // this->id1 == the other file's id1
471 474 qpdf.getPaddedUserPassword());
472 475 }
... ... @@ -569,8 +572,11 @@ void
569 572 QPDFWriter::setEncryptionParametersInternal(
570 573 int V, int R, int key_len, long P,
571 574 std::string const& O, std::string const& U,
  575 + std::string const& OE, std::string const& UE, std::string const& Perms,
572 576 std::string const& id1, std::string const& user_password)
573 577 {
  578 + // XXXX OE, UE, Perms, V=5
  579 +
574 580 encryption_dictionary["/Filter"] = "/Standard";
575 581 encryption_dictionary["/V"] = QUtil::int_to_string(V);
576 582 encryption_dictionary["/Length"] = QUtil::int_to_string(key_len * 8);
... ... @@ -606,7 +612,7 @@ QPDFWriter::setEncryptionParametersInternal(
606 612  
607 613 this->encrypted = true;
608 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 616 this->encryption_key = QPDF::compute_encryption_key(
611 617 user_password, encryption_data);
612 618 }
... ...
libqpdf/QPDF_encryption.cc
... ... @@ -63,6 +63,24 @@ QPDF::EncryptionData::getU() const
63 63 }
64 64  
65 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 84 QPDF::EncryptionData::getId1() const
67 85 {
68 86 return this->id1;
... ... @@ -86,6 +104,21 @@ QPDF::EncryptionData::setU(std::string const& U)
86 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 122 static void
90 123 pad_or_truncate_password(std::string const& password, char k1[key_bytes])
91 124 {
... ... @@ -557,7 +590,8 @@ QPDF::initializeEncryption()
557 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 595 if (check_owner_password(
562 596 this->user_password, this->provided_password, data))
563 597 {
... ... @@ -779,7 +813,8 @@ QPDF::compute_encryption_O_U(
779 813 int V, int R, int key_len, int P, bool encrypt_metadata,
780 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 818 data.setO(compute_O_value(user_password, owner_password, data));
784 819 O = data.getO();
785 820 data.setU(compute_U_value(user_password, data));
... ...