| 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/signed_settings.h" | 5 #include "chrome/browser/chromeos/login/signed_settings.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/ref_counted.h" | 10 #include "base/ref_counted.h" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/browser_thread.h" | 13 #include "chrome/browser/browser_thread.h" |
| 14 #include "chrome/browser/chromeos/cros/cros_library.h" | 14 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 15 #include "chrome/browser/chromeos/cros/login_library.h" | 15 #include "chrome/browser/chromeos/cros/login_library.h" |
| 16 #include "chrome/browser/chromeos/login/ownership_service.h" | 16 #include "chrome/browser/chromeos/login/ownership_service.h" |
| 17 #include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" | 17 #include "chrome/browser/chromeos/login/signed_settings_temp_storage.h" |
| 18 | 18 |
| 19 namespace chromeos { | 19 namespace chromeos { |
| 20 | 20 |
| 21 SignedSettings::SignedSettings() | 21 SignedSettings::SignedSettings() |
| 22 : service_(OwnershipService::GetSharedInstance()) { | 22 : service_(OwnershipService::GetSharedInstance()) { |
| 23 } | 23 } |
| 24 | 24 |
| 25 SignedSettings::~SignedSettings() {} | 25 SignedSettings::~SignedSettings() {} |
| 26 | 26 |
| 27 SignedSettings::FailureCode SignedSettings::MapKeyOpCode( | 27 SignedSettings::ReturnCode SignedSettings::MapKeyOpCode( |
| 28 OwnerManager::KeyOpCode return_code) { | 28 OwnerManager::KeyOpCode return_code) { |
| 29 return (return_code == OwnerManager::KEY_UNAVAILABLE ? | 29 return (return_code == OwnerManager::KEY_UNAVAILABLE ? |
| 30 KEY_UNAVAILABLE : OPERATION_FAILED); | 30 KEY_UNAVAILABLE : OPERATION_FAILED); |
| 31 } | 31 } |
| 32 | 32 |
| 33 class CheckWhitelistOp : public SignedSettings { | 33 class CheckWhitelistOp : public SignedSettings { |
| 34 public: | 34 public: |
| 35 CheckWhitelistOp(const std::string& email, | 35 CheckWhitelistOp(const std::string& email, |
| 36 SignedSettings::Delegate<bool>* d); | 36 SignedSettings::Delegate<bool>* d); |
| 37 virtual ~CheckWhitelistOp(); | 37 virtual ~CheckWhitelistOp(); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 : email_(email), | 142 : email_(email), |
| 143 d_(d) { | 143 d_(d) { |
| 144 } | 144 } |
| 145 | 145 |
| 146 CheckWhitelistOp::~CheckWhitelistOp() {} | 146 CheckWhitelistOp::~CheckWhitelistOp() {} |
| 147 | 147 |
| 148 void CheckWhitelistOp::Execute() { | 148 void CheckWhitelistOp::Execute() { |
| 149 CHECK(chromeos::CrosLibrary::Get()->EnsureLoaded()); | 149 CHECK(chromeos::CrosLibrary::Get()->EnsureLoaded()); |
| 150 std::vector<uint8> sig; | 150 std::vector<uint8> sig; |
| 151 if (!CrosLibrary::Get()->GetLoginLibrary()->CheckWhitelist(email_, &sig)) { | 151 if (!CrosLibrary::Get()->GetLoginLibrary()->CheckWhitelist(email_, &sig)) { |
| 152 d_->OnSettingsOpFailed(NOT_FOUND); | 152 d_->OnSettingsOpCompleted(NOT_FOUND, false); |
| 153 return; | 153 return; |
| 154 } | 154 } |
| 155 // Posts a task to the FILE thread to verify |sig|. | 155 // Posts a task to the FILE thread to verify |sig|. |
| 156 service_->StartVerifyAttempt(email_, sig, this); | 156 service_->StartVerifyAttempt(email_, sig, this); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void CheckWhitelistOp::OnKeyOpComplete( | 159 void CheckWhitelistOp::OnKeyOpComplete( |
| 160 const OwnerManager::KeyOpCode return_code, | 160 const OwnerManager::KeyOpCode return_code, |
| 161 const std::vector<uint8>& payload) { | 161 const std::vector<uint8>& payload) { |
| 162 // Ensure we're on the UI thread, due to the need to send DBus traffic. | 162 // Ensure we're on the UI thread, due to the need to send DBus traffic. |
| 163 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 163 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 164 BrowserThread::PostTask( | 164 BrowserThread::PostTask( |
| 165 BrowserThread::UI, FROM_HERE, | 165 BrowserThread::UI, FROM_HERE, |
| 166 NewRunnableMethod(this, | 166 NewRunnableMethod(this, |
| 167 &CheckWhitelistOp::OnKeyOpComplete, | 167 &CheckWhitelistOp::OnKeyOpComplete, |
| 168 return_code, payload)); | 168 return_code, payload)); |
| 169 return; | 169 return; |
| 170 } | 170 } |
| 171 if (return_code == OwnerManager::SUCCESS) { | 171 if (return_code == OwnerManager::SUCCESS) { |
| 172 d_->OnSettingsOpSucceeded(true); | 172 d_->OnSettingsOpCompleted(SUCCESS, true); |
| 173 } else { | 173 } else { |
| 174 d_->OnSettingsOpFailed(SignedSettings::MapKeyOpCode(return_code)); | 174 d_->OnSettingsOpCompleted(SignedSettings::MapKeyOpCode(return_code), false); |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 WhitelistOp::WhitelistOp(const std::string& email, | 178 WhitelistOp::WhitelistOp(const std::string& email, |
| 179 bool add_to_whitelist, | 179 bool add_to_whitelist, |
| 180 SignedSettings::Delegate<bool>* d) | 180 SignedSettings::Delegate<bool>* d) |
| 181 : email_(email), | 181 : email_(email), |
| 182 add_to_whitelist_(add_to_whitelist), | 182 add_to_whitelist_(add_to_whitelist), |
| 183 d_(d) { | 183 d_(d) { |
| 184 } | 184 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 198 BrowserThread::UI, FROM_HERE, | 198 BrowserThread::UI, FROM_HERE, |
| 199 NewRunnableMethod(this, | 199 NewRunnableMethod(this, |
| 200 &WhitelistOp::OnKeyOpComplete, | 200 &WhitelistOp::OnKeyOpComplete, |
| 201 return_code, payload)); | 201 return_code, payload)); |
| 202 return; | 202 return; |
| 203 } | 203 } |
| 204 // Now, sure we're on the UI thread. | 204 // Now, sure we're on the UI thread. |
| 205 if (return_code == OwnerManager::SUCCESS) { | 205 if (return_code == OwnerManager::SUCCESS) { |
| 206 // OnComplete() will be called by this call, if it succeeds. | 206 // OnComplete() will be called by this call, if it succeeds. |
| 207 if (!InitiateWhitelistOp(payload)) | 207 if (!InitiateWhitelistOp(payload)) |
| 208 d_->OnSettingsOpFailed(OPERATION_FAILED); | 208 d_->OnSettingsOpCompleted(OPERATION_FAILED, false); |
| 209 } else { | 209 } else { |
| 210 d_->OnSettingsOpFailed(SignedSettings::MapKeyOpCode(return_code)); | 210 d_->OnSettingsOpCompleted(SignedSettings::MapKeyOpCode(return_code), false); |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 | 213 |
| 214 void WhitelistOp::OnComplete(bool value) { | 214 void WhitelistOp::OnComplete(bool value) { |
| 215 if (value) | 215 if (value) |
| 216 d_->OnSettingsOpSucceeded(value); | 216 d_->OnSettingsOpCompleted(SUCCESS, value); |
| 217 else | 217 else |
| 218 d_->OnSettingsOpFailed(NOT_FOUND); | 218 d_->OnSettingsOpCompleted(NOT_FOUND, false); |
| 219 } | 219 } |
| 220 | 220 |
| 221 bool WhitelistOp::InitiateWhitelistOp(const std::vector<uint8>& signature) { | 221 bool WhitelistOp::InitiateWhitelistOp(const std::vector<uint8>& signature) { |
| 222 LoginLibrary* library = CrosLibrary::Get()->GetLoginLibrary(); | 222 LoginLibrary* library = CrosLibrary::Get()->GetLoginLibrary(); |
| 223 if (add_to_whitelist_) | 223 if (add_to_whitelist_) |
| 224 return library->WhitelistAsync(email_, signature, this); | 224 return library->WhitelistAsync(email_, signature, this); |
| 225 return library->UnwhitelistAsync(email_, signature, this); | 225 return library->UnwhitelistAsync(email_, signature, this); |
| 226 } | 226 } |
| 227 | 227 |
| 228 StorePropertyOp::StorePropertyOp(const std::string& name, | 228 StorePropertyOp::StorePropertyOp(const std::string& name, |
| 229 const std::string& value, | 229 const std::string& value, |
| 230 SignedSettings::Delegate<bool>* d) | 230 SignedSettings::Delegate<bool>* d) |
| 231 : name_(name), | 231 : name_(name), |
| 232 value_(value), | 232 value_(value), |
| 233 d_(d) { | 233 d_(d) { |
| 234 } | 234 } |
| 235 | 235 |
| 236 StorePropertyOp::~StorePropertyOp() {} | 236 StorePropertyOp::~StorePropertyOp() {} |
| 237 | 237 |
| 238 void StorePropertyOp::Execute() { | 238 void StorePropertyOp::Execute() { |
| 239 if (!service_->IsAlreadyOwned()) { | 239 if (!service_->IsAlreadyOwned()) { |
| 240 if (g_browser_process && | 240 if (g_browser_process && |
| 241 g_browser_process->local_state() && | 241 g_browser_process->local_state() && |
| 242 SignedSettingsTempStorage::Store(name_, value_, | 242 SignedSettingsTempStorage::Store(name_, value_, |
| 243 g_browser_process->local_state())) { | 243 g_browser_process->local_state())) { |
| 244 d_->OnSettingsOpSucceeded(true); | 244 d_->OnSettingsOpCompleted(SUCCESS, true); |
| 245 return; | 245 return; |
| 246 } | 246 } |
| 247 } | 247 } |
| 248 // Posts a task to the FILE thread to sign |name_|=|value_|. | 248 // Posts a task to the FILE thread to sign |name_|=|value_|. |
| 249 std::string to_sign = base::StringPrintf("%s=%s", | 249 std::string to_sign = base::StringPrintf("%s=%s", |
| 250 name_.c_str(), | 250 name_.c_str(), |
| 251 value_.c_str()); | 251 value_.c_str()); |
| 252 service_->StartSigningAttempt(to_sign, this); | 252 service_->StartSigningAttempt(to_sign, this); |
| 253 } | 253 } |
| 254 | 254 |
| 255 void StorePropertyOp::OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, | 255 void StorePropertyOp::OnKeyOpComplete(const OwnerManager::KeyOpCode return_code, |
| 256 const std::vector<uint8>& payload) { | 256 const std::vector<uint8>& payload) { |
| 257 // Ensure we're on the UI thread, due to the need to send DBus traffic. | 257 // Ensure we're on the UI thread, due to the need to send DBus traffic. |
| 258 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 258 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 259 BrowserThread::PostTask( | 259 BrowserThread::PostTask( |
| 260 BrowserThread::UI, FROM_HERE, | 260 BrowserThread::UI, FROM_HERE, |
| 261 NewRunnableMethod(this, | 261 NewRunnableMethod(this, |
| 262 &StorePropertyOp::OnKeyOpComplete, | 262 &StorePropertyOp::OnKeyOpComplete, |
| 263 return_code, payload)); | 263 return_code, payload)); |
| 264 return; | 264 return; |
| 265 } | 265 } |
| 266 VLOG(2) << "StorePropertyOp::OnKeyOpComplete return_code = " << return_code; |
| 266 // Now, sure we're on the UI thread. | 267 // Now, sure we're on the UI thread. |
| 267 if (return_code == OwnerManager::SUCCESS) { | 268 if (return_code == OwnerManager::SUCCESS) { |
| 268 // OnComplete() will be called by this call, if it succeeds. | 269 // OnComplete() will be called by this call, if it succeeds. |
| 269 if (!CrosLibrary::Get()->GetLoginLibrary()->StorePropertyAsync(name_, | 270 if (!CrosLibrary::Get()->GetLoginLibrary()->StorePropertyAsync(name_, |
| 270 value_, | 271 value_, |
| 271 payload, | 272 payload, |
| 272 this)) { | 273 this)) { |
| 273 d_->OnSettingsOpFailed(OPERATION_FAILED); | 274 d_->OnSettingsOpCompleted(OPERATION_FAILED, false); |
| 274 } | 275 } |
| 275 } else { | 276 } else { |
| 276 d_->OnSettingsOpFailed(SignedSettings::MapKeyOpCode(return_code)); | 277 d_->OnSettingsOpCompleted(SignedSettings::MapKeyOpCode(return_code), false); |
| 277 } | 278 } |
| 278 } | 279 } |
| 279 | 280 |
| 280 void StorePropertyOp::OnComplete(bool value) { | 281 void StorePropertyOp::OnComplete(bool value) { |
| 281 if (value) | 282 if (value) |
| 282 d_->OnSettingsOpSucceeded(value); | 283 d_->OnSettingsOpCompleted(SUCCESS, value); |
| 283 else | 284 else |
| 284 d_->OnSettingsOpFailed(NOT_FOUND); | 285 d_->OnSettingsOpCompleted(NOT_FOUND, false); |
| 285 } | 286 } |
| 286 | 287 |
| 287 RetrievePropertyOp::RetrievePropertyOp(const std::string& name, | 288 RetrievePropertyOp::RetrievePropertyOp(const std::string& name, |
| 288 SignedSettings::Delegate<std::string>* d) | 289 SignedSettings::Delegate<std::string>* d) |
| 289 : name_(name), | 290 : name_(name), |
| 290 d_(d) { | 291 d_(d) { |
| 291 } | 292 } |
| 292 | 293 |
| 293 RetrievePropertyOp::~RetrievePropertyOp() {} | 294 RetrievePropertyOp::~RetrievePropertyOp() {} |
| 294 | 295 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 309 NewRunnableMethod(this, | 310 NewRunnableMethod(this, |
| 310 &RetrievePropertyOp::OnKeyOpComplete, | 311 &RetrievePropertyOp::OnKeyOpComplete, |
| 311 OwnerManager::SUCCESS, std::vector<uint8>())); | 312 OwnerManager::SUCCESS, std::vector<uint8>())); |
| 312 return; | 313 return; |
| 313 } | 314 } |
| 314 } | 315 } |
| 315 std::vector<uint8> sig; | 316 std::vector<uint8> sig; |
| 316 if (!CrosLibrary::Get()->GetLoginLibrary()->RetrieveProperty(name_, | 317 if (!CrosLibrary::Get()->GetLoginLibrary()->RetrieveProperty(name_, |
| 317 &value_, | 318 &value_, |
| 318 &sig)) { | 319 &sig)) { |
| 319 d_->OnSettingsOpFailed(NOT_FOUND); | 320 d_->OnSettingsOpCompleted(NOT_FOUND, std::string()); |
| 320 return; | 321 return; |
| 321 } | 322 } |
| 322 std::string to_verify = base::StringPrintf("%s=%s", | 323 std::string to_verify = base::StringPrintf("%s=%s", |
| 323 name_.c_str(), | 324 name_.c_str(), |
| 324 value_.c_str()); | 325 value_.c_str()); |
| 325 // Posts a task to the FILE thread to verify |sig|. | 326 // Posts a task to the FILE thread to verify |sig|. |
| 326 service_->StartVerifyAttempt(to_verify, sig, this); | 327 service_->StartVerifyAttempt(to_verify, sig, this); |
| 327 } | 328 } |
| 328 | 329 |
| 329 void RetrievePropertyOp::OnKeyOpComplete( | 330 void RetrievePropertyOp::OnKeyOpComplete( |
| 330 const OwnerManager::KeyOpCode return_code, | 331 const OwnerManager::KeyOpCode return_code, |
| 331 const std::vector<uint8>& payload) { | 332 const std::vector<uint8>& payload) { |
| 332 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 333 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 333 BrowserThread::PostTask( | 334 BrowserThread::PostTask( |
| 334 BrowserThread::UI, FROM_HERE, | 335 BrowserThread::UI, FROM_HERE, |
| 335 NewRunnableMethod(this, | 336 NewRunnableMethod(this, |
| 336 &RetrievePropertyOp::OnKeyOpComplete, | 337 &RetrievePropertyOp::OnKeyOpComplete, |
| 337 return_code, payload)); | 338 return_code, payload)); |
| 338 return; | 339 return; |
| 339 } | 340 } |
| 340 // Now, sure we're on the UI thread. | 341 // Now, sure we're on the UI thread. |
| 341 if (return_code == OwnerManager::SUCCESS) | 342 if (return_code == OwnerManager::SUCCESS) |
| 342 d_->OnSettingsOpSucceeded(value_); | 343 d_->OnSettingsOpCompleted(SUCCESS, value_); |
| 343 else | 344 else |
| 344 d_->OnSettingsOpFailed(SignedSettings::MapKeyOpCode(return_code)); | 345 d_->OnSettingsOpCompleted(SignedSettings::MapKeyOpCode(return_code), |
| 346 std::string()); |
| 345 } | 347 } |
| 346 | 348 |
| 347 } // namespace chromeos | 349 } // namespace chromeos |
| OLD | NEW |