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 792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 CreateAesCbcAlgorithm(iv), | 803 CreateAesCbcAlgorithm(iv), |
804 true, | 804 true, |
805 blink::WebCryptoKeyUsageEncrypt, | 805 blink::WebCryptoKeyUsageEncrypt, |
806 &key)); | 806 &key)); |
807 } | 807 } |
808 | 808 |
809 // Fail exporting the key in SPKI and PKCS#8 formats (not allowed for secret | 809 // Fail exporting the key in SPKI and PKCS#8 formats (not allowed for secret |
810 // keys). | 810 // keys). |
811 EXPECT_STATUS(Status::ErrorUnexpectedKeyType(), | 811 EXPECT_STATUS(Status::ErrorUnexpectedKeyType(), |
812 ExportKey(blink::WebCryptoKeyFormatSpki, key, &output)); | 812 ExportKey(blink::WebCryptoKeyFormatSpki, key, &output)); |
813 EXPECT_STATUS(Status::ErrorUnsupported(), | 813 EXPECT_STATUS(Status::ErrorUnexpectedKeyType(), |
814 ExportKey(blink::WebCryptoKeyFormatPkcs8, key, &output)); | 814 ExportKey(blink::WebCryptoKeyFormatPkcs8, key, &output)); |
815 } | 815 } |
816 | 816 |
817 TEST_F(SharedCryptoTest, MAYBE(AesCbcSampleSets)) { | 817 TEST_F(SharedCryptoTest, MAYBE(AesCbcSampleSets)) { |
818 scoped_ptr<base::ListValue> tests; | 818 scoped_ptr<base::ListValue> tests; |
819 ASSERT_TRUE(ReadJsonTestFileToList("aes_cbc.json", &tests)); | 819 ASSERT_TRUE(ReadJsonTestFileToList("aes_cbc.json", &tests)); |
820 | 820 |
821 for (size_t test_index = 0; test_index < tests->GetSize(); ++test_index) { | 821 for (size_t test_index = 0; test_index < tests->GetSize(); ++test_index) { |
822 SCOPED_TRACE(test_index); | 822 SCOPED_TRACE(test_index); |
823 base::DictionaryValue* test; | 823 base::DictionaryValue* test; |
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1674 CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5), | 1674 CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5), |
1675 false, | 1675 false, |
1676 blink::WebCryptoKeyUsageEncrypt, | 1676 blink::WebCryptoKeyUsageEncrypt, |
1677 &key)); | 1677 &key)); |
1678 EXPECT_TRUE(key.handle()); | 1678 EXPECT_TRUE(key.handle()); |
1679 EXPECT_FALSE(key.extractable()); | 1679 EXPECT_FALSE(key.extractable()); |
1680 EXPECT_STATUS(Status::ErrorKeyNotExtractable(), | 1680 EXPECT_STATUS(Status::ErrorKeyNotExtractable(), |
1681 ExportKey(blink::WebCryptoKeyFormatSpki, key, &output)); | 1681 ExportKey(blink::WebCryptoKeyFormatSpki, key, &output)); |
1682 } | 1682 } |
1683 | 1683 |
1684 TEST_F(SharedCryptoTest, MAYBE(ImportPkcs8)) { | 1684 TEST_F(SharedCryptoTest, MAYBE(ImportExportPkcs8)) { |
1685 // Passing case: Import a valid RSA key in PKCS#8 format. | 1685 // Passing case: Import a valid RSA key in PKCS#8 format. |
1686 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 1686 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
1687 ASSERT_STATUS_SUCCESS(ImportKey( | 1687 ASSERT_STATUS_SUCCESS(ImportKey( |
1688 blink::WebCryptoKeyFormatPkcs8, | 1688 blink::WebCryptoKeyFormatPkcs8, |
1689 CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)), | 1689 CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)), |
1690 CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 1690 CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
1691 blink::WebCryptoAlgorithmIdSha1), | 1691 blink::WebCryptoAlgorithmIdSha1), |
1692 true, | 1692 true, |
1693 blink::WebCryptoKeyUsageSign, | 1693 blink::WebCryptoKeyUsageSign, |
1694 &key)); | 1694 &key)); |
1695 EXPECT_TRUE(key.handle()); | 1695 EXPECT_TRUE(key.handle()); |
1696 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, key.type()); | 1696 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, key.type()); |
1697 EXPECT_TRUE(key.extractable()); | 1697 EXPECT_TRUE(key.extractable()); |
1698 EXPECT_EQ(blink::WebCryptoKeyUsageSign, key.usages()); | 1698 EXPECT_EQ(blink::WebCryptoKeyUsageSign, key.usages()); |
1699 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha1, | 1699 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha1, |
1700 key.algorithm().rsaHashedParams()->hash().id()); | 1700 key.algorithm().rsaHashedParams()->hash().id()); |
1701 EXPECT_EQ(kModulusLengthBits, | 1701 EXPECT_EQ(kModulusLengthBits, |
1702 key.algorithm().rsaHashedParams()->modulusLengthBits()); | 1702 key.algorithm().rsaHashedParams()->modulusLengthBits()); |
1703 ExpectCryptoDataMatchesHex( | 1703 ExpectCryptoDataMatchesHex( |
1704 "010001", | 1704 "010001", |
1705 CryptoData(key.algorithm().rsaHashedParams()->publicExponent())); | 1705 CryptoData(key.algorithm().rsaHashedParams()->publicExponent())); |
1706 | 1706 |
| 1707 blink::WebArrayBuffer exported_key; |
| 1708 ASSERT_STATUS_SUCCESS( |
| 1709 ExportKey(blink::WebCryptoKeyFormatPkcs8, key, &exported_key)); |
| 1710 ExpectArrayBufferMatchesHex(kPrivateKeyPkcs8DerHex, exported_key); |
| 1711 |
1707 // Failing case: Empty PKCS#8 data | 1712 // Failing case: Empty PKCS#8 data |
1708 EXPECT_STATUS(Status::ErrorImportEmptyKeyData(), | 1713 EXPECT_STATUS(Status::ErrorImportEmptyKeyData(), |
1709 ImportKey(blink::WebCryptoKeyFormatPkcs8, | 1714 ImportKey(blink::WebCryptoKeyFormatPkcs8, |
1710 CryptoData(std::vector<uint8>()), | 1715 CryptoData(std::vector<uint8>()), |
1711 CreateRsaHashedImportAlgorithm( | 1716 CreateRsaHashedImportAlgorithm( |
1712 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | 1717 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, |
1713 blink::WebCryptoAlgorithmIdSha1), | 1718 blink::WebCryptoAlgorithmIdSha1), |
1714 true, | 1719 true, |
1715 blink::WebCryptoKeyUsageSign, | 1720 blink::WebCryptoKeyUsageSign, |
1716 &key)); | 1721 &key)); |
(...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3042 algorithm, | 3047 algorithm, |
3043 CreateAesCbcAlgorithm(std::vector<uint8>(0, 16)), | 3048 CreateAesCbcAlgorithm(std::vector<uint8>(0, 16)), |
3044 true, | 3049 true, |
3045 blink::WebCryptoKeyUsageEncrypt, | 3050 blink::WebCryptoKeyUsageEncrypt, |
3046 &unwrapped_key)); | 3051 &unwrapped_key)); |
3047 } | 3052 } |
3048 | 3053 |
3049 } // namespace webcrypto | 3054 } // namespace webcrypto |
3050 | 3055 |
3051 } // namespace content | 3056 } // namespace content |
OLD | NEW |