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

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

Issue 213423007: [webcrypto] Fix a bug where generated RSA private keys couldn't be exported. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comment to match wtc's suggestion 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
« no previous file with comments | « content/child/webcrypto/platform_crypto_nss.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1877 matching lines...) Expand 10 before | Expand all | Expand 10 after
1888 TEST_F(SharedCryptoTest, MAYBE(GenerateKeyPairRsa)) { 1888 TEST_F(SharedCryptoTest, MAYBE(GenerateKeyPairRsa)) {
1889 // Note: using unrealistic short key lengths here to avoid bogging down tests. 1889 // Note: using unrealistic short key lengths here to avoid bogging down tests.
1890 1890
1891 // Successful WebCryptoAlgorithmIdRsaEsPkcs1v1_5 key generation. 1891 // Successful WebCryptoAlgorithmIdRsaEsPkcs1v1_5 key generation.
1892 const unsigned int modulus_length = 256; 1892 const unsigned int modulus_length = 256;
1893 const std::vector<uint8> public_exponent = HexStringToBytes("010001"); 1893 const std::vector<uint8> public_exponent = HexStringToBytes("010001");
1894 blink::WebCryptoAlgorithm algorithm = 1894 blink::WebCryptoAlgorithm algorithm =
1895 CreateRsaKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, 1895 CreateRsaKeyGenAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5,
1896 modulus_length, 1896 modulus_length,
1897 public_exponent); 1897 public_exponent);
1898 bool extractable = false; 1898 bool extractable = true;
1899 const blink::WebCryptoKeyUsageMask usage_mask = 0; 1899 const blink::WebCryptoKeyUsageMask usage_mask = 0;
1900 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); 1900 blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull();
1901 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); 1901 blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull();
1902 ASSERT_STATUS_SUCCESS(GenerateKeyPair( 1902 ASSERT_STATUS_SUCCESS(GenerateKeyPair(
1903 algorithm, extractable, usage_mask, &public_key, &private_key)); 1903 algorithm, extractable, usage_mask, &public_key, &private_key));
1904 EXPECT_FALSE(public_key.isNull()); 1904 EXPECT_FALSE(public_key.isNull());
1905 EXPECT_FALSE(private_key.isNull()); 1905 EXPECT_FALSE(private_key.isNull());
1906 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); 1906 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type());
1907 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); 1907 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type());
1908 EXPECT_TRUE(public_key.extractable()); 1908 EXPECT_TRUE(public_key.extractable());
1909 EXPECT_EQ(extractable, private_key.extractable()); 1909 EXPECT_EQ(extractable, private_key.extractable());
1910 EXPECT_EQ(usage_mask, public_key.usages()); 1910 EXPECT_EQ(usage_mask, public_key.usages());
1911 EXPECT_EQ(usage_mask, private_key.usages()); 1911 EXPECT_EQ(usage_mask, private_key.usages());
1912 1912
1913 // Try exporting the generated key pair, and then re-importing to verify that
1914 // the exported data was valid.
1915 blink::WebArrayBuffer public_key_spki;
1916 EXPECT_STATUS_SUCCESS(
1917 ExportKey(blink::WebCryptoKeyFormatSpki, public_key, &public_key_spki));
1918 public_key = blink::WebCryptoKey::createNull();
1919 EXPECT_STATUS_SUCCESS(
1920 ImportKey(blink::WebCryptoKeyFormatSpki,
1921 CryptoData(public_key_spki),
1922 CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5),
1923 true,
1924 usage_mask,
1925 &public_key));
1926 EXPECT_EQ(modulus_length,
1927 public_key.algorithm().rsaParams()->modulusLengthBits());
1928
1929 blink::WebArrayBuffer private_key_pkcs8;
1930 EXPECT_STATUS_SUCCESS(ExportKey(
1931 blink::WebCryptoKeyFormatPkcs8, private_key, &private_key_pkcs8));
1932 private_key = blink::WebCryptoKey::createNull();
1933 EXPECT_STATUS_SUCCESS(
1934 ImportKey(blink::WebCryptoKeyFormatPkcs8,
1935 CryptoData(private_key_pkcs8),
1936 CreateAlgorithm(blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5),
1937 true,
1938 usage_mask,
1939 &private_key));
1940 EXPECT_EQ(modulus_length,
1941 private_key.algorithm().rsaParams()->modulusLengthBits());
1942
1913 // Fail with bad modulus. 1943 // Fail with bad modulus.
1914 algorithm = CreateRsaKeyGenAlgorithm( 1944 algorithm = CreateRsaKeyGenAlgorithm(
1915 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, 0, public_exponent); 1945 blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5, 0, public_exponent);
1916 EXPECT_STATUS( 1946 EXPECT_STATUS(
1917 Status::ErrorGenerateRsaZeroModulus(), 1947 Status::ErrorGenerateRsaZeroModulus(),
1918 GenerateKeyPair( 1948 GenerateKeyPair(
1919 algorithm, extractable, usage_mask, &public_key, &private_key)); 1949 algorithm, extractable, usage_mask, &public_key, &private_key));
1920 1950
1921 // Fail with bad exponent: larger than unsigned long. 1951 // Fail with bad exponent: larger than unsigned long.
1922 unsigned int exponent_length = sizeof(unsigned long) + 1; // NOLINT 1952 unsigned int exponent_length = sizeof(unsigned long) + 1; // NOLINT
(...skipping 1269 matching lines...) Expand 10 before | Expand all | Expand 10 after
3192 algorithm, 3222 algorithm,
3193 CreateAesCbcAlgorithm(std::vector<uint8>(0, 16)), 3223 CreateAesCbcAlgorithm(std::vector<uint8>(0, 16)),
3194 true, 3224 true,
3195 blink::WebCryptoKeyUsageEncrypt, 3225 blink::WebCryptoKeyUsageEncrypt,
3196 &unwrapped_key)); 3226 &unwrapped_key));
3197 } 3227 }
3198 3228
3199 } // namespace webcrypto 3229 } // namespace webcrypto
3200 3230
3201 } // namespace content 3231 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/platform_crypto_nss.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698