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

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

Issue 3078001: Update OwnerKeyUtils API (Closed)
Patch Set: address comments Created 10 years, 4 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
« no previous file with comments | « chrome/browser/chromeos/login/owner_key_utils.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 (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> 7 #include <cert.h>
8 #include <keyhi.h> 8 #include <keyhi.h>
9 #include <keythi.h> // KeyType enum 9 #include <keythi.h> // KeyType enum
10 #include <pk11pub.h> 10 #include <pk11pub.h>
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 62 }
63 63
64 TEST_F(OwnerKeyUtilsTest, ExportImportPublicKey) { 64 TEST_F(OwnerKeyUtilsTest, ExportImportPublicKey) {
65 EXPECT_TRUE(utils_->GenerateKeyPair(&private_key_, &public_key_)); 65 EXPECT_TRUE(utils_->GenerateKeyPair(&private_key_, &public_key_));
66 66
67 ScopedTempDir tmpdir; 67 ScopedTempDir tmpdir;
68 FilePath tmpfile; 68 FilePath tmpfile;
69 ASSERT_TRUE(tmpdir.CreateUniqueTempDir()); 69 ASSERT_TRUE(tmpdir.CreateUniqueTempDir());
70 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(tmpdir.path(), &tmpfile)); 70 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(tmpdir.path(), &tmpfile));
71 71
72 EXPECT_TRUE(utils_->ExportPublicKey(public_key_, tmpfile)); 72 EXPECT_TRUE(utils_->ExportPublicKeyToFile(public_key_, tmpfile));
73 73
74 // Now, verify that we can look up the private key, given the public key 74 // Now, verify that we can look up the private key, given the public
75 // we exported. We'll create 75 // key we exported. Then we'll make sure it's the same as |private_key_|
76 // an ID from the key, and then use that ID to query the token in the
77 // default slot for a matching private key. Then we'll make sure it's
78 // the same as |private_key_|
79 PK11SlotInfo* slot = NULL;
80 SECItem* ck_id = NULL;
81 SECKEYPublicKey* from_disk = NULL; 76 SECKEYPublicKey* from_disk = NULL;
82 SECKEYPrivateKey* found = NULL; 77 SECKEYPrivateKey* found = NULL;
83 78
84 slot = base::GetDefaultNSSKeySlot();
85 EXPECT_TRUE(slot != NULL);
86 if (NULL == slot)
87 goto cleanup;
88
89 from_disk = utils_->ImportPublicKey(tmpfile); 79 from_disk = utils_->ImportPublicKey(tmpfile);
90 ASSERT_TRUE(from_disk != NULL); 80 ASSERT_TRUE(from_disk != NULL);
91 81
92 ck_id = PK11_MakeIDFromPubKey(&(from_disk->u.rsa.modulus)); 82 found = utils_->FindPrivateKey(from_disk);
93 EXPECT_TRUE(ck_id != NULL);
94 if (NULL == ck_id)
95 goto cleanup;
96
97 found = PK11_FindKeyByKeyID(slot, ck_id, NULL);
98 EXPECT_TRUE(found != NULL); 83 EXPECT_TRUE(found != NULL);
99 if (NULL == found) 84 if (NULL == found)
100 goto cleanup; 85 goto cleanup;
101 86
102 EXPECT_EQ(private_key_->pkcs11ID, found->pkcs11ID); 87 EXPECT_EQ(private_key_->pkcs11ID, found->pkcs11ID);
103 88
104 cleanup: 89 cleanup:
105 if (slot)
106 PK11_FreeSlot(slot);
107 if (from_disk) 90 if (from_disk)
108 SECKEY_DestroyPublicKey(from_disk); 91 SECKEY_DestroyPublicKey(from_disk);
109 if (found) 92 if (found)
110 SECKEY_DestroyPrivateKey(found); 93 SECKEY_DestroyPrivateKey(found);
111 if (ck_id)
112 SECITEM_ZfreeItem(ck_id, PR_TRUE);
113 } 94 }
114 95
115 } // namespace chromeos 96 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/owner_key_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698