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 "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "chrome/browser/chrome_thread.h" | 9 #include "chrome/browser/chrome_thread.h" |
10 #include "chrome/common/notification_service.h" | 10 #include "chrome/common/notification_service.h" |
11 #include "chrome/common/notification_type.h" | 11 #include "chrome/common/notification_type.h" |
12 | 12 |
13 namespace chromeos { | 13 namespace chromeos { |
14 | 14 |
15 OwnerManager::OwnerManager() | 15 OwnerManager::OwnerManager() |
16 : private_key_(NULL), | 16 : private_key_(NULL), |
17 public_key_(NULL), | 17 public_key_(NULL), |
18 utils_(OwnerKeyUtils::Create()) { | 18 utils_(OwnerKeyUtils::Create()) { |
19 } | 19 } |
20 | 20 |
21 OwnerManager::~OwnerManager() {} | 21 OwnerManager::~OwnerManager() {} |
22 | 22 |
23 bool OwnerManager::IsAlreadyOwned() { | |
24 return file_util::PathExists(utils_->GetOwnerKeyFilePath()); | |
25 } | |
26 | |
27 bool OwnerManager::StartLoadOwnerKeyAttempt() { | |
28 if (!IsAlreadyOwned()) { | |
29 LOG(ERROR) << "Device not yet owned"; | |
30 return false; | |
31 } | |
32 ChromeThread::PostTask( | |
33 ChromeThread::FILE, FROM_HERE, | |
34 NewRunnableMethod(this, &OwnerManager::LoadOwnerKey)); | |
35 return true; | |
36 } | |
37 | |
38 bool OwnerManager::StartTakeOwnershipAttempt() { | |
39 if (IsAlreadyOwned()) { | |
40 LOG(ERROR) << "Device is already owned"; | |
41 return false; | |
42 } | |
43 ChromeThread::PostTask( | |
44 ChromeThread::FILE, FROM_HERE, | |
45 NewRunnableMethod(this, &OwnerManager::GenerateKeysAndExportPublic)); | |
46 return true; | |
47 } | |
48 | |
49 bool OwnerManager::StartSigningAttempt(const std::string& data, Delegate* d) { | |
50 if (!IsAlreadyOwned()) { | |
51 LOG(ERROR) << "Device not yet owned"; | |
52 return false; | |
53 } | |
54 ChromeThread::ID thread_id; | |
55 if (!ChromeThread::GetCurrentThreadIdentifier(&thread_id)) | |
56 thread_id = ChromeThread::UI; | |
57 ChromeThread::PostTask( | |
58 ChromeThread::FILE, FROM_HERE, | |
59 NewRunnableMethod(this, &OwnerManager::Sign, thread_id, data, d)); | |
60 return true; | |
61 } | |
62 | |
63 bool OwnerManager::StartVerifyAttempt(const std::string& data, | |
64 const std::string& signature, | |
65 Delegate* d) { | |
66 if (!IsAlreadyOwned()) { | |
67 LOG(ERROR) << "Device not yet owned"; | |
68 return false; | |
69 } | |
70 ChromeThread::ID thread_id; | |
71 if (!ChromeThread::GetCurrentThreadIdentifier(&thread_id)) | |
72 thread_id = ChromeThread::UI; | |
73 ChromeThread::PostTask( | |
74 ChromeThread::FILE, FROM_HERE, | |
75 NewRunnableMethod(this, | |
76 &OwnerManager::Verify, | |
77 thread_id, | |
78 data, | |
79 signature, | |
80 d)); | |
81 return true; | |
82 } | |
83 | |
84 void OwnerManager::LoadOwnerKey() { | 23 void OwnerManager::LoadOwnerKey() { |
85 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); | 24 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::FILE)); |
86 NotificationType result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED; | 25 NotificationType result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED; |
87 if (utils_->ImportPublicKey(utils_->GetOwnerKeyFilePath(), &public_key_)) | 26 if (utils_->ImportPublicKey(utils_->GetOwnerKeyFilePath(), &public_key_)) |
88 result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED; | 27 result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED; |
89 | 28 |
90 // Whether we loaded the public key or not, send a notification indicating | 29 // Whether we loaded the public key or not, send a notification indicating |
91 // that we're done with this attempt. | 30 // that we're done with this attempt. |
92 ChromeThread::PostTask( | 31 ChromeThread::PostTask( |
93 ChromeThread::UI, FROM_HERE, | 32 ChromeThread::UI, FROM_HERE, |
(...skipping 19 matching lines...) Expand all Loading... |
113 ChromeThread::PostTask( | 52 ChromeThread::PostTask( |
114 ChromeThread::UI, FROM_HERE, | 53 ChromeThread::UI, FROM_HERE, |
115 NewRunnableMethod(this, | 54 NewRunnableMethod(this, |
116 &OwnerManager::SendNotification, | 55 &OwnerManager::SendNotification, |
117 result, | 56 result, |
118 NotificationService::NoDetails())); | 57 NotificationService::NoDetails())); |
119 } | 58 } |
120 } | 59 } |
121 | 60 |
122 void OwnerManager::ExportKey() { | 61 void OwnerManager::ExportKey() { |
| 62 if (!utils_->ExportPublicKeyViaDbus(private_key_.get(), this)) { |
| 63 private_key_.reset(NULL); |
| 64 ChromeThread::PostTask( |
| 65 ChromeThread::UI, FROM_HERE, |
| 66 NewRunnableMethod(this, |
| 67 &OwnerManager::SendNotification, |
| 68 NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED, |
| 69 NotificationService::NoDetails())); |
| 70 } |
| 71 } |
| 72 |
| 73 void OwnerManager::Run(bool value) { |
123 NotificationType result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED; | 74 NotificationType result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_SUCCEEDED; |
124 if (!utils_->ExportPublicKeyViaDbus(private_key_.get())) { | 75 if (!value) |
125 private_key_.reset(NULL); | |
126 result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED; | 76 result = NotificationType::OWNER_KEY_FETCH_ATTEMPT_FAILED; |
127 } | |
128 | 77 |
129 // Whether we generated the keys or not, send a notification indicating | 78 // Whether we exported the public key or not, send a notification indicating |
130 // that we're done with this attempt. | 79 // that we're done with this attempt. |
131 ChromeThread::PostTask( | 80 ChromeThread::PostTask( |
132 ChromeThread::UI, FROM_HERE, | 81 ChromeThread::UI, FROM_HERE, |
133 NewRunnableMethod(this, | 82 NewRunnableMethod(this, |
134 &OwnerManager::SendNotification, | 83 &OwnerManager::SendNotification, |
135 result, | 84 result, |
136 NotificationService::NoDetails())); | 85 NotificationService::NoDetails())); |
| 86 |
137 } | 87 } |
138 | 88 |
139 bool OwnerManager::EnsurePublicKey() { | 89 bool OwnerManager::EnsurePublicKey() { |
140 if (public_key_.empty()) | 90 if (public_key_.empty()) |
141 LoadOwnerKey(); | 91 LoadOwnerKey(); |
142 | 92 |
143 return !public_key_.empty(); | 93 return !public_key_.empty(); |
144 } | 94 } |
145 | 95 |
146 bool OwnerManager::EnsurePrivateKey() { | 96 bool OwnerManager::EnsurePrivateKey() { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 154 |
205 void OwnerManager::SendNotification(NotificationType type, | 155 void OwnerManager::SendNotification(NotificationType type, |
206 const NotificationDetails& details) { | 156 const NotificationDetails& details) { |
207 NotificationService::current()->Notify( | 157 NotificationService::current()->Notify( |
208 type, | 158 type, |
209 NotificationService::AllSources(), | 159 NotificationService::AllSources(), |
210 details); | 160 details); |
211 } | 161 } |
212 | 162 |
213 } // namespace chromeos | 163 } // namespace chromeos |
OLD | NEW |