OLD | NEW |
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_manager.h" | 5 #include "chrome/browser/chromeos/login/owner_manager.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "chrome/browser/browser_thread.h" | 12 #include "chrome/browser/browser_thread.h" |
13 #include "chrome/common/notification_service.h" | 13 #include "chrome/common/notification_service.h" |
14 #include "chrome/common/notification_type.h" | 14 #include "chrome/common/notification_type.h" |
15 | 15 |
16 namespace chromeos { | 16 namespace chromeos { |
17 | 17 |
18 OwnerManager::OwnerManager() | 18 OwnerManager::OwnerManager() |
19 : private_key_(NULL), | 19 : private_key_(NULL), |
20 public_key_(NULL), | 20 public_key_(NULL), |
21 utils_(OwnerKeyUtils::Create()) { | 21 utils_(OwnerKeyUtils::Create()) { |
22 } | 22 } |
23 | 23 |
24 OwnerManager::~OwnerManager() {} | 24 OwnerManager::~OwnerManager() {} |
25 | 25 |
26 void OwnerManager::LoadOwnerKey() { | 26 void OwnerManager::LoadOwnerKey() { |
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
28 LOG(INFO) << "Loading owner key"; | 28 VLOG(1) << "Loading owner key"; |
29 NotificationType result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED; | 29 NotificationType result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED; |
30 | 30 |
31 // If |public_key_| isn't empty, we already have the key, so don't | 31 // If |public_key_| isn't empty, we already have the key, so don't |
32 // try to import again. | 32 // try to import again. |
33 if (public_key_.empty() && | 33 if (public_key_.empty() && |
34 !utils_->ImportPublicKey(utils_->GetOwnerKeyFilePath(), &public_key_)) { | 34 !utils_->ImportPublicKey(utils_->GetOwnerKeyFilePath(), &public_key_)) { |
35 result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED; | 35 result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED; |
36 } | 36 } |
37 | 37 |
38 // Whether we loaded the public key or not, send a notification indicating | 38 // Whether we loaded the public key or not, send a notification indicating |
39 // that we're done with this attempt. | 39 // that we're done with this attempt. |
40 BrowserThread::PostTask( | 40 BrowserThread::PostTask( |
41 BrowserThread::UI, FROM_HERE, | 41 BrowserThread::UI, FROM_HERE, |
42 NewRunnableMethod(this, | 42 NewRunnableMethod(this, |
43 &OwnerManager::SendNotification, | 43 &OwnerManager::SendNotification, |
44 result, | 44 result, |
45 NotificationService::NoDetails())); | 45 NotificationService::NoDetails())); |
46 } | 46 } |
47 | 47 |
48 void OwnerManager::GenerateKeysAndExportPublic() { | 48 void OwnerManager::GenerateKeysAndExportPublic() { |
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
50 LOG(INFO) << "Generating key pair"; | 50 VLOG(1) << "Generating key pair"; |
51 | 51 |
52 private_key_.reset(utils_->GenerateKeyPair()); | 52 private_key_.reset(utils_->GenerateKeyPair()); |
53 | 53 |
54 if (private_key_.get() && private_key_->ExportPublicKey(&public_key_)) { | 54 if (private_key_.get() && private_key_->ExportPublicKey(&public_key_)) { |
55 // If we generated the keys successfully, export them. | 55 // If we generated the keys successfully, export them. |
56 BrowserThread::PostTask( | 56 BrowserThread::PostTask( |
57 BrowserThread::UI, FROM_HERE, | 57 BrowserThread::UI, FROM_HERE, |
58 NewRunnableMethod(this, &OwnerManager::ExportKey)); | 58 NewRunnableMethod(this, &OwnerManager::ExportKey)); |
59 } else { | 59 } else { |
60 private_key_.reset(NULL); | 60 private_key_.reset(NULL); |
61 // If we didn't generate the key, send along a notification of failure. | 61 // If we didn't generate the key, send along a notification of failure. |
62 BrowserThread::PostTask( | 62 BrowserThread::PostTask( |
63 BrowserThread::UI, FROM_HERE, | 63 BrowserThread::UI, FROM_HERE, |
64 NewRunnableMethod(this, | 64 NewRunnableMethod(this, |
65 &OwnerManager::SendNotification, | 65 &OwnerManager::SendNotification, |
66 NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED, | 66 NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED, |
67 NotificationService::NoDetails())); | 67 NotificationService::NoDetails())); |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 void OwnerManager::ExportKey() { | 71 void OwnerManager::ExportKey() { |
72 LOG(INFO) << "Exporting public key"; | 72 VLOG(1) << "Exporting public key"; |
73 if (!utils_->ExportPublicKeyViaDbus(private_key_.get(), this)) { | 73 if (!utils_->ExportPublicKeyViaDbus(private_key_.get(), this)) { |
74 private_key_.reset(NULL); | 74 private_key_.reset(NULL); |
75 BrowserThread::PostTask( | 75 BrowserThread::PostTask( |
76 BrowserThread::UI, FROM_HERE, | 76 BrowserThread::UI, FROM_HERE, |
77 NewRunnableMethod(this, | 77 NewRunnableMethod(this, |
78 &OwnerManager::SendNotification, | 78 &OwnerManager::SendNotification, |
79 NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED, | 79 NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED, |
80 NotificationService::NoDetails())); | 80 NotificationService::NoDetails())); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 void OwnerManager::OnComplete(bool value) { | 84 void OwnerManager::OnComplete(bool value) { |
85 LOG(INFO) << "Export public key attempt: " << (value ? "success" : "fail"); | 85 VLOG(1) << "Export public key attempt: " << (value ? "success" : "fail"); |
86 NotificationType result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED; | 86 NotificationType result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED; |
87 if (!value) | 87 if (!value) |
88 result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED; | 88 result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED; |
89 | 89 |
90 // Whether we exported the public key or not, send a notification indicating | 90 // Whether we exported the public key or not, send a notification indicating |
91 // that we're done with this attempt. | 91 // that we're done with this attempt. |
92 BrowserThread::PostTask( | 92 BrowserThread::PostTask( |
93 BrowserThread::UI, FROM_HERE, | 93 BrowserThread::UI, FROM_HERE, |
94 NewRunnableMethod(this, | 94 NewRunnableMethod(this, |
95 &OwnerManager::SendNotification, | 95 &OwnerManager::SendNotification, |
(...skipping 27 matching lines...) Expand all Loading... |
123 // If it's not the case that we can get both keys... | 123 // If it's not the case that we can get both keys... |
124 if (!(EnsurePublicKey() && EnsurePrivateKey())) { | 124 if (!(EnsurePublicKey() && EnsurePrivateKey())) { |
125 BrowserThread::PostTask( | 125 BrowserThread::PostTask( |
126 thread_id, FROM_HERE, | 126 thread_id, FROM_HERE, |
127 NewRunnableMethod(this, | 127 NewRunnableMethod(this, |
128 &OwnerManager::CallDelegate, | 128 &OwnerManager::CallDelegate, |
129 d, KEY_UNAVAILABLE, std::vector<uint8>())); | 129 d, KEY_UNAVAILABLE, std::vector<uint8>())); |
130 return; | 130 return; |
131 } | 131 } |
132 | 132 |
133 LOG(INFO) << "Starting signing attempt"; | 133 VLOG(1) << "Starting signing attempt"; |
134 KeyOpCode return_code = SUCCESS; | 134 KeyOpCode return_code = SUCCESS; |
135 std::vector<uint8> signature; | 135 std::vector<uint8> signature; |
136 if (!utils_->Sign(data, &signature, private_key_.get())) { | 136 if (!utils_->Sign(data, &signature, private_key_.get())) { |
137 return_code = OPERATION_FAILED; | 137 return_code = OPERATION_FAILED; |
138 } | 138 } |
139 | 139 |
140 BrowserThread::PostTask( | 140 BrowserThread::PostTask( |
141 thread_id, FROM_HERE, | 141 thread_id, FROM_HERE, |
142 NewRunnableMethod(this, | 142 NewRunnableMethod(this, |
143 &OwnerManager::CallDelegate, | 143 &OwnerManager::CallDelegate, |
144 d, return_code, signature)); | 144 d, return_code, signature)); |
145 } | 145 } |
146 | 146 |
147 void OwnerManager::Verify(const BrowserThread::ID thread_id, | 147 void OwnerManager::Verify(const BrowserThread::ID thread_id, |
148 const std::string& data, | 148 const std::string& data, |
149 const std::vector<uint8>& signature, | 149 const std::vector<uint8>& signature, |
150 Delegate* d) { | 150 Delegate* d) { |
151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 151 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
152 | 152 |
153 if (!EnsurePublicKey()) { | 153 if (!EnsurePublicKey()) { |
154 BrowserThread::PostTask( | 154 BrowserThread::PostTask( |
155 thread_id, FROM_HERE, | 155 thread_id, FROM_HERE, |
156 NewRunnableMethod(this, | 156 NewRunnableMethod(this, |
157 &OwnerManager::CallDelegate, | 157 &OwnerManager::CallDelegate, |
158 d, KEY_UNAVAILABLE, std::vector<uint8>())); | 158 d, KEY_UNAVAILABLE, std::vector<uint8>())); |
159 return; | 159 return; |
160 } | 160 } |
161 | 161 |
162 LOG(INFO) << "Starting verify attempt"; | 162 VLOG(1) << "Starting verify attempt"; |
163 KeyOpCode return_code = SUCCESS; | 163 KeyOpCode return_code = SUCCESS; |
164 if (!utils_->Verify(data, signature, public_key_)) { | 164 if (!utils_->Verify(data, signature, public_key_)) { |
165 return_code = OPERATION_FAILED; | 165 return_code = OPERATION_FAILED; |
166 } | 166 } |
167 BrowserThread::PostTask( | 167 BrowserThread::PostTask( |
168 thread_id, FROM_HERE, | 168 thread_id, FROM_HERE, |
169 NewRunnableMethod(this, | 169 NewRunnableMethod(this, |
170 &OwnerManager::CallDelegate, | 170 &OwnerManager::CallDelegate, |
171 d, return_code, std::vector<uint8>())); | 171 d, return_code, std::vector<uint8>())); |
172 } | 172 } |
173 | 173 |
174 void OwnerManager::SendNotification(NotificationType type, | 174 void OwnerManager::SendNotification(NotificationType type, |
175 const NotificationDetails& details) { | 175 const NotificationDetails& details) { |
176 NotificationService::current()->Notify( | 176 NotificationService::current()->Notify( |
177 type, | 177 type, |
178 NotificationService::AllSources(), | 178 NotificationService::AllSources(), |
179 details); | 179 details); |
180 } | 180 } |
181 | 181 |
182 } // namespace chromeos | 182 } // namespace chromeos |
OLD | NEW |