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 <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 dict->SetString("alg", "RSA1_5"); | 110 dict->SetString("alg", "RSA1_5"); |
111 dict->SetString("use", "enc"); | 111 dict->SetString("use", "enc"); |
112 dict->SetBoolean("extractable", false); | 112 dict->SetBoolean("extractable", false); |
113 dict->SetString("n", | 113 dict->SetString("n", |
114 "qLOyhK-OtQs4cDSoYPFGxJGfMYdjzWxVmMiuSBGh4KvEx-CwgtaTpef87Wdc9GaFEncsDLxk" | 114 "qLOyhK-OtQs4cDSoYPFGxJGfMYdjzWxVmMiuSBGh4KvEx-CwgtaTpef87Wdc9GaFEncsDLxk" |
115 "p0LGxjD1M8jMcvYq6DPEC_JYQumEu3i9v5fAEH1VvbZi9cTg-rmEXLUUjvc5LdOq_5OuHmtm" | 115 "p0LGxjD1M8jMcvYq6DPEC_JYQumEu3i9v5fAEH1VvbZi9cTg-rmEXLUUjvc5LdOq_5OuHmtm" |
116 "e7PUJHYW1PW6ENTP0ibeiNOfFvs"); | 116 "e7PUJHYW1PW6ENTP0ibeiNOfFvs"); |
117 dict->SetString("e", "AQAB"); | 117 dict->SetString("e", "AQAB"); |
118 } | 118 } |
119 | 119 |
| 120 blink::WebCryptoAlgorithm CreateRsaAlgorithmWithInnerHash( |
| 121 blink::WebCryptoAlgorithmId algorithm_id, |
| 122 blink::WebCryptoAlgorithmId hash_id) { |
| 123 DCHECK(algorithm_id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 || |
| 124 algorithm_id == blink::WebCryptoAlgorithmIdRsaOaep); |
| 125 DCHECK(webcrypto::IsHashAlgorithm(hash_id)); |
| 126 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
| 127 algorithm_id, |
| 128 new blink::WebCryptoRsaSsaParams(webcrypto::CreateAlgorithm(hash_id))); |
| 129 } |
| 130 |
120 // Determines if two ArrayBuffers have identical content. | 131 // Determines if two ArrayBuffers have identical content. |
121 bool ArrayBuffersEqual( | 132 bool ArrayBuffersEqual( |
122 const blink::WebArrayBuffer& a, | 133 const blink::WebArrayBuffer& a, |
123 const blink::WebArrayBuffer& b) { | 134 const blink::WebArrayBuffer& b) { |
124 return a.byteLength() == b.byteLength() && | 135 return a.byteLength() == b.byteLength() && |
125 memcmp(a.data(), b.data(), a.byteLength()) == 0; | 136 memcmp(a.data(), b.data(), a.byteLength()) == 0; |
126 } | 137 } |
127 | 138 |
128 // Given a vector of WebArrayBuffers, determines if there are any copies. | 139 // Given a vector of WebArrayBuffers, determines if there are any copies. |
129 bool CopiesExist(std::vector<blink::WebArrayBuffer> bufs) { | 140 bool CopiesExist(std::vector<blink::WebArrayBuffer> bufs) { |
(...skipping 24 matching lines...) Expand all Loading... |
154 return CreateAesKeyGenAlgorithm(blink::WebCryptoAlgorithmIdAesGcm, | 165 return CreateAesKeyGenAlgorithm(blink::WebCryptoAlgorithmIdAesGcm, |
155 key_length_bits); | 166 key_length_bits); |
156 } | 167 } |
157 | 168 |
158 blink::WebCryptoAlgorithm CreateAesKwKeyGenAlgorithm( | 169 blink::WebCryptoAlgorithm CreateAesKwKeyGenAlgorithm( |
159 unsigned short key_length_bits) { | 170 unsigned short key_length_bits) { |
160 return CreateAesKeyGenAlgorithm(blink::WebCryptoAlgorithmIdAesKw, | 171 return CreateAesKeyGenAlgorithm(blink::WebCryptoAlgorithmIdAesKw, |
161 key_length_bits); | 172 key_length_bits); |
162 } | 173 } |
163 | 174 |
| 175 // The following key pair is comprised of the SPKI (public key) and PKCS#8 |
| 176 // (private key) representations of the key pair provided in Example 1 of the |
| 177 // NIST test vectors at |
| 178 // ftp://ftp.rsa.com/pub/rsalabs/tmp/pkcs1v15sign-vectors.txt |
| 179 const unsigned kModulusLength = 1024; |
| 180 const char* const kPublicKeySpkiDerHex = |
| 181 "30819f300d06092a864886f70d010101050003818d0030818902818100a5" |
| 182 "6e4a0e701017589a5187dc7ea841d156f2ec0e36ad52a44dfeb1e61f7ad9" |
| 183 "91d8c51056ffedb162b4c0f283a12a88a394dff526ab7291cbb307ceabfc" |
| 184 "e0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921cb23c270a70e2598e" |
| 185 "6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef22e1e1f20d0ce8cf" |
| 186 "fb2249bd9a21370203010001"; |
| 187 const char* const kPrivateKeyPkcs8DerHex = |
| 188 "30820275020100300d06092a864886f70d01010105000482025f3082025b" |
| 189 "02010002818100a56e4a0e701017589a5187dc7ea841d156f2ec0e36ad52" |
| 190 "a44dfeb1e61f7ad991d8c51056ffedb162b4c0f283a12a88a394dff526ab" |
| 191 "7291cbb307ceabfce0b1dfd5cd9508096d5b2b8b6df5d671ef6377c0921c" |
| 192 "b23c270a70e2598e6ff89d19f105acc2d3f0cb35f29280e1386b6f64c4ef" |
| 193 "22e1e1f20d0ce8cffb2249bd9a2137020301000102818033a5042a90b27d" |
| 194 "4f5451ca9bbbd0b44771a101af884340aef9885f2a4bbe92e894a724ac3c" |
| 195 "568c8f97853ad07c0266c8c6a3ca0929f1e8f11231884429fc4d9ae55fee" |
| 196 "896a10ce707c3ed7e734e44727a39574501a532683109c2abacaba283c31" |
| 197 "b4bd2f53c3ee37e352cee34f9e503bd80c0622ad79c6dcee883547c6a3b3" |
| 198 "25024100e7e8942720a877517273a356053ea2a1bc0c94aa72d55c6e8629" |
| 199 "6b2dfc967948c0a72cbccca7eacb35706e09a1df55a1535bd9b3cc34160b" |
| 200 "3b6dcd3eda8e6443024100b69dca1cf7d4d7ec81e75b90fcca874abcde12" |
| 201 "3fd2700180aa90479b6e48de8d67ed24f9f19d85ba275874f542cd20dc72" |
| 202 "3e6963364a1f9425452b269a6799fd024028fa13938655be1f8a159cbaca" |
| 203 "5a72ea190c30089e19cd274a556f36c4f6e19f554b34c077790427bbdd8d" |
| 204 "d3ede2448328f385d81b30e8e43b2fffa02786197902401a8b38f398fa71" |
| 205 "2049898d7fb79ee0a77668791299cdfa09efc0e507acb21ed74301ef5bfd" |
| 206 "48be455eaeb6e1678255827580a8e4e8e14151d1510a82a3f2e729024027" |
| 207 "156aba4126d24a81f3a528cbfb27f56886f840a9f6e86e17a44b94fe9319" |
| 208 "584b8e22fdde1e5a2e3bd8aa5ba8d8584194eb2190acf832b847f13a3d24" |
| 209 "a79f4d"; |
| 210 |
164 } // namespace | 211 } // namespace |
165 | 212 |
166 class WebCryptoImplTest : public testing::Test { | 213 class WebCryptoImplTest : public testing::Test { |
167 protected: | 214 protected: |
168 blink::WebCryptoKey ImportSecretKeyFromRawHexString( | 215 blink::WebCryptoKey ImportSecretKeyFromRawHexString( |
169 const std::string& key_hex, | 216 const std::string& key_hex, |
170 const blink::WebCryptoAlgorithm& algorithm, | 217 const blink::WebCryptoAlgorithm& algorithm, |
171 blink::WebCryptoKeyUsageMask usage) { | 218 blink::WebCryptoKeyUsageMask usage) { |
172 std::vector<uint8> key_raw = HexStringToBytes(key_hex); | 219 std::vector<uint8> key_raw = HexStringToBytes(key_hex); |
173 | 220 |
174 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 221 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
175 bool extractable = true; | 222 bool extractable = true; |
176 EXPECT_TRUE(crypto_.ImportKeyInternal(blink::WebCryptoKeyFormatRaw, | 223 EXPECT_TRUE(crypto_.ImportKeyInternal(blink::WebCryptoKeyFormatRaw, |
177 webcrypto::Uint8VectorStart(key_raw), | 224 webcrypto::Uint8VectorStart(key_raw), |
178 key_raw.size(), | 225 key_raw.size(), |
179 algorithm, | 226 algorithm, |
180 extractable, | 227 extractable, |
181 usage, | 228 usage, |
182 &key)); | 229 &key)); |
183 | 230 |
184 EXPECT_FALSE(key.isNull()); | 231 EXPECT_FALSE(key.isNull()); |
185 EXPECT_TRUE(key.handle()); | 232 EXPECT_TRUE(key.handle()); |
186 EXPECT_EQ(blink::WebCryptoKeyTypeSecret, key.type()); | 233 EXPECT_EQ(blink::WebCryptoKeyTypeSecret, key.type()); |
187 EXPECT_EQ(algorithm.id(), key.algorithm().id()); | 234 EXPECT_EQ(algorithm.id(), key.algorithm().id()); |
188 EXPECT_EQ(extractable, key.extractable()); | 235 EXPECT_EQ(extractable, key.extractable()); |
189 EXPECT_EQ(usage, key.usages()); | 236 EXPECT_EQ(usage, key.usages()); |
190 return key; | 237 return key; |
191 } | 238 } |
192 | 239 |
| 240 void ImportRsaKeyPair( |
| 241 const std::string& spki_der_hex, |
| 242 const std::string& pkcs8_der_hex, |
| 243 const blink::WebCryptoAlgorithm& algorithm, |
| 244 bool extractable, |
| 245 blink::WebCryptoKeyUsageMask usage_mask, |
| 246 blink::WebCryptoKey* public_key, |
| 247 blink::WebCryptoKey* private_key) { |
| 248 EXPECT_TRUE(ImportKeyInternal( |
| 249 blink::WebCryptoKeyFormatSpki, |
| 250 HexStringToBytes(spki_der_hex), |
| 251 algorithm, |
| 252 true, |
| 253 usage_mask, |
| 254 public_key)); |
| 255 EXPECT_FALSE(public_key->isNull()); |
| 256 EXPECT_TRUE(public_key->handle()); |
| 257 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key->type()); |
| 258 EXPECT_EQ(algorithm.id(), public_key->algorithm().id()); |
| 259 EXPECT_EQ(extractable, extractable); |
| 260 EXPECT_EQ(usage_mask, public_key->usages()); |
| 261 |
| 262 EXPECT_TRUE(ImportKeyInternal( |
| 263 blink::WebCryptoKeyFormatPkcs8, |
| 264 HexStringToBytes(pkcs8_der_hex), |
| 265 algorithm, |
| 266 extractable, |
| 267 usage_mask, |
| 268 private_key)); |
| 269 EXPECT_FALSE(private_key->isNull()); |
| 270 EXPECT_TRUE(private_key->handle()); |
| 271 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key->type()); |
| 272 EXPECT_EQ(algorithm.id(), private_key->algorithm().id()); |
| 273 EXPECT_EQ(extractable, extractable); |
| 274 EXPECT_EQ(usage_mask, private_key->usages()); |
| 275 } |
| 276 |
193 // TODO(eroman): For Linux builds using system NSS, AES-GCM support is a | 277 // TODO(eroman): For Linux builds using system NSS, AES-GCM support is a |
194 // runtime dependency. Test it by trying to import a key. | 278 // runtime dependency. Test it by trying to import a key. |
195 bool SupportsAesGcm() { | 279 bool SupportsAesGcm() { |
196 std::vector<uint8> key_raw(16, 0); | 280 std::vector<uint8> key_raw(16, 0); |
197 | 281 |
198 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 282 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
199 return crypto_.ImportKeyInternal( | 283 return crypto_.ImportKeyInternal( |
200 blink::WebCryptoKeyFormatRaw, | 284 blink::WebCryptoKeyFormatRaw, |
201 webcrypto::Uint8VectorStart(key_raw), | 285 webcrypto::Uint8VectorStart(key_raw), |
202 key_raw.size(), | 286 key_raw.size(), |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 bool* signature_match) { | 414 bool* signature_match) { |
331 return crypto_.VerifySignatureInternal(algorithm, | 415 return crypto_.VerifySignatureInternal(algorithm, |
332 key, | 416 key, |
333 signature, | 417 signature, |
334 signature_size, | 418 signature_size, |
335 webcrypto::Uint8VectorStart(data), | 419 webcrypto::Uint8VectorStart(data), |
336 data.size(), | 420 data.size(), |
337 signature_match); | 421 signature_match); |
338 } | 422 } |
339 | 423 |
| 424 bool VerifySignatureInternal( |
| 425 const blink::WebCryptoAlgorithm& algorithm, |
| 426 const blink::WebCryptoKey& key, |
| 427 const std::vector<uint8>& signature, |
| 428 const std::vector<uint8>& data, |
| 429 bool* signature_match) { |
| 430 return crypto_.VerifySignatureInternal( |
| 431 algorithm, |
| 432 key, |
| 433 webcrypto::Uint8VectorStart(signature), |
| 434 signature.size(), |
| 435 webcrypto::Uint8VectorStart(data), |
| 436 data.size(), |
| 437 signature_match); |
| 438 } |
| 439 |
340 bool EncryptInternal( | 440 bool EncryptInternal( |
341 const blink::WebCryptoAlgorithm& algorithm, | 441 const blink::WebCryptoAlgorithm& algorithm, |
342 const blink::WebCryptoKey& key, | 442 const blink::WebCryptoKey& key, |
343 const unsigned char* data, | 443 const unsigned char* data, |
344 unsigned data_size, | 444 unsigned data_size, |
345 blink::WebArrayBuffer* buffer) { | 445 blink::WebArrayBuffer* buffer) { |
346 return crypto_.EncryptInternal(algorithm, key, data, data_size, buffer); | 446 return crypto_.EncryptInternal(algorithm, key, data, data_size, buffer); |
347 } | 447 } |
348 | 448 |
349 bool EncryptInternal( | 449 bool EncryptInternal( |
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1282 | 1382 |
1283 const std::string mac_raw = | 1383 const std::string mac_raw = |
1284 "769f00d3e6a6cc1fb426a14a4f76c6462e6149726e0dee0ec0cf97a16605ac8b"; | 1384 "769f00d3e6a6cc1fb426a14a4f76c6462e6149726e0dee0ec0cf97a16605ac8b"; |
1285 | 1385 |
1286 ExpectArrayBufferMatchesHex(mac_raw, output); | 1386 ExpectArrayBufferMatchesHex(mac_raw, output); |
1287 | 1387 |
1288 // TODO(padolph): Import an RSA public key JWK and use it | 1388 // TODO(padolph): Import an RSA public key JWK and use it |
1289 } | 1389 } |
1290 | 1390 |
1291 TEST_F(WebCryptoImplTest, MAYBE(ImportExportSpki)) { | 1391 TEST_F(WebCryptoImplTest, MAYBE(ImportExportSpki)) { |
1292 // openssl genrsa -out pair.pem 2048 | |
1293 // openssl rsa -in pair.pem -out pubkey.der -outform DER -pubout | |
1294 // xxd -p pubkey.der | |
1295 const std::string hex_rsa_spki_der = | |
1296 "30820122300d06092a864886f70d01010105000382010f003082010a0282" | |
1297 "010100f19e40f94e3780858701577a571cca000cb9795db89ddf8e98ab0e" | |
1298 "5eecfa47516cb08dc591cae5ab7fa43d6db402e95991d4a2de52e7cd3a66" | |
1299 "4f58284be2eb4675d5a849a2582c585d2b3c6c225a8f2c53a0414d5dbd06" | |
1300 "172371cefdf953e9ec3000fc9ad000743023f74e82d12aa93917a2c9b832" | |
1301 "696085ee0711154cf98a6d098f44cee00ea3b7584236503a5483ba8b6792" | |
1302 "fee588d1a8f4a0618333c4cb3447d760b43d5a0d9ed6ef79763df670cd8b" | |
1303 "5eb869a20833f1e3e6d8b88240a5d4335c73fd20487f2a7d112af8692357" | |
1304 "6425e44a273e5ad2e93d6b50a28e65f9e133958e4f0c7d12e0adc90fedd4" | |
1305 "f6b6848e7b6900666642a08b520a6534a35d4f0203010001"; | |
1306 | |
1307 // Passing case: Import a valid RSA key in SPKI format. | 1392 // Passing case: Import a valid RSA key in SPKI format. |
1308 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 1393 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
1309 ASSERT_TRUE(ImportKeyInternal( | 1394 ASSERT_TRUE(ImportKeyInternal( |
1310 blink::WebCryptoKeyFormatSpki, | 1395 blink::WebCryptoKeyFormatSpki, |
1311 HexStringToBytes(hex_rsa_spki_der), | 1396 HexStringToBytes(kPublicKeySpkiDerHex), |
1312 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5), | 1397 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5), |
1313 true, | 1398 true, |
1314 blink::WebCryptoKeyUsageEncrypt, | 1399 blink::WebCryptoKeyUsageEncrypt, |
1315 &key)); | 1400 &key)); |
1316 EXPECT_TRUE(key.handle()); | 1401 EXPECT_TRUE(key.handle()); |
1317 EXPECT_EQ(blink::WebCryptoKeyTypePublic, key.type()); | 1402 EXPECT_EQ(blink::WebCryptoKeyTypePublic, key.type()); |
1318 EXPECT_TRUE(key.extractable()); | 1403 EXPECT_TRUE(key.extractable()); |
1319 EXPECT_EQ(blink::WebCryptoKeyUsageEncrypt, key.usages()); | 1404 EXPECT_EQ(blink::WebCryptoKeyUsageEncrypt, key.usages()); |
1320 | 1405 |
1321 // Failing case: Empty SPKI data | 1406 // Failing case: Empty SPKI data |
1322 EXPECT_FALSE(ImportKeyInternal( | 1407 EXPECT_FALSE(ImportKeyInternal( |
1323 blink::WebCryptoKeyFormatSpki, | 1408 blink::WebCryptoKeyFormatSpki, |
1324 std::vector<uint8>(), | 1409 std::vector<uint8>(), |
1325 blink::WebCryptoAlgorithm::createNull(), | 1410 blink::WebCryptoAlgorithm::createNull(), |
1326 true, | 1411 true, |
1327 blink::WebCryptoKeyUsageEncrypt, | 1412 blink::WebCryptoKeyUsageEncrypt, |
1328 &key)); | 1413 &key)); |
1329 | 1414 |
1330 // Failing case: Import RSA key with NULL input algorithm. This is not | 1415 // Failing case: Import RSA key with NULL input algorithm. This is not |
1331 // allowed because the SPKI ASN.1 format for RSA keys is not specific enough | 1416 // allowed because the SPKI ASN.1 format for RSA keys is not specific enough |
1332 // to map to a Web Crypto algorithm. | 1417 // to map to a Web Crypto algorithm. |
1333 EXPECT_FALSE(ImportKeyInternal( | 1418 EXPECT_FALSE(ImportKeyInternal( |
1334 blink::WebCryptoKeyFormatSpki, | 1419 blink::WebCryptoKeyFormatSpki, |
1335 HexStringToBytes(hex_rsa_spki_der), | 1420 HexStringToBytes(kPublicKeySpkiDerHex), |
1336 blink::WebCryptoAlgorithm::createNull(), | 1421 blink::WebCryptoAlgorithm::createNull(), |
1337 true, | 1422 true, |
1338 blink::WebCryptoKeyUsageEncrypt, | 1423 blink::WebCryptoKeyUsageEncrypt, |
1339 &key)); | 1424 &key)); |
1340 | 1425 |
1341 // Failing case: Bad DER encoding. | 1426 // Failing case: Bad DER encoding. |
1342 EXPECT_FALSE(ImportKeyInternal( | 1427 EXPECT_FALSE(ImportKeyInternal( |
1343 blink::WebCryptoKeyFormatSpki, | 1428 blink::WebCryptoKeyFormatSpki, |
1344 HexStringToBytes("618333c4cb"), | 1429 HexStringToBytes("618333c4cb"), |
1345 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5), | 1430 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5), |
1346 true, | 1431 true, |
1347 blink::WebCryptoKeyUsageEncrypt, | 1432 blink::WebCryptoKeyUsageEncrypt, |
1348 &key)); | 1433 &key)); |
1349 | 1434 |
1350 // Failing case: Import RSA key but provide an inconsistent input algorithm. | 1435 // Failing case: Import RSA key but provide an inconsistent input algorithm. |
1351 EXPECT_FALSE(ImportKeyInternal( | 1436 EXPECT_FALSE(ImportKeyInternal( |
1352 blink::WebCryptoKeyFormatSpki, | 1437 blink::WebCryptoKeyFormatSpki, |
1353 HexStringToBytes(hex_rsa_spki_der), | 1438 HexStringToBytes(kPublicKeySpkiDerHex), |
1354 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), | 1439 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), |
1355 true, | 1440 true, |
1356 blink::WebCryptoKeyUsageEncrypt, | 1441 blink::WebCryptoKeyUsageEncrypt, |
1357 &key)); | 1442 &key)); |
1358 | 1443 |
1359 // Passing case: Export a previously imported RSA public key in SPKI format | 1444 // Passing case: Export a previously imported RSA public key in SPKI format |
1360 // and compare to original data. | 1445 // and compare to original data. |
1361 blink::WebArrayBuffer output; | 1446 blink::WebArrayBuffer output; |
1362 ASSERT_TRUE(ExportKeyInternal(blink::WebCryptoKeyFormatSpki, key, &output)); | 1447 ASSERT_TRUE(ExportKeyInternal(blink::WebCryptoKeyFormatSpki, key, &output)); |
1363 ExpectArrayBufferMatchesHex(hex_rsa_spki_der, output); | 1448 ExpectArrayBufferMatchesHex(kPublicKeySpkiDerHex, output); |
1364 | 1449 |
1365 // Failing case: Try to export a previously imported RSA public key in raw | 1450 // Failing case: Try to export a previously imported RSA public key in raw |
1366 // format (not allowed for a public key). | 1451 // format (not allowed for a public key). |
1367 EXPECT_FALSE(ExportKeyInternal(blink::WebCryptoKeyFormatRaw, key, &output)); | 1452 EXPECT_FALSE(ExportKeyInternal(blink::WebCryptoKeyFormatRaw, key, &output)); |
1368 | 1453 |
1369 // Failing case: Try to export a non-extractable key | 1454 // Failing case: Try to export a non-extractable key |
1370 ASSERT_TRUE(ImportKeyInternal( | 1455 ASSERT_TRUE(ImportKeyInternal( |
1371 blink::WebCryptoKeyFormatSpki, | 1456 blink::WebCryptoKeyFormatSpki, |
1372 HexStringToBytes(hex_rsa_spki_der), | 1457 HexStringToBytes(kPublicKeySpkiDerHex), |
1373 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5), | 1458 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5), |
1374 false, | 1459 false, |
1375 blink::WebCryptoKeyUsageEncrypt, | 1460 blink::WebCryptoKeyUsageEncrypt, |
1376 &key)); | 1461 &key)); |
1377 EXPECT_TRUE(key.handle()); | 1462 EXPECT_TRUE(key.handle()); |
1378 EXPECT_FALSE(key.extractable()); | 1463 EXPECT_FALSE(key.extractable()); |
1379 EXPECT_FALSE(ExportKeyInternal(blink::WebCryptoKeyFormatSpki, key, &output)); | 1464 EXPECT_FALSE(ExportKeyInternal(blink::WebCryptoKeyFormatSpki, key, &output)); |
1380 } | 1465 } |
1381 | 1466 |
1382 TEST_F(WebCryptoImplTest, MAYBE(ImportPkcs8)) { | 1467 TEST_F(WebCryptoImplTest, MAYBE(ImportPkcs8)) { |
1383 | |
1384 // The following is a DER-encoded PKCS#8 representation of the RSA key from | |
1385 // Example 1 of NIST's "Test vectors for RSA PKCS#1 v1.5 Signature". | |
1386 // ftp://ftp.rsa.com/pub/rsalabs/tmp/pkcs1v15sign-vectors.txt | |
1387 const std::string hex_rsa_pkcs8_der = | |
1388 "30820275020100300D06092A864886F70D01010105000482025F3082025B020100028181" | |
1389 "00A56E4A0E701017589A5187DC7EA841D156F2EC0E36AD52A44DFEB1E61F7AD991D8C510" | |
1390 "56FFEDB162B4C0F283A12A88A394DFF526AB7291CBB307CEABFCE0B1DFD5CD9508096D5B" | |
1391 "2B8B6DF5D671EF6377C0921CB23C270A70E2598E6FF89D19F105ACC2D3F0CB35F29280E1" | |
1392 "386B6F64C4EF22E1E1F20D0CE8CFFB2249BD9A2137020301000102818033A5042A90B27D" | |
1393 "4F5451CA9BBBD0B44771A101AF884340AEF9885F2A4BBE92E894A724AC3C568C8F97853A" | |
1394 "D07C0266C8C6A3CA0929F1E8F11231884429FC4D9AE55FEE896A10CE707C3ED7E734E447" | |
1395 "27A39574501A532683109C2ABACABA283C31B4BD2F53C3EE37E352CEE34F9E503BD80C06" | |
1396 "22AD79C6DCEE883547C6A3B325024100E7E8942720A877517273A356053EA2A1BC0C94AA" | |
1397 "72D55C6E86296B2DFC967948C0A72CBCCCA7EACB35706E09A1DF55A1535BD9B3CC34160B" | |
1398 "3B6DCD3EDA8E6443024100B69DCA1CF7D4D7EC81E75B90FCCA874ABCDE123FD2700180AA" | |
1399 "90479B6E48DE8D67ED24F9F19D85BA275874F542CD20DC723E6963364A1F9425452B269A" | |
1400 "6799FD024028FA13938655BE1F8A159CBACA5A72EA190C30089E19CD274A556F36C4F6E1" | |
1401 "9F554B34C077790427BBDD8DD3EDE2448328F385D81B30E8E43B2FFFA02786197902401A" | |
1402 "8B38F398FA712049898D7FB79EE0A77668791299CDFA09EFC0E507ACB21ED74301EF5BFD" | |
1403 "48BE455EAEB6E1678255827580A8E4E8E14151D1510A82A3F2E729024027156ABA4126D2" | |
1404 "4A81F3A528CBFB27F56886F840A9F6E86E17A44B94FE9319584B8E22FDDE1E5A2E3BD8AA" | |
1405 "5BA8D8584194EB2190ACF832B847F13A3D24A79F4D"; | |
1406 | |
1407 // Passing case: Import a valid RSA key in PKCS#8 format. | 1468 // Passing case: Import a valid RSA key in PKCS#8 format. |
1408 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 1469 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
1409 ASSERT_TRUE(ImportKeyInternal( | 1470 ASSERT_TRUE(ImportKeyInternal( |
1410 blink::WebCryptoKeyFormatPkcs8, | 1471 blink::WebCryptoKeyFormatPkcs8, |
1411 HexStringToBytes(hex_rsa_pkcs8_der), | 1472 HexStringToBytes(kPrivateKeyPkcs8DerHex), |
1412 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5), | 1473 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5), |
1413 true, | 1474 true, |
1414 blink::WebCryptoKeyUsageSign, | 1475 blink::WebCryptoKeyUsageSign, |
1415 &key)); | 1476 &key)); |
1416 EXPECT_TRUE(key.handle()); | 1477 EXPECT_TRUE(key.handle()); |
1417 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, key.type()); | 1478 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, key.type()); |
1418 EXPECT_TRUE(key.extractable()); | 1479 EXPECT_TRUE(key.extractable()); |
1419 EXPECT_EQ(blink::WebCryptoKeyUsageSign, key.usages()); | 1480 EXPECT_EQ(blink::WebCryptoKeyUsageSign, key.usages()); |
1420 | 1481 |
1421 // Failing case: Empty PKCS#8 data | 1482 // Failing case: Empty PKCS#8 data |
1422 EXPECT_FALSE(ImportKeyInternal( | 1483 EXPECT_FALSE(ImportKeyInternal( |
1423 blink::WebCryptoKeyFormatPkcs8, | 1484 blink::WebCryptoKeyFormatPkcs8, |
1424 std::vector<uint8>(), | 1485 std::vector<uint8>(), |
1425 blink::WebCryptoAlgorithm::createNull(), | 1486 blink::WebCryptoAlgorithm::createNull(), |
1426 true, | 1487 true, |
1427 blink::WebCryptoKeyUsageSign, | 1488 blink::WebCryptoKeyUsageSign, |
1428 &key)); | 1489 &key)); |
1429 | 1490 |
1430 // Failing case: Import RSA key with NULL input algorithm. This is not | 1491 // Failing case: Import RSA key with NULL input algorithm. This is not |
1431 // allowed because the PKCS#8 ASN.1 format for RSA keys is not specific enough | 1492 // allowed because the PKCS#8 ASN.1 format for RSA keys is not specific enough |
1432 // to map to a Web Crypto algorithm. | 1493 // to map to a Web Crypto algorithm. |
1433 EXPECT_FALSE(ImportKeyInternal( | 1494 EXPECT_FALSE(ImportKeyInternal( |
1434 blink::WebCryptoKeyFormatPkcs8, | 1495 blink::WebCryptoKeyFormatPkcs8, |
1435 HexStringToBytes(hex_rsa_pkcs8_der), | 1496 HexStringToBytes(kPrivateKeyPkcs8DerHex), |
1436 blink::WebCryptoAlgorithm::createNull(), | 1497 blink::WebCryptoAlgorithm::createNull(), |
1437 true, | 1498 true, |
1438 blink::WebCryptoKeyUsageSign, | 1499 blink::WebCryptoKeyUsageSign, |
1439 &key)); | 1500 &key)); |
1440 | 1501 |
1441 // Failing case: Bad DER encoding. | 1502 // Failing case: Bad DER encoding. |
1442 EXPECT_FALSE(ImportKeyInternal( | 1503 EXPECT_FALSE(ImportKeyInternal( |
1443 blink::WebCryptoKeyFormatPkcs8, | 1504 blink::WebCryptoKeyFormatPkcs8, |
1444 HexStringToBytes("618333c4cb"), | 1505 HexStringToBytes("618333c4cb"), |
1445 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5), | 1506 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5), |
1446 true, | 1507 true, |
1447 blink::WebCryptoKeyUsageSign, | 1508 blink::WebCryptoKeyUsageSign, |
1448 &key)); | 1509 &key)); |
1449 | 1510 |
1450 // Failing case: Import RSA key but provide an inconsistent input algorithm. | 1511 // Failing case: Import RSA key but provide an inconsistent input algorithm. |
1451 EXPECT_FALSE(ImportKeyInternal( | 1512 EXPECT_FALSE(ImportKeyInternal( |
1452 blink::WebCryptoKeyFormatPkcs8, | 1513 blink::WebCryptoKeyFormatPkcs8, |
1453 HexStringToBytes(hex_rsa_pkcs8_der), | 1514 HexStringToBytes(kPrivateKeyPkcs8DerHex), |
1454 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), | 1515 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), |
1455 true, | 1516 true, |
1456 blink::WebCryptoKeyUsageSign, | 1517 blink::WebCryptoKeyUsageSign, |
1457 &key)); | 1518 &key)); |
1458 } | 1519 } |
1459 | 1520 |
1460 TEST_F(WebCryptoImplTest, MAYBE(GenerateKeyPairRsa)) { | 1521 TEST_F(WebCryptoImplTest, MAYBE(GenerateKeyPairRsa)) { |
1461 // Note: using unrealistic short key lengths here to avoid bogging down tests. | 1522 // Note: using unrealistic short key lengths here to avoid bogging down tests. |
1462 | 1523 |
1463 // Successful WebCryptoAlgorithmIdRsaEsPkcs1v1_5 key generation. | 1524 // Successful WebCryptoAlgorithmIdRsaEsPkcs1v1_5 key generation. |
(...skipping 21 matching lines...) Expand all Loading... |
1485 // Fail with bad modulus. | 1546 // Fail with bad modulus. |
1486 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( | 1547 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( |
1487 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, 0, public_exponent); | 1548 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, 0, public_exponent); |
1488 EXPECT_FALSE(GenerateKeyPairInternal( | 1549 EXPECT_FALSE(GenerateKeyPairInternal( |
1489 algorithm, extractable, usage_mask, &public_key, &private_key)); | 1550 algorithm, extractable, usage_mask, &public_key, &private_key)); |
1490 | 1551 |
1491 // Fail with bad exponent: larger than unsigned long. | 1552 // Fail with bad exponent: larger than unsigned long. |
1492 unsigned exponent_length = sizeof(unsigned long) + 1; // NOLINT | 1553 unsigned exponent_length = sizeof(unsigned long) + 1; // NOLINT |
1493 const std::vector<uint8> long_exponent(exponent_length, 0x01); | 1554 const std::vector<uint8> long_exponent(exponent_length, 0x01); |
1494 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( | 1555 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( |
1495 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, modulus_length, long_exponent); | 1556 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, |
| 1557 modulus_length, |
| 1558 long_exponent); |
1496 EXPECT_FALSE(GenerateKeyPairInternal( | 1559 EXPECT_FALSE(GenerateKeyPairInternal( |
1497 algorithm, extractable, usage_mask, &public_key, &private_key)); | 1560 algorithm, extractable, usage_mask, &public_key, &private_key)); |
1498 | 1561 |
1499 // Fail with bad exponent: empty. | 1562 // Fail with bad exponent: empty. |
1500 const std::vector<uint8> empty_exponent; | 1563 const std::vector<uint8> empty_exponent; |
1501 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( | 1564 algorithm = webcrypto::CreateRsaKeyGenAlgorithm( |
1502 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, | 1565 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, |
1503 modulus_length, | 1566 modulus_length, |
1504 empty_exponent); | 1567 empty_exponent); |
1505 EXPECT_FALSE(GenerateKeyPairInternal( | 1568 EXPECT_FALSE(GenerateKeyPairInternal( |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1565 | 1628 |
1566 // Fail SPKI export of private key. This is an ExportKey test, but do it here | 1629 // Fail SPKI export of private key. This is an ExportKey test, but do it here |
1567 // since it is expensive to generate an RSA key pair and we already have a | 1630 // since it is expensive to generate an RSA key pair and we already have a |
1568 // private key here. | 1631 // private key here. |
1569 blink::WebArrayBuffer output; | 1632 blink::WebArrayBuffer output; |
1570 EXPECT_FALSE( | 1633 EXPECT_FALSE( |
1571 ExportKeyInternal(blink::WebCryptoKeyFormatSpki, private_key, &output)); | 1634 ExportKeyInternal(blink::WebCryptoKeyFormatSpki, private_key, &output)); |
1572 } | 1635 } |
1573 | 1636 |
1574 TEST_F(WebCryptoImplTest, MAYBE(RsaEsRoundTrip)) { | 1637 TEST_F(WebCryptoImplTest, MAYBE(RsaEsRoundTrip)) { |
1575 // Note: using unrealistic short key length here to avoid bogging down tests. | 1638 // Import a key pair. |
1576 | |
1577 // Create a key pair. | |
1578 const unsigned kModulusLength = 256; | |
1579 blink::WebCryptoAlgorithm algorithm = | 1639 blink::WebCryptoAlgorithm algorithm = |
1580 webcrypto::CreateRsaKeyGenAlgorithm( | 1640 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5); |
1581 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, | |
1582 kModulusLength, | |
1583 HexStringToBytes("010001")); | |
1584 const blink::WebCryptoKeyUsageMask usage_mask = | |
1585 blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt; | |
1586 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | 1641 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
1587 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); | 1642 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); |
1588 EXPECT_TRUE(GenerateKeyPairInternal( | 1643 ImportRsaKeyPair( |
1589 algorithm, false, usage_mask, &public_key, &private_key)); | 1644 kPublicKeySpkiDerHex, |
1590 EXPECT_FALSE(public_key.isNull()); | 1645 kPrivateKeyPkcs8DerHex, |
1591 EXPECT_FALSE(private_key.isNull()); | 1646 algorithm, |
| 1647 false, |
| 1648 blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt, |
| 1649 &public_key, |
| 1650 &private_key); |
1592 | 1651 |
1593 // Make a maximum-length data message. RSAES can operate on messages up to | 1652 // Make a maximum-length data message. RSAES can operate on messages up to |
1594 // length of k - 11 bytes, where k is the octet length of the RSA modulus. | 1653 // length of k - 11 bytes, where k is the octet length of the RSA modulus. |
1595 const unsigned kMaxMsgSizeBytes = kModulusLength / 8 - 11; | 1654 const unsigned kMaxMsgSizeBytes = kModulusLength / 8 - 11; |
1596 // There are two hex chars for each byte. | 1655 // There are two hex chars for each byte. |
1597 const unsigned kMsgHexSize = kMaxMsgSizeBytes * 2; | 1656 const unsigned kMsgHexSize = kMaxMsgSizeBytes * 2; |
1598 char max_data_hex[kMsgHexSize+1]; | 1657 char max_data_hex[kMsgHexSize+1]; |
1599 std::fill(&max_data_hex[0], &max_data_hex[0] + kMsgHexSize, 'a'); | 1658 std::fill(&max_data_hex[0], &max_data_hex[0] + kMsgHexSize, 'a'); |
1600 max_data_hex[kMsgHexSize] = '\0'; | 1659 max_data_hex[kMsgHexSize] = '\0'; |
1601 | 1660 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1687 "ec358ed141c45d7e03d4c6338aebad718e8bcbbf8f8ee6f8d9f4b9ef06d8" | 1746 "ec358ed141c45d7e03d4c6338aebad718e8bcbbf8f8ee6f8d9f4b9ef06d8" |
1688 "84739a398c6bcbc688418b2ff64761dc0ccd40e7d52bed03e06946d0957a" | 1747 "84739a398c6bcbc688418b2ff64761dc0ccd40e7d52bed03e06946d0957a" |
1689 "eef9e822"; | 1748 "eef9e822"; |
1690 const std::string ciphertext_hex = | 1749 const std::string ciphertext_hex = |
1691 "6106441c2b7a4b1a16260ed1ae4fe6135247345dc8e674754bbda6588c6c" | 1750 "6106441c2b7a4b1a16260ed1ae4fe6135247345dc8e674754bbda6588c6c" |
1692 "0d95a3d4d26bb34cdbcbe327723e80343bd7a15cd4c91c3a44e6cb9c6cd6" | 1751 "0d95a3d4d26bb34cdbcbe327723e80343bd7a15cd4c91c3a44e6cb9c6cd6" |
1693 "7ad2e8bf41523188d9b36dc364a838642dcbc2c25e85dfb2106ba47578ca" | 1752 "7ad2e8bf41523188d9b36dc364a838642dcbc2c25e85dfb2106ba47578ca" |
1694 "3bbf8915055aea4fa7c3cbfdfbcc163f04c234fb6d847f39bab9612ecbee" | 1753 "3bbf8915055aea4fa7c3cbfdfbcc163f04c234fb6d847f39bab9612ecbee" |
1695 "04626e945c3ccf42"; | 1754 "04626e945c3ccf42"; |
1696 | 1755 |
1697 // Import the public key. | 1756 // Import the key pair. |
1698 const blink::WebCryptoAlgorithm algorithm = | 1757 blink::WebCryptoAlgorithm algorithm = |
1699 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5); | 1758 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5); |
1700 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | 1759 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
1701 ASSERT_TRUE(ImportKeyInternal( | 1760 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); |
1702 blink::WebCryptoKeyFormatSpki, | 1761 ImportRsaKeyPair( |
1703 HexStringToBytes(rsa_spki_der_hex), | 1762 rsa_spki_der_hex, |
| 1763 rsa_pkcs8_der_hex, |
1704 algorithm, | 1764 algorithm, |
1705 true, | 1765 false, |
1706 blink::WebCryptoKeyUsageEncrypt, | 1766 blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt, |
1707 &public_key)); | 1767 &public_key, |
1708 EXPECT_FALSE(public_key.isNull()); | 1768 &private_key); |
1709 EXPECT_TRUE(public_key.handle()); | |
1710 | |
1711 // Import the private key. | |
1712 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); | |
1713 ASSERT_TRUE(ImportKeyInternal( | |
1714 blink::WebCryptoKeyFormatPkcs8, | |
1715 HexStringToBytes(rsa_pkcs8_der_hex), | |
1716 algorithm, | |
1717 true, | |
1718 blink::WebCryptoKeyUsageDecrypt, | |
1719 &private_key)); | |
1720 EXPECT_FALSE(private_key.isNull()); | |
1721 EXPECT_TRUE(private_key.handle()); | |
1722 | 1769 |
1723 // Decrypt the known-good ciphertext with the private key. As a check we must | 1770 // Decrypt the known-good ciphertext with the private key. As a check we must |
1724 // get the known original cleartext. | 1771 // get the known original cleartext. |
1725 blink::WebArrayBuffer decrypted_data; | 1772 blink::WebArrayBuffer decrypted_data; |
1726 ASSERT_TRUE(DecryptInternal( | 1773 ASSERT_TRUE(DecryptInternal( |
1727 algorithm, | 1774 algorithm, |
1728 private_key, | 1775 private_key, |
1729 HexStringToBytes(ciphertext_hex), | 1776 HexStringToBytes(ciphertext_hex), |
1730 &decrypted_data)); | 1777 &decrypted_data)); |
1731 EXPECT_FALSE(decrypted_data.isNull()); | 1778 EXPECT_FALSE(decrypted_data.isNull()); |
(...skipping 16 matching lines...) Expand all Loading... |
1748 algorithm, | 1795 algorithm, |
1749 private_key, | 1796 private_key, |
1750 reinterpret_cast<const unsigned char*>(encrypted_data.data()), | 1797 reinterpret_cast<const unsigned char*>(encrypted_data.data()), |
1751 encrypted_data.byteLength(), | 1798 encrypted_data.byteLength(), |
1752 &decrypted_data)); | 1799 &decrypted_data)); |
1753 EXPECT_FALSE(decrypted_data.isNull()); | 1800 EXPECT_FALSE(decrypted_data.isNull()); |
1754 ExpectArrayBufferMatchesHex(cleartext_hex, decrypted_data); | 1801 ExpectArrayBufferMatchesHex(cleartext_hex, decrypted_data); |
1755 } | 1802 } |
1756 | 1803 |
1757 TEST_F(WebCryptoImplTest, MAYBE(RsaEsFailures)) { | 1804 TEST_F(WebCryptoImplTest, MAYBE(RsaEsFailures)) { |
1758 // Note: using unrealistic short key length here to avoid bogging down tests. | 1805 // Import a key pair. |
1759 | |
1760 // Create a key pair. | |
1761 const unsigned kModulusLength = 256; | |
1762 blink::WebCryptoAlgorithm algorithm = | 1806 blink::WebCryptoAlgorithm algorithm = |
1763 webcrypto::CreateRsaKeyGenAlgorithm( | 1807 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5); |
1764 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, | |
1765 kModulusLength, | |
1766 HexStringToBytes("010001")); | |
1767 const blink::WebCryptoKeyUsageMask usage_mask = | |
1768 blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt; | |
1769 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); | 1808 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
1770 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); | 1809 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); |
1771 EXPECT_TRUE(GenerateKeyPairInternal( | 1810 ImportRsaKeyPair( |
1772 algorithm, false, usage_mask, &public_key, &private_key)); | 1811 kPublicKeySpkiDerHex, |
1773 EXPECT_FALSE(public_key.isNull()); | 1812 kPrivateKeyPkcs8DerHex, |
1774 EXPECT_FALSE(private_key.isNull()); | 1813 algorithm, |
| 1814 false, |
| 1815 blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt, |
| 1816 &public_key, |
| 1817 &private_key); |
1775 | 1818 |
1776 // Fail encrypt with a private key. | 1819 // Fail encrypt with a private key. |
1777 algorithm = | |
1778 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5); | |
1779 blink::WebArrayBuffer encrypted_data; | 1820 blink::WebArrayBuffer encrypted_data; |
1780 const std::string message_hex_str("0102030405060708090a0b0c0d0e0f"); | 1821 const std::string message_hex_str("0102030405060708090a0b0c0d0e0f"); |
1781 const std::vector<uint8> message_hex(HexStringToBytes(message_hex_str)); | 1822 const std::vector<uint8> message_hex(HexStringToBytes(message_hex_str)); |
1782 EXPECT_FALSE( | 1823 EXPECT_FALSE( |
1783 EncryptInternal(algorithm, private_key, message_hex, &encrypted_data)); | 1824 EncryptInternal(algorithm, private_key, message_hex, &encrypted_data)); |
1784 | 1825 |
1785 // Fail encrypt with empty message. | 1826 // Fail encrypt with empty message. |
1786 EXPECT_FALSE(EncryptInternal( | 1827 EXPECT_FALSE(EncryptInternal( |
1787 algorithm, public_key, std::vector<uint8>(), &encrypted_data)); | 1828 algorithm, public_key, std::vector<uint8>(), &encrypted_data)); |
1788 | 1829 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1821 // Do a successful decrypt with good data just for confirmation. | 1862 // Do a successful decrypt with good data just for confirmation. |
1822 EXPECT_TRUE(DecryptInternal( | 1863 EXPECT_TRUE(DecryptInternal( |
1823 algorithm, | 1864 algorithm, |
1824 private_key, | 1865 private_key, |
1825 reinterpret_cast<const unsigned char*>(encrypted_data.data()), | 1866 reinterpret_cast<const unsigned char*>(encrypted_data.data()), |
1826 encrypted_data.byteLength(), | 1867 encrypted_data.byteLength(), |
1827 &decrypted_data)); | 1868 &decrypted_data)); |
1828 ExpectArrayBufferMatchesHex(message_hex_str, decrypted_data); | 1869 ExpectArrayBufferMatchesHex(message_hex_str, decrypted_data); |
1829 } | 1870 } |
1830 | 1871 |
| 1872 TEST_F(WebCryptoImplTest, MAYBE(RsaSsaSignVerifyFailures)) { |
| 1873 // Import a key pair. |
| 1874 blink::WebCryptoAlgorithm algorithm = CreateRsaAlgorithmWithInnerHash( |
| 1875 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
| 1876 blink::WebCryptoAlgorithmIdSha1); |
| 1877 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
| 1878 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); |
| 1879 ImportRsaKeyPair( |
| 1880 kPublicKeySpkiDerHex, |
| 1881 kPrivateKeyPkcs8DerHex, |
| 1882 algorithm, |
| 1883 false, |
| 1884 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageVerify, |
| 1885 &public_key, |
| 1886 &private_key); |
| 1887 |
| 1888 blink::WebArrayBuffer signature; |
| 1889 bool signature_match; |
| 1890 |
| 1891 // Compute a signature. |
| 1892 const std::vector<uint8> data = HexStringToBytes("010203040506070809"); |
| 1893 ASSERT_TRUE(SignInternal(algorithm, private_key, data, &signature)); |
| 1894 |
| 1895 // Ensure truncated signature does not verify by passing one less byte. |
| 1896 EXPECT_TRUE(VerifySignatureInternal( |
| 1897 algorithm, |
| 1898 public_key, |
| 1899 static_cast<const unsigned char*>(signature.data()), |
| 1900 signature.byteLength() - 1, |
| 1901 data, |
| 1902 &signature_match)); |
| 1903 EXPECT_FALSE(signature_match); |
| 1904 |
| 1905 // Ensure corrupted signature does not verify. |
| 1906 std::vector<uint8> corrupt_sig( |
| 1907 static_cast<uint8*>(signature.data()), |
| 1908 static_cast<uint8*>(signature.data()) + signature.byteLength()); |
| 1909 corrupt_sig[corrupt_sig.size() / 2] ^= 0x1; |
| 1910 EXPECT_TRUE(VerifySignatureInternal( |
| 1911 algorithm, |
| 1912 public_key, |
| 1913 webcrypto::Uint8VectorStart(corrupt_sig), |
| 1914 corrupt_sig.size(), |
| 1915 data, |
| 1916 &signature_match)); |
| 1917 EXPECT_FALSE(signature_match); |
| 1918 |
| 1919 // Ensure signatures that are greater than the modulus size fail. |
| 1920 const unsigned long_message_size_bytes = 1024; |
| 1921 DCHECK_GT(long_message_size_bytes, kModulusLength/8); |
| 1922 const unsigned char kLongSignature[long_message_size_bytes] = { 0 }; |
| 1923 EXPECT_TRUE(VerifySignatureInternal( |
| 1924 algorithm, |
| 1925 public_key, |
| 1926 kLongSignature, |
| 1927 sizeof(kLongSignature), |
| 1928 data, |
| 1929 &signature_match)); |
| 1930 EXPECT_FALSE(signature_match); |
| 1931 |
| 1932 // Ensure that verifying using a private key, rather than a public key, fails. |
| 1933 EXPECT_FALSE(VerifySignatureInternal( |
| 1934 algorithm, |
| 1935 private_key, |
| 1936 static_cast<const unsigned char*>(signature.data()), |
| 1937 signature.byteLength(), |
| 1938 data, |
| 1939 &signature_match)); |
| 1940 |
| 1941 // Ensure that signing using a public key, rather than a private key, fails. |
| 1942 EXPECT_FALSE(SignInternal(algorithm, public_key, data, &signature)); |
| 1943 |
| 1944 // Ensure that signing and verifying with an incompatible algorithm fails. |
| 1945 algorithm = |
| 1946 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5); |
| 1947 EXPECT_FALSE(SignInternal(algorithm, private_key, data, &signature)); |
| 1948 EXPECT_FALSE(VerifySignatureInternal( |
| 1949 algorithm, |
| 1950 public_key, |
| 1951 static_cast<const unsigned char*>(signature.data()), |
| 1952 signature.byteLength(), |
| 1953 data, |
| 1954 &signature_match)); |
| 1955 |
| 1956 // Some crypto libraries (NSS) can automatically select the RSA SSA inner hash |
| 1957 // based solely on the contents of the input signature data. In the Web Crypto |
| 1958 // implementation, the inner hash should be specified uniquely by the input |
| 1959 // algorithm parameter. To validate this behavior, call Verify with a computed |
| 1960 // signature that used one hash type (SHA-1), but pass in an algorithm with a |
| 1961 // different inner hash type (SHA-256). If the hash type is determined by the |
| 1962 // signature itself (undesired), the verify will pass, while if the hash type |
| 1963 // is specified by the input algorithm (desired), the verify will fail. |
| 1964 |
| 1965 // Compute a signature using SHA-1 as the inner hash. |
| 1966 EXPECT_TRUE(SignInternal(CreateRsaAlgorithmWithInnerHash( |
| 1967 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
| 1968 blink::WebCryptoAlgorithmIdSha1), |
| 1969 private_key, |
| 1970 data, |
| 1971 &signature)); |
| 1972 |
| 1973 // Now verify using an algorithm whose inner hash is SHA-256, not SHA-1. The |
| 1974 // signature should not verify. |
| 1975 // NOTE: public_key was produced by generateKey, and so its associated |
| 1976 // algorithm has WebCryptoRsaKeyGenParams and not WebCryptoRsaSsaParams. Thus |
| 1977 // it has no inner hash to conflict with the input algorithm. |
| 1978 bool is_match; |
| 1979 EXPECT_TRUE(VerifySignatureInternal( |
| 1980 CreateRsaAlgorithmWithInnerHash( |
| 1981 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
| 1982 blink::WebCryptoAlgorithmIdSha256), |
| 1983 public_key, |
| 1984 static_cast<const unsigned char*>(signature.data()), |
| 1985 signature.byteLength(), |
| 1986 data, |
| 1987 &is_match)); |
| 1988 EXPECT_FALSE(is_match); |
| 1989 } |
| 1990 |
| 1991 TEST_F(WebCryptoImplTest, MAYBE(RsaSignVerifyKnownAnswer)) { |
| 1992 // Use the NIST test vectors from Example 1 of |
| 1993 // ftp://ftp.rsa.com/pub/rsalabs/tmp/pkcs1v15sign-vectors.txt |
| 1994 // These vectors are known answers for RSA PKCS#1 v1.5 Signature with a SHA-1 |
| 1995 // digest, using a predefined key pair. |
| 1996 |
| 1997 struct TestCase { |
| 1998 const std::string message_hex; |
| 1999 const std::string signature_hex; |
| 2000 }; |
| 2001 |
| 2002 // The following data are the input messages and corresponding computed RSA |
| 2003 // PKCS#1 v1.5 signatures from the NIST link above. |
| 2004 const TestCase kTests[] = { |
| 2005 // PKCS#1 v1.5 Signature Example 1.1 |
| 2006 {"cdc87da223d786df3b45e0bbbc721326d1ee2af806cc315475cc6f0d9c66e1b6" |
| 2007 "2371d45ce2392e1ac92844c310102f156a0d8d52c1f4c40ba3aa65095786cb76" |
| 2008 "9757a6563ba958fed0bcc984e8b517a3d5f515b23b8a41e74aa867693f90dfb0" |
| 2009 "61a6e86dfaaee64472c00e5f20945729cbebe77f06ce78e08f4098fba41f9d61" |
| 2010 "93c0317e8b60d4b6084acb42d29e3808a3bc372d85e331170fcbf7cc72d0b71c" |
| 2011 "296648b3a4d10f416295d0807aa625cab2744fd9ea8fd223c42537029828bd16" |
| 2012 "be02546f130fd2e33b936d2676e08aed1b73318b750a0167d0", |
| 2013 "6bc3a06656842930a247e30d5864b4d819236ba7c68965862ad7dbc4e24af28e" |
| 2014 "86bb531f03358be5fb74777c6086f850caef893f0d6fcc2d0c91ec013693b4ea" |
| 2015 "00b80cd49aac4ecb5f8911afe539ada4a8f3823d1d13e472d1490547c659c761" |
| 2016 "7f3d24087ddb6f2b72096167fc097cab18e9a458fcb634cdce8ee35894c484d7"}, |
| 2017 // PKCS#1 v1.5 Signature Example 1.2 |
| 2018 {"851384cdfe819c22ed6c4ccb30daeb5cf059bc8e1166b7e3530c4c233e2b5f8f" |
| 2019 "71a1cca582d43ecc72b1bca16dfc7013226b9e", |
| 2020 "84fd2ce734ec1da828d0f15bf49a8707c15d05948136de537a3db421384167c8" |
| 2021 "6fae022587ee9e137daee754738262932d271c744c6d3a189ad4311bdb020492" |
| 2022 "e322fbddc40406ea860d4e8ea2a4084aa98b9622a446756fdb740ddb3d91db76" |
| 2023 "70e211661bbf8709b11c08a70771422d1a12def29f0688a192aebd89e0f896f8"}, |
| 2024 // PKCS#1 v1.5 Signature Example1.3 |
| 2025 {"a4b159941761c40c6a82f2b80d1b94f5aa2654fd17e12d588864679b54cd04ef" |
| 2026 "8bd03012be8dc37f4b83af7963faff0dfa225477437c48017ff2be8191cf3955" |
| 2027 "fc07356eab3f322f7f620e21d254e5db4324279fe067e0910e2e81ca2cab31c7" |
| 2028 "45e67a54058eb50d993cdb9ed0b4d029c06d21a94ca661c3ce27fae1d6cb20f4" |
| 2029 "564d66ce4767583d0e5f060215b59017be85ea848939127bd8c9c4d47b51056c" |
| 2030 "031cf336f17c9980f3b8f5b9b6878e8b797aa43b882684333e17893fe9caa6aa" |
| 2031 "299f7ed1a18ee2c54864b7b2b99b72618fb02574d139ef50f019c9eef4169713" |
| 2032 "38e7d470", |
| 2033 "0b1f2e5180e5c7b4b5e672929f664c4896e50c35134b6de4d5a934252a3a245f" |
| 2034 "f48340920e1034b7d5a5b524eb0e1cf12befef49b27b732d2c19e1c43217d6e1" |
| 2035 "417381111a1d36de6375cf455b3c9812639dbc27600c751994fb61799ecf7da6" |
| 2036 "bcf51540afd0174db4033188556675b1d763360af46feeca5b60f882829ee7b2"}, |
| 2037 // PKCS#1 v1.5 Signature Example 1.4 |
| 2038 {"bc656747fa9eafb3f0", |
| 2039 "45607ad611cf5747a41ac94d0ffec878bdaf63f6b57a4b088bf36e34e109f840" |
| 2040 "f24b742ada16102dabf951cbc44f8982e94ed4cd09448d20ec0efa73545f80b6" |
| 2041 "5406bed6194a61c340b4ad1568cbb75851049f11af1734964076e02029aee200" |
| 2042 "e40e80be0f4361f69841c4f92a4450a2286d43289b405554c54d25c6ecb584f4"}, |
| 2043 // PKCS#1 v1.5 Signature Example 1.5 |
| 2044 {"b45581547e5427770c768e8b82b75564e0ea4e9c32594d6bff706544de0a8776" |
| 2045 "c7a80b4576550eee1b2acabc7e8b7d3ef7bb5b03e462c11047eadd00629ae575" |
| 2046 "480ac1470fe046f13a2bf5af17921dc4b0aa8b02bee6334911651d7f8525d10f" |
| 2047 "32b51d33be520d3ddf5a709955a3dfe78283b9e0ab54046d150c177f037fdccc" |
| 2048 "5be4ea5f68b5e5a38c9d7edcccc4975f455a6909b4", |
| 2049 "54be9d90877515f450279c15b5f61ad6f15ecc95f18cbed82b65b1667a575809" |
| 2050 "587994668044f3bc2ae7f884501f64f0b43f588cfa205a6ab704328c2d4ab92a" |
| 2051 "7ae13440614d3e085f401da9ad28e2105e4a0edb681a6424df047388ce051ee9" |
| 2052 "df7bc2163fe347520ad51ccd518064383e741acad3cbdc2cb5a7c68e868464c2"}, |
| 2053 // PKCS#1 v1.5 Signature Example 1.6 |
| 2054 {"10aae9a0ab0b595d0841207b700d48d75faedde3b775cd6b4cc88ae06e4694ec" |
| 2055 "74ba18f8520d4f5ea69cbbe7cc2beba43efdc10215ac4eb32dc302a1f53dc6c4" |
| 2056 "352267e7936cfebf7c8d67035784a3909fa859c7b7b59b8e39c5c2349f1886b7" |
| 2057 "05a30267d402f7486ab4f58cad5d69adb17ab8cd0ce1caf5025af4ae24b1fb87" |
| 2058 "94c6070cc09a51e2f9911311e3877d0044c71c57a993395008806b723ac38373" |
| 2059 "d395481818528c1e7053739282053529510e935cd0fa77b8fa53cc2d474bd4fb" |
| 2060 "3cc5c672d6ffdc90a00f9848712c4bcfe46c60573659b11e6457e861f0f604b6" |
| 2061 "138d144f8ce4e2da73", |
| 2062 "0e6ff63a856b9cbd5dbe423183122047dd39d6f76d1b2310e546fe9ee73b33ef" |
| 2063 "a7c78f9474455c9e5b88cb383aafc3698668e7b7a59a9cbb5b0897b6c5afb7f8" |
| 2064 "bac4b924e98d760a15fc43d2814ab2d5187f79bed9915a93397ebc22a7677506" |
| 2065 "a02e076d3ffdc0441dbd4db00453dc28d830e0573f77b817b505c38b4a4bb5d0"}, |
| 2066 // PKCS#1 v1.5 Signature Example 1.7 |
| 2067 {"efb5da1b4d1e6d9a5dff92d0184da7e31f877d1281ddda625664869e8379e67a" |
| 2068 "d3b75eae74a580e9827abd6eb7a002cb5411f5266797768fb8e95ae40e3e8b34" |
| 2069 "66f5ab15d69553952939ec23e61d58497fac76aa1c0bb5a3cb4a54383587c7bb" |
| 2070 "78d13eefda205443e6ce4365802df55c64713497984e7ca96722b3edf84d56", |
| 2071 "8385d58533a995f72df262b70f40b391ddf515f464b9d2cc2d66398fc05689d8" |
| 2072 "11632946d62eabdca7a31fcf6cd6c981d28bbc29083e4a6d5b2b378ca4e540f0" |
| 2073 "60b96d53ad2693f82178b94e2e2f86b9accfa02025107e062ab7080175684501" |
| 2074 "028f676461d81c008fe4750671649970878fc175cf98e96b2ecbf6874d77dacb"}, |
| 2075 // PKCS#1 v1.5 Signature Example 1.8 |
| 2076 {"53bb58ce42f1984940552657233b14969af365c0a561a4132af18af39432280e" |
| 2077 "3e437082434b19231837184f02cf2b2e726bebf74d7ae3256d8b72f3eafdb134" |
| 2078 "d33de06f2991d299d59f5468d43b9958d6a968f5969edbbc6e7185cbc716c7c9" |
| 2079 "45dafa9cc71ddfaaa01094a452ddf5e2407320400bf05ea9729cafbf0600e788" |
| 2080 "07ef9462e3fde32ed7d981a56f4751ef64fb4549910ecc911d728053b3994300" |
| 2081 "4740e6f5821fe8d75c0617bf2c6b24bbfc34013fc95f0dedf5ba297f504fb833" |
| 2082 "da2a436d1d8ff1cc5193e2a64389fced918e7feb6716330f66801db9497549cf" |
| 2083 "1d3bd97cf1bc6255", |
| 2084 "8e1f3d26ec7c6bbb8c54c5d25f3120587803af6d3c2b99a37ced6a3657d4ae54" |
| 2085 "266f63fffde660c866d65d0ab0589e1d12d9ce6054b05c8668ae127171ccaae7" |
| 2086 "f1cd409677f52157b6123ab227f27a00966d1439b42a32169d1070394026fc8b" |
| 2087 "c93545b1ac252d0f7da751c02e33a47831fbd71514c2bbbd3adb6740c0fd68ad"}, |
| 2088 // PKCS#1 v1.5 Signature Example 1.9 |
| 2089 {"27cadc698450945f204ec3cf8c6cbd8ceb4cc0cbe312274fa96b04deac855160" |
| 2090 "c0e04e4ac5d38210c27c", |
| 2091 "7b63f9223356f35f6117f68c8f8220034fc2384ab5dc6904141f139314d6ee89" |
| 2092 "f54ec6ffd18c413a23c5931c7fbb13c555ccfd590e0eaa853c8c94d2520cd425" |
| 2093 "0d9a05a193b65dc749b82478af0156ee1de55ddad33ec1f0099cad6c891a3617" |
| 2094 "c7393d05fbfbbb00528a001df0b204ebdf1a341090dea89f870a877458427f7b"}, |
| 2095 // PKCS#1 v1.5 Signature Example 1.10 |
| 2096 {"716407e901b9ef92d761b013fd13eb7ad72aed", |
| 2097 "2a22dbe3774d5b297201b55a0f17f42dce63b7845cb325cfe951d0badb5c5a14" |
| 2098 "472143d896c86cc339f83671164215abc97862f2151654e75a3b357c37311b3d" |
| 2099 "7268cab540202e23bee52736f2cd86cce0c7dbde95e1c600a47395dc5eb0a472" |
| 2100 "153fbc4fb21b643e0c04ae14dd37e97e617a7567c89652219781001ba6f83298"}, |
| 2101 // PKCS#1 v1.5 Signature Example 1.11 |
| 2102 {"46c24e4103001629c712dd4ce8d747ee595d6c744ccc4f71347d9b8abf49d1b8" |
| 2103 "fb2ef91b95dc899d4c0e3d2997e638f4cf3f68e0498de5aabd13f0dfe02ff26b" |
| 2104 "a4379104e78ffa95ffbd15067ef8cbd7eb7860fecc71abe13d5c720a66851f2d" |
| 2105 "efd4e795054d7bec024bb422a46a7368b56d95b47aebafbeadd612812593a70d" |
| 2106 "b9f96d451ee15edb299308d777f4bb68ed3377c32156b41b7a9c92a14c8b8114" |
| 2107 "4399c56a5a432f4f770aa97da8415d0bda2e813206031e70620031c881d616bf" |
| 2108 "fd5f03bf147c1e73766c26246208", |
| 2109 "12235b0b406126d9d260d447e923a11051fb243079f446fd73a70181d53634d7" |
| 2110 "a0968e4ee27777eda63f6e4a3a91ad5985998a4848da59ce697b24bb332fa2ad" |
| 2111 "9ce462ca4affdc21dab908e8ce15af6eb9105b1abcf39142aa17b34c4c092386" |
| 2112 "a7abbfe028afdbebc14f2ce26fbee5edeca11502d39a6b7403154843d98a62a7"}, |
| 2113 // PKCS#1 v1.5 Signature Example 1.12 |
| 2114 {"bc99a932aa16d622bfff79c50b4c42358673261129e28d6a918ff1b0f1c4f46a" |
| 2115 "d8afa98b0ca0f56f967975b0a29be882e93b6cd3fc33e1faef72e52b2ae0a3f1" |
| 2116 "2024506e25690e902e782982145556532284cf505789738f4da31fa1333d3af8" |
| 2117 "62b2ba6b6ce7ab4cce6aba", |
| 2118 "872ec5ad4f1846256f17e9936ac50e43e9963ea8c1e76f15879b7874d77d122a" |
| 2119 "609dc8c561145b94bf4ffdffdeb17e6e76ffc6c10c0747f5e37a9f434f5609e7" |
| 2120 "9da5250215a457afdf12c6507cc1551f54a28010595826a2c9b97fa0aa851cc6" |
| 2121 "8b705d7a06d720ba027e4a1c0b019500fb63b78071684dcfa9772700b982dc66"}, |
| 2122 // PKCS#1 v1.5 Signature Example 1.13 |
| 2123 {"731e172ac063992c5b11ba170dfb23bb000d47ba195329cf278061037381514c" |
| 2124 "146064c5285db130dd5bae98b772225950eab05d3ea996f6fffb9a8c8622913f" |
| 2125 "279914c89ada4f3dd77666a868bfcbff2b95b7daf453d4e2c9d75beee7f8e709" |
| 2126 "05e4066a4f73aecc67f956aa5a3292b8488c917d317cfdc86253e690381e15ab", |
| 2127 "76204eacc1d63ec1d6ad5bd0692e1a2f686df6e64ca945c77a824de212efa6d9" |
| 2128 "782d81b4591403ff4020620298c07ebd3a8a61c5bf4dad62cbfc4ae6a03937be" |
| 2129 "4b49a216d570fc6e81872937876e27bd19cf601effc30ddca573c9d56cd4569b" |
| 2130 "db4851c450c42cb21e738cdd61027b8be5e9b410fc46aa3f29e4be9e64451346"}, |
| 2131 // PKCS#1 v1.5 Signature Example 1.14 |
| 2132 {"0211382683a74d8d2a2cb6a06550563be1c26ca62821e4ff163b720464fc3a28" |
| 2133 "d91bedddc62749a5538eaf41fbe0c82a77e06ad99383c9e985ffb8a93fd4d7c5" |
| 2134 "8db51ad91ba461d69a8fd7ddabe2496757a0c49122c1a79a85cc0553e8214d03" |
| 2135 "6dfe0185efa0d05860c612fa0882c82d246e5830a67355dff18a2c36b732f988" |
| 2136 "cfedc562264c6254b40fcabb97b760947568dcd6a17cda6ee8855bddbab93702" |
| 2137 "471aa0cfb1bed2e13118eba1175b73c96253c108d0b2aba05ab8e17e84392e20" |
| 2138 "085f47404d8365527dc3fb8f2bb48a50038e71361ccf973407", |
| 2139 "525500918331f1042eae0c5c2054aa7f92deb26991b5796634f229daf9b49eb2" |
| 2140 "054d87319f3cfa9b466bd075ef6699aea4bd4a195a1c52968b5e2b75e092d846" |
| 2141 "ea1b5cc27905a8e1d5e5de0edfdb21391ebb951864ebd9f0b0ec35b654287136" |
| 2142 "0a317b7ef13ae06af684e38e21b1e19bc7298e5d6fe0013a164bfa25d3e7313d"}, |
| 2143 // PKCS#1 v1.5 Signature Example 1.15 |
| 2144 {"fc6b700d22583388ab2f8dafcaf1a05620698020da4bae44dafbd0877b501250" |
| 2145 "6dc3181d5c66bf023f348b41fd9f94795ab96452a4219f2d39d72af359cf1956" |
| 2146 "51c7", |
| 2147 "4452a6cc2626b01e95ab306df0d0cc7484fbab3c22e9703283567f66eadc248d" |
| 2148 "bda58fce7dd0c70cce3f150fca4b369dff3b6237e2b16281ab55b53fb13089c8" |
| 2149 "5cd265056b3d62a88bfc2135b16791f7fbcab9fd2dc33becb617be419d2c0461" |
| 2150 "42a4d47b338314552edd4b6fe9ce1104ecec4a9958d7331e930fc09bf08a6e64"}, |
| 2151 // PKCS#1 v1.5 Signature Example 1.16 |
| 2152 {"13ba086d709cfa5fedaa557a89181a6140f2300ed6d7c3febb6cf68abebcbc67" |
| 2153 "8f2bca3dc2330295eec45bb1c4075f3ada987eae88b39c51606cb80429e649d9" |
| 2154 "8acc8441b1f8897db86c5a4ce0abf28b1b81dca3667697b850696b74a5ebd85d" |
| 2155 "ec56c90f8abe513efa857853720be319607921bca947522cd8fac8cace5b827c" |
| 2156 "3e5a129e7ee57f6b84932f14141ac4274e8cbb46e6912b0d3e2177d499d1840c" |
| 2157 "d47d4d7ae0b4cdc4d3", |
| 2158 "1f3b5a87db72a2c97bb3eff2a65a301268eacd89f42abc1098c1f2de77b0832a" |
| 2159 "65d7815feb35070063f221bb3453bd434386c9a3fde18e3ca1687fb649e86c51" |
| 2160 "d658619dde5debb86fe15491ff77ab748373f1be508880d66ea81e870e91cdf1" |
| 2161 "704875c17f0b10103188bc64eef5a3551b414c733670215b1a22702562581ab1"}, |
| 2162 // PKCS#1 v1.5 Signature Example 1.17 |
| 2163 {"eb1e5935", |
| 2164 "370cb9839ae6074f84b2acd6e6f6b7921b4b523463757f6446716140c4e6c0e7" |
| 2165 "5bec6ad0197ebfa86bf46d094f5f6cd36dca3a5cc73c8bbb70e2c7c9ab5d964e" |
| 2166 "c8e3dfde481b4a1beffd01b4ad15b31ae7aebb9b70344a9411083165fdf9c375" |
| 2167 "4bbb8b94dd34bd4813dfada1f6937de4267d5597ca09a31e83d7f1a79dd19b5e"}, |
| 2168 // PKCS#1 v1.5 Signature Example 1.18 |
| 2169 {"6346b153e889c8228209630071c8a57783f368760b8eb908cfc2b276", |
| 2170 "2479c975c5b1ae4c4e940f473a9045b8bf5b0bfca78ec29a38dfbedc8a749b7a" |
| 2171 "2692f7c52d5bc7c831c7232372a00fed3b6b49e760ec99e074ff2eead5134e83" |
| 2172 "05725dfa39212b84bd4b8d80bc8bc17a512823a3beb18fc08e45ed19c26c8177" |
| 2173 "07d67fb05832ef1f12a33e90cd93b8a780319e2963ca25a2af7b09ad8f595c21"}, |
| 2174 // PKCS#1 v1.5 Signature Example 1.19 |
| 2175 {"64702db9f825a0f3abc361974659f5e9d30c3aa4f56feac69050c72905e77fe0" |
| 2176 "c22f88a378c21fcf45fe8a5c717302093929", |
| 2177 "152f3451c858d69594e6567dfb31291c1ee7860b9d15ebd5a5edd276ac3e6f7a" |
| 2178 "8d1480e42b3381d2be023acf7ebbdb28de3d2163ae44259c6df98c335d045b61" |
| 2179 "dac9dba9dbbb4e6ab4a083cd76b580cbe472206a1a9fd60680ceea1a570a29b0" |
| 2180 "881c775eaef5525d6d2f344c28837d0aca422bbb0f1aba8f6861ae18bd73fe44"}, |
| 2181 // PKCS#1 v1.5 Signature Example 1.20 |
| 2182 {"941921de4a1c9c1618d6f3ca3c179f6e29bae6ddf9a6a564f929e3ce82cf3265" |
| 2183 "d7837d5e692be8dcc9e86c", |
| 2184 "7076c287fc6fff2b20537435e5a3107ce4da10716186d01539413e609d27d1da" |
| 2185 "6fd952c61f4bab91c045fa4f8683ecc4f8dde74227f773cff3d96db84718c494" |
| 2186 "4b06affeba94b725f1b07d3928b2490a85c2f1abf492a9177a7cd2ea0c966875" |
| 2187 "6f825bbec900fa8ac3824e114387ef573780ca334882387b94e5aad7a27a28dc"}}; |
| 2188 |
| 2189 // Import the key pair. |
| 2190 blink::WebCryptoAlgorithm algorithm = CreateRsaAlgorithmWithInnerHash( |
| 2191 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
| 2192 blink::WebCryptoAlgorithmIdSha1); |
| 2193 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
| 2194 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); |
| 2195 ImportRsaKeyPair( |
| 2196 kPublicKeySpkiDerHex, |
| 2197 kPrivateKeyPkcs8DerHex, |
| 2198 algorithm, |
| 2199 false, |
| 2200 blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageVerify, |
| 2201 &public_key, |
| 2202 &private_key); |
| 2203 |
| 2204 // Validate the signatures are computed and verified as expected. |
| 2205 blink::WebArrayBuffer signature; |
| 2206 for (size_t idx = 0; idx < ARRAYSIZE_UNSAFE(kTests); ++idx) { |
| 2207 SCOPED_TRACE(idx); |
| 2208 const TestCase& test = kTests[idx]; |
| 2209 const std::vector<uint8> message = HexStringToBytes(test.message_hex); |
| 2210 |
| 2211 signature.reset(); |
| 2212 ASSERT_TRUE(SignInternal(algorithm, private_key, message, &signature)); |
| 2213 ExpectArrayBufferMatchesHex(test.signature_hex, signature); |
| 2214 |
| 2215 bool is_match = false; |
| 2216 ASSERT_TRUE(VerifySignatureInternal( |
| 2217 algorithm, |
| 2218 public_key, |
| 2219 HexStringToBytes(test.signature_hex), |
| 2220 message, |
| 2221 &is_match)); |
| 2222 EXPECT_TRUE(is_match); |
| 2223 } |
| 2224 } |
| 2225 |
1831 TEST_F(WebCryptoImplTest, MAYBE(AesKwKeyImport)) { | 2226 TEST_F(WebCryptoImplTest, MAYBE(AesKwKeyImport)) { |
1832 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 2227 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
1833 blink::WebCryptoAlgorithm algorithm = | 2228 blink::WebCryptoAlgorithm algorithm = |
1834 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); | 2229 webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesKw); |
1835 | 2230 |
1836 // Import a 128-bit Key Encryption Key (KEK) | 2231 // Import a 128-bit Key Encryption Key (KEK) |
1837 std::string key_raw_hex_in = "025a8cf3f08b4f6c5f33bbc76a471939"; | 2232 std::string key_raw_hex_in = "025a8cf3f08b4f6c5f33bbc76a471939"; |
1838 ASSERT_TRUE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, | 2233 ASSERT_TRUE(ImportKeyInternal(blink::WebCryptoKeyFormatRaw, |
1839 HexStringToBytes(key_raw_hex_in), | 2234 HexStringToBytes(key_raw_hex_in), |
1840 algorithm, | 2235 algorithm, |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2083 if (test_tag_size_bits == wrong_tag_size_bits) | 2478 if (test_tag_size_bits == wrong_tag_size_bits) |
2084 continue; | 2479 continue; |
2085 EXPECT_FALSE(AesGcmDecrypt(key, test_iv, test_additional_data, | 2480 EXPECT_FALSE(AesGcmDecrypt(key, test_iv, test_additional_data, |
2086 wrong_tag_size_bits, test_cipher_text, | 2481 wrong_tag_size_bits, test_cipher_text, |
2087 test_authentication_tag, &plain_text)); | 2482 test_authentication_tag, &plain_text)); |
2088 } | 2483 } |
2089 } | 2484 } |
2090 } | 2485 } |
2091 | 2486 |
2092 } // namespace content | 2487 } // namespace content |
OLD | NEW |