OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium 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 #include "content/renderer/webcrypto/webcrypto_impl.h" | 5 #include "content/renderer/webcrypto/webcrypto_impl.h" |
6 | 6 |
7 #include <algorithm> | |
7 #include <string> | 8 #include <string> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
14 #include "content/public/renderer/content_renderer_client.h" | 15 #include "content/public/renderer/content_renderer_client.h" |
15 #include "content/renderer/renderer_webkitplatformsupport_impl.h" | 16 #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 new blink::WebCryptoAesCbcParams(Start(iv), iv.size())); | 74 new blink::WebCryptoAesCbcParams(Start(iv), iv.size())); |
74 } | 75 } |
75 | 76 |
76 blink::WebCryptoAlgorithm CreateAesCbcAlgorithm( | 77 blink::WebCryptoAlgorithm CreateAesCbcAlgorithm( |
77 unsigned short key_length_bits) { // NOLINT | 78 unsigned short key_length_bits) { // NOLINT |
78 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 79 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
79 blink::WebCryptoAlgorithmIdAesCbc, | 80 blink::WebCryptoAlgorithmIdAesCbc, |
80 new blink::WebCryptoAesKeyGenParams(key_length_bits)); | 81 new blink::WebCryptoAesKeyGenParams(key_length_bits)); |
81 } | 82 } |
82 | 83 |
83 #if !defined(USE_OPENSSL) | 84 blink::WebCryptoAlgorithm CreateRsaKeyGenAlgorithm( |
84 blink::WebCryptoAlgorithm CreateRsaAlgorithm( | |
85 blink::WebCryptoAlgorithmId algorithm_id, | 85 blink::WebCryptoAlgorithmId algorithm_id, |
86 unsigned modulus_length, | 86 unsigned modulus_length, |
87 const std::vector<uint8>& public_exponent) { | 87 const std::vector<uint8>& public_exponent) { |
88 DCHECK(algorithm_id == blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5 || | 88 DCHECK(algorithm_id == blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5 || |
89 algorithm_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 || | 89 algorithm_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 || |
90 algorithm_id == blink::WebCryptoAlgorithmIdRsaOaep); | 90 algorithm_id == blink::WebCryptoAlgorithmIdRsaOaep); |
91 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 91 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
92 algorithm_id, | 92 algorithm_id, |
93 new blink::WebCryptoRsaKeyGenParams( | 93 new blink::WebCryptoRsaKeyGenParams( |
94 modulus_length, Start(public_exponent), public_exponent.size())); | 94 modulus_length, Start(public_exponent), public_exponent.size())); |
95 } | 95 } |
96 #endif // !defined(USE_OPENSSL) | |
97 | 96 |
98 } // namespace | 97 } // namespace |
99 | 98 |
100 namespace content { | 99 namespace content { |
101 | 100 |
102 class WebCryptoImplTest : public testing::Test { | 101 class WebCryptoImplTest : public testing::Test { |
103 protected: | 102 protected: |
104 blink::WebCryptoKey ImportSecretKeyFromRawHexString( | 103 blink::WebCryptoKey ImportSecretKeyFromRawHexString( |
105 const std::string& key_hex, | 104 const std::string& key_hex, |
106 const blink::WebCryptoAlgorithm& algorithm, | 105 const blink::WebCryptoAlgorithm& algorithm, |
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
690 | 689 |
691 #if !defined(USE_OPENSSL) | 690 #if !defined(USE_OPENSSL) |
692 | 691 |
693 TEST_F(WebCryptoImplTest, GenerateKeyPairRsa) { | 692 TEST_F(WebCryptoImplTest, GenerateKeyPairRsa) { |
694 // Note: using unrealistic short key lengths here to avoid bogging down tests. | 693 // Note: using unrealistic short key lengths here to avoid bogging down tests. |
695 | 694 |
696 // Successful WebCryptoAlgorithmIdRsaEsPkcs1v1_5 key generation. | 695 // Successful WebCryptoAlgorithmIdRsaEsPkcs1v1_5 key generation. |
697 const unsigned modulus_length = 256; | 696 const unsigned modulus_length = 256; |
698 const std::vector<uint8> public_exponent = HexStringToBytes("010001"); | 697 const std::vector<uint8> public_exponent = HexStringToBytes("010001"); |
699 blink::WebCryptoAlgorithm algorithm = | 698 blink::WebCryptoAlgorithm algorithm = |
700 CreateRsaAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, | 699 CreateRsaKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, |
701 modulus_length, | 700 modulus_length, |
702 public_exponent); | 701 public_exponent); |
703 bool extractable = false; | 702 bool extractable = false; |
704 const blink::WebCryptoKeyUsageMask usage_mask = 0; | 703 const blink::WebCryptoKeyUsageMask usage_mask = 0; |
705 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | 704 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
706 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); | 705 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); |
707 EXPECT_TRUE(GenerateKeyPairInternal( | 706 EXPECT_TRUE(GenerateKeyPairInternal( |
708 algorithm, extractable, usage_mask, &public_key, &private_key)); | 707 algorithm, extractable, usage_mask, &public_key, &private_key)); |
709 EXPECT_FALSE(public_key.isNull()); | 708 EXPECT_FALSE(public_key.isNull()); |
710 EXPECT_FALSE(private_key.isNull()); | 709 EXPECT_FALSE(private_key.isNull()); |
711 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); | 710 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); |
712 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); | 711 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); |
713 EXPECT_EQ(extractable, public_key.extractable()); | 712 EXPECT_EQ(extractable, public_key.extractable()); |
714 EXPECT_EQ(extractable, private_key.extractable()); | 713 EXPECT_EQ(extractable, private_key.extractable()); |
715 EXPECT_EQ(usage_mask, public_key.usages()); | 714 EXPECT_EQ(usage_mask, public_key.usages()); |
716 EXPECT_EQ(usage_mask, private_key.usages()); | 715 EXPECT_EQ(usage_mask, private_key.usages()); |
717 | 716 |
718 // Fail with bad modulus. | 717 // Fail with bad modulus. |
719 algorithm = CreateRsaAlgorithm( | 718 algorithm = CreateRsaKeyGenAlgorithm( |
720 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, 0, public_exponent); | 719 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, 0, public_exponent); |
721 EXPECT_FALSE(GenerateKeyPairInternal( | 720 EXPECT_FALSE(GenerateKeyPairInternal( |
722 algorithm, extractable, usage_mask, &public_key, &private_key)); | 721 algorithm, extractable, usage_mask, &public_key, &private_key)); |
723 | 722 |
724 // Fail with bad exponent: larger than unsigned long. | 723 // Fail with bad exponent: larger than unsigned long. |
725 unsigned exponent_length = sizeof(unsigned long) + 1; // NOLINT | 724 unsigned exponent_length = sizeof(unsigned long) + 1; // NOLINT |
726 const std::vector<uint8> long_exponent(exponent_length, 0x01); | 725 const std::vector<uint8> long_exponent(exponent_length, 0x01); |
727 algorithm = CreateRsaAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, | 726 algorithm = CreateRsaKeyGenAlgorithm( |
728 modulus_length, | 727 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, modulus_length, long_exponent); |
729 long_exponent); | |
730 EXPECT_FALSE(GenerateKeyPairInternal( | 728 EXPECT_FALSE(GenerateKeyPairInternal( |
731 algorithm, extractable, usage_mask, &public_key, &private_key)); | 729 algorithm, extractable, usage_mask, &public_key, &private_key)); |
732 | 730 |
733 // Fail with bad exponent: empty. | 731 // Fail with bad exponent: empty. |
734 const std::vector<uint8> empty_exponent; | 732 const std::vector<uint8> empty_exponent; |
735 algorithm = CreateRsaAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, | 733 algorithm = |
736 modulus_length, | 734 CreateRsaKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, |
737 empty_exponent); | 735 modulus_length, |
736 empty_exponent); | |
738 EXPECT_FALSE(GenerateKeyPairInternal( | 737 EXPECT_FALSE(GenerateKeyPairInternal( |
739 algorithm, extractable, usage_mask, &public_key, &private_key)); | 738 algorithm, extractable, usage_mask, &public_key, &private_key)); |
740 | 739 |
741 // Fail with bad exponent: all zeros. | 740 // Fail with bad exponent: all zeros. |
742 std::vector<uint8> exponent_with_leading_zeros(15, 0x00); | 741 std::vector<uint8> exponent_with_leading_zeros(15, 0x00); |
743 algorithm = CreateRsaAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, | 742 algorithm = |
744 modulus_length, | 743 CreateRsaKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, |
745 exponent_with_leading_zeros); | 744 modulus_length, |
745 exponent_with_leading_zeros); | |
746 EXPECT_FALSE(GenerateKeyPairInternal( | 746 EXPECT_FALSE(GenerateKeyPairInternal( |
747 algorithm, extractable, usage_mask, &public_key, &private_key)); | 747 algorithm, extractable, usage_mask, &public_key, &private_key)); |
748 | 748 |
749 // Key generation success using exponent with leading zeros. | 749 // Key generation success using exponent with leading zeros. |
750 exponent_with_leading_zeros.insert(exponent_with_leading_zeros.end(), | 750 exponent_with_leading_zeros.insert(exponent_with_leading_zeros.end(), |
751 public_exponent.begin(), | 751 public_exponent.begin(), |
752 public_exponent.end()); | 752 public_exponent.end()); |
753 algorithm = CreateRsaAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, | 753 algorithm = |
754 modulus_length, | 754 CreateRsaKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, |
755 exponent_with_leading_zeros); | 755 modulus_length, |
756 exponent_with_leading_zeros); | |
756 EXPECT_TRUE(GenerateKeyPairInternal( | 757 EXPECT_TRUE(GenerateKeyPairInternal( |
757 algorithm, extractable, usage_mask, &public_key, &private_key)); | 758 algorithm, extractable, usage_mask, &public_key, &private_key)); |
758 EXPECT_FALSE(public_key.isNull()); | 759 EXPECT_FALSE(public_key.isNull()); |
759 EXPECT_FALSE(private_key.isNull()); | 760 EXPECT_FALSE(private_key.isNull()); |
760 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); | 761 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); |
761 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); | 762 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); |
762 EXPECT_EQ(extractable, public_key.extractable()); | 763 EXPECT_EQ(extractable, public_key.extractable()); |
763 EXPECT_EQ(extractable, private_key.extractable()); | 764 EXPECT_EQ(extractable, private_key.extractable()); |
764 EXPECT_EQ(usage_mask, public_key.usages()); | 765 EXPECT_EQ(usage_mask, public_key.usages()); |
765 EXPECT_EQ(usage_mask, private_key.usages()); | 766 EXPECT_EQ(usage_mask, private_key.usages()); |
766 | 767 |
767 // Successful WebCryptoAlgorithmIdRsaOaep key generation. | 768 // Successful WebCryptoAlgorithmIdRsaOaep key generation. |
768 algorithm = CreateRsaAlgorithm( | 769 algorithm = CreateRsaKeyGenAlgorithm( |
769 blink::WebCryptoAlgorithmIdRsaOaep, modulus_length, public_exponent); | 770 blink::WebCryptoAlgorithmIdRsaOaep, modulus_length, public_exponent); |
770 EXPECT_TRUE(GenerateKeyPairInternal( | 771 EXPECT_TRUE(GenerateKeyPairInternal( |
771 algorithm, extractable, usage_mask, &public_key, &private_key)); | 772 algorithm, extractable, usage_mask, &public_key, &private_key)); |
772 EXPECT_FALSE(public_key.isNull()); | 773 EXPECT_FALSE(public_key.isNull()); |
773 EXPECT_FALSE(private_key.isNull()); | 774 EXPECT_FALSE(private_key.isNull()); |
774 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); | 775 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); |
775 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); | 776 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); |
776 EXPECT_EQ(extractable, public_key.extractable()); | 777 EXPECT_EQ(extractable, public_key.extractable()); |
777 EXPECT_EQ(extractable, private_key.extractable()); | 778 EXPECT_EQ(extractable, private_key.extractable()); |
778 EXPECT_EQ(usage_mask, public_key.usages()); | 779 EXPECT_EQ(usage_mask, public_key.usages()); |
779 EXPECT_EQ(usage_mask, private_key.usages()); | 780 EXPECT_EQ(usage_mask, private_key.usages()); |
780 | 781 |
781 // Successful WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 key generation. | 782 // Successful WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 key generation. |
782 algorithm = CreateRsaAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 783 algorithm = |
783 modulus_length, | 784 CreateRsaKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
784 public_exponent); | 785 modulus_length, |
786 public_exponent); | |
785 EXPECT_TRUE(GenerateKeyPairInternal( | 787 EXPECT_TRUE(GenerateKeyPairInternal( |
786 algorithm, extractable, usage_mask, &public_key, &private_key)); | 788 algorithm, extractable, usage_mask, &public_key, &private_key)); |
787 EXPECT_FALSE(public_key.isNull()); | 789 EXPECT_FALSE(public_key.isNull()); |
788 EXPECT_FALSE(private_key.isNull()); | 790 EXPECT_FALSE(private_key.isNull()); |
789 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); | 791 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); |
790 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); | 792 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); |
791 EXPECT_EQ(extractable, public_key.extractable()); | 793 EXPECT_EQ(extractable, public_key.extractable()); |
792 EXPECT_EQ(extractable, private_key.extractable()); | 794 EXPECT_EQ(extractable, private_key.extractable()); |
793 EXPECT_EQ(usage_mask, public_key.usages()); | 795 EXPECT_EQ(usage_mask, public_key.usages()); |
794 EXPECT_EQ(usage_mask, private_key.usages()); | 796 EXPECT_EQ(usage_mask, private_key.usages()); |
795 } | 797 } |
796 | 798 |
799 // TODO(padolph): It is not clear whether we can check RSAES encryption against | |
800 // NIST vectors, because the random data in PKCS1.5 padding makes the encryption | |
801 // output non-deterministic unless we can force-seed NSS's PRNG. | |
802 | |
803 TEST_F(WebCryptoImplTest, RsaEsRoundTrip) { | |
804 // Note: using unrealistic short key length here to avoid bogging down tests. | |
805 | |
806 // Create a key pair. | |
807 const unsigned kModulusLength = 256; | |
808 blink::WebCryptoAlgorithm algorithm = | |
809 CreateRsaKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, | |
810 kModulusLength, | |
811 HexStringToBytes("010001")); | |
812 const blink::WebCryptoKeyUsageMask usage_mask = | |
813 blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt; | |
814 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | |
815 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); | |
816 EXPECT_TRUE(GenerateKeyPairInternal( | |
817 algorithm, false, usage_mask, &public_key, &private_key)); | |
818 EXPECT_FALSE(public_key.isNull()); | |
819 EXPECT_FALSE(private_key.isNull()); | |
820 | |
821 // Make a maximum-length data message. RSAES can operate on messages up to | |
822 // length of k - 11 bytes, where k is the octet length of the RSA modulus. | |
823 const unsigned kMaxMsgSizeBytes = kModulusLength / 8 - 11; | |
824 // There are two hex chars for each byte. | |
825 const unsigned kMsgHexSize = kMaxMsgSizeBytes * 2; | |
826 char max_data_hex[kMsgHexSize]; | |
827 std::fill(&max_data_hex[0], &max_data_hex[0] + kMsgHexSize, 'a'); | |
828 max_data_hex[kMsgHexSize] = '\0'; | |
829 | |
830 // Verify encrypt / decrypt round trip on a few messages. Note that RSA | |
831 // encryption does not support empty input. | |
832 algorithm = CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5); | |
833 const char* const kTestDataHex[] = { | |
834 "ff", | |
835 "0102030405060708090a0b0c0d0e0f", | |
836 max_data_hex | |
837 }; | |
838 blink::WebArrayBuffer encrypted_data; | |
839 blink::WebArrayBuffer decrypted_data; | |
840 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestDataHex); ++i) { | |
841 SCOPED_TRACE(i); | |
842 ASSERT_TRUE(EncryptInternal( | |
843 algorithm, | |
844 public_key, | |
845 HexStringToBytes(kTestDataHex[i]), | |
846 &encrypted_data)); | |
847 EXPECT_EQ(kModulusLength/8, encrypted_data.byteLength()); | |
848 ASSERT_TRUE(DecryptInternal( | |
849 algorithm, | |
850 private_key, | |
851 reinterpret_cast<const unsigned char*>(encrypted_data.data()), | |
852 encrypted_data.byteLength(), | |
853 &decrypted_data)); | |
854 ExpectArrayBufferMatchesHex(kTestDataHex[i], decrypted_data); | |
855 } | |
856 } | |
857 | |
858 TEST_F(WebCryptoImplTest, RsaEsFailures) { | |
859 // Note: using unrealistic short key length here to avoid bogging down tests. | |
860 | |
861 // Create a key pair. | |
862 const unsigned kModulusLength = 256; | |
863 blink::WebCryptoAlgorithm algorithm = | |
864 CreateRsaKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, | |
865 kModulusLength, | |
866 HexStringToBytes("010001")); | |
867 const blink::WebCryptoKeyUsageMask usage_mask = | |
868 blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt; | |
869 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | |
870 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); | |
871 EXPECT_TRUE(GenerateKeyPairInternal( | |
872 algorithm, false, usage_mask, &public_key, &private_key)); | |
873 EXPECT_FALSE(public_key.isNull()); | |
874 EXPECT_FALSE(private_key.isNull()); | |
875 | |
876 // Fail encrypt with a private key. | |
877 algorithm = CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5); | |
878 blink::WebArrayBuffer encrypted_data; | |
879 const std::string message_hex_str("0102030405060708090a0b0c0d0e0f"); | |
880 const std::vector<uint8> message_hex(HexStringToBytes(message_hex_str)); | |
881 EXPECT_FALSE( | |
882 EncryptInternal(algorithm, private_key, message_hex, &encrypted_data)); | |
883 | |
884 // Fail encrypt with empty message. | |
885 EXPECT_FALSE(EncryptInternal( | |
886 algorithm, public_key, std::vector<uint8>(), &encrypted_data)); | |
887 | |
888 // Fail encrypt with message too large. RSAES can operate on messages up to | |
889 // length of k - 11 bytes, where k is the octet length of the RSA modulus. | |
890 const unsigned kMaxMsgSizeBytes = kModulusLength / 8 - 11; | |
891 EXPECT_FALSE(EncryptInternal(algorithm, | |
892 public_key, | |
893 std::vector<uint8>(kMaxMsgSizeBytes + 1, '0'), | |
894 &encrypted_data)); | |
895 | |
896 // Do a passing encrypt to generate data for decrypt. | |
eroman
2013/11/21 00:18:26
Not sure what a "passing encrypt" means
padolph
2013/11/21 01:56:11
Done.
| |
897 EXPECT_TRUE( | |
898 EncryptInternal(algorithm, public_key, message_hex, &encrypted_data)); | |
899 | |
900 // Fail decrypt with a public key. | |
901 blink::WebArrayBuffer decrypted_data; | |
902 EXPECT_FALSE(DecryptInternal( | |
903 algorithm, | |
904 public_key, | |
905 reinterpret_cast<const unsigned char*>(encrypted_data.data()), | |
906 encrypted_data.byteLength(), | |
907 &decrypted_data)); | |
908 | |
909 // Corrupt encrypted data, ensure decrypt fails because padding was disrupted. | |
910 std::vector<uint8> corrupted_data( | |
911 static_cast<uint8*>(encrypted_data.data()), | |
912 static_cast<uint8*>(encrypted_data.data()) + encrypted_data.byteLength()); | |
913 corrupted_data[corrupted_data.size() / 2] ^= 0x01; | |
914 EXPECT_FALSE( | |
915 DecryptInternal(algorithm, private_key, corrupted_data, &decrypted_data)); | |
916 | |
917 // TODO(padolph): Are there other specific data corruption scenarios to | |
918 // consider? | |
919 | |
920 // Pass decrypt with good data just for confirmation. | |
921 EXPECT_TRUE(DecryptInternal( | |
922 algorithm, | |
923 private_key, | |
924 reinterpret_cast<const unsigned char*>(encrypted_data.data()), | |
925 encrypted_data.byteLength(), | |
926 &decrypted_data)); | |
927 ExpectArrayBufferMatchesHex(message_hex_str, decrypted_data); | |
928 } | |
929 | |
797 #endif // #if !defined(USE_OPENSSL) | 930 #endif // #if !defined(USE_OPENSSL) |
798 | 931 |
799 } // namespace content | 932 } // namespace content |
OLD | NEW |