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

Side by Side Diff: base/crypto/rsa_private_key_unittest.cc

Issue 1271002: Annotated the scoped leak inside base::RSAPrivateKey::CreateFromPrivateKeyInf... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 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 (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/crypto/rsa_private_key.h" 5 #include "base/crypto/rsa_private_key.h"
6 #include "base/leak_annotations.h"
7 #include "base/scoped_ptr.h" 6 #include "base/scoped_ptr.h"
8 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
9 8
10 // Generate random private keys with two different sizes. Reimport, then 9 // Generate random private keys with two different sizes. Reimport, then
11 // export them again. We should get back the same exact bytes. 10 // export them again. We should get back the same exact bytes.
12 TEST(RSAPrivateKeyUnitTest, InitRandomTest) { 11 TEST(RSAPrivateKeyUnitTest, InitRandomTest) {
13 // This test currently leaks some memory,
14 // see http://crbug.com/34742
15 ANNOTATE_SCOPED_MEMORY_LEAK;
16
17 scoped_ptr<base::RSAPrivateKey> keypair1(base::RSAPrivateKey::Create(1024)); 12 scoped_ptr<base::RSAPrivateKey> keypair1(base::RSAPrivateKey::Create(1024));
18 scoped_ptr<base::RSAPrivateKey> keypair2(base::RSAPrivateKey::Create(2048)); 13 scoped_ptr<base::RSAPrivateKey> keypair2(base::RSAPrivateKey::Create(2048));
19 ASSERT_TRUE(keypair1.get()); 14 ASSERT_TRUE(keypair1.get());
20 ASSERT_TRUE(keypair2.get()); 15 ASSERT_TRUE(keypair2.get());
21 16
22 std::vector<uint8> privkey1; 17 std::vector<uint8> privkey1;
23 std::vector<uint8> privkey2; 18 std::vector<uint8> privkey2;
24 std::vector<uint8> pubkey1; 19 std::vector<uint8> pubkey1;
25 std::vector<uint8> pubkey2; 20 std::vector<uint8> pubkey2;
26 21
(...skipping 19 matching lines...) Expand all
46 ASSERT_TRUE(0 == memcmp(&privkey1.front(), &privkey3.front(), 41 ASSERT_TRUE(0 == memcmp(&privkey1.front(), &privkey3.front(),
47 privkey1.size())); 42 privkey1.size()));
48 ASSERT_TRUE(0 == memcmp(&privkey2.front(), &privkey4.front(), 43 ASSERT_TRUE(0 == memcmp(&privkey2.front(), &privkey4.front(),
49 privkey2.size())); 44 privkey2.size()));
50 } 45 }
51 46
52 47
53 // Verify that generated public keys look good. This test data was generated 48 // Verify that generated public keys look good. This test data was generated
54 // with the openssl command line tool. 49 // with the openssl command line tool.
55 TEST(RSAPrivateKeyUnitTest, PublicKeyTest) { 50 TEST(RSAPrivateKeyUnitTest, PublicKeyTest) {
56 // This test currently leaks some memory,
57 // see http://crbug.com/34742
58 ANNOTATE_SCOPED_MEMORY_LEAK;
59
60 const uint8 private_key_info[] = { 51 const uint8 private_key_info[] = {
61 0x30, 0x82, 0x02, 0x78, 0x02, 0x01, 0x00, 0x30, 52 0x30, 0x82, 0x02, 0x78, 0x02, 0x01, 0x00, 0x30,
62 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 53 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
63 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, 54 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
64 0x02, 0x62, 0x30, 0x82, 0x02, 0x5e, 0x02, 0x01, 55 0x02, 0x62, 0x30, 0x82, 0x02, 0x5e, 0x02, 0x01,
65 0x00, 0x02, 0x81, 0x81, 0x00, 0xb8, 0x7f, 0x2b, 56 0x00, 0x02, 0x81, 0x81, 0x00, 0xb8, 0x7f, 0x2b,
66 0x20, 0xdc, 0x7c, 0x9b, 0x0c, 0xdc, 0x51, 0x61, 57 0x20, 0xdc, 0x7c, 0x9b, 0x0c, 0xdc, 0x51, 0x61,
67 0x99, 0x0d, 0x36, 0x0f, 0xd4, 0x66, 0x88, 0x08, 58 0x99, 0x0d, 0x36, 0x0f, 0xd4, 0x66, 0x88, 0x08,
68 0x55, 0x84, 0xd5, 0x3a, 0xbf, 0x2b, 0xa4, 0x64, 59 0x55, 0x84, 0xd5, 0x3a, 0xbf, 0x2b, 0xa4, 0x64,
69 0x85, 0x7b, 0x0c, 0x04, 0x13, 0x3f, 0x8d, 0xf4, 60 0x85, 0x7b, 0x0c, 0x04, 0x13, 0x3f, 0x8d, 0xf4,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // See also: http://code.google.com/p/chromium/issues/detail?id=14877. 178 // See also: http://code.google.com/p/chromium/issues/detail?id=14877.
188 // 179 //
189 // Before we were handling this correctly, we would see one of two failures: 180 // Before we were handling this correctly, we would see one of two failures:
190 // * RSAPrivateKey::CreateFromPrivateKeyInfo would return null because the 181 // * RSAPrivateKey::CreateFromPrivateKeyInfo would return null because the
191 // underlying windows API failed to import the key. 182 // underlying windows API failed to import the key.
192 // * The import would succeed, but incorrectly interpret the data. On export, 183 // * The import would succeed, but incorrectly interpret the data. On export,
193 // the key would contain different values. 184 // the key would contain different values.
194 // 185 //
195 // This test case verifies these two failures modes don't occur. 186 // This test case verifies these two failures modes don't occur.
196 TEST(RSAPrivateKeyUnitTest, ShortIntegers) { 187 TEST(RSAPrivateKeyUnitTest, ShortIntegers) {
197 // This test currently leaks some memory,
198 // see http://crbug.com/34742
199 ANNOTATE_SCOPED_MEMORY_LEAK;
200
201 const uint8 short_integer_with_high_bit[] = { 188 const uint8 short_integer_with_high_bit[] = {
202 0x30, 0x82, 0x02, 0x77, 0x02, 0x01, 0x00, 0x30, 189 0x30, 0x82, 0x02, 0x77, 0x02, 0x01, 0x00, 0x30,
203 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 190 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
204 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, 191 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
205 0x02, 0x61, 0x30, 0x82, 0x02, 0x5d, 0x02, 0x01, 192 0x02, 0x61, 0x30, 0x82, 0x02, 0x5d, 0x02, 0x01,
206 0x00, 0x02, 0x81, 0x81, 0x00, 0x92, 0x59, 0x32, 193 0x00, 0x02, 0x81, 0x81, 0x00, 0x92, 0x59, 0x32,
207 0x7d, 0x8e, 0xaf, 0x2e, 0xd5, 0xb2, 0x5c, 0x67, 194 0x7d, 0x8e, 0xaf, 0x2e, 0xd5, 0xb2, 0x5c, 0x67,
208 0xc8, 0x7d, 0x48, 0xb7, 0x84, 0x12, 0xd0, 0x76, 195 0xc8, 0x7d, 0x48, 0xb7, 0x84, 0x12, 0xd0, 0x76,
209 0xda, 0xe1, 0xa3, 0x1e, 0x40, 0x01, 0x14, 0x5c, 196 0xda, 0xe1, 0xa3, 0x1e, 0x40, 0x01, 0x14, 0x5c,
210 0xef, 0x26, 0x6e, 0x28, 0xa2, 0xf7, 0xa5, 0xb4, 197 0xef, 0x26, 0x6e, 0x28, 0xa2, 0xf7, 0xa5, 0xb4,
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 ASSERT_TRUE(keypair1->ExportPrivateKey(&output1)); 374 ASSERT_TRUE(keypair1->ExportPrivateKey(&output1));
388 ASSERT_TRUE(keypair2->ExportPrivateKey(&output2)); 375 ASSERT_TRUE(keypair2->ExportPrivateKey(&output2));
389 376
390 ASSERT_EQ(input1.size(), output1.size()); 377 ASSERT_EQ(input1.size(), output1.size());
391 ASSERT_EQ(input2.size(), output2.size()); 378 ASSERT_EQ(input2.size(), output2.size());
392 ASSERT_TRUE(0 == memcmp(&output1.front(), &input1.front(), 379 ASSERT_TRUE(0 == memcmp(&output1.front(), &input1.front(),
393 input1.size())); 380 input1.size()));
394 ASSERT_TRUE(0 == memcmp(&output2.front(), &input2.front(), 381 ASSERT_TRUE(0 == memcmp(&output2.front(), &input2.front(),
395 input2.size())); 382 input2.size()));
396 } 383 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698