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

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

Issue 3141031: [Chrome OS] Wire up ownership API from libcros (Closed)
Patch Set: address davemoore comments Created 10 years, 3 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
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 <cert.h>
8 #include <keyhi.h>
9 #include <keythi.h> // KeyType enum
10 #include <pk11pub.h>
11 #include <stdlib.h>
12
13 #include <string> 7 #include <string>
14 #include <vector> 8 #include <vector>
15 9
16 #include "base/crypto/rsa_private_key.h" 10 #include "base/crypto/rsa_private_key.h"
17 #include "base/file_path.h" 11 #include "base/file_path.h"
18 #include "base/file_util.h" 12 #include "base/file_util.h"
19 #include "base/logging.h" 13 #include "base/logging.h"
20 #include "base/nss_util_internal.h" 14 #include "base/nss_util_internal.h"
21 #include "base/nss_util.h" 15 #include "base/nss_util.h"
22 #include "base/scoped_ptr.h" 16 #include "base/ref_counted.h"
23 #include "base/scoped_temp_dir.h" 17 #include "base/scoped_temp_dir.h"
24 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
25 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
26 20
27 namespace chromeos { 21 namespace chromeos {
28 22
29 class OwnerKeyUtilsTest : public ::testing::Test { 23 class OwnerKeyUtilsTest : public ::testing::Test {
30 public: 24 public:
31 OwnerKeyUtilsTest() : utils_(OwnerKeyUtils::Create()) { 25 OwnerKeyUtilsTest() : utils_(OwnerKeyUtils::Create()) {
32 26
33 } 27 }
34 virtual ~OwnerKeyUtilsTest() {} 28 virtual ~OwnerKeyUtilsTest() {}
35 29
36 virtual void SetUp() { 30 virtual void SetUp() {
37 base::OpenPersistentNSSDB(); 31 base::OpenPersistentNSSDB();
38 } 32 }
39 33
40 scoped_ptr<OwnerKeyUtils> utils_; 34 scoped_refptr<OwnerKeyUtils> utils_;
41 }; 35 };
42 36
43 TEST_F(OwnerKeyUtilsTest, ExportImportPublicKey) { 37 TEST_F(OwnerKeyUtilsTest, ExportImportPublicKey) {
44 scoped_ptr<base::RSAPrivateKey> pair(utils_->GenerateKeyPair()); 38 scoped_ptr<base::RSAPrivateKey> pair(utils_->GenerateKeyPair());
45 ASSERT_NE(pair.get(), reinterpret_cast<base::RSAPrivateKey*>(NULL)); 39 ASSERT_NE(pair.get(), reinterpret_cast<base::RSAPrivateKey*>(NULL));
46 40
47 // Export public key to file. 41 // Export public key to file.
48 ScopedTempDir tmpdir; 42 ScopedTempDir tmpdir;
49 FilePath tmpfile; 43 FilePath tmpfile;
50 ASSERT_TRUE(tmpdir.CreateUniqueTempDir()); 44 ASSERT_TRUE(tmpdir.CreateUniqueTempDir());
51 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(tmpdir.path(), &tmpfile)); 45 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(tmpdir.path(), &tmpfile));
52 ASSERT_TRUE(utils_->ExportPublicKeyToFile(pair.get(), tmpfile)); 46 ASSERT_TRUE(utils_->ExportPublicKeyToFile(pair.get(), tmpfile));
53 47
54 // Export public key, so that we can compare it to the one we get off disk. 48 // Export public key, so that we can compare it to the one we get off disk.
55 std::vector<uint8> public_key; 49 std::vector<uint8> public_key;
56 ASSERT_TRUE(pair->ExportPublicKey(&public_key)); 50 ASSERT_TRUE(pair->ExportPublicKey(&public_key));
57 std::vector<uint8> from_disk; 51 std::vector<uint8> from_disk;
58 ASSERT_TRUE(utils_->ImportPublicKey(tmpfile, &from_disk)); 52 ASSERT_TRUE(utils_->ImportPublicKey(tmpfile, &from_disk));
59 53
60 std::vector<uint8>::iterator pubkey_it; 54 std::vector<uint8>::iterator pubkey_it;
61 std::vector<uint8>::iterator disk_it; 55 std::vector<uint8>::iterator disk_it;
62 for (pubkey_it = public_key.begin(), disk_it = from_disk.begin(); 56 for (pubkey_it = public_key.begin(), disk_it = from_disk.begin();
63 pubkey_it < public_key.end(); 57 pubkey_it < public_key.end();
64 pubkey_it++, disk_it++) { 58 pubkey_it++, disk_it++) {
65 EXPECT_EQ(*pubkey_it, *disk_it); 59 EXPECT_EQ(*pubkey_it, *disk_it);
66 } 60 }
67 } 61 }
68 62
69 } // namespace chromeos 63 } // 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