Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdf_security_handler_embeddertest.cpp
Go to the documentation of this file.
1// Copyright 2016 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <string>
6
7#include "build/build_config.h"
8#include "core/fpdfapi/parser/cpdf_dictionary.h"
9#include "core/fpdfapi/parser/cpdf_document.h"
10#include "core/fpdfapi/parser/cpdf_parser.h"
11#include "core/fxcrt/fx_system.h"
12#include "core/fxge/cfx_defaultrenderdevice.h"
13#include "public/cpp/fpdf_scopers.h"
14#include "public/fpdf_edit.h"
15#include "public/fpdf_save.h"
16#include "public/fpdfview.h"
17#include "testing/embedder_test.h"
18#include "testing/embedder_test_constants.h"
19#include "testing/gtest/include/gtest/gtest.h"
20
21namespace {
22
23const char kAgeUTF8[] =
24 "\xc3\xa2"
25 "ge";
26const char kAgeLatin1[] =
27 "\xe2"
28 "ge";
29
30const char kHotelUTF8[] =
31 "h"
32 "\xc3\xb4"
33 "tel";
34const char kHotelLatin1[] =
35 "h"
36 "\xf4"
37 "tel";
38
39} // namespace
40
42 protected:
44 const char* password) {
45 ASSERT_TRUE(OpenDocumentWithPassword(filename, password));
46 FPDF_PAGE page = LoadPage(0);
47 VerifyHelloWorldPage(page);
48 UnloadPage(page);
49 }
50
51 void VerifySavedHelloWorldDocumentWithPassword(const char* password) {
52 ASSERT_TRUE(OpenSavedDocumentWithPassword(password));
53 FPDF_PAGE page = LoadSavedPage(0);
54 VerifyHelloWorldPage(page);
55 CloseSavedPage(page);
57 }
58
60 ASSERT_TRUE(OpenSavedDocumentWithPassword(password));
61 FPDF_PAGE page = LoadSavedPage(0);
62 VerifyModifiedHelloWorldPage(page);
63 CloseSavedPage(page);
65 }
66
68 // This is cheating slightly to avoid a layering violation, since this file
69 // cannot include fpdfsdk/cpdfsdk_helpers.h to get access to
70 // CPDFDocumentFromFPDFDocument().
71 CPDF_Document* doc = reinterpret_cast<CPDF_Document*>((document()));
72 ASSERT_TRUE(doc);
73 CPDF_Parser* parser = doc->GetParser();
74 ASSERT_TRUE(parser);
75 CPDF_Dictionary* trailer = parser->GetMutableTrailerForTesting();
76 ASSERT_TRUE(trailer);
77 ASSERT_TRUE(trailer->RemoveFor("ID"));
78 }
79
81 FPDF_PAGE page = LoadPage(0);
82 {
83 ScopedFPDFPageObject goodbye_object(FPDFPage_GetObject(page, 1));
84 ASSERT_TRUE(goodbye_object);
85 ASSERT_TRUE(FPDFPage_RemoveObject(page, goodbye_object.get()));
86 }
87 ASSERT_TRUE(FPDFPage_GenerateContent(page));
88 VerifyModifiedHelloWorldPage(page);
89 UnloadPage(page);
90 }
91
92 private:
93 void VerifyHelloWorldPage(FPDF_PAGE page) {
94 ASSERT_TRUE(page);
95
96 ScopedFPDFBitmap page_bitmap = RenderPage(page);
97 CompareBitmap(page_bitmap.get(), 200, 200, pdfium::HelloWorldChecksum());
98 }
99
100 void VerifyModifiedHelloWorldPage(FPDF_PAGE page) {
101 ASSERT_TRUE(page);
102
103 ScopedFPDFBitmap page_bitmap = RenderPage(page);
104 CompareBitmap(page_bitmap.get(), 200, 200,
106 }
107};
108
110 ASSERT_TRUE(OpenDocument("about_blank.pdf"));
111 // parser is missing a security handler, so always results in 0xFFFFFFFF
112 EXPECT_EQ(0xFFFFFFFF, FPDF_GetDocPermissions(document()));
113 EXPECT_EQ(0xFFFFFFFF, FPDF_GetDocUserPermissions(document()));
114}
115
117 ASSERT_TRUE(OpenDocumentWithPassword("about_blank.pdf", "foobar"));
118 // parser is missing a security handler, so always results in 0xFFFFFFFF
119 EXPECT_EQ(0xFFFFFFFF, FPDF_GetDocPermissions(document()));
120 EXPECT_EQ(0xFFFFFFFF, FPDF_GetDocUserPermissions(document()));
121}
122
124 EXPECT_FALSE(OpenDocument("encrypted.pdf"));
125}
126
128 EXPECT_FALSE(OpenDocumentWithPassword("encrypted.pdf", "tiger"));
129}
130
132 ASSERT_TRUE(OpenDocumentWithPassword("encrypted.pdf", "1234"));
133 EXPECT_EQ(0xFFFFF2C0, FPDF_GetDocPermissions(document()));
134 EXPECT_EQ(0xFFFFF2C0, FPDF_GetDocUserPermissions(document()));
135}
136
138 ASSERT_TRUE(OpenDocumentWithPassword("encrypted.pdf", "5678"));
139 EXPECT_EQ(0xFFFFFFFC, FPDF_GetDocPermissions(document()));
140 EXPECT_EQ(0xFFFFF2C0, FPDF_GetDocUserPermissions(document()));
141}
142
144 const char* checksum = []() {
145 if (CFX_DefaultRenderDevice::UseSkiaRenderer()) {
146#if BUILDFLAG(IS_WIN)
147 return "caa4bfda016a9c48a540ff7c6716468c";
148#elif BUILDFLAG(IS_APPLE)
149 return "6c1a242ce886df5cf578401eeeaa1929";
150#else
151 return "ad97491cab71c02f1f4ef5ba0a7b5593";
152#endif
153 }
154#if BUILDFLAG(IS_APPLE)
155 return "2a308e8cc20a6221112c387d122075a8";
156#else
157 return "9fe7eef8e51d15a604001854be6ed1ee";
158#endif // BUILDFLAG(IS_APPLE)
159 }();
160 {
161 ASSERT_TRUE(OpenDocumentWithOptions("encrypted.pdf", "5678",
162 LinearizeOption::kMustLinearize,
163 JavaScriptOption::kEnableJavaScript));
164 FPDF_PAGE page = LoadPage(0);
165 ASSERT_TRUE(page);
166 FPDF_PAGEOBJECT red_rect = FPDFPageObj_CreateNewRect(10, 10, 20, 20);
167 ASSERT_TRUE(red_rect);
168 EXPECT_TRUE(FPDFPageObj_SetFillColor(red_rect, 255, 0, 0, 255));
170 FPDFPage_InsertObject(page, red_rect);
171 ScopedFPDFBitmap bitmap = RenderLoadedPage(page);
172 CompareBitmap(bitmap.get(), 612, 792, checksum);
173 EXPECT_TRUE(FPDFPage_GenerateContent(page));
174 SetWholeFileAvailable();
175 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
176 UnloadPage(page);
177 }
178 std::string new_file = GetString();
179 FPDF_FILEACCESS file_access;
180 memset(&file_access, 0, sizeof(file_access));
181 file_access.m_FileLen = new_file.size();
182 file_access.m_GetBlock = GetBlockFromString;
183 file_access.m_Param = &new_file;
184 EXPECT_FALSE(FPDF_LoadCustomDocument(&file_access, nullptr));
185
186 struct {
187 const char* password;
188 const unsigned long permissions;
189 } tests[] = {{"1234", 0xFFFFF2C0}, {"5678", 0xFFFFFFFC}};
190
191 for (const auto& test : tests) {
192 ASSERT_TRUE(OpenSavedDocumentWithPassword(test.password));
193 FPDF_PAGE page = LoadSavedPage(0);
194 ASSERT_TRUE(page);
195 VerifySavedRendering(page, 612, 792, checksum);
196 EXPECT_EQ(test.permissions, FPDF_GetDocPermissions(saved_document()));
197
198 CloseSavedPage(page);
199 CloseSavedDocument();
200 }
201}
202
204 ASSERT_FALSE(OpenDocument("bug_644.pdf"));
205}
206
208 ASSERT_FALSE(OpenDocumentWithPassword("bug_644.pdf", "tiger"));
209}
210
212 ASSERT_TRUE(OpenDocumentWithPassword("bug_644.pdf", "a"));
213 EXPECT_EQ(0xFFFFFFFC, FPDF_GetDocPermissions(document()));
214}
215
217 ASSERT_TRUE(OpenDocumentWithPassword("bug_644.pdf", "b"));
218 EXPECT_EQ(0xFFFFFFFC, FPDF_GetDocPermissions(document()));
219}
220
221// Should not crash. https://crbug.com/pdfium/1436
223 EXPECT_FALSE(
224 OpenDocumentWithPassword("encrypted_hello_world_r2_bad_okey.pdf", "a"));
225}
226
227// Should not crash. https://crbug.com/pdfium/1436
229 EXPECT_FALSE(
230 OpenDocumentWithPassword("encrypted_hello_world_r3_bad_okey.pdf", "a"));
231}
232
234 // The password is "age", where the 'a' has a circumflex. Encoding the
235 // password as UTF-8 works.
236 OpenAndVerifyHelloWorldDocumentWithPassword("encrypted_hello_world_r2.pdf",
237 kAgeUTF8);
238 EXPECT_EQ(2, FPDF_GetSecurityHandlerRevision(document()));
239 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
240 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
241 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
242 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
243 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
244
245 ClearString();
246 RemoveTrailerIdFromDocument();
247 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
248 // With revision 2 and 3, the owner password is not tied to the document ID in
249 // the trailer, so the owner password entry remains in the copy and is still
250 // valid, even though the document ID has changed.
251 // The user password is tied to the document ID, so without an existing ID,
252 // the user password entry has to be regenerated with the owner password.
253 // Since the user password was not used to decrypt the document, it cannot be
254 // recovered. Thus only verify the owner password, which is now also the user
255 // password.
256 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
257 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
258
259 ClearString();
260 RemoveGoodbyeObject();
261 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
262 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
263 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
264}
265
267 // The same password encoded as Latin-1 also works at revision 2.
268 OpenAndVerifyHelloWorldDocumentWithPassword("encrypted_hello_world_r2.pdf",
269 kAgeLatin1);
270 EXPECT_EQ(2, FPDF_GetSecurityHandlerRevision(document()));
271 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
272 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
273 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
274 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
275 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
276
277 ClearString();
278 RemoveTrailerIdFromDocument();
279 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
280 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
281 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
282
283 ClearString();
284 RemoveGoodbyeObject();
285 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
286 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
287 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
288}
289
291 // Same as OwnerPasswordVersion2UTF8 test above.
292 OpenAndVerifyHelloWorldDocumentWithPassword("encrypted_hello_world_r3.pdf",
293 kAgeUTF8);
294 EXPECT_EQ(3, FPDF_GetSecurityHandlerRevision(document()));
295 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
296 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
297 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
298 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
299 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
300
301 ClearString();
302 RemoveTrailerIdFromDocument();
303 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
304 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
305 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
306
307 ClearString();
308 RemoveGoodbyeObject();
309 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
310 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
311 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
312}
313
315 // Same as OwnerPasswordVersion2Latin1 test above.
316 OpenAndVerifyHelloWorldDocumentWithPassword("encrypted_hello_world_r3.pdf",
317 kAgeLatin1);
318 EXPECT_EQ(3, FPDF_GetSecurityHandlerRevision(document()));
319 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
320 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
321 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
322 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
323 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
324
325 ClearString();
326 RemoveTrailerIdFromDocument();
327 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
328 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
329 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
330
331 ClearString();
332 RemoveGoodbyeObject();
333 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
334 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
335 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
336}
337
339 // Same as OwnerPasswordVersion2UTF8 test above.
340 OpenAndVerifyHelloWorldDocumentWithPassword("encrypted_hello_world_r5.pdf",
341 kAgeUTF8);
342 EXPECT_EQ(5, FPDF_GetSecurityHandlerRevision(document()));
343 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
344 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
345 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
346 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
347 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
348
349 ClearString();
350 RemoveTrailerIdFromDocument();
351 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
352 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
353 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
354 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
355 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
356
357 ClearString();
358 RemoveGoodbyeObject();
359 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
360 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
361 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
362 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
363 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
364}
365
367 // Same as OwnerPasswordVersion2Latin1 test above.
368 OpenAndVerifyHelloWorldDocumentWithPassword("encrypted_hello_world_r5.pdf",
369 kAgeLatin1);
370 EXPECT_EQ(5, FPDF_GetSecurityHandlerRevision(document()));
371 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
372 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
373 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
374 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
375 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
376
377 ClearString();
378 RemoveTrailerIdFromDocument();
379 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
380 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
381 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
382 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
383 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
384
385 ClearString();
386 RemoveGoodbyeObject();
387 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
388 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
389 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
390 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
391 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
392}
393
395 // Same as OwnerPasswordVersion2UTF8 test above.
396 OpenAndVerifyHelloWorldDocumentWithPassword("encrypted_hello_world_r6.pdf",
397 kAgeUTF8);
398 EXPECT_EQ(6, FPDF_GetSecurityHandlerRevision(document()));
399 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
400 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
401 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
402 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
403 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
404
405 ClearString();
406 RemoveTrailerIdFromDocument();
407 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
408 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
409 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
410 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
411 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
412
413 ClearString();
414 RemoveGoodbyeObject();
415 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
416 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
417 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
418 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
419 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
420}
421
423 // Same as OwnerPasswordVersion2Latin1 test above.
424 OpenAndVerifyHelloWorldDocumentWithPassword("encrypted_hello_world_r6.pdf",
425 kAgeLatin1);
426 EXPECT_EQ(6, FPDF_GetSecurityHandlerRevision(document()));
427 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
428 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
429 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
430 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
431 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
432
433 ClearString();
434 RemoveTrailerIdFromDocument();
435 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
436 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
437 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
438 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
439 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
440
441 ClearString();
442 RemoveGoodbyeObject();
443 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
444 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
445 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
446 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
447 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
448}
449
451 // The password is "hotel", where the 'o' has a circumflex. Encoding the
452 // password as UTF-8 works.
453 OpenAndVerifyHelloWorldDocumentWithPassword("encrypted_hello_world_r2.pdf",
454 kHotelUTF8);
455 EXPECT_EQ(2, FPDF_GetSecurityHandlerRevision(document()));
456 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
457 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
458 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
459 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
460 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
461
462 ClearString();
463 RemoveTrailerIdFromDocument();
464 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
465 // Unlike the OwnerPasswordVersion2UTF8 test case, the user password was used
466 // to decrypt the document, so it is available to regenerated the user
467 // password entry. Thus it is possible to verify with both the unmodified
468 // owner password, and the updated user password.
469 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
470 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
471 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
472 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
473
474 ClearString();
475 RemoveGoodbyeObject();
476 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
477 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
478 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
479 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
480 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
481}
482
484 // The same password encoded as Latin-1 also works at revision 2.
485 OpenAndVerifyHelloWorldDocumentWithPassword("encrypted_hello_world_r2.pdf",
486 kHotelLatin1);
487 EXPECT_EQ(2, FPDF_GetSecurityHandlerRevision(document()));
488 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
489 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
490 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
491 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
492 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
493
494 ClearString();
495 RemoveTrailerIdFromDocument();
496 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
497 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
498 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
499 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
500 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
501
502 ClearString();
503 RemoveGoodbyeObject();
504 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
505 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
506 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
507 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
508 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
509}
510
512 // Same as UserPasswordVersion2UTF8 test above.
513 OpenAndVerifyHelloWorldDocumentWithPassword("encrypted_hello_world_r3.pdf",
514 kHotelUTF8);
515 EXPECT_EQ(3, FPDF_GetSecurityHandlerRevision(document()));
516 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
517 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
518 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
519 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
520 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
521
522 ClearString();
523 RemoveTrailerIdFromDocument();
524 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
525 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
526 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
527 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
528 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
529
530 ClearString();
531 RemoveGoodbyeObject();
532 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
533 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
534 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
535 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
536 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
537}
538
540 // Same as UserPasswordVersion2Latin1 test above.
541 OpenAndVerifyHelloWorldDocumentWithPassword("encrypted_hello_world_r3.pdf",
542 kHotelLatin1);
543 EXPECT_EQ(3, FPDF_GetSecurityHandlerRevision(document()));
544 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
545 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
546 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
547 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
548 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
549
550 ClearString();
551 RemoveTrailerIdFromDocument();
552 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
553 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
554 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
555 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
556 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
557
558 ClearString();
559 RemoveGoodbyeObject();
560 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
561 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
562 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
563 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
564 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
565}
566
568 // Same as UserPasswordVersion2UTF8 test above.
569 OpenAndVerifyHelloWorldDocumentWithPassword("encrypted_hello_world_r5.pdf",
570 kHotelUTF8);
571 EXPECT_EQ(5, FPDF_GetSecurityHandlerRevision(document()));
572 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
573 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
574 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
575 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
576 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
577
578 ClearString();
579 RemoveTrailerIdFromDocument();
580 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
581 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
582 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
583 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
584 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
585
586 ClearString();
587 RemoveGoodbyeObject();
588 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
589 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
590 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
591 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
592 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
593}
594
596 // Same as UserPasswordVersion2Latin1 test above.
597 OpenAndVerifyHelloWorldDocumentWithPassword("encrypted_hello_world_r5.pdf",
598 kHotelLatin1);
599 EXPECT_EQ(5, FPDF_GetSecurityHandlerRevision(document()));
600 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
601 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
602 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
603 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
604 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
605
606 ClearString();
607 RemoveTrailerIdFromDocument();
608 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
609 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
610 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
611 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
612 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
613
614 ClearString();
615 RemoveGoodbyeObject();
616 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
617 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
618 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
619 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
620 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
621}
622
624 // Same as UserPasswordVersion2UTF8 test above.
625 OpenAndVerifyHelloWorldDocumentWithPassword("encrypted_hello_world_r6.pdf",
626 kHotelUTF8);
627 EXPECT_EQ(6, FPDF_GetSecurityHandlerRevision(document()));
628 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
629 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
630 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
631 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
632 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
633
634 ClearString();
635 RemoveTrailerIdFromDocument();
636 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
637 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
638 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
639 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
640 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
641
642 ClearString();
643 RemoveGoodbyeObject();
644 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
645 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
646 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
647 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
648 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
649}
650
652 // Same as UserPasswordVersion2Latin1 test above.
653 OpenAndVerifyHelloWorldDocumentWithPassword("encrypted_hello_world_r6.pdf",
654 kHotelLatin1);
655 EXPECT_EQ(6, FPDF_GetSecurityHandlerRevision(document()));
656 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
657 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
658 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
659 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
660 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
661
662 ClearString();
663 RemoveTrailerIdFromDocument();
664 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
665 VerifySavedHelloWorldDocumentWithPassword(kAgeLatin1);
666 VerifySavedHelloWorldDocumentWithPassword(kAgeUTF8);
667 VerifySavedHelloWorldDocumentWithPassword(kHotelLatin1);
668 VerifySavedHelloWorldDocumentWithPassword(kHotelUTF8);
669
670 ClearString();
671 RemoveGoodbyeObject();
672 EXPECT_TRUE(FPDF_SaveAsCopy(document(), this, 0));
673 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeLatin1);
674 VerifySavedModifiedHelloWorldDocumentWithPassword(kAgeUTF8);
675 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelLatin1);
676 VerifySavedModifiedHelloWorldDocumentWithPassword(kHotelUTF8);
677}
678
680 OpenAndVerifyHelloWorldDocumentWithPassword("bug_1124998.pdf", "test");
681}
void VerifySavedHelloWorldDocumentWithPassword(const char *password)
void VerifySavedModifiedHelloWorldDocumentWithPassword(const char *password)
void OpenAndVerifyHelloWorldDocumentWithPassword(const char *filename, const char *password)
RetainPtr< CPDF_Object > RemoveFor(ByteStringView key)
CPDF_Parser * GetParser() const
CPDF_Dictionary * GetMutableTrailerForTesting()
FPDF_DOCUMENT OpenSavedDocumentWithPassword(const char *password)
void CloseSavedDocument()
static void CompareBitmap(FPDF_BITMAP bitmap, int expected_width, int expected_height, const char *expected_md5sum)
void UnloadPage(FPDF_PAGE page)
FPDF_DOCUMENT document() const
void CloseSavedPage(FPDF_PAGE page)
FPDF_PAGE LoadPage(int page_number)
FPDF_PAGE LoadSavedPage(int page_number)
TEST_F(CPDFSecurityHandlerEmbedderTest, Unencrypted)
#define FPDF_FILLMODE_ALTERNATE
Definition fpdf_edit.h:52
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPath_SetDrawMode(FPDF_PAGEOBJECT path, int fillmode, FPDF_BOOL stroke)
FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertObject(FPDF_PAGE page, FPDF_PAGEOBJECT page_object)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPageObj_SetFillColor(FPDF_PAGEOBJECT page_object, unsigned int R, unsigned int G, unsigned int B, unsigned int A)
FPDF_EXPORT FPDF_PAGEOBJECT FPDF_CALLCONV FPDFPageObj_CreateNewRect(float x, float y, float w, float h)
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV FPDFPage_GenerateContent(FPDF_PAGE page)
FPDF_EXPORT FPDF_DOCUMENT FPDF_CALLCONV FPDF_LoadCustomDocument(FPDF_FILEACCESS *pFileAccess, FPDF_BYTESTRING password)
const char * HelloWorldChecksum()
const char * HelloWorldRemovedChecksum()