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_PARSER_CPDF_SECURITY_HANDLER_H_ | 7 #ifndef CORE_FPDFAPI_PARSER_CPDF_SECURITY_HANDLER_H_ |
8 #define CORE_FPDFAPI_PARSER_CPDF_SECURITY_HANDLER_H_ | 8 #define CORE_FPDFAPI_PARSER_CPDF_SECURITY_HANDLER_H_ |
9 | 9 |
10 #include "core/fxcrt/fx_string.h" | 10 #include "core/fxcrt/fx_string.h" |
11 #include "core/fxcrt/fx_system.h" | 11 #include "core/fxcrt/fx_system.h" |
12 | 12 |
13 #define FXCIPHER_NONE 0 | 13 #define FXCIPHER_NONE 0 |
14 #define FXCIPHER_RC4 1 | 14 #define FXCIPHER_RC4 1 |
15 #define FXCIPHER_AES 2 | 15 #define FXCIPHER_AES 2 |
16 #define FXCIPHER_AES2 3 | 16 #define FXCIPHER_AES2 3 |
17 | 17 |
18 #define PDF_ENCRYPT_CONTENT 0 | 18 #define PDF_ENCRYPT_CONTENT 0 |
19 | 19 |
20 class CPDF_Array; | 20 class CPDF_Array; |
21 class CPDF_CryptoHandler; | 21 class CPDF_CryptoHandler; |
22 class CPDF_Dictionary; | 22 class CPDF_Dictionary; |
23 class CPDF_Parser; | 23 class CPDF_Parser; |
24 | 24 |
25 class CPDF_SecurityHandler { | 25 class CPDF_SecurityHandler { |
26 public: | 26 public: |
27 CPDF_SecurityHandler(); | 27 CPDF_SecurityHandler(); |
28 ~CPDF_SecurityHandler(); | 28 ~CPDF_SecurityHandler(); |
29 | 29 |
30 FX_BOOL OnInit(CPDF_Parser* pParser, CPDF_Dictionary* pEncryptDict); | 30 bool OnInit(CPDF_Parser* pParser, CPDF_Dictionary* pEncryptDict); |
31 uint32_t GetPermissions(); | 31 uint32_t GetPermissions(); |
32 FX_BOOL GetCryptInfo(int& cipher, const uint8_t*& buffer, int& keylen); | 32 bool GetCryptInfo(int& cipher, const uint8_t*& buffer, int& keylen); |
33 bool IsMetadataEncrypted() const; | 33 bool IsMetadataEncrypted() const; |
34 CPDF_CryptoHandler* CreateCryptoHandler(); | 34 CPDF_CryptoHandler* CreateCryptoHandler(); |
35 | 35 |
36 void OnCreate(CPDF_Dictionary* pEncryptDict, | 36 void OnCreate(CPDF_Dictionary* pEncryptDict, |
37 CPDF_Array* pIdArray, | 37 CPDF_Array* pIdArray, |
38 const uint8_t* user_pass, | 38 const uint8_t* user_pass, |
39 uint32_t user_size, | 39 uint32_t user_size, |
40 const uint8_t* owner_pass, | 40 const uint8_t* owner_pass, |
41 uint32_t owner_size, | 41 uint32_t owner_size, |
42 uint32_t type = PDF_ENCRYPT_CONTENT); | 42 uint32_t type = PDF_ENCRYPT_CONTENT); |
43 | 43 |
44 void OnCreate(CPDF_Dictionary* pEncryptDict, | 44 void OnCreate(CPDF_Dictionary* pEncryptDict, |
45 CPDF_Array* pIdArray, | 45 CPDF_Array* pIdArray, |
46 const uint8_t* user_pass, | 46 const uint8_t* user_pass, |
47 uint32_t user_size, | 47 uint32_t user_size, |
48 uint32_t type = PDF_ENCRYPT_CONTENT); | 48 uint32_t type = PDF_ENCRYPT_CONTENT); |
49 | 49 |
50 CFX_ByteString GetUserPassword(const uint8_t* owner_pass, | 50 CFX_ByteString GetUserPassword(const uint8_t* owner_pass, |
51 uint32_t pass_size, | 51 uint32_t pass_size, |
52 int32_t key_len); | 52 int32_t key_len); |
53 FX_BOOL CheckPassword(const uint8_t* password, | 53 bool CheckPassword(const uint8_t* password, |
54 uint32_t pass_size, | 54 uint32_t pass_size, |
55 FX_BOOL bOwner, | 55 bool bOwner, |
56 uint8_t* key, | 56 uint8_t* key, |
57 int key_len); | 57 int key_len); |
58 | 58 |
59 private: | 59 private: |
60 FX_BOOL LoadDict(CPDF_Dictionary* pEncryptDict); | 60 bool LoadDict(CPDF_Dictionary* pEncryptDict); |
61 FX_BOOL LoadDict(CPDF_Dictionary* pEncryptDict, | 61 bool LoadDict(CPDF_Dictionary* pEncryptDict, |
62 uint32_t type, | 62 uint32_t type, |
63 int& cipher, | 63 int& cipher, |
64 int& key_len); | 64 int& key_len); |
65 | 65 |
66 FX_BOOL CheckUserPassword(const uint8_t* password, | 66 bool CheckUserPassword(const uint8_t* password, |
67 uint32_t pass_size, | 67 uint32_t pass_size, |
68 FX_BOOL bIgnoreEncryptMeta, | 68 bool bIgnoreEncryptMeta, |
69 uint8_t* key, | 69 uint8_t* key, |
70 int32_t key_len); | 70 int32_t key_len); |
71 | 71 |
72 FX_BOOL CheckOwnerPassword(const uint8_t* password, | 72 bool CheckOwnerPassword(const uint8_t* password, |
73 uint32_t pass_size, | 73 uint32_t pass_size, |
74 uint8_t* key, | 74 uint8_t* key, |
75 int32_t key_len); | 75 int32_t key_len); |
76 FX_BOOL AES256_CheckPassword(const uint8_t* password, | 76 bool AES256_CheckPassword(const uint8_t* password, |
77 uint32_t size, | 77 uint32_t size, |
78 FX_BOOL bOwner, | 78 bool bOwner, |
79 uint8_t* key); | 79 uint8_t* key); |
80 void AES256_SetPassword(CPDF_Dictionary* pEncryptDict, | 80 void AES256_SetPassword(CPDF_Dictionary* pEncryptDict, |
81 const uint8_t* password, | 81 const uint8_t* password, |
82 uint32_t size, | 82 uint32_t size, |
83 FX_BOOL bOwner, | 83 bool bOwner, |
84 const uint8_t* key); | 84 const uint8_t* key); |
85 void AES256_SetPerms(CPDF_Dictionary* pEncryptDict, | 85 void AES256_SetPerms(CPDF_Dictionary* pEncryptDict, |
86 uint32_t permission, | 86 uint32_t permission, |
87 FX_BOOL bEncryptMetadata, | 87 bool bEncryptMetadata, |
88 const uint8_t* key); | 88 const uint8_t* key); |
89 void OnCreate(CPDF_Dictionary* pEncryptDict, | 89 void OnCreate(CPDF_Dictionary* pEncryptDict, |
90 CPDF_Array* pIdArray, | 90 CPDF_Array* pIdArray, |
91 const uint8_t* user_pass, | 91 const uint8_t* user_pass, |
92 uint32_t user_size, | 92 uint32_t user_size, |
93 const uint8_t* owner_pass, | 93 const uint8_t* owner_pass, |
94 uint32_t owner_size, | 94 uint32_t owner_size, |
95 FX_BOOL bDefault, | 95 bool bDefault, |
96 uint32_t type); | 96 uint32_t type); |
97 FX_BOOL CheckSecurity(int32_t key_len); | 97 bool CheckSecurity(int32_t key_len); |
98 | 98 |
99 int m_Version; | 99 int m_Version; |
100 int m_Revision; | 100 int m_Revision; |
101 CPDF_Parser* m_pParser; | 101 CPDF_Parser* m_pParser; |
102 CPDF_Dictionary* m_pEncryptDict; | 102 CPDF_Dictionary* m_pEncryptDict; |
103 uint32_t m_Permissions; | 103 uint32_t m_Permissions; |
104 int m_Cipher; | 104 int m_Cipher; |
105 uint8_t m_EncryptKey[32]; | 105 uint8_t m_EncryptKey[32]; |
106 int m_KeyLen; | 106 int m_KeyLen; |
107 bool m_bOwnerUnlocked; | 107 bool m_bOwnerUnlocked; |
108 }; | 108 }; |
109 | 109 |
110 #endif // CORE_FPDFAPI_PARSER_CPDF_SECURITY_HANDLER_H_ | 110 #endif // CORE_FPDFAPI_PARSER_CPDF_SECURITY_HANDLER_H_ |
OLD | NEW |