OLD | NEW |
| (Empty) |
1 // Copyright 2016 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #ifndef CORE_FPDFAPI_FPDF_PARSER_CPDF_STANDARD_SECURITY_HANDLER_H_ | |
8 #define CORE_FPDFAPI_FPDF_PARSER_CPDF_STANDARD_SECURITY_HANDLER_H_ | |
9 | |
10 #include "core/fpdfapi/fpdf_parser/ipdf_security_handler.h" | |
11 #include "core/fxcrt/include/fx_string.h" | |
12 #include "core/fxcrt/include/fx_system.h" | |
13 | |
14 class CPDF_Array; | |
15 | |
16 #define PDF_ENCRYPT_CONTENT 0 | |
17 | |
18 class CPDF_StandardSecurityHandler : public IPDF_SecurityHandler { | |
19 public: | |
20 CPDF_StandardSecurityHandler(); | |
21 ~CPDF_StandardSecurityHandler() override; | |
22 | |
23 // IPDF_SecurityHandler: | |
24 FX_BOOL OnInit(CPDF_Parser* pParser, CPDF_Dictionary* pEncryptDict) override; | |
25 uint32_t GetPermissions() override; | |
26 FX_BOOL GetCryptInfo(int& cipher, | |
27 const uint8_t*& buffer, | |
28 int& keylen) override; | |
29 FX_BOOL IsMetadataEncrypted() override; | |
30 IPDF_CryptoHandler* CreateCryptoHandler() override; | |
31 | |
32 void OnCreate(CPDF_Dictionary* pEncryptDict, | |
33 CPDF_Array* pIdArray, | |
34 const uint8_t* user_pass, | |
35 uint32_t user_size, | |
36 const uint8_t* owner_pass, | |
37 uint32_t owner_size, | |
38 uint32_t type = PDF_ENCRYPT_CONTENT); | |
39 | |
40 void OnCreate(CPDF_Dictionary* pEncryptDict, | |
41 CPDF_Array* pIdArray, | |
42 const uint8_t* user_pass, | |
43 uint32_t user_size, | |
44 uint32_t type = PDF_ENCRYPT_CONTENT); | |
45 | |
46 CFX_ByteString GetUserPassword(const uint8_t* owner_pass, | |
47 uint32_t pass_size, | |
48 int32_t key_len); | |
49 int CheckPassword(const uint8_t* password, | |
50 uint32_t pass_size, | |
51 FX_BOOL bOwner, | |
52 uint8_t* key, | |
53 int key_len); | |
54 | |
55 private: | |
56 FX_BOOL LoadDict(CPDF_Dictionary* pEncryptDict); | |
57 FX_BOOL LoadDict(CPDF_Dictionary* pEncryptDict, | |
58 uint32_t type, | |
59 int& cipher, | |
60 int& key_len); | |
61 | |
62 FX_BOOL CheckUserPassword(const uint8_t* password, | |
63 uint32_t pass_size, | |
64 FX_BOOL bIgnoreEncryptMeta, | |
65 uint8_t* key, | |
66 int32_t key_len); | |
67 | |
68 FX_BOOL CheckOwnerPassword(const uint8_t* password, | |
69 uint32_t pass_size, | |
70 uint8_t* key, | |
71 int32_t key_len); | |
72 FX_BOOL AES256_CheckPassword(const uint8_t* password, | |
73 uint32_t size, | |
74 FX_BOOL bOwner, | |
75 uint8_t* key); | |
76 void AES256_SetPassword(CPDF_Dictionary* pEncryptDict, | |
77 const uint8_t* password, | |
78 uint32_t size, | |
79 FX_BOOL bOwner, | |
80 const uint8_t* key); | |
81 void AES256_SetPerms(CPDF_Dictionary* pEncryptDict, | |
82 uint32_t permission, | |
83 FX_BOOL bEncryptMetadata, | |
84 const uint8_t* key); | |
85 void OnCreate(CPDF_Dictionary* pEncryptDict, | |
86 CPDF_Array* pIdArray, | |
87 const uint8_t* user_pass, | |
88 uint32_t user_size, | |
89 const uint8_t* owner_pass, | |
90 uint32_t owner_size, | |
91 FX_BOOL bDefault, | |
92 uint32_t type); | |
93 FX_BOOL CheckSecurity(int32_t key_len); | |
94 | |
95 int m_Version; | |
96 int m_Revision; | |
97 CPDF_Parser* m_pParser; | |
98 CPDF_Dictionary* m_pEncryptDict; | |
99 uint32_t m_Permissions; | |
100 int m_Cipher; | |
101 uint8_t m_EncryptKey[32]; | |
102 int m_KeyLen; | |
103 }; | |
104 | |
105 #endif // CORE_FPDFAPI_FPDF_PARSER_CPDF_STANDARD_SECURITY_HANDLER_H_ | |
OLD | NEW |