Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: content/child/webcrypto/shared_crypto_unittest.cc

Issue 328903003: [webcrypto] Remove support for AES 192-bit keys (2 of 2) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase onto master Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/child/webcrypto/shared_crypto.cc ('k') | content/child/webcrypto/status.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/child/webcrypto/shared_crypto.h" 5 #include "content/child/webcrypto/shared_crypto.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 CryptoData(&test_cipher_text[0], test_cipher_text.size() - 3), 1072 CryptoData(&test_cipher_text[0], test_cipher_text.size() - 3),
1073 &output)); 1073 &output));
1074 } 1074 }
1075 } 1075 }
1076 } 1076 }
1077 1077
1078 TEST_F(SharedCryptoTest, MAYBE(GenerateKeyAes)) { 1078 TEST_F(SharedCryptoTest, MAYBE(GenerateKeyAes)) {
1079 // Check key generation for each of AES-CBC, AES-GCM, and AES-KW, and for each 1079 // Check key generation for each of AES-CBC, AES-GCM, and AES-KW, and for each
1080 // allowed key length. 1080 // allowed key length.
1081 std::vector<blink::WebCryptoAlgorithm> algorithm; 1081 std::vector<blink::WebCryptoAlgorithm> algorithm;
1082 const unsigned short kKeyLength[] = {128, 192, 256}; 1082 const unsigned short kKeyLength[] = {128, 256};
1083 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kKeyLength); ++i) { 1083 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kKeyLength); ++i) {
1084 algorithm.push_back(CreateAesCbcKeyGenAlgorithm(kKeyLength[i])); 1084 algorithm.push_back(CreateAesCbcKeyGenAlgorithm(kKeyLength[i]));
1085 algorithm.push_back(CreateAesKwKeyGenAlgorithm(kKeyLength[i])); 1085 algorithm.push_back(CreateAesKwKeyGenAlgorithm(kKeyLength[i]));
1086 if (SupportsAesGcm()) 1086 if (SupportsAesGcm())
1087 algorithm.push_back(CreateAesGcmKeyGenAlgorithm(kKeyLength[i])); 1087 algorithm.push_back(CreateAesGcmKeyGenAlgorithm(kKeyLength[i]));
1088 } 1088 }
1089 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); 1089 blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
1090 std::vector<std::vector<uint8> > keys; 1090 std::vector<std::vector<uint8> > keys;
1091 std::vector<uint8> key_bytes; 1091 std::vector<uint8> key_bytes;
1092 for (size_t i = 0; i < algorithm.size(); ++i) { 1092 for (size_t i = 0; i < algorithm.size(); ++i) {
(...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after
1819 1819
1820 EXPECT_BYTES_EQ_HEX(mac_raw, output); 1820 EXPECT_BYTES_EQ_HEX(mac_raw, output);
1821 1821
1822 // TODO(padolph): Import an RSA public key JWK and use it 1822 // TODO(padolph): Import an RSA public key JWK and use it
1823 } 1823 }
1824 1824
1825 TEST_F(SharedCryptoTest, MAYBE(ImportExportJwkSymmetricKey)) { 1825 TEST_F(SharedCryptoTest, MAYBE(ImportExportJwkSymmetricKey)) {
1826 // Raw keys are generated by openssl: 1826 // Raw keys are generated by openssl:
1827 // % openssl rand -hex <key length bytes> 1827 // % openssl rand -hex <key length bytes>
1828 const char* const key_hex_128 = "3f1e7cd4f6f8543f6b1e16002e688623"; 1828 const char* const key_hex_128 = "3f1e7cd4f6f8543f6b1e16002e688623";
1829 const char* const key_hex_192 =
1830 "ed91f916dc034eba68a0f9e7f34ddd48b98bd2848109e243";
1831 const char* const key_hex_256 = 1829 const char* const key_hex_256 =
1832 "bd08286b81a74783fd1ccf46b7e05af84ee25ae021210074159e0c4d9d907692"; 1830 "bd08286b81a74783fd1ccf46b7e05af84ee25ae021210074159e0c4d9d907692";
1833 const char* const key_hex_384 = 1831 const char* const key_hex_384 =
1834 "a22c5441c8b185602283d64c7221de1d0951e706bfc09539435ec0e0ed614e1d406623f2" 1832 "a22c5441c8b185602283d64c7221de1d0951e706bfc09539435ec0e0ed614e1d406623f2"
1835 "b31d31819fec30993380dd82"; 1833 "b31d31819fec30993380dd82";
1836 const char* const key_hex_512 = 1834 const char* const key_hex_512 =
1837 "5834f639000d4cf82de124fbfd26fb88d463e99f839a76ba41ac88967c80a3f61e1239a4" 1835 "5834f639000d4cf82de124fbfd26fb88d463e99f839a76ba41ac88967c80a3f61e1239a4"
1838 "52e573dba0750e988152988576efd75b8d0229b7aca2ada2afd392ee"; 1836 "52e573dba0750e988152988576efd75b8d0229b7aca2ada2afd392ee";
1839 const blink::WebCryptoAlgorithm aes_cbc_alg = 1837 const blink::WebCryptoAlgorithm aes_cbc_alg =
1840 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc); 1838 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc);
(...skipping 16 matching lines...) Expand all
1857 const blink::WebCryptoKeyUsageMask usage; 1855 const blink::WebCryptoKeyUsageMask usage;
1858 const char* const jwk_alg; 1856 const char* const jwk_alg;
1859 }; 1857 };
1860 1858
1861 // TODO(padolph): Test AES-CTR JWK export, once AES-CTR import works. 1859 // TODO(padolph): Test AES-CTR JWK export, once AES-CTR import works.
1862 const TestCase kTests[] = { 1860 const TestCase kTests[] = {
1863 // AES-CBC 128 1861 // AES-CBC 128
1864 {key_hex_128, aes_cbc_alg, 1862 {key_hex_128, aes_cbc_alg,
1865 blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt, 1863 blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt,
1866 "A128CBC"}, 1864 "A128CBC"},
1867 // AES-CBC 192
1868 {key_hex_192, aes_cbc_alg, blink::WebCryptoKeyUsageEncrypt, "A192CBC"},
1869 // AES-CBC 256 1865 // AES-CBC 256
1870 {key_hex_256, aes_cbc_alg, blink::WebCryptoKeyUsageDecrypt, "A256CBC"}, 1866 {key_hex_256, aes_cbc_alg, blink::WebCryptoKeyUsageDecrypt, "A256CBC"},
1871 // AES-GCM 128 1867 // AES-GCM 128
1872 {key_hex_128, aes_gcm_alg, 1868 {key_hex_128, aes_gcm_alg,
1873 blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt, 1869 blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt,
1874 "A128GCM"}, 1870 "A128GCM"},
1875 // AES-CGM 192
1876 {key_hex_192, aes_gcm_alg, blink::WebCryptoKeyUsageEncrypt, "A192GCM"},
1877 // AES-GCM 256 1871 // AES-GCM 256
1878 {key_hex_256, aes_gcm_alg, blink::WebCryptoKeyUsageDecrypt, "A256GCM"}, 1872 {key_hex_256, aes_gcm_alg, blink::WebCryptoKeyUsageDecrypt, "A256GCM"},
1879 // AES-KW 128 1873 // AES-KW 128
1880 {key_hex_128, aes_kw_alg, 1874 {key_hex_128, aes_kw_alg,
1881 blink::WebCryptoKeyUsageWrapKey | blink::WebCryptoKeyUsageUnwrapKey, 1875 blink::WebCryptoKeyUsageWrapKey | blink::WebCryptoKeyUsageUnwrapKey,
1882 "A128KW"}, 1876 "A128KW"},
1883 // AES-KW 192
1884 {key_hex_192, aes_kw_alg,
1885 blink::WebCryptoKeyUsageWrapKey | blink::WebCryptoKeyUsageUnwrapKey,
1886 "A192KW"},
1887 // AES-KW 256 1877 // AES-KW 256
1888 {key_hex_256, aes_kw_alg, 1878 {key_hex_256, aes_kw_alg,
1889 blink::WebCryptoKeyUsageWrapKey | blink::WebCryptoKeyUsageUnwrapKey, 1879 blink::WebCryptoKeyUsageWrapKey | blink::WebCryptoKeyUsageUnwrapKey,
1890 "A256KW"}, 1880 "A256KW"},
1891 // HMAC SHA-1 1881 // HMAC SHA-1
1892 {key_hex_256, hmac_sha_1_alg, 1882 {key_hex_256, hmac_sha_1_alg,
1893 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageVerify, "HS1"}, 1883 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageVerify, "HS1"},
1894 // HMAC SHA-384 1884 // HMAC SHA-384
1895 {key_hex_384, hmac_sha_384_alg, blink::WebCryptoKeyUsageSign, "HS384"}, 1885 {key_hex_384, hmac_sha_384_alg, blink::WebCryptoKeyUsageSign, "HS384"},
1896 // HMAC SHA-512 1886 // HMAC SHA-512
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
2808 true, 2798 true,
2809 blink::WebCryptoKeyUsageWrapKey, 2799 blink::WebCryptoKeyUsageWrapKey,
2810 &key)); 2800 &key));
2811 std::vector<uint8> key_raw_out; 2801 std::vector<uint8> key_raw_out;
2812 EXPECT_EQ(Status::Success(), 2802 EXPECT_EQ(Status::Success(),
2813 ExportKey(blink::WebCryptoKeyFormatRaw, key, &key_raw_out)); 2803 ExportKey(blink::WebCryptoKeyFormatRaw, key, &key_raw_out));
2814 EXPECT_BYTES_EQ_HEX(key_raw_hex_in, key_raw_out); 2804 EXPECT_BYTES_EQ_HEX(key_raw_hex_in, key_raw_out);
2815 2805
2816 // Import a 192-bit KEK 2806 // Import a 192-bit KEK
2817 key_raw_hex_in = "c0192c6466b2370decbb62b2cfef4384544ffeb4d2fbc103"; 2807 key_raw_hex_in = "c0192c6466b2370decbb62b2cfef4384544ffeb4d2fbc103";
2818 ASSERT_EQ(Status::Success(), 2808 ASSERT_EQ(Status::ErrorAes192BitUnsupported(),
2819 ImportKey(blink::WebCryptoKeyFormatRaw, 2809 ImportKey(blink::WebCryptoKeyFormatRaw,
2820 CryptoData(HexStringToBytes(key_raw_hex_in)), 2810 CryptoData(HexStringToBytes(key_raw_hex_in)),
2821 algorithm, 2811 algorithm,
2822 true, 2812 true,
2823 blink::WebCryptoKeyUsageWrapKey, 2813 blink::WebCryptoKeyUsageWrapKey,
2824 &key)); 2814 &key));
2825 EXPECT_EQ(Status::Success(),
2826 ExportKey(blink::WebCryptoKeyFormatRaw, key, &key_raw_out));
2827 EXPECT_BYTES_EQ_HEX(key_raw_hex_in, key_raw_out);
2828 2815
2829 // Import a 256-bit Key Encryption Key (KEK) 2816 // Import a 256-bit Key Encryption Key (KEK)
2830 key_raw_hex_in = 2817 key_raw_hex_in =
2831 "e11fe66380d90fa9ebefb74e0478e78f95664d0c67ca20ce4a0b5842863ac46f"; 2818 "e11fe66380d90fa9ebefb74e0478e78f95664d0c67ca20ce4a0b5842863ac46f";
2832 ASSERT_EQ(Status::Success(), 2819 ASSERT_EQ(Status::Success(),
2833 ImportKey(blink::WebCryptoKeyFormatRaw, 2820 ImportKey(blink::WebCryptoKeyFormatRaw,
2834 CryptoData(HexStringToBytes(key_raw_hex_in)), 2821 CryptoData(HexStringToBytes(key_raw_hex_in)),
2835 algorithm, 2822 algorithm,
2836 true, 2823 true,
2837 blink::WebCryptoKeyUsageWrapKey, 2824 blink::WebCryptoKeyUsageWrapKey,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2928 2915
2929 // Import the wrapping key. 2916 // Import the wrapping key.
2930 blink::WebCryptoKey wrapping_key = ImportSecretKeyFromRaw( 2917 blink::WebCryptoKey wrapping_key = ImportSecretKeyFromRaw(
2931 test_kek, 2918 test_kek,
2932 wrapping_algorithm, 2919 wrapping_algorithm,
2933 blink::WebCryptoKeyUsageWrapKey | blink::WebCryptoKeyUsageUnwrapKey); 2920 blink::WebCryptoKeyUsageWrapKey | blink::WebCryptoKeyUsageUnwrapKey);
2934 2921
2935 // Import the key to be wrapped. 2922 // Import the key to be wrapped.
2936 blink::WebCryptoKey key = ImportSecretKeyFromRaw( 2923 blink::WebCryptoKey key = ImportSecretKeyFromRaw(
2937 test_key, 2924 test_key,
2938 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), 2925 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1),
2939 blink::WebCryptoKeyUsageEncrypt); 2926 blink::WebCryptoKeyUsageSign);
2940 2927
2941 // Wrap the key and verify the ciphertext result against the known answer. 2928 // Wrap the key and verify the ciphertext result against the known answer.
2942 std::vector<uint8> wrapped_key; 2929 std::vector<uint8> wrapped_key;
2943 ASSERT_EQ(Status::Success(), 2930 ASSERT_EQ(Status::Success(),
2944 WrapKey(blink::WebCryptoKeyFormatRaw, 2931 WrapKey(blink::WebCryptoKeyFormatRaw,
2945 key, 2932 key,
2946 wrapping_key, 2933 wrapping_key,
2947 wrapping_algorithm, 2934 wrapping_algorithm,
2948 &wrapped_key)); 2935 &wrapped_key));
2949 EXPECT_BYTES_EQ(test_ciphertext, wrapped_key); 2936 EXPECT_BYTES_EQ(test_ciphertext, wrapped_key);
2950 2937
2951 // Unwrap the known ciphertext to get a new test_key. 2938 // Unwrap the known ciphertext to get a new test_key.
2952 blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull(); 2939 blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull();
2953 ASSERT_EQ( 2940 ASSERT_EQ(
2954 Status::Success(), 2941 Status::Success(),
2955 UnwrapKey(blink::WebCryptoKeyFormatRaw, 2942 UnwrapKey(blink::WebCryptoKeyFormatRaw,
2956 CryptoData(test_ciphertext), 2943 CryptoData(test_ciphertext),
2957 wrapping_key, 2944 wrapping_key,
2958 wrapping_algorithm, 2945 wrapping_algorithm,
2959 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), 2946 CreateHmacImportAlgorithm(blink::WebCryptoAlgorithmIdSha1),
2960 true, 2947 true,
2961 blink::WebCryptoKeyUsageEncrypt, 2948 blink::WebCryptoKeyUsageSign,
2962 &unwrapped_key)); 2949 &unwrapped_key));
2963 EXPECT_FALSE(key.isNull()); 2950 EXPECT_FALSE(key.isNull());
2964 EXPECT_TRUE(key.handle()); 2951 EXPECT_TRUE(key.handle());
2965 EXPECT_EQ(blink::WebCryptoKeyTypeSecret, key.type()); 2952 EXPECT_EQ(blink::WebCryptoKeyTypeSecret, key.type());
2966 EXPECT_EQ(blink::WebCryptoAlgorithmIdAesCbc, key.algorithm().id()); 2953 EXPECT_EQ(blink::WebCryptoAlgorithmIdHmac, key.algorithm().id());
2967 EXPECT_EQ(true, key.extractable()); 2954 EXPECT_EQ(true, key.extractable());
2968 EXPECT_EQ(blink::WebCryptoKeyUsageEncrypt, key.usages()); 2955 EXPECT_EQ(blink::WebCryptoKeyUsageSign, key.usages());
2969 2956
2970 // Export the new key and compare its raw bytes with the original known key. 2957 // Export the new key and compare its raw bytes with the original known key.
2971 std::vector<uint8> raw_key; 2958 std::vector<uint8> raw_key;
2972 EXPECT_EQ(Status::Success(), 2959 EXPECT_EQ(Status::Success(),
2973 ExportKey(blink::WebCryptoKeyFormatRaw, unwrapped_key, &raw_key)); 2960 ExportKey(blink::WebCryptoKeyFormatRaw, unwrapped_key, &raw_key));
2974 EXPECT_BYTES_EQ(test_key, raw_key); 2961 EXPECT_BYTES_EQ(test_key, raw_key);
2975 } 2962 }
2976 } 2963 }
2977 2964
2978 // Unwrap a HMAC key using AES-KW, and then try doing a sign/verify with the 2965 // Unwrap a HMAC key using AES-KW, and then try doing a sign/verify with the
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
3031 CryptoData(signature), 3018 CryptoData(signature),
3032 CryptoData(test_message), 3019 CryptoData(test_message),
3033 &verify_result)); 3020 &verify_result));
3034 } 3021 }
3035 3022
3036 TEST_F(SharedCryptoTest, MAYBE(AesKwRawSymkeyWrapUnwrapErrors)) { 3023 TEST_F(SharedCryptoTest, MAYBE(AesKwRawSymkeyWrapUnwrapErrors)) {
3037 scoped_ptr<base::ListValue> tests; 3024 scoped_ptr<base::ListValue> tests;
3038 ASSERT_TRUE(ReadJsonTestFileToList("aes_kw.json", &tests)); 3025 ASSERT_TRUE(ReadJsonTestFileToList("aes_kw.json", &tests));
3039 base::DictionaryValue* test; 3026 base::DictionaryValue* test;
3040 // Use 256 bits of data with a 256-bit KEK 3027 // Use 256 bits of data with a 256-bit KEK
3041 ASSERT_TRUE(tests->GetDictionary(5, &test)); 3028 ASSERT_TRUE(tests->GetDictionary(3, &test));
3042 const std::vector<uint8> test_kek = GetBytesFromHexString(test, "kek"); 3029 const std::vector<uint8> test_kek = GetBytesFromHexString(test, "kek");
3043 const std::vector<uint8> test_key = GetBytesFromHexString(test, "key"); 3030 const std::vector<uint8> test_key = GetBytesFromHexString(test, "key");
3044 const std::vector<uint8> test_ciphertext = 3031 const std::vector<uint8> test_ciphertext =
3045 GetBytesFromHexString(test, "ciphertext"); 3032 GetBytesFromHexString(test, "ciphertext");
3046 const blink::WebCryptoAlgorithm wrapping_algorithm = 3033 const blink::WebCryptoAlgorithm wrapping_algorithm =
3047 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); 3034 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw);
3048 const blink::WebCryptoAlgorithm key_algorithm = 3035 const blink::WebCryptoAlgorithm key_algorithm =
3049 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc); 3036 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc);
3050 // Import the wrapping key. 3037 // Import the wrapping key.
3051 blink::WebCryptoKey wrapping_key = ImportSecretKeyFromRaw( 3038 blink::WebCryptoKey wrapping_key = ImportSecretKeyFromRaw(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3084 true, 3071 true,
3085 blink::WebCryptoKeyUsageEncrypt, 3072 blink::WebCryptoKeyUsageEncrypt,
3086 &unwrapped_key)); 3073 &unwrapped_key));
3087 } 3074 }
3088 3075
3089 TEST_F(SharedCryptoTest, MAYBE(AesKwRawSymkeyUnwrapCorruptData)) { 3076 TEST_F(SharedCryptoTest, MAYBE(AesKwRawSymkeyUnwrapCorruptData)) {
3090 scoped_ptr<base::ListValue> tests; 3077 scoped_ptr<base::ListValue> tests;
3091 ASSERT_TRUE(ReadJsonTestFileToList("aes_kw.json", &tests)); 3078 ASSERT_TRUE(ReadJsonTestFileToList("aes_kw.json", &tests));
3092 base::DictionaryValue* test; 3079 base::DictionaryValue* test;
3093 // Use 256 bits of data with a 256-bit KEK 3080 // Use 256 bits of data with a 256-bit KEK
3094 ASSERT_TRUE(tests->GetDictionary(5, &test)); 3081 ASSERT_TRUE(tests->GetDictionary(3, &test));
3095 const std::vector<uint8> test_kek = GetBytesFromHexString(test, "kek"); 3082 const std::vector<uint8> test_kek = GetBytesFromHexString(test, "kek");
3096 const std::vector<uint8> test_key = GetBytesFromHexString(test, "key"); 3083 const std::vector<uint8> test_key = GetBytesFromHexString(test, "key");
3097 const std::vector<uint8> test_ciphertext = 3084 const std::vector<uint8> test_ciphertext =
3098 GetBytesFromHexString(test, "ciphertext"); 3085 GetBytesFromHexString(test, "ciphertext");
3099 const blink::WebCryptoAlgorithm wrapping_algorithm = 3086 const blink::WebCryptoAlgorithm wrapping_algorithm =
3100 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); 3087 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw);
3101 3088
3102 // Import the wrapping key. 3089 // Import the wrapping key.
3103 blink::WebCryptoKey wrapping_key = ImportSecretKeyFromRaw( 3090 blink::WebCryptoKey wrapping_key = ImportSecretKeyFromRaw(
3104 test_kek, 3091 test_kek,
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
3291 test_iv, 3278 test_iv,
3292 test_additional_data, 3279 test_additional_data,
3293 wrong_tag_size_bits, 3280 wrong_tag_size_bits,
3294 test_cipher_text, 3281 test_cipher_text,
3295 test_authentication_tag, 3282 test_authentication_tag,
3296 &plain_text)); 3283 &plain_text));
3297 } 3284 }
3298 } 3285 }
3299 } 3286 }
3300 3287
3288 // AES 192-bit is not allowed: http://crbug.com/381829
3289 TEST_F(SharedCryptoTest, MAYBE(ImportAesCbc192Raw)) {
3290 std::vector<uint8> key_raw(24, 0);
3291 blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
3292 Status status = ImportKey(blink::WebCryptoKeyFormatRaw,
3293 CryptoData(key_raw),
3294 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc),
3295 true,
3296 blink::WebCryptoKeyUsageEncrypt,
3297 &key);
3298 ASSERT_EQ(Status::ErrorAes192BitUnsupported(), status);
3299 }
3300
3301 // AES 192-bit is not allowed: http://crbug.com/381829
3302 TEST_F(SharedCryptoTest, MAYBE(ImportAesCbc192Jwk)) {
3303 blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
3304
3305 base::DictionaryValue dict;
3306 dict.SetString("kty", "oct");
3307 dict.SetString("alg", "A192CBC");
3308 dict.SetString("k", "YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh");
3309
3310 EXPECT_EQ(
3311 Status::ErrorAes192BitUnsupported(),
3312 ImportKeyJwkFromDict(dict,
3313 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc),
3314 false,
3315 blink::WebCryptoKeyUsageEncrypt,
3316 &key));
3317 }
3318
3319 // AES 192-bit is not allowed: http://crbug.com/381829
3320 TEST_F(SharedCryptoTest, MAYBE(GenerateAesCbc192)) {
3321 blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
3322 Status status = GenerateSecretKey(CreateAesCbcKeyGenAlgorithm(192),
3323 true,
3324 blink::WebCryptoKeyUsageEncrypt,
3325 &key);
3326 ASSERT_EQ(Status::ErrorAes192BitUnsupported(), status);
3327 }
3328
3329 // AES 192-bit is not allowed: http://crbug.com/381829
3330 TEST_F(SharedCryptoTest, MAYBE(UnwrapAesCbc192)) {
3331 std::vector<uint8> wrapping_key_data(16, 0);
3332 std::vector<uint8> wrapped_key = HexStringToBytes(
3333 "1A07ACAB6C906E50883173C29441DB1DE91D34F45C435B5F99C822867FB3956F");
3334
3335 blink::WebCryptoKey wrapping_key =
3336 ImportSecretKeyFromRaw(wrapping_key_data,
3337 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw),
3338 blink::WebCryptoKeyUsageUnwrapKey);
3339
3340 blink::WebCryptoKey unwrapped_key = blink::WebCryptoKey::createNull();
3341 ASSERT_EQ(Status::ErrorAes192BitUnsupported(),
3342 UnwrapKey(blink::WebCryptoKeyFormatRaw,
3343 CryptoData(wrapped_key),
3344 wrapping_key,
3345 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw),
3346 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc),
3347 true,
3348 blink::WebCryptoKeyUsageEncrypt,
3349 &unwrapped_key));
3350 }
3351
3301 class SharedCryptoRsaOaepTest : public ::testing::Test { 3352 class SharedCryptoRsaOaepTest : public ::testing::Test {
3302 public: 3353 public:
3303 SharedCryptoRsaOaepTest() { Init(); } 3354 SharedCryptoRsaOaepTest() { Init(); }
3304 3355
3305 scoped_ptr<base::DictionaryValue> CreatePublicKeyJwkDict() { 3356 scoped_ptr<base::DictionaryValue> CreatePublicKeyJwkDict() {
3306 scoped_ptr<base::DictionaryValue> jwk(new base::DictionaryValue()); 3357 scoped_ptr<base::DictionaryValue> jwk(new base::DictionaryValue());
3307 jwk->SetString("kty", "RSA"); 3358 jwk->SetString("kty", "RSA");
3308 jwk->SetString("n", 3359 jwk->SetString("n",
3309 Base64EncodeUrlSafe(HexStringToBytes(kPublicKeyModulusHex))); 3360 Base64EncodeUrlSafe(HexStringToBytes(kPublicKeyModulusHex)));
3310 jwk->SetString( 3361 jwk->SetString(
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after
4266 EXPECT_EQ(public_key_spki, unwrapped_public_key_spki); 4317 EXPECT_EQ(public_key_spki, unwrapped_public_key_spki);
4267 EXPECT_EQ(private_key_pkcs8, unwrapped_private_key_pkcs8); 4318 EXPECT_EQ(private_key_pkcs8, unwrapped_private_key_pkcs8);
4268 4319
4269 EXPECT_NE(public_key_spki, wrapped_public_key); 4320 EXPECT_NE(public_key_spki, wrapped_public_key);
4270 EXPECT_NE(private_key_pkcs8, wrapped_private_key); 4321 EXPECT_NE(private_key_pkcs8, wrapped_private_key);
4271 } 4322 }
4272 4323
4273 } // namespace webcrypto 4324 } // namespace webcrypto
4274 4325
4275 } // namespace content 4326 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/shared_crypto.cc ('k') | content/child/webcrypto/status.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698