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 "base/stl_util.h" | 5 #include "base/stl_util.h" |
6 #include "content/child/webcrypto/algorithm_dispatch.h" | 6 #include "content/child/webcrypto/algorithm_dispatch.h" |
7 #include "content/child/webcrypto/crypto_data.h" | 7 #include "content/child/webcrypto/crypto_data.h" |
8 #include "content/child/webcrypto/status.h" | 8 #include "content/child/webcrypto/status.h" |
9 #include "content/child/webcrypto/test/test_helpers.h" | 9 #include "content/child/webcrypto/test/test_helpers.h" |
10 #include "content/child/webcrypto/webcrypto_util.h" | 10 #include "content/child/webcrypto/webcrypto_util.h" |
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 false, | 632 false, |
633 blink::WebCryptoKeyUsageEncrypt, | 633 blink::WebCryptoKeyUsageEncrypt, |
634 &key)); | 634 &key)); |
635 } | 635 } |
636 | 636 |
637 // Import a JWK with unrecognized values for "key_ops". | 637 // Import a JWK with unrecognized values for "key_ops". |
638 TEST(WebCryptoAesCbcTest, ImportJwkUnrecognizedKeyOps) { | 638 TEST(WebCryptoAesCbcTest, ImportJwkUnrecognizedKeyOps) { |
639 blink::WebCryptoKey key; | 639 blink::WebCryptoKey key; |
640 blink::WebCryptoAlgorithm algorithm = | 640 blink::WebCryptoAlgorithm algorithm = |
641 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc); | 641 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc); |
642 blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageEncrypt; | 642 blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageEncrypt; |
643 | 643 |
644 base::DictionaryValue dict; | 644 base::DictionaryValue dict; |
645 dict.SetString("kty", "oct"); | 645 dict.SetString("kty", "oct"); |
646 dict.SetString("alg", "A128CBC"); | 646 dict.SetString("alg", "A128CBC"); |
647 dict.SetString("use", "enc"); | 647 dict.SetString("use", "enc"); |
648 dict.SetBoolean("ext", false); | 648 dict.SetBoolean("ext", false); |
649 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); | 649 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); |
650 | 650 |
651 base::ListValue* key_ops = new base::ListValue; | 651 base::ListValue* key_ops = new base::ListValue; |
652 dict.Set("key_ops", key_ops); | 652 dict.Set("key_ops", key_ops); |
653 key_ops->AppendString("foo"); | 653 key_ops->AppendString("foo"); |
654 key_ops->AppendString("bar"); | 654 key_ops->AppendString("bar"); |
655 key_ops->AppendString("baz"); | 655 key_ops->AppendString("baz"); |
656 key_ops->AppendString("encrypt"); | 656 key_ops->AppendString("encrypt"); |
657 EXPECT_EQ(Status::Success(), | 657 EXPECT_EQ(Status::Success(), |
658 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); | 658 ImportKeyJwkFromDict(dict, algorithm, false, usages, &key)); |
659 } | 659 } |
660 | 660 |
661 // Import a JWK with a value in key_ops array that is not a string. | 661 // Import a JWK with a value in key_ops array that is not a string. |
662 TEST(WebCryptoAesCbcTest, ImportJwkNonStringKeyOp) { | 662 TEST(WebCryptoAesCbcTest, ImportJwkNonStringKeyOp) { |
663 blink::WebCryptoKey key; | 663 blink::WebCryptoKey key; |
664 blink::WebCryptoAlgorithm algorithm = | 664 blink::WebCryptoAlgorithm algorithm = |
665 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc); | 665 CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc); |
666 blink::WebCryptoKeyUsageMask usage_mask = blink::WebCryptoKeyUsageEncrypt; | 666 blink::WebCryptoKeyUsageMask usages = blink::WebCryptoKeyUsageEncrypt; |
667 | 667 |
668 base::DictionaryValue dict; | 668 base::DictionaryValue dict; |
669 dict.SetString("kty", "oct"); | 669 dict.SetString("kty", "oct"); |
670 dict.SetString("alg", "A128CBC"); | 670 dict.SetString("alg", "A128CBC"); |
671 dict.SetString("use", "enc"); | 671 dict.SetString("use", "enc"); |
672 dict.SetBoolean("ext", false); | 672 dict.SetBoolean("ext", false); |
673 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); | 673 dict.SetString("k", "GADWrMRHwQfoNaXU5fZvTg=="); |
674 | 674 |
675 base::ListValue* key_ops = new base::ListValue; | 675 base::ListValue* key_ops = new base::ListValue; |
676 dict.Set("key_ops", key_ops); | 676 dict.Set("key_ops", key_ops); |
677 key_ops->AppendString("encrypt"); | 677 key_ops->AppendString("encrypt"); |
678 key_ops->AppendInteger(3); | 678 key_ops->AppendInteger(3); |
679 EXPECT_EQ(Status::ErrorJwkPropertyWrongType("key_ops[1]", "string"), | 679 EXPECT_EQ(Status::ErrorJwkPropertyWrongType("key_ops[1]", "string"), |
680 ImportKeyJwkFromDict(dict, algorithm, false, usage_mask, &key)); | 680 ImportKeyJwkFromDict(dict, algorithm, false, usages, &key)); |
681 } | 681 } |
682 | 682 |
683 // Fail on missing k. | 683 // Fail on missing k. |
684 TEST(WebCryptoAesCbcTest, ImportJwkMissingK) { | 684 TEST(WebCryptoAesCbcTest, ImportJwkMissingK) { |
685 blink::WebCryptoKey key; | 685 blink::WebCryptoKey key; |
686 | 686 |
687 base::DictionaryValue dict; | 687 base::DictionaryValue dict; |
688 dict.SetString("kty", "oct"); | 688 dict.SetString("kty", "oct"); |
689 | 689 |
690 EXPECT_EQ( | 690 EXPECT_EQ( |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1032 | 1032 |
1033 EXPECT_NE(public_key_spki, wrapped_public_key); | 1033 EXPECT_NE(public_key_spki, wrapped_public_key); |
1034 EXPECT_NE(private_key_pkcs8, wrapped_private_key); | 1034 EXPECT_NE(private_key_pkcs8, wrapped_private_key); |
1035 } | 1035 } |
1036 | 1036 |
1037 } // namespace | 1037 } // namespace |
1038 | 1038 |
1039 } // namespace webcrypto | 1039 } // namespace webcrypto |
1040 | 1040 |
1041 } // namespace content | 1041 } // namespace content |
OLD | NEW |