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

Side by Side Diff: content/child/webcrypto/test/ecdsa_unittest.cc

Issue 751883002: Revert of Check that usage isn't empty when generateKey() is called (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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
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 "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/jwk.h" 8 #include "content/child/webcrypto/jwk.h"
9 #include "content/child/webcrypto/status.h" 9 #include "content/child/webcrypto/status.h"
10 #include "content/child/webcrypto/test/test_helpers.h" 10 #include "content/child/webcrypto/test/test_helpers.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 blink::WebCryptoNamedCurve named_curve = blink::WebCryptoNamedCurveP256; 78 blink::WebCryptoNamedCurve named_curve = blink::WebCryptoNamedCurveP256;
79 79
80 std::vector<std::vector<uint8_t>> serialized_keys; 80 std::vector<std::vector<uint8_t>> serialized_keys;
81 81
82 // Generate a small sample of keys. 82 // Generate a small sample of keys.
83 for (int j = 0; j < 4; ++j) { 83 for (int j = 0; j < 4; ++j) {
84 blink::WebCryptoKey public_key; 84 blink::WebCryptoKey public_key;
85 blink::WebCryptoKey private_key; 85 blink::WebCryptoKey private_key;
86 86
87 ASSERT_EQ(Status::Success(), 87 ASSERT_EQ(Status::Success(),
88 GenerateKeyPair(CreateEcdsaKeyGenAlgorithm(named_curve), true, 88 GenerateKeyPair(CreateEcdsaKeyGenAlgorithm(named_curve), true, 0,
89 blink::WebCryptoKeyUsageSign, &public_key, 89 &public_key, &private_key));
90 &private_key));
91 90
92 // Basic sanity checks on the generated key pair. 91 // Basic sanity checks on the generated key pair.
93 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type()); 92 EXPECT_EQ(blink::WebCryptoKeyTypePublic, public_key.type());
94 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type()); 93 EXPECT_EQ(blink::WebCryptoKeyTypePrivate, private_key.type());
95 EXPECT_EQ(named_curve, public_key.algorithm().ecParams()->namedCurve()); 94 EXPECT_EQ(named_curve, public_key.algorithm().ecParams()->namedCurve());
96 EXPECT_EQ(named_curve, private_key.algorithm().ecParams()->namedCurve()); 95 EXPECT_EQ(named_curve, private_key.algorithm().ecParams()->namedCurve());
97 96
98 // Export the key pair to JWK. 97 // Export the key pair to JWK.
99 std::vector<uint8_t> key_bytes; 98 std::vector<uint8_t> key_bytes;
100 ASSERT_EQ(Status::Success(), 99 ASSERT_EQ(Status::Success(),
101 ExportKey(blink::WebCryptoKeyFormatJwk, public_key, &key_bytes)); 100 ExportKey(blink::WebCryptoKeyFormatJwk, public_key, &key_bytes));
102 serialized_keys.push_back(key_bytes); 101 serialized_keys.push_back(key_bytes);
103 102
104 ASSERT_EQ(Status::Success(), 103 ASSERT_EQ(Status::Success(),
105 ExportKey(blink::WebCryptoKeyFormatJwk, private_key, &key_bytes)); 104 ExportKey(blink::WebCryptoKeyFormatJwk, private_key, &key_bytes));
106 serialized_keys.push_back(key_bytes); 105 serialized_keys.push_back(key_bytes);
107 } 106 }
108 107
109 // Ensure all entries in the key sample set are unique. This is a simplistic 108 // Ensure all entries in the key sample set are unique. This is a simplistic
110 // estimate of whether the generated keys appear random. 109 // estimate of whether the generated keys appear random.
111 EXPECT_FALSE(CopiesExist(serialized_keys)); 110 EXPECT_FALSE(CopiesExist(serialized_keys));
112 } 111 }
113 112
114 TEST(WebCryptoEcdsaTest, GenerateKeyEmptyUsage) {
115 if (!SupportsEcdsa())
116 return;
117
118 blink::WebCryptoNamedCurve named_curve = blink::WebCryptoNamedCurveP256;
119 blink::WebCryptoKey public_key;
120 blink::WebCryptoKey private_key;
121 ASSERT_EQ(Status::ErrorCreateKeyEmptyUsages(),
122 GenerateKeyPair(CreateEcdsaKeyGenAlgorithm(named_curve), true, 0,
123 &public_key, &private_key));
124 }
125
126 // Verify that ECDSA signatures are probabilistic. Signing the same message two 113 // Verify that ECDSA signatures are probabilistic. Signing the same message two
127 // times should yield different signatures. However both signatures should 114 // times should yield different signatures. However both signatures should
128 // verify correctly. 115 // verify correctly.
129 TEST(WebCryptoEcdsaTest, SignatureIsRandom) { 116 TEST(WebCryptoEcdsaTest, SignatureIsRandom) {
130 if (!SupportsEcdsa()) 117 if (!SupportsEcdsa())
131 return; 118 return;
132 119
133 // Import a public and private keypair from "ec_private_keys.json". It doesn't 120 // Import a public and private keypair from "ec_private_keys.json". It doesn't
134 // really matter which one is used since they are all valid. In this case 121 // really matter which one is used since they are all valid. In this case
135 // using the first one. 122 // using the first one.
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 ExportKey(blink::WebCryptoKeyFormatJwk, key, &exported_bytes)); 313 ExportKey(blink::WebCryptoKeyFormatJwk, key, &exported_bytes));
327 EXPECT_EQ(CryptoData(jwk_bytes), CryptoData(exported_bytes)); 314 EXPECT_EQ(CryptoData(jwk_bytes), CryptoData(exported_bytes));
328 } 315 }
329 } 316 }
330 317
331 } // namespace 318 } // namespace
332 319
333 } // namespace webcrypto 320 } // namespace webcrypto
334 321
335 } // namespace content 322 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/test/aes_kw_unittest.cc ('k') | content/child/webcrypto/test/hmac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698