| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "core/fpdfapi/fpdf_parser/cpdf_standard_security_handler.h" | 7 #include "core/fpdfapi/fpdf_parser/cpdf_standard_security_handler.h" |
| 8 | 8 |
| 9 #include <time.h> | 9 #include <time.h> |
| 10 | 10 |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 m_Revision = pEncryptDict->GetIntegerBy("R"); | 166 m_Revision = pEncryptDict->GetIntegerBy("R"); |
| 167 m_Permissions = pEncryptDict->GetIntegerBy("P", -1); | 167 m_Permissions = pEncryptDict->GetIntegerBy("P", -1); |
| 168 if (m_Version < 4) { | 168 if (m_Version < 4) { |
| 169 return _LoadCryptInfo(pEncryptDict, CFX_ByteStringC(), m_Cipher, m_KeyLen); | 169 return _LoadCryptInfo(pEncryptDict, CFX_ByteStringC(), m_Cipher, m_KeyLen); |
| 170 } | 170 } |
| 171 CFX_ByteString stmf_name = pEncryptDict->GetStringBy("StmF"); | 171 CFX_ByteString stmf_name = pEncryptDict->GetStringBy("StmF"); |
| 172 CFX_ByteString strf_name = pEncryptDict->GetStringBy("StrF"); | 172 CFX_ByteString strf_name = pEncryptDict->GetStringBy("StrF"); |
| 173 if (stmf_name != strf_name) { | 173 if (stmf_name != strf_name) { |
| 174 return FALSE; | 174 return FALSE; |
| 175 } | 175 } |
| 176 if (!_LoadCryptInfo(pEncryptDict, strf_name.AsByteStringC(), m_Cipher, | 176 if (!_LoadCryptInfo(pEncryptDict, strf_name.AsStringC(), m_Cipher, |
| 177 m_KeyLen)) { | 177 m_KeyLen)) { |
| 178 return FALSE; | 178 return FALSE; |
| 179 } | 179 } |
| 180 return TRUE; | 180 return TRUE; |
| 181 } | 181 } |
| 182 | 182 |
| 183 FX_BOOL CPDF_StandardSecurityHandler::LoadDict(CPDF_Dictionary* pEncryptDict, | 183 FX_BOOL CPDF_StandardSecurityHandler::LoadDict(CPDF_Dictionary* pEncryptDict, |
| 184 uint32_t type, | 184 uint32_t type, |
| 185 int& cipher, | 185 int& cipher, |
| 186 int& key_len) { | 186 int& key_len) { |
| 187 m_pEncryptDict = pEncryptDict; | 187 m_pEncryptDict = pEncryptDict; |
| 188 m_Version = pEncryptDict->GetIntegerBy("V"); | 188 m_Version = pEncryptDict->GetIntegerBy("V"); |
| 189 m_Revision = pEncryptDict->GetIntegerBy("R"); | 189 m_Revision = pEncryptDict->GetIntegerBy("R"); |
| 190 m_Permissions = pEncryptDict->GetIntegerBy("P", -1); | 190 m_Permissions = pEncryptDict->GetIntegerBy("P", -1); |
| 191 CFX_ByteString strf_name, stmf_name; | 191 CFX_ByteString strf_name, stmf_name; |
| 192 if (m_Version >= 4) { | 192 if (m_Version >= 4) { |
| 193 stmf_name = pEncryptDict->GetStringBy("StmF"); | 193 stmf_name = pEncryptDict->GetStringBy("StmF"); |
| 194 strf_name = pEncryptDict->GetStringBy("StrF"); | 194 strf_name = pEncryptDict->GetStringBy("StrF"); |
| 195 if (stmf_name != strf_name) { | 195 if (stmf_name != strf_name) { |
| 196 return FALSE; | 196 return FALSE; |
| 197 } | 197 } |
| 198 } | 198 } |
| 199 if (!_LoadCryptInfo(pEncryptDict, strf_name.AsByteStringC(), cipher, | 199 if (!_LoadCryptInfo(pEncryptDict, strf_name.AsStringC(), cipher, key_len)) { |
| 200 key_len)) { | |
| 201 return FALSE; | 200 return FALSE; |
| 202 } | 201 } |
| 203 m_Cipher = cipher; | 202 m_Cipher = cipher; |
| 204 m_KeyLen = key_len; | 203 m_KeyLen = key_len; |
| 205 return TRUE; | 204 return TRUE; |
| 206 } | 205 } |
| 207 | 206 |
| 208 FX_BOOL CPDF_StandardSecurityHandler::GetCryptInfo(int& cipher, | 207 FX_BOOL CPDF_StandardSecurityHandler::GetCryptInfo(int& cipher, |
| 209 const uint8_t*& buffer, | 208 const uint8_t*& buffer, |
| 210 int& keylen) { | 209 int& keylen) { |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 buf[11] = 'b'; | 706 buf[11] = 'b'; |
| 708 uint8_t* aes = FX_Alloc(uint8_t, 2048); | 707 uint8_t* aes = FX_Alloc(uint8_t, 2048); |
| 709 CRYPT_AESSetKey(aes, 16, key, 32, TRUE); | 708 CRYPT_AESSetKey(aes, 16, key, 32, TRUE); |
| 710 uint8_t iv[16], buf1[16]; | 709 uint8_t iv[16], buf1[16]; |
| 711 FXSYS_memset(iv, 0, 16); | 710 FXSYS_memset(iv, 0, 16); |
| 712 CRYPT_AESSetIV(aes, iv); | 711 CRYPT_AESSetIV(aes, iv); |
| 713 CRYPT_AESEncrypt(aes, buf1, buf, 16); | 712 CRYPT_AESEncrypt(aes, buf1, buf, 16); |
| 714 FX_Free(aes); | 713 FX_Free(aes); |
| 715 pEncryptDict->SetAtString("Perms", CFX_ByteString(buf1, 16)); | 714 pEncryptDict->SetAtString("Perms", CFX_ByteString(buf1, 16)); |
| 716 } | 715 } |
| OLD | NEW |