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_security_handler.h" | 7 #include "core/fpdfapi/fpdf_parser/cpdf_security_handler.h" |
8 | 8 |
9 #include <time.h> | 9 #include <time.h> |
10 | 10 |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 uint32_t type) { | 524 uint32_t type) { |
525 int cipher = 0, key_len = 0; | 525 int cipher = 0, key_len = 0; |
526 if (!LoadDict(pEncryptDict, type, cipher, key_len)) { | 526 if (!LoadDict(pEncryptDict, type, cipher, key_len)) { |
527 return; | 527 return; |
528 } | 528 } |
529 if (bDefault && (!owner_pass || owner_size == 0)) { | 529 if (bDefault && (!owner_pass || owner_size == 0)) { |
530 owner_pass = user_pass; | 530 owner_pass = user_pass; |
531 owner_size = user_size; | 531 owner_size = user_size; |
532 } | 532 } |
533 if (m_Revision >= 5) { | 533 if (m_Revision >= 5) { |
534 int t = (int)time(NULL); | 534 int t = (int)time(nullptr); |
535 uint8_t sha[128]; | 535 uint8_t sha[128]; |
536 CRYPT_SHA256Start(sha); | 536 CRYPT_SHA256Start(sha); |
537 CRYPT_SHA256Update(sha, (uint8_t*)&t, sizeof t); | 537 CRYPT_SHA256Update(sha, (uint8_t*)&t, sizeof t); |
538 CRYPT_SHA256Update(sha, m_EncryptKey, 32); | 538 CRYPT_SHA256Update(sha, m_EncryptKey, 32); |
539 CRYPT_SHA256Update(sha, (uint8_t*)"there", 5); | 539 CRYPT_SHA256Update(sha, (uint8_t*)"there", 5); |
540 CRYPT_SHA256Finish(sha, m_EncryptKey); | 540 CRYPT_SHA256Finish(sha, m_EncryptKey); |
541 AES256_SetPassword(pEncryptDict, user_pass, user_size, FALSE, m_EncryptKey); | 541 AES256_SetPassword(pEncryptDict, user_pass, user_size, FALSE, m_EncryptKey); |
542 if (bDefault) { | 542 if (bDefault) { |
543 AES256_SetPassword(pEncryptDict, owner_pass, owner_size, TRUE, | 543 AES256_SetPassword(pEncryptDict, owner_pass, owner_size, TRUE, |
544 m_EncryptKey); | 544 m_EncryptKey); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 uint32_t owner_size, | 613 uint32_t owner_size, |
614 uint32_t type) { | 614 uint32_t type) { |
615 OnCreate(pEncryptDict, pIdArray, user_pass, user_size, owner_pass, owner_size, | 615 OnCreate(pEncryptDict, pIdArray, user_pass, user_size, owner_pass, owner_size, |
616 TRUE, type); | 616 TRUE, type); |
617 } | 617 } |
618 void CPDF_SecurityHandler::OnCreate(CPDF_Dictionary* pEncryptDict, | 618 void CPDF_SecurityHandler::OnCreate(CPDF_Dictionary* pEncryptDict, |
619 CPDF_Array* pIdArray, | 619 CPDF_Array* pIdArray, |
620 const uint8_t* user_pass, | 620 const uint8_t* user_pass, |
621 uint32_t user_size, | 621 uint32_t user_size, |
622 uint32_t type) { | 622 uint32_t type) { |
623 OnCreate(pEncryptDict, pIdArray, user_pass, user_size, NULL, 0, FALSE, type); | 623 OnCreate(pEncryptDict, pIdArray, user_pass, user_size, nullptr, 0, FALSE, |
| 624 type); |
624 } | 625 } |
625 void CPDF_SecurityHandler::AES256_SetPassword(CPDF_Dictionary* pEncryptDict, | 626 void CPDF_SecurityHandler::AES256_SetPassword(CPDF_Dictionary* pEncryptDict, |
626 const uint8_t* password, | 627 const uint8_t* password, |
627 uint32_t size, | 628 uint32_t size, |
628 FX_BOOL bOwner, | 629 FX_BOOL bOwner, |
629 const uint8_t* key) { | 630 const uint8_t* key) { |
630 uint8_t sha[128]; | 631 uint8_t sha[128]; |
631 CRYPT_SHA1Start(sha); | 632 CRYPT_SHA1Start(sha); |
632 CRYPT_SHA1Update(sha, key, 32); | 633 CRYPT_SHA1Update(sha, key, 32); |
633 CRYPT_SHA1Update(sha, (uint8_t*)"hello", 5); | 634 CRYPT_SHA1Update(sha, (uint8_t*)"hello", 5); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 buf[11] = 'b'; | 690 buf[11] = 'b'; |
690 uint8_t* aes = FX_Alloc(uint8_t, 2048); | 691 uint8_t* aes = FX_Alloc(uint8_t, 2048); |
691 CRYPT_AESSetKey(aes, 16, key, 32, TRUE); | 692 CRYPT_AESSetKey(aes, 16, key, 32, TRUE); |
692 uint8_t iv[16], buf1[16]; | 693 uint8_t iv[16], buf1[16]; |
693 FXSYS_memset(iv, 0, 16); | 694 FXSYS_memset(iv, 0, 16); |
694 CRYPT_AESSetIV(aes, iv); | 695 CRYPT_AESSetIV(aes, iv); |
695 CRYPT_AESEncrypt(aes, buf1, buf, 16); | 696 CRYPT_AESEncrypt(aes, buf1, buf, 16); |
696 FX_Free(aes); | 697 FX_Free(aes); |
697 pEncryptDict->SetAtString("Perms", CFX_ByteString(buf1, 16)); | 698 pEncryptDict->SetAtString("Perms", CFX_ByteString(buf1, 16)); |
698 } | 699 } |
OLD | NEW |