1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-23 20:27:35 +00:00

LibPDF: Plumb OE, UE, Perms values to StandardSecurityHandler

This commit is contained in:
Nico Weber 2023-07-19 21:25:37 -04:00 committed by Andreas Kling
parent 57768325cc
commit f8a3022ca2
3 changed files with 23 additions and 3 deletions

View file

@ -111,6 +111,7 @@
A(Names) \ A(Names) \
A(Next) \ A(Next) \
A(O) \ A(O) \
A(OE) \
A(OP) \ A(OP) \
A(OPM) \ A(OPM) \
A(Ordering) \ A(Ordering) \
@ -119,6 +120,7 @@
A(Pages) \ A(Pages) \
A(Parent) \ A(Parent) \
A(Pattern) \ A(Pattern) \
A(Perms) \
A(Predictor) \ A(Predictor) \
A(Prev) \ A(Prev) \
A(Producer) \ A(Producer) \
@ -146,6 +148,7 @@
A(Type) \ A(Type) \
A(Type1C) \ A(Type1C) \
A(U) \ A(U) \
A(UE) \
A(UCR) \ A(UCR) \
A(UseBlackPTComp) \ A(UseBlackPTComp) \
A(UserUnit) \ A(UserUnit) \

View file

@ -166,7 +166,12 @@ PDFErrorOr<NonnullRefPtr<StandardSecurityHandler>> StandardSecurityHandler::crea
if (encryption_dict->contains(CommonNames::EncryptMetadata)) if (encryption_dict->contains(CommonNames::EncryptMetadata))
encryption_dict->get_value(CommonNames::EncryptMetadata).get<bool>(); encryption_dict->get_value(CommonNames::EncryptMetadata).get<bool>();
DeprecatedString oe, ue, perms;
if (v >= 5) { if (v >= 5) {
oe = TRY(encryption_dict->get_string(document, CommonNames::OE))->string();
ue = TRY(encryption_dict->get_string(document, CommonNames::UE))->string();
perms = TRY(encryption_dict->get_string(document, CommonNames::Perms))->string();
// O and U are 48 bytes for V == 5, but some files pad them with nul bytes to 127 bytes. So trim them, if necessary. // O and U are 48 bytes for V == 5, but some files pad them with nul bytes to 127 bytes. So trim them, if necessary.
if (o.length() > 48) if (o.length() > 48)
o = o.substring(0, 48); o = o.substring(0, 48);
@ -175,18 +180,27 @@ PDFErrorOr<NonnullRefPtr<StandardSecurityHandler>> StandardSecurityHandler::crea
if (o.length() != 48) if (o.length() != 48)
return Error(Error::Type::Parse, "Invalid O size"); return Error(Error::Type::Parse, "Invalid O size");
if (oe.length() != 32)
return Error(Error::Type::Parse, "Invalid OE size");
if (u.length() != 48) if (u.length() != 48)
return Error(Error::Type::Parse, "Invalid U size"); return Error(Error::Type::Parse, "Invalid U size");
if (ue.length() != 32)
return Error(Error::Type::Parse, "Invalid UE size");
if (perms.length() != 16)
return Error(Error::Type::Parse, "Invalid Perms size");
} }
return adopt_ref(*new StandardSecurityHandler(document, revision, o, u, p, encrypt_metadata, length, method)); return adopt_ref(*new StandardSecurityHandler(document, revision, o, oe, u, ue, perms, p, encrypt_metadata, length, method));
} }
StandardSecurityHandler::StandardSecurityHandler(Document* document, size_t revision, DeprecatedString const& o_entry, DeprecatedString const& u_entry, u32 flags, bool encrypt_metadata, size_t length, CryptFilterMethod method) StandardSecurityHandler::StandardSecurityHandler(Document* document, size_t revision, DeprecatedString const& o_entry, DeprecatedString const& oe_entry, DeprecatedString const& u_entry, DeprecatedString const& ue_entry, DeprecatedString const& perms_entry, u32 flags, bool encrypt_metadata, size_t length, CryptFilterMethod method)
: m_document(document) : m_document(document)
, m_revision(revision) , m_revision(revision)
, m_o_entry(o_entry) , m_o_entry(o_entry)
, m_oe_entry(oe_entry)
, m_u_entry(u_entry) , m_u_entry(u_entry)
, m_ue_entry(ue_entry)
, m_perms_entry(perms_entry)
, m_flags(flags) , m_flags(flags)
, m_encrypt_metadata(encrypt_metadata) , m_encrypt_metadata(encrypt_metadata)
, m_length(length) , m_length(length)

View file

@ -39,7 +39,7 @@ class StandardSecurityHandler : public SecurityHandler {
public: public:
static PDFErrorOr<NonnullRefPtr<StandardSecurityHandler>> create(Document*, NonnullRefPtr<DictObject> encryption_dict); static PDFErrorOr<NonnullRefPtr<StandardSecurityHandler>> create(Document*, NonnullRefPtr<DictObject> encryption_dict);
StandardSecurityHandler(Document*, size_t revision, DeprecatedString const& o_entry, DeprecatedString const& u_entry, u32 flags, bool encrypt_metadata, size_t length, CryptFilterMethod method); StandardSecurityHandler(Document*, size_t revision, DeprecatedString const& o_entry, DeprecatedString const& oe_entry, DeprecatedString const& u_entry, DeprecatedString const& ue_entry, DeprecatedString const& perms, u32 flags, bool encrypt_metadata, size_t length, CryptFilterMethod method);
~StandardSecurityHandler() override = default; ~StandardSecurityHandler() override = default;
@ -74,7 +74,10 @@ private:
size_t m_revision; size_t m_revision;
Optional<ByteBuffer> m_encryption_key; Optional<ByteBuffer> m_encryption_key;
DeprecatedString m_o_entry; DeprecatedString m_o_entry;
DeprecatedString m_oe_entry;
DeprecatedString m_u_entry; DeprecatedString m_u_entry;
DeprecatedString m_ue_entry;
DeprecatedString m_perms_entry;
u32 m_flags; u32 m_flags;
bool m_encrypt_metadata; bool m_encrypt_metadata;
size_t m_length; size_t m_length;