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/parser/cpdf_security_handler.h" | 7 #include "core/fpdfapi/parser/cpdf_security_handler.h" |
8 | 8 |
9 #include <time.h> | 9 #include <time.h> |
10 | 10 |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 if (FXDWORD_GET_LSBFIRST(buf) != m_Permissions) { | 380 if (FXDWORD_GET_LSBFIRST(buf) != m_Permissions) { |
381 return FALSE; | 381 return FALSE; |
382 } | 382 } |
383 if ((buf[8] == 'T' && !IsMetadataEncrypted()) || | 383 if ((buf[8] == 'T' && !IsMetadataEncrypted()) || |
384 (buf[8] == 'F' && IsMetadataEncrypted())) { | 384 (buf[8] == 'F' && IsMetadataEncrypted())) { |
385 return FALSE; | 385 return FALSE; |
386 } | 386 } |
387 return TRUE; | 387 return TRUE; |
388 } | 388 } |
389 | 389 |
390 int CPDF_SecurityHandler::CheckPassword(const uint8_t* password, | 390 FX_BOOL CPDF_SecurityHandler::CheckPassword(const uint8_t* password, |
391 uint32_t size, | 391 uint32_t size, |
392 FX_BOOL bOwner, | 392 FX_BOOL bOwner, |
393 uint8_t* key, | 393 uint8_t* key, |
394 int32_t key_len) { | 394 int32_t key_len) { |
395 if (m_Revision >= 5) { | 395 if (m_Revision >= 5) |
396 return AES256_CheckPassword(password, size, bOwner, key); | 396 return AES256_CheckPassword(password, size, bOwner, key); |
397 } | 397 |
398 uint8_t keybuf[32]; | 398 uint8_t keybuf[32]; |
399 if (!key) { | 399 if (!key) |
400 key = keybuf; | 400 key = keybuf; |
401 } | 401 |
402 if (bOwner) { | 402 if (bOwner) |
403 return CheckOwnerPassword(password, size, key, key_len); | 403 return CheckOwnerPassword(password, size, key, key_len); |
404 } | 404 |
405 return CheckUserPassword(password, size, FALSE, key, key_len) || | 405 return CheckUserPassword(password, size, FALSE, key, key_len) || |
406 CheckUserPassword(password, size, TRUE, key, key_len); | 406 CheckUserPassword(password, size, TRUE, key, key_len); |
407 } | 407 } |
408 FX_BOOL CPDF_SecurityHandler::CheckUserPassword(const uint8_t* password, | 408 FX_BOOL CPDF_SecurityHandler::CheckUserPassword(const uint8_t* password, |
409 uint32_t pass_size, | 409 uint32_t pass_size, |
410 FX_BOOL bIgnoreEncryptMeta, | 410 FX_BOOL bIgnoreEncryptMeta, |
411 uint8_t* key, | 411 uint8_t* key, |
412 int32_t key_len) { | 412 int32_t key_len) { |
413 CalcEncryptKey(m_pEncryptDict, password, pass_size, key, key_len, | 413 CalcEncryptKey(m_pEncryptDict, password, pass_size, key, key_len, |
414 bIgnoreEncryptMeta, m_pParser->GetIDArray()); | 414 bIgnoreEncryptMeta, m_pParser->GetIDArray()); |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 buf[11] = 'b'; | 690 buf[11] = 'b'; |
691 uint8_t* aes = FX_Alloc(uint8_t, 2048); | 691 uint8_t* aes = FX_Alloc(uint8_t, 2048); |
692 CRYPT_AESSetKey(aes, 16, key, 32, TRUE); | 692 CRYPT_AESSetKey(aes, 16, key, 32, TRUE); |
693 uint8_t iv[16], buf1[16]; | 693 uint8_t iv[16], buf1[16]; |
694 FXSYS_memset(iv, 0, 16); | 694 FXSYS_memset(iv, 0, 16); |
695 CRYPT_AESSetIV(aes, iv); | 695 CRYPT_AESSetIV(aes, iv); |
696 CRYPT_AESEncrypt(aes, buf1, buf, 16); | 696 CRYPT_AESEncrypt(aes, buf1, buf, 16); |
697 FX_Free(aes); | 697 FX_Free(aes); |
698 pEncryptDict->SetStringFor("Perms", CFX_ByteString(buf1, 16)); | 698 pEncryptDict->SetStringFor("Perms", CFX_ByteString(buf1, 16)); |
699 } | 699 } |
OLD | NEW |