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