OLD | NEW |
---|---|
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/renderer/webcrypto/webcrypto_impl.h" | 5 #include "content/renderer/webcrypto/webcrypto_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/file_util.h" | |
13 #include "base/json/json_reader.h" | |
12 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
13 #include "base/logging.h" | 15 #include "base/logging.h" |
14 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/path_service.h" | |
15 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/values.h" | |
20 #include "content/public/common/content_paths.h" | |
16 #include "content/public/renderer/content_renderer_client.h" | 21 #include "content/public/renderer/content_renderer_client.h" |
17 #include "content/renderer/renderer_webkitplatformsupport_impl.h" | 22 #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
18 #include "content/renderer/webcrypto/webcrypto_util.h" | 23 #include "content/renderer/webcrypto/webcrypto_util.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" | 25 #include "third_party/WebKit/public/platform/WebArrayBuffer.h" |
21 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" | 26 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
22 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" | 27 #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
23 #include "third_party/WebKit/public/platform/WebCryptoKey.h" | 28 #include "third_party/WebKit/public/platform/WebCryptoKey.h" |
29 #include "third_party/re2/re2/re2.h" | |
Ryan Sleevi
2014/01/28 20:37:21
I don't think this sort ordering is correct
eroman
2014/01/29 03:26:53
I believe this is correct -- it is in lexicographi
| |
24 | 30 |
25 // The OpenSSL implementation of WebCrypto is less complete, so don't run all of | 31 // The OpenSSL implementation of WebCrypto is less complete, so don't run all of |
26 // the tests: http://crbug.com/267888 | 32 // the tests: http://crbug.com/267888 |
27 #if defined(USE_OPENSSL) | 33 #if defined(USE_OPENSSL) |
28 #define MAYBE(test_name) DISABLED_##test_name | 34 #define MAYBE(test_name) DISABLED_##test_name |
29 #else | 35 #else |
30 #define MAYBE(test_name) test_name | 36 #define MAYBE(test_name) test_name |
31 #endif | 37 #endif |
32 | 38 |
33 // Helper macros to verify the value of a Status. | 39 // Helper macros to verify the value of a Status. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 std::vector<uint8> MakeJsonVector(const std::string& json_string) { | 87 std::vector<uint8> MakeJsonVector(const std::string& json_string) { |
82 return std::vector<uint8>(json_string.begin(), json_string.end()); | 88 return std::vector<uint8>(json_string.begin(), json_string.end()); |
83 } | 89 } |
84 | 90 |
85 std::vector<uint8> MakeJsonVector(const base::DictionaryValue& dict) { | 91 std::vector<uint8> MakeJsonVector(const base::DictionaryValue& dict) { |
86 std::string json; | 92 std::string json; |
87 base::JSONWriter::Write(&dict, &json); | 93 base::JSONWriter::Write(&dict, &json); |
88 return MakeJsonVector(json); | 94 return MakeJsonVector(json); |
89 } | 95 } |
90 | 96 |
97 // Helpers for working with JSON data files for test expectations. | |
98 | |
99 ::testing::AssertionResult ReadJsonTestFile( | |
Ryan Sleevi
2014/01/28 20:37:21
Document
eroman
2014/01/29 03:26:53
Done.
| |
100 const char* test_file_name, | |
101 scoped_ptr<base::Value>* value) { | |
102 // Get a path to the test files (src/content/test/data/webcrypto) | |
103 base::FilePath test_data_dir; | |
104 if (!PathService::Get(DIR_TEST_DATA, &test_data_dir)) | |
105 return ::testing::AssertionFailure() << "Couldn't retrieve test dir"; | |
106 | |
107 base::FilePath file_path = | |
108 test_data_dir.AppendASCII("webcrypto").AppendASCII(test_file_name); | |
109 | |
110 std::string file_contents; | |
111 if (!base::ReadFileToString(file_path, &file_contents)) { | |
112 return ::testing::AssertionFailure() << "Couldn't read test file: " | |
113 << file_path.value(); | |
Ryan Sleevi
2014/01/28 20:37:21
nit: align
eroman
2014/01/29 03:26:53
Done.
| |
114 } | |
115 | |
116 // Strip C++ style comments out of the "json" file, otherwise it cannot be | |
117 // parsed. | |
118 re2::RE2::GlobalReplace(&file_contents, re2::RE2("\\s*//.*"), ""); | |
119 LOG(ERROR) << file_contents; | |
Ryan Sleevi
2014/01/28 20:37:21
Debug spam?
eroman
2014/01/29 03:26:53
Oops! Removed.
| |
120 | |
121 // Parse the JSON to a dictionary. | |
122 value->reset(base::JSONReader::Read(file_contents)); | |
123 if (!value->get()) { | |
124 return ::testing::AssertionFailure() << "Couldn't parse test file JSON: " | |
125 << file_path.value(); | |
126 } | |
127 | |
128 return ::testing::AssertionSuccess(); | |
129 } | |
130 | |
131 ::testing::AssertionResult ReadJsonTestFileToList( | |
Ryan Sleevi
2014/01/28 20:37:21
Document
eroman
2014/01/29 03:26:53
Done.
| |
132 const char* test_file_name, | |
133 scoped_ptr<base::ListValue>* list) { | |
134 // Read the JSON. | |
135 scoped_ptr<base::Value> json; | |
136 ::testing::AssertionResult result = ReadJsonTestFile(test_file_name, &json); | |
137 if (!result) | |
138 return result; | |
139 | |
140 // Cast to an ListValue. | |
141 base::ListValue* list_value = NULL; | |
142 if (!json->GetAsList(&list_value) || !list_value) | |
143 return ::testing::AssertionFailure() << "The JSON was not a list"; | |
144 | |
145 list->reset(list_value); | |
146 ignore_result(json.release()); | |
147 | |
148 return ::testing::AssertionSuccess(); | |
149 } | |
150 | |
151 // Helper to read a hex string and convert the hex to bytes. | |
152 ::testing::AssertionResult GetBytesFromHexString( | |
153 base::DictionaryValue* dict, | |
154 const char* property_name, | |
155 std::vector<uint8>* bytes) { | |
156 | |
157 std::string hex_string; | |
158 if (!dict->GetString(property_name, &hex_string)) { | |
159 return ::testing::AssertionFailure() << "Couldn't get string property: " | |
160 << property_name; | |
161 } | |
162 | |
163 *bytes = HexStringToBytes(hex_string); | |
164 return ::testing::AssertionSuccess(); | |
165 } | |
166 | |
91 // Helper for ImportJwkFailures and ImportJwkOctFailures. Restores the JWK JSON | 167 // Helper for ImportJwkFailures and ImportJwkOctFailures. Restores the JWK JSON |
92 // dictionary to a good state | 168 // dictionary to a good state |
93 void RestoreJwkOctDictionary(base::DictionaryValue* dict) { | 169 void RestoreJwkOctDictionary(base::DictionaryValue* dict) { |
94 dict->Clear(); | 170 dict->Clear(); |
95 dict->SetString("kty", "oct"); | 171 dict->SetString("kty", "oct"); |
96 dict->SetString("alg", "A128CBC"); | 172 dict->SetString("alg", "A128CBC"); |
97 dict->SetString("use", "enc"); | 173 dict->SetString("use", "enc"); |
98 dict->SetBoolean("extractable", false); | 174 dict->SetBoolean("extractable", false); |
99 dict->SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); | 175 dict->SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); |
100 } | 176 } |
(...skipping 1970 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2071 blink::WebCryptoAlgorithmIdSha256), | 2147 blink::WebCryptoAlgorithmIdSha256), |
2072 public_key, | 2148 public_key, |
2073 static_cast<const unsigned char*>(signature.data()), | 2149 static_cast<const unsigned char*>(signature.data()), |
2074 signature.byteLength(), | 2150 signature.byteLength(), |
2075 data, | 2151 data, |
2076 &is_match)); | 2152 &is_match)); |
2077 EXPECT_FALSE(is_match); | 2153 EXPECT_FALSE(is_match); |
2078 } | 2154 } |
2079 | 2155 |
2080 TEST_F(WebCryptoImplTest, MAYBE(RsaSignVerifyKnownAnswer)) { | 2156 TEST_F(WebCryptoImplTest, MAYBE(RsaSignVerifyKnownAnswer)) { |
2081 // Use the NIST test vectors from Example 1 of | 2157 scoped_ptr<base::ListValue> tests; |
2082 // ftp://ftp.rsa.com/pub/rsalabs/tmp/pkcs1v15sign-vectors.txt | 2158 ASSERT_TRUE(ReadJsonTestFileToList("pkcs1v15sign.json", &tests)); |
Ryan Sleevi
2014/01/28 20:37:21
nit: Add some form of word separator
pkcs1v15_sig
eroman
2014/01/29 03:26:53
The name was inspired by the ftp:// URL (but inter
| |
2083 // These vectors are known answers for RSA PKCS#1 v1.5 Signature with a SHA-1 | |
2084 // digest, using a predefined key pair. | |
2085 | |
2086 struct TestCase { | |
2087 const std::string message_hex; | |
2088 const std::string signature_hex; | |
2089 }; | |
2090 | |
2091 // The following data are the input messages and corresponding computed RSA | |
2092 // PKCS#1 v1.5 signatures from the NIST link above. | |
2093 const TestCase kTests[] = { | |
2094 // PKCS#1 v1.5 Signature Example 1.1 | |
2095 {"cdc87da223d786df3b45e0bbbc721326d1ee2af806cc315475cc6f0d9c66e1b6" | |
2096 "2371d45ce2392e1ac92844c310102f156a0d8d52c1f4c40ba3aa65095786cb76" | |
2097 "9757a6563ba958fed0bcc984e8b517a3d5f515b23b8a41e74aa867693f90dfb0" | |
2098 "61a6e86dfaaee64472c00e5f20945729cbebe77f06ce78e08f4098fba41f9d61" | |
2099 "93c0317e8b60d4b6084acb42d29e3808a3bc372d85e331170fcbf7cc72d0b71c" | |
2100 "296648b3a4d10f416295d0807aa625cab2744fd9ea8fd223c42537029828bd16" | |
2101 "be02546f130fd2e33b936d2676e08aed1b73318b750a0167d0", | |
2102 "6bc3a06656842930a247e30d5864b4d819236ba7c68965862ad7dbc4e24af28e" | |
2103 "86bb531f03358be5fb74777c6086f850caef893f0d6fcc2d0c91ec013693b4ea" | |
2104 "00b80cd49aac4ecb5f8911afe539ada4a8f3823d1d13e472d1490547c659c761" | |
2105 "7f3d24087ddb6f2b72096167fc097cab18e9a458fcb634cdce8ee35894c484d7"}, | |
2106 // PKCS#1 v1.5 Signature Example 1.2 | |
2107 {"851384cdfe819c22ed6c4ccb30daeb5cf059bc8e1166b7e3530c4c233e2b5f8f" | |
2108 "71a1cca582d43ecc72b1bca16dfc7013226b9e", | |
2109 "84fd2ce734ec1da828d0f15bf49a8707c15d05948136de537a3db421384167c8" | |
2110 "6fae022587ee9e137daee754738262932d271c744c6d3a189ad4311bdb020492" | |
2111 "e322fbddc40406ea860d4e8ea2a4084aa98b9622a446756fdb740ddb3d91db76" | |
2112 "70e211661bbf8709b11c08a70771422d1a12def29f0688a192aebd89e0f896f8"}, | |
2113 // PKCS#1 v1.5 Signature Example1.3 | |
2114 {"a4b159941761c40c6a82f2b80d1b94f5aa2654fd17e12d588864679b54cd04ef" | |
2115 "8bd03012be8dc37f4b83af7963faff0dfa225477437c48017ff2be8191cf3955" | |
2116 "fc07356eab3f322f7f620e21d254e5db4324279fe067e0910e2e81ca2cab31c7" | |
2117 "45e67a54058eb50d993cdb9ed0b4d029c06d21a94ca661c3ce27fae1d6cb20f4" | |
2118 "564d66ce4767583d0e5f060215b59017be85ea848939127bd8c9c4d47b51056c" | |
2119 "031cf336f17c9980f3b8f5b9b6878e8b797aa43b882684333e17893fe9caa6aa" | |
2120 "299f7ed1a18ee2c54864b7b2b99b72618fb02574d139ef50f019c9eef4169713" | |
2121 "38e7d470", | |
2122 "0b1f2e5180e5c7b4b5e672929f664c4896e50c35134b6de4d5a934252a3a245f" | |
2123 "f48340920e1034b7d5a5b524eb0e1cf12befef49b27b732d2c19e1c43217d6e1" | |
2124 "417381111a1d36de6375cf455b3c9812639dbc27600c751994fb61799ecf7da6" | |
2125 "bcf51540afd0174db4033188556675b1d763360af46feeca5b60f882829ee7b2"}, | |
2126 // PKCS#1 v1.5 Signature Example 1.4 | |
2127 {"bc656747fa9eafb3f0", | |
2128 "45607ad611cf5747a41ac94d0ffec878bdaf63f6b57a4b088bf36e34e109f840" | |
2129 "f24b742ada16102dabf951cbc44f8982e94ed4cd09448d20ec0efa73545f80b6" | |
2130 "5406bed6194a61c340b4ad1568cbb75851049f11af1734964076e02029aee200" | |
2131 "e40e80be0f4361f69841c4f92a4450a2286d43289b405554c54d25c6ecb584f4"}, | |
2132 // PKCS#1 v1.5 Signature Example 1.5 | |
2133 {"b45581547e5427770c768e8b82b75564e0ea4e9c32594d6bff706544de0a8776" | |
2134 "c7a80b4576550eee1b2acabc7e8b7d3ef7bb5b03e462c11047eadd00629ae575" | |
2135 "480ac1470fe046f13a2bf5af17921dc4b0aa8b02bee6334911651d7f8525d10f" | |
2136 "32b51d33be520d3ddf5a709955a3dfe78283b9e0ab54046d150c177f037fdccc" | |
2137 "5be4ea5f68b5e5a38c9d7edcccc4975f455a6909b4", | |
2138 "54be9d90877515f450279c15b5f61ad6f15ecc95f18cbed82b65b1667a575809" | |
2139 "587994668044f3bc2ae7f884501f64f0b43f588cfa205a6ab704328c2d4ab92a" | |
2140 "7ae13440614d3e085f401da9ad28e2105e4a0edb681a6424df047388ce051ee9" | |
2141 "df7bc2163fe347520ad51ccd518064383e741acad3cbdc2cb5a7c68e868464c2"}, | |
2142 // PKCS#1 v1.5 Signature Example 1.6 | |
2143 {"10aae9a0ab0b595d0841207b700d48d75faedde3b775cd6b4cc88ae06e4694ec" | |
2144 "74ba18f8520d4f5ea69cbbe7cc2beba43efdc10215ac4eb32dc302a1f53dc6c4" | |
2145 "352267e7936cfebf7c8d67035784a3909fa859c7b7b59b8e39c5c2349f1886b7" | |
2146 "05a30267d402f7486ab4f58cad5d69adb17ab8cd0ce1caf5025af4ae24b1fb87" | |
2147 "94c6070cc09a51e2f9911311e3877d0044c71c57a993395008806b723ac38373" | |
2148 "d395481818528c1e7053739282053529510e935cd0fa77b8fa53cc2d474bd4fb" | |
2149 "3cc5c672d6ffdc90a00f9848712c4bcfe46c60573659b11e6457e861f0f604b6" | |
2150 "138d144f8ce4e2da73", | |
2151 "0e6ff63a856b9cbd5dbe423183122047dd39d6f76d1b2310e546fe9ee73b33ef" | |
2152 "a7c78f9474455c9e5b88cb383aafc3698668e7b7a59a9cbb5b0897b6c5afb7f8" | |
2153 "bac4b924e98d760a15fc43d2814ab2d5187f79bed9915a93397ebc22a7677506" | |
2154 "a02e076d3ffdc0441dbd4db00453dc28d830e0573f77b817b505c38b4a4bb5d0"}, | |
2155 // PKCS#1 v1.5 Signature Example 1.7 | |
2156 {"efb5da1b4d1e6d9a5dff92d0184da7e31f877d1281ddda625664869e8379e67a" | |
2157 "d3b75eae74a580e9827abd6eb7a002cb5411f5266797768fb8e95ae40e3e8b34" | |
2158 "66f5ab15d69553952939ec23e61d58497fac76aa1c0bb5a3cb4a54383587c7bb" | |
2159 "78d13eefda205443e6ce4365802df55c64713497984e7ca96722b3edf84d56", | |
2160 "8385d58533a995f72df262b70f40b391ddf515f464b9d2cc2d66398fc05689d8" | |
2161 "11632946d62eabdca7a31fcf6cd6c981d28bbc29083e4a6d5b2b378ca4e540f0" | |
2162 "60b96d53ad2693f82178b94e2e2f86b9accfa02025107e062ab7080175684501" | |
2163 "028f676461d81c008fe4750671649970878fc175cf98e96b2ecbf6874d77dacb"}, | |
2164 // PKCS#1 v1.5 Signature Example 1.8 | |
2165 {"53bb58ce42f1984940552657233b14969af365c0a561a4132af18af39432280e" | |
2166 "3e437082434b19231837184f02cf2b2e726bebf74d7ae3256d8b72f3eafdb134" | |
2167 "d33de06f2991d299d59f5468d43b9958d6a968f5969edbbc6e7185cbc716c7c9" | |
2168 "45dafa9cc71ddfaaa01094a452ddf5e2407320400bf05ea9729cafbf0600e788" | |
2169 "07ef9462e3fde32ed7d981a56f4751ef64fb4549910ecc911d728053b3994300" | |
2170 "4740e6f5821fe8d75c0617bf2c6b24bbfc34013fc95f0dedf5ba297f504fb833" | |
2171 "da2a436d1d8ff1cc5193e2a64389fced918e7feb6716330f66801db9497549cf" | |
2172 "1d3bd97cf1bc6255", | |
2173 "8e1f3d26ec7c6bbb8c54c5d25f3120587803af6d3c2b99a37ced6a3657d4ae54" | |
2174 "266f63fffde660c866d65d0ab0589e1d12d9ce6054b05c8668ae127171ccaae7" | |
2175 "f1cd409677f52157b6123ab227f27a00966d1439b42a32169d1070394026fc8b" | |
2176 "c93545b1ac252d0f7da751c02e33a47831fbd71514c2bbbd3adb6740c0fd68ad"}, | |
2177 // PKCS#1 v1.5 Signature Example 1.9 | |
2178 {"27cadc698450945f204ec3cf8c6cbd8ceb4cc0cbe312274fa96b04deac855160" | |
2179 "c0e04e4ac5d38210c27c", | |
2180 "7b63f9223356f35f6117f68c8f8220034fc2384ab5dc6904141f139314d6ee89" | |
2181 "f54ec6ffd18c413a23c5931c7fbb13c555ccfd590e0eaa853c8c94d2520cd425" | |
2182 "0d9a05a193b65dc749b82478af0156ee1de55ddad33ec1f0099cad6c891a3617" | |
2183 "c7393d05fbfbbb00528a001df0b204ebdf1a341090dea89f870a877458427f7b"}, | |
2184 // PKCS#1 v1.5 Signature Example 1.10 | |
2185 {"716407e901b9ef92d761b013fd13eb7ad72aed", | |
2186 "2a22dbe3774d5b297201b55a0f17f42dce63b7845cb325cfe951d0badb5c5a14" | |
2187 "472143d896c86cc339f83671164215abc97862f2151654e75a3b357c37311b3d" | |
2188 "7268cab540202e23bee52736f2cd86cce0c7dbde95e1c600a47395dc5eb0a472" | |
2189 "153fbc4fb21b643e0c04ae14dd37e97e617a7567c89652219781001ba6f83298"}, | |
2190 // PKCS#1 v1.5 Signature Example 1.11 | |
2191 {"46c24e4103001629c712dd4ce8d747ee595d6c744ccc4f71347d9b8abf49d1b8" | |
2192 "fb2ef91b95dc899d4c0e3d2997e638f4cf3f68e0498de5aabd13f0dfe02ff26b" | |
2193 "a4379104e78ffa95ffbd15067ef8cbd7eb7860fecc71abe13d5c720a66851f2d" | |
2194 "efd4e795054d7bec024bb422a46a7368b56d95b47aebafbeadd612812593a70d" | |
2195 "b9f96d451ee15edb299308d777f4bb68ed3377c32156b41b7a9c92a14c8b8114" | |
2196 "4399c56a5a432f4f770aa97da8415d0bda2e813206031e70620031c881d616bf" | |
2197 "fd5f03bf147c1e73766c26246208", | |
2198 "12235b0b406126d9d260d447e923a11051fb243079f446fd73a70181d53634d7" | |
2199 "a0968e4ee27777eda63f6e4a3a91ad5985998a4848da59ce697b24bb332fa2ad" | |
2200 "9ce462ca4affdc21dab908e8ce15af6eb9105b1abcf39142aa17b34c4c092386" | |
2201 "a7abbfe028afdbebc14f2ce26fbee5edeca11502d39a6b7403154843d98a62a7"}, | |
2202 // PKCS#1 v1.5 Signature Example 1.12 | |
2203 {"bc99a932aa16d622bfff79c50b4c42358673261129e28d6a918ff1b0f1c4f46a" | |
2204 "d8afa98b0ca0f56f967975b0a29be882e93b6cd3fc33e1faef72e52b2ae0a3f1" | |
2205 "2024506e25690e902e782982145556532284cf505789738f4da31fa1333d3af8" | |
2206 "62b2ba6b6ce7ab4cce6aba", | |
2207 "872ec5ad4f1846256f17e9936ac50e43e9963ea8c1e76f15879b7874d77d122a" | |
2208 "609dc8c561145b94bf4ffdffdeb17e6e76ffc6c10c0747f5e37a9f434f5609e7" | |
2209 "9da5250215a457afdf12c6507cc1551f54a28010595826a2c9b97fa0aa851cc6" | |
2210 "8b705d7a06d720ba027e4a1c0b019500fb63b78071684dcfa9772700b982dc66"}, | |
2211 // PKCS#1 v1.5 Signature Example 1.13 | |
2212 {"731e172ac063992c5b11ba170dfb23bb000d47ba195329cf278061037381514c" | |
2213 "146064c5285db130dd5bae98b772225950eab05d3ea996f6fffb9a8c8622913f" | |
2214 "279914c89ada4f3dd77666a868bfcbff2b95b7daf453d4e2c9d75beee7f8e709" | |
2215 "05e4066a4f73aecc67f956aa5a3292b8488c917d317cfdc86253e690381e15ab", | |
2216 "76204eacc1d63ec1d6ad5bd0692e1a2f686df6e64ca945c77a824de212efa6d9" | |
2217 "782d81b4591403ff4020620298c07ebd3a8a61c5bf4dad62cbfc4ae6a03937be" | |
2218 "4b49a216d570fc6e81872937876e27bd19cf601effc30ddca573c9d56cd4569b" | |
2219 "db4851c450c42cb21e738cdd61027b8be5e9b410fc46aa3f29e4be9e64451346"}, | |
2220 // PKCS#1 v1.5 Signature Example 1.14 | |
2221 {"0211382683a74d8d2a2cb6a06550563be1c26ca62821e4ff163b720464fc3a28" | |
2222 "d91bedddc62749a5538eaf41fbe0c82a77e06ad99383c9e985ffb8a93fd4d7c5" | |
2223 "8db51ad91ba461d69a8fd7ddabe2496757a0c49122c1a79a85cc0553e8214d03" | |
2224 "6dfe0185efa0d05860c612fa0882c82d246e5830a67355dff18a2c36b732f988" | |
2225 "cfedc562264c6254b40fcabb97b760947568dcd6a17cda6ee8855bddbab93702" | |
2226 "471aa0cfb1bed2e13118eba1175b73c96253c108d0b2aba05ab8e17e84392e20" | |
2227 "085f47404d8365527dc3fb8f2bb48a50038e71361ccf973407", | |
2228 "525500918331f1042eae0c5c2054aa7f92deb26991b5796634f229daf9b49eb2" | |
2229 "054d87319f3cfa9b466bd075ef6699aea4bd4a195a1c52968b5e2b75e092d846" | |
2230 "ea1b5cc27905a8e1d5e5de0edfdb21391ebb951864ebd9f0b0ec35b654287136" | |
2231 "0a317b7ef13ae06af684e38e21b1e19bc7298e5d6fe0013a164bfa25d3e7313d"}, | |
2232 // PKCS#1 v1.5 Signature Example 1.15 | |
2233 {"fc6b700d22583388ab2f8dafcaf1a05620698020da4bae44dafbd0877b501250" | |
2234 "6dc3181d5c66bf023f348b41fd9f94795ab96452a4219f2d39d72af359cf1956" | |
2235 "51c7", | |
2236 "4452a6cc2626b01e95ab306df0d0cc7484fbab3c22e9703283567f66eadc248d" | |
2237 "bda58fce7dd0c70cce3f150fca4b369dff3b6237e2b16281ab55b53fb13089c8" | |
2238 "5cd265056b3d62a88bfc2135b16791f7fbcab9fd2dc33becb617be419d2c0461" | |
2239 "42a4d47b338314552edd4b6fe9ce1104ecec4a9958d7331e930fc09bf08a6e64"}, | |
2240 // PKCS#1 v1.5 Signature Example 1.16 | |
2241 {"13ba086d709cfa5fedaa557a89181a6140f2300ed6d7c3febb6cf68abebcbc67" | |
2242 "8f2bca3dc2330295eec45bb1c4075f3ada987eae88b39c51606cb80429e649d9" | |
2243 "8acc8441b1f8897db86c5a4ce0abf28b1b81dca3667697b850696b74a5ebd85d" | |
2244 "ec56c90f8abe513efa857853720be319607921bca947522cd8fac8cace5b827c" | |
2245 "3e5a129e7ee57f6b84932f14141ac4274e8cbb46e6912b0d3e2177d499d1840c" | |
2246 "d47d4d7ae0b4cdc4d3", | |
2247 "1f3b5a87db72a2c97bb3eff2a65a301268eacd89f42abc1098c1f2de77b0832a" | |
2248 "65d7815feb35070063f221bb3453bd434386c9a3fde18e3ca1687fb649e86c51" | |
2249 "d658619dde5debb86fe15491ff77ab748373f1be508880d66ea81e870e91cdf1" | |
2250 "704875c17f0b10103188bc64eef5a3551b414c733670215b1a22702562581ab1"}, | |
2251 // PKCS#1 v1.5 Signature Example 1.17 | |
2252 {"eb1e5935", | |
2253 "370cb9839ae6074f84b2acd6e6f6b7921b4b523463757f6446716140c4e6c0e7" | |
2254 "5bec6ad0197ebfa86bf46d094f5f6cd36dca3a5cc73c8bbb70e2c7c9ab5d964e" | |
2255 "c8e3dfde481b4a1beffd01b4ad15b31ae7aebb9b70344a9411083165fdf9c375" | |
2256 "4bbb8b94dd34bd4813dfada1f6937de4267d5597ca09a31e83d7f1a79dd19b5e"}, | |
2257 // PKCS#1 v1.5 Signature Example 1.18 | |
2258 {"6346b153e889c8228209630071c8a57783f368760b8eb908cfc2b276", | |
2259 "2479c975c5b1ae4c4e940f473a9045b8bf5b0bfca78ec29a38dfbedc8a749b7a" | |
2260 "2692f7c52d5bc7c831c7232372a00fed3b6b49e760ec99e074ff2eead5134e83" | |
2261 "05725dfa39212b84bd4b8d80bc8bc17a512823a3beb18fc08e45ed19c26c8177" | |
2262 "07d67fb05832ef1f12a33e90cd93b8a780319e2963ca25a2af7b09ad8f595c21"}, | |
2263 // PKCS#1 v1.5 Signature Example 1.19 | |
2264 {"64702db9f825a0f3abc361974659f5e9d30c3aa4f56feac69050c72905e77fe0" | |
2265 "c22f88a378c21fcf45fe8a5c717302093929", | |
2266 "152f3451c858d69594e6567dfb31291c1ee7860b9d15ebd5a5edd276ac3e6f7a" | |
2267 "8d1480e42b3381d2be023acf7ebbdb28de3d2163ae44259c6df98c335d045b61" | |
2268 "dac9dba9dbbb4e6ab4a083cd76b580cbe472206a1a9fd60680ceea1a570a29b0" | |
2269 "881c775eaef5525d6d2f344c28837d0aca422bbb0f1aba8f6861ae18bd73fe44"}, | |
2270 // PKCS#1 v1.5 Signature Example 1.20 | |
2271 {"941921de4a1c9c1618d6f3ca3c179f6e29bae6ddf9a6a564f929e3ce82cf3265" | |
2272 "d7837d5e692be8dcc9e86c", | |
2273 "7076c287fc6fff2b20537435e5a3107ce4da10716186d01539413e609d27d1da" | |
2274 "6fd952c61f4bab91c045fa4f8683ecc4f8dde74227f773cff3d96db84718c494" | |
2275 "4b06affeba94b725f1b07d3928b2490a85c2f1abf492a9177a7cd2ea0c966875" | |
2276 "6f825bbec900fa8ac3824e114387ef573780ca334882387b94e5aad7a27a28dc"}}; | |
2277 | 2159 |
2278 // Import the key pair. | 2160 // Import the key pair. |
2279 blink::WebCryptoAlgorithm algorithm = CreateRsaAlgorithmWithInnerHash( | 2161 blink::WebCryptoAlgorithm algorithm = CreateRsaAlgorithmWithInnerHash( |
2280 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 2162 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
2281 blink::WebCryptoAlgorithmIdSha1); | 2163 blink::WebCryptoAlgorithmIdSha1); |
2282 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | 2164 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
2283 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); | 2165 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); |
2284 ImportRsaKeyPair( | 2166 ImportRsaKeyPair( |
2285 kPublicKeySpkiDerHex, | 2167 kPublicKeySpkiDerHex, |
2286 kPrivateKeyPkcs8DerHex, | 2168 kPrivateKeyPkcs8DerHex, |
2287 algorithm, | 2169 algorithm, |
2288 false, | 2170 false, |
2289 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageVerify, | 2171 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageVerify, |
2290 &public_key, | 2172 &public_key, |
2291 &private_key); | 2173 &private_key); |
2292 | 2174 |
2293 // Validate the signatures are computed and verified as expected. | 2175 // Validate the signatures are computed and verified as expected. |
2294 blink::WebArrayBuffer signature; | 2176 blink::WebArrayBuffer signature; |
2295 for (size_t idx = 0; idx < ARRAYSIZE_UNSAFE(kTests); ++idx) { | 2177 for (size_t idx = 0; idx < tests->GetSize(); ++idx) { |
2296 SCOPED_TRACE(idx); | 2178 SCOPED_TRACE(idx); |
2297 const TestCase& test = kTests[idx]; | 2179 |
2298 const std::vector<uint8> message = HexStringToBytes(test.message_hex); | 2180 base::DictionaryValue* test; |
2181 ASSERT_TRUE(tests->GetDictionary(idx, &test)); | |
2182 | |
2183 std::vector<uint8> message; | |
2184 std::string signature_hex; | |
2185 ASSERT_TRUE(GetBytesFromHexString(test, "message_hex", &message)); | |
2186 ASSERT_TRUE(test->GetString("signature_hex", &signature_hex)); | |
2299 | 2187 |
2300 signature.reset(); | 2188 signature.reset(); |
2301 ASSERT_STATUS_SUCCESS( | 2189 ASSERT_STATUS_SUCCESS( |
2302 SignInternal(algorithm, private_key, message, &signature)); | 2190 SignInternal(algorithm, private_key, message, &signature)); |
2303 ExpectArrayBufferMatchesHex(test.signature_hex, signature); | 2191 ExpectArrayBufferMatchesHex(signature_hex, signature); |
2304 | 2192 |
2305 bool is_match = false; | 2193 bool is_match = false; |
2306 ASSERT_STATUS_SUCCESS(VerifySignatureInternal( | 2194 ASSERT_STATUS_SUCCESS(VerifySignatureInternal( |
2307 algorithm, | 2195 algorithm, |
2308 public_key, | 2196 public_key, |
2309 HexStringToBytes(test.signature_hex), | 2197 HexStringToBytes(signature_hex), |
2310 message, | 2198 message, |
2311 &is_match)); | 2199 &is_match)); |
2312 EXPECT_TRUE(is_match); | 2200 EXPECT_TRUE(is_match); |
2313 } | 2201 } |
2314 } | 2202 } |
2315 | 2203 |
2316 TEST_F(WebCryptoImplTest, MAYBE(AesKwKeyImport)) { | 2204 TEST_F(WebCryptoImplTest, MAYBE(AesKwKeyImport)) { |
2317 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 2205 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
2318 blink::WebCryptoAlgorithm algorithm = | 2206 blink::WebCryptoAlgorithm algorithm = |
2319 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); | 2207 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2577 if (test_tag_size_bits == wrong_tag_size_bits) | 2465 if (test_tag_size_bits == wrong_tag_size_bits) |
2578 continue; | 2466 continue; |
2579 EXPECT_STATUS_ERROR(AesGcmDecrypt(key, test_iv, test_additional_data, | 2467 EXPECT_STATUS_ERROR(AesGcmDecrypt(key, test_iv, test_additional_data, |
2580 wrong_tag_size_bits, test_cipher_text, | 2468 wrong_tag_size_bits, test_cipher_text, |
2581 test_authentication_tag, &plain_text)); | 2469 test_authentication_tag, &plain_text)); |
2582 } | 2470 } |
2583 } | 2471 } |
2584 } | 2472 } |
2585 | 2473 |
2586 } // namespace content | 2474 } // namespace content |
OLD | NEW |