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/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 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1390 EXPECT_EQ(Status::ErrorJwkPropertyWrongType("ext", "boolean"), | 1390 EXPECT_EQ(Status::ErrorJwkPropertyWrongType("ext", "boolean"), |
1391 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); | 1391 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); |
1392 RestoreJwkOctDictionary(&dict); | 1392 RestoreJwkOctDictionary(&dict); |
1393 | 1393 |
1394 // Fail on invalid key_ops (wrong type). | 1394 // Fail on invalid key_ops (wrong type). |
1395 dict.SetBoolean("key_ops", true); | 1395 dict.SetBoolean("key_ops", true); |
1396 EXPECT_EQ(Status::ErrorJwkPropertyWrongType("key_ops", "list"), | 1396 EXPECT_EQ(Status::ErrorJwkPropertyWrongType("key_ops", "list"), |
1397 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); | 1397 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); |
1398 RestoreJwkOctDictionary(&dict); | 1398 RestoreJwkOctDictionary(&dict); |
1399 | 1399 |
1400 // Fail on invalid key_ops (wrong element value). | 1400 // Fail on inconsistent key_ops - asking for "encrypt" however JWK contains |
| 1401 // only "foo". |
1401 base::ListValue* key_ops = new base::ListValue; | 1402 base::ListValue* key_ops = new base::ListValue; |
1402 // Note: the following call makes dict assume ownership of key_ops. | 1403 // Note: the following call makes dict assume ownership of key_ops. |
1403 dict.Set("key_ops", key_ops); | 1404 dict.Set("key_ops", key_ops); |
1404 key_ops->AppendString("foo"); | 1405 key_ops->AppendString("foo"); |
1405 EXPECT_EQ(Status::ErrorJwkUnrecognizedKeyop(), | 1406 EXPECT_EQ(Status::ErrorJwkKeyopsInconsistent(), |
1406 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); | 1407 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); |
1407 RestoreJwkOctDictionary(&dict); | 1408 RestoreJwkOctDictionary(&dict); |
1408 } | 1409 } |
1409 | 1410 |
| 1411 // Import a JWK with unrecognized values for "key_ops". |
| 1412 TEST_F(SharedCryptoTest, ImportJwkUnrecognizedKeyOps) { |
| 1413 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
| 1414 blink::WebCryptoAlgorithm algorithm = |
| 1415 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc); |
| 1416 blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageEncrypt; |
| 1417 |
| 1418 base::DictionaryValue dict; |
| 1419 RestoreJwkOctDictionary(&dict); |
| 1420 |
| 1421 base::ListValue* key_ops = new base::ListValue; |
| 1422 dict.Set("key_ops", key_ops); |
| 1423 key_ops->AppendString("foo"); |
| 1424 key_ops->AppendString("bar"); |
| 1425 key_ops->AppendString("baz"); |
| 1426 key_ops->AppendString("encrypt"); |
| 1427 EXPECT_EQ(Status::Success(), |
| 1428 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); |
| 1429 } |
| 1430 |
| 1431 // Import a JWK with a value in key_ops array that is not a string. |
| 1432 TEST_F(SharedCryptoTest, ImportJwkNonStringKeyOp) { |
| 1433 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
| 1434 blink::WebCryptoAlgorithm algorithm = |
| 1435 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc); |
| 1436 blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageEncrypt; |
| 1437 |
| 1438 base::DictionaryValue dict; |
| 1439 RestoreJwkOctDictionary(&dict); |
| 1440 |
| 1441 base::ListValue* key_ops = new base::ListValue; |
| 1442 dict.Set("key_ops", key_ops); |
| 1443 key_ops->AppendString("encrypt"); |
| 1444 key_ops->AppendInteger(3); |
| 1445 EXPECT_EQ(Status::ErrorJwkPropertyWrongType("key_ops[1]", "string"), |
| 1446 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); |
| 1447 } |
| 1448 |
1410 TEST_F(SharedCryptoTest, ImportJwkOctFailures) { | 1449 TEST_F(SharedCryptoTest, ImportJwkOctFailures) { |
1411 base::DictionaryValue dict; | 1450 base::DictionaryValue dict; |
1412 RestoreJwkOctDictionary(&dict); | 1451 RestoreJwkOctDictionary(&dict); |
1413 blink::WebCryptoAlgorithm algorithm = | 1452 blink::WebCryptoAlgorithm algorithm = |
1414 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc); | 1453 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc); |
1415 blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageEncrypt; | 1454 blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageEncrypt; |
1416 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 1455 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
1417 | 1456 |
1418 // Baseline pass. | 1457 // Baseline pass. |
1419 EXPECT_EQ(Status::Success(), | 1458 EXPECT_EQ(Status::Success(), |
(...skipping 2649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4069 EXPECT_EQ(public_key_spki, unwrapped_public_key_spki); | 4108 EXPECT_EQ(public_key_spki, unwrapped_public_key_spki); |
4070 EXPECT_EQ(private_key_pkcs8, unwrapped_private_key_pkcs8); | 4109 EXPECT_EQ(private_key_pkcs8, unwrapped_private_key_pkcs8); |
4071 | 4110 |
4072 EXPECT_NE(public_key_spki, wrapped_public_key); | 4111 EXPECT_NE(public_key_spki, wrapped_public_key); |
4073 EXPECT_NE(private_key_pkcs8, wrapped_private_key); | 4112 EXPECT_NE(private_key_pkcs8, wrapped_private_key); |
4074 } | 4113 } |
4075 | 4114 |
4076 } // namespace webcrypto | 4115 } // namespace webcrypto |
4077 | 4116 |
4078 } // namespace content | 4117 } // namespace content |
OLD | NEW |