Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1890)

Side by Side Diff: content/child/webcrypto/shared_crypto_unittest.cc

Issue 203753009: [webcrypto] Add PKCS#8 export for RSA private keys for NSS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove static Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 790 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 CreateAesCbcAlgorithm(iv), 801 CreateAesCbcAlgorithm(iv),
802 true, 802 true,
803 blink::WebCryptoKeyUsageEncrypt, 803 blink::WebCryptoKeyUsageEncrypt,
804 &key)); 804 &key));
805 } 805 }
806 806
807 // Fail exporting the key in SPKI and PKCS#8 formats (not allowed for secret 807 // Fail exporting the key in SPKI and PKCS#8 formats (not allowed for secret
808 // keys). 808 // keys).
809 EXPECT_STATUS(Status::ErrorUnexpectedKeyType(), 809 EXPECT_STATUS(Status::ErrorUnexpectedKeyType(),
810 ExportKey(blink::WebCryptoKeyFormatSpki, key, &output)); 810 ExportKey(blink::WebCryptoKeyFormatSpki, key, &output));
811 EXPECT_STATUS(Status::ErrorUnsupported(), 811 EXPECT_STATUS(Status::ErrorUnexpectedKeyType(),
812 ExportKey(blink::WebCryptoKeyFormatPkcs8, key, &output)); 812 ExportKey(blink::WebCryptoKeyFormatPkcs8, key, &output));
813 } 813 }
814 814
815 TEST_F(SharedCryptoTest, MAYBE(AesCbcSampleSets)) { 815 TEST_F(SharedCryptoTest, MAYBE(AesCbcSampleSets)) {
816 scoped_ptr<base::ListValue> tests; 816 scoped_ptr<base::ListValue> tests;
817 ASSERT_TRUE(ReadJsonTestFileToList("aes_cbc.json", &tests)); 817 ASSERT_TRUE(ReadJsonTestFileToList("aes_cbc.json", &tests));
818 818
819 for (size_t test_index = 0; test_index < tests->GetSize(); ++test_index) { 819 for (size_t test_index = 0; test_index < tests->GetSize(); ++test_index) {
820 SCOPED_TRACE(test_index); 820 SCOPED_TRACE(test_index);
821 base::DictionaryValue* test; 821 base::DictionaryValue* test;
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5), 1705 CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5),
1706 false, 1706 false,
1707 blink::WebCryptoKeyUsageEncrypt, 1707 blink::WebCryptoKeyUsageEncrypt,
1708 &key)); 1708 &key));
1709 EXPECT_TRUE(key.handle()); 1709 EXPECT_TRUE(key.handle());
1710 EXPECT_FALSE(key.extractable()); 1710 EXPECT_FALSE(key.extractable());
1711 EXPECT_STATUS(Status::ErrorKeyNotExtractable(), 1711 EXPECT_STATUS(Status::ErrorKeyNotExtractable(),
1712 ExportKey(blink::WebCryptoKeyFormatSpki, key, &output)); 1712 ExportKey(blink::WebCryptoKeyFormatSpki, key, &output));
1713 } 1713 }
1714 1714
1715 TEST_F(SharedCryptoTest, MAYBE(ImportPkcs8)) { 1715 TEST_F(SharedCryptoTest, MAYBE(ImportExportPkcs8)) {
1716 // Passing case: Import a valid RSA key in PKCS#8 format. 1716 // Passing case: Import a valid RSA key in PKCS#8 format.
1717 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); 1717 blink::WebCryptoKey key = blink::WebCryptoKey::createNull();
1718 ASSERT_STATUS_SUCCESS(ImportKey( 1718 ASSERT_STATUS_SUCCESS(ImportKey(
1719 blink::WebCryptoKeyFormatPkcs8, 1719 blink::WebCryptoKeyFormatPkcs8,
1720 CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)), 1720 CryptoData(HexStringToBytes(kPrivateKeyPkcs8DerHex)),
1721 CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, 1721 CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5,
1722 blink::WebCryptoAlgorithmIdSha1), 1722 blink::WebCryptoAlgorithmIdSha1),
1723 true, 1723 true,
1724 blink::WebCryptoKeyUsageSign, 1724 blink::WebCryptoKeyUsageSign,
1725 &key)); 1725 &key));
1726 EXPECT_TRUE(key.handle()); 1726 EXPECT_TRUE(key.handle());
1727 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, key.type()); 1727 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, key.type());
1728 EXPECT_TRUE(key.extractable()); 1728 EXPECT_TRUE(key.extractable());
1729 EXPECT_EQ(blink::WebCryptoKeyUsageSign, key.usages()); 1729 EXPECT_EQ(blink::WebCryptoKeyUsageSign, key.usages());
1730 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha1, 1730 EXPECT_EQ(blink::WebCryptoAlgorithmIdSha1,
1731 key.algorithm().rsaHashedParams()->hash().id()); 1731 key.algorithm().rsaHashedParams()->hash().id());
1732 EXPECT_EQ(kModulusLengthBits, 1732 EXPECT_EQ(kModulusLengthBits,
1733 key.algorithm().rsaHashedParams()->modulusLengthBits()); 1733 key.algorithm().rsaHashedParams()->modulusLengthBits());
1734 ExpectCryptoDataMatchesHex( 1734 ExpectCryptoDataMatchesHex(
1735 "010001", 1735 "010001",
1736 CryptoData(key.algorithm().rsaHashedParams()->publicExponent())); 1736 CryptoData(key.algorithm().rsaHashedParams()->publicExponent()));
1737 1737
1738 blink::WebArrayBuffer exported_key;
1739 ASSERT_STATUS_SUCCESS(
1740 ExportKey(blink::WebCryptoKeyFormatPkcs8, key, &exported_key));
1741 ExpectArrayBufferMatchesHex(kPrivateKeyPkcs8DerHex, exported_key);
1742
1738 // Failing case: Empty PKCS#8 data 1743 // Failing case: Empty PKCS#8 data
1739 EXPECT_STATUS(Status::ErrorImportEmptyKeyData(), 1744 EXPECT_STATUS(Status::ErrorImportEmptyKeyData(),
1740 ImportKey(blink::WebCryptoKeyFormatPkcs8, 1745 ImportKey(blink::WebCryptoKeyFormatPkcs8,
1741 CryptoData(std::vector<uint8>()), 1746 CryptoData(std::vector<uint8>()),
1742 blink::WebCryptoAlgorithm::createNull(), 1747 blink::WebCryptoAlgorithm::createNull(),
1743 true, 1748 true,
1744 blink::WebCryptoKeyUsageSign, 1749 blink::WebCryptoKeyUsageSign,
1745 &key)); 1750 &key));
1746 1751
1747 // Failing case: Import RSA key with NULL input algorithm. This is not 1752 // Failing case: Import RSA key with NULL input algorithm. This is not
(...skipping 1226 matching lines...) Expand 10 before | Expand all | Expand 10 after
2974 wrapping_algorithm, 2979 wrapping_algorithm,
2975 key_algorithm, 2980 key_algorithm,
2976 true, 2981 true,
2977 blink::WebCryptoKeyUsageSign, 2982 blink::WebCryptoKeyUsageSign,
2978 &unwrapped_key)); 2983 &unwrapped_key));
2979 } 2984 }
2980 2985
2981 } // namespace webcrypto 2986 } // namespace webcrypto
2982 2987
2983 } // namespace content 2988 } // namespace content
OLDNEW
« content/child/webcrypto/platform_crypto_nss.cc ('K') | « content/child/webcrypto/shared_crypto.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698