| 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 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 uint32_t type) { | 527 uint32_t type) { |
| 528 int cipher = 0, key_len = 0; | 528 int cipher = 0, key_len = 0; |
| 529 if (!LoadDict(pEncryptDict, type, cipher, key_len)) { | 529 if (!LoadDict(pEncryptDict, type, cipher, key_len)) { |
| 530 return; | 530 return; |
| 531 } | 531 } |
| 532 if (bDefault && (!owner_pass || owner_size == 0)) { | 532 if (bDefault && (!owner_pass || owner_size == 0)) { |
| 533 owner_pass = user_pass; | 533 owner_pass = user_pass; |
| 534 owner_size = user_size; | 534 owner_size = user_size; |
| 535 } | 535 } |
| 536 if (m_Revision >= 5) { | 536 if (m_Revision >= 5) { |
| 537 int t = (int)time(NULL); | 537 int t = (int)time(nullptr); |
| 538 uint8_t sha[128]; | 538 uint8_t sha[128]; |
| 539 CRYPT_SHA256Start(sha); | 539 CRYPT_SHA256Start(sha); |
| 540 CRYPT_SHA256Update(sha, (uint8_t*)&t, sizeof t); | 540 CRYPT_SHA256Update(sha, (uint8_t*)&t, sizeof t); |
| 541 CRYPT_SHA256Update(sha, m_EncryptKey, 32); | 541 CRYPT_SHA256Update(sha, m_EncryptKey, 32); |
| 542 CRYPT_SHA256Update(sha, (uint8_t*)"there", 5); | 542 CRYPT_SHA256Update(sha, (uint8_t*)"there", 5); |
| 543 CRYPT_SHA256Finish(sha, m_EncryptKey); | 543 CRYPT_SHA256Finish(sha, m_EncryptKey); |
| 544 AES256_SetPassword(pEncryptDict, user_pass, user_size, FALSE, m_EncryptKey); | 544 AES256_SetPassword(pEncryptDict, user_pass, user_size, FALSE, m_EncryptKey); |
| 545 if (bDefault) { | 545 if (bDefault) { |
| 546 AES256_SetPassword(pEncryptDict, owner_pass, owner_size, TRUE, | 546 AES256_SetPassword(pEncryptDict, owner_pass, owner_size, TRUE, |
| 547 m_EncryptKey); | 547 m_EncryptKey); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 uint32_t owner_size, | 619 uint32_t owner_size, |
| 620 uint32_t type) { | 620 uint32_t type) { |
| 621 OnCreate(pEncryptDict, pIdArray, user_pass, user_size, owner_pass, owner_size, | 621 OnCreate(pEncryptDict, pIdArray, user_pass, user_size, owner_pass, owner_size, |
| 622 TRUE, type); | 622 TRUE, type); |
| 623 } | 623 } |
| 624 void CPDF_SecurityHandler::OnCreate(CPDF_Dictionary* pEncryptDict, | 624 void CPDF_SecurityHandler::OnCreate(CPDF_Dictionary* pEncryptDict, |
| 625 CPDF_Array* pIdArray, | 625 CPDF_Array* pIdArray, |
| 626 const uint8_t* user_pass, | 626 const uint8_t* user_pass, |
| 627 uint32_t user_size, | 627 uint32_t user_size, |
| 628 uint32_t type) { | 628 uint32_t type) { |
| 629 OnCreate(pEncryptDict, pIdArray, user_pass, user_size, NULL, 0, FALSE, type); | 629 OnCreate(pEncryptDict, pIdArray, user_pass, user_size, nullptr, 0, FALSE, |
| 630 type); |
| 630 } | 631 } |
| 631 void CPDF_SecurityHandler::AES256_SetPassword(CPDF_Dictionary* pEncryptDict, | 632 void CPDF_SecurityHandler::AES256_SetPassword(CPDF_Dictionary* pEncryptDict, |
| 632 const uint8_t* password, | 633 const uint8_t* password, |
| 633 uint32_t size, | 634 uint32_t size, |
| 634 FX_BOOL bOwner, | 635 FX_BOOL bOwner, |
| 635 const uint8_t* key) { | 636 const uint8_t* key) { |
| 636 uint8_t sha[128]; | 637 uint8_t sha[128]; |
| 637 CRYPT_SHA1Start(sha); | 638 CRYPT_SHA1Start(sha); |
| 638 CRYPT_SHA1Update(sha, key, 32); | 639 CRYPT_SHA1Update(sha, key, 32); |
| 639 CRYPT_SHA1Update(sha, (uint8_t*)"hello", 5); | 640 CRYPT_SHA1Update(sha, (uint8_t*)"hello", 5); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 buf[11] = 'b'; | 696 buf[11] = 'b'; |
| 696 uint8_t* aes = FX_Alloc(uint8_t, 2048); | 697 uint8_t* aes = FX_Alloc(uint8_t, 2048); |
| 697 CRYPT_AESSetKey(aes, 16, key, 32, TRUE); | 698 CRYPT_AESSetKey(aes, 16, key, 32, TRUE); |
| 698 uint8_t iv[16], buf1[16]; | 699 uint8_t iv[16], buf1[16]; |
| 699 FXSYS_memset(iv, 0, 16); | 700 FXSYS_memset(iv, 0, 16); |
| 700 CRYPT_AESSetIV(aes, iv); | 701 CRYPT_AESSetIV(aes, iv); |
| 701 CRYPT_AESEncrypt(aes, buf1, buf, 16); | 702 CRYPT_AESEncrypt(aes, buf1, buf, 16); |
| 702 FX_Free(aes); | 703 FX_Free(aes); |
| 703 pEncryptDict->SetAtString("Perms", CFX_ByteString(buf1, 16)); | 704 pEncryptDict->SetAtString("Perms", CFX_ByteString(buf1, 16)); |
| 704 } | 705 } |
| OLD | NEW |