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

Side by Side Diff: chrome/browser/chromeos/login/owner_key_utils_unittest.cc

Issue 6538098: [Chrome OS] Owner keys are generated outside Chrome now; handle appropriately (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/login/owner_key_utils.h" 5 #include "chrome/browser/chromeos/login/owner_key_utils.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/crypto/rsa_private_key.h" 10 #include "base/crypto/rsa_private_key.h"
(...skipping 10 matching lines...) Expand all
21 21
22 class OwnerKeyUtilsTest : public ::testing::Test { 22 class OwnerKeyUtilsTest : public ::testing::Test {
23 public: 23 public:
24 OwnerKeyUtilsTest() : utils_(OwnerKeyUtils::Create()) {} 24 OwnerKeyUtilsTest() : utils_(OwnerKeyUtils::Create()) {}
25 virtual ~OwnerKeyUtilsTest() {} 25 virtual ~OwnerKeyUtilsTest() {}
26 26
27 virtual void SetUp() { 27 virtual void SetUp() {
28 base::OpenPersistentNSSDB(); 28 base::OpenPersistentNSSDB();
29 } 29 }
30 30
31 // Key generation parameters.
32 static const uint16 kKeySizeInBits;
33
31 scoped_refptr<OwnerKeyUtils> utils_; 34 scoped_refptr<OwnerKeyUtils> utils_;
32 }; 35 };
33 36
37 // We're generating and using 2048-bit RSA keys.
38 // static
39 const uint16 OwnerKeyUtilsTest::kKeySizeInBits = 2048;
40
34 TEST_F(OwnerKeyUtilsTest, ExportImportPublicKey) { 41 TEST_F(OwnerKeyUtilsTest, ExportImportPublicKey) {
35 scoped_ptr<base::RSAPrivateKey> pair(utils_->GenerateKeyPair()); 42 scoped_ptr<base::RSAPrivateKey> pair(
43 base::RSAPrivateKey::CreateSensitive(kKeySizeInBits));
36 ASSERT_NE(pair.get(), reinterpret_cast<base::RSAPrivateKey*>(NULL)); 44 ASSERT_NE(pair.get(), reinterpret_cast<base::RSAPrivateKey*>(NULL));
37 45
38 // Export public key to file. 46 // Export public key to file.
39 ScopedTempDir tmpdir; 47 ScopedTempDir tmpdir;
40 FilePath tmpfile; 48 FilePath tmpfile;
41 ASSERT_TRUE(tmpdir.CreateUniqueTempDir()); 49 ASSERT_TRUE(tmpdir.CreateUniqueTempDir());
42 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(tmpdir.path(), &tmpfile)); 50 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(tmpdir.path(), &tmpfile));
43 ASSERT_TRUE(utils_->ExportPublicKeyToFile(pair.get(), tmpfile)); 51 ASSERT_TRUE(utils_->ExportPublicKeyToFile(pair.get(), tmpfile));
44 52
45 // Export public key, so that we can compare it to the one we get off disk. 53 // Export public key, so that we can compare it to the one we get off disk.
46 std::vector<uint8> public_key; 54 std::vector<uint8> public_key;
47 ASSERT_TRUE(pair->ExportPublicKey(&public_key)); 55 ASSERT_TRUE(pair->ExportPublicKey(&public_key));
48 std::vector<uint8> from_disk; 56 std::vector<uint8> from_disk;
49 ASSERT_TRUE(utils_->ImportPublicKey(tmpfile, &from_disk)); 57 ASSERT_TRUE(utils_->ImportPublicKey(tmpfile, &from_disk));
50 58
51 std::vector<uint8>::iterator pubkey_it; 59 std::vector<uint8>::iterator pubkey_it;
52 std::vector<uint8>::iterator disk_it; 60 std::vector<uint8>::iterator disk_it;
53 for (pubkey_it = public_key.begin(), disk_it = from_disk.begin(); 61 for (pubkey_it = public_key.begin(), disk_it = from_disk.begin();
54 pubkey_it < public_key.end(); 62 pubkey_it < public_key.end();
55 pubkey_it++, disk_it++) { 63 pubkey_it++, disk_it++) {
56 EXPECT_EQ(*pubkey_it, *disk_it); 64 EXPECT_EQ(*pubkey_it, *disk_it);
57 } 65 }
58 } 66 }
59 67
60 } // namespace chromeos 68 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/owner_key_utils.cc ('k') | chrome/browser/chromeos/login/owner_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698