| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/signin/easy_unlock_service_signin_chromeos.h" | 5 #include "chrome/browser/signin/easy_unlock_service_signin_chromeos.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | |
| 10 #include "base/location.h" | 9 #include "base/location.h" |
| 11 #include "base/logging.h" | 10 #include "base/logging.h" |
| 12 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 13 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
| 14 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 15 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 16 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" | 15 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" |
| 17 #include "chrome/browser/chromeos/login/session/user_session_manager.h" | 16 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
| 18 #include "chrome/browser/signin/easy_unlock_app_manager.h" | 17 #include "chrome/browser/signin/easy_unlock_app_manager.h" |
| 19 #include "chrome/browser/signin/easy_unlock_metrics.h" | 18 #include "chrome/browser/signin/easy_unlock_metrics.h" |
| 20 #include "chromeos/login/auth/user_context.h" | 19 #include "chromeos/login/auth/user_context.h" |
| 21 #include "chromeos/tpm/tpm_token_loader.h" | 20 #include "chromeos/tpm/tpm_token_loader.h" |
| 22 #include "components/proximity_auth/cryptauth/base64url.h" | |
| 23 #include "components/proximity_auth/logging/logging.h" | |
| 24 #include "components/proximity_auth/remote_device.h" | |
| 25 #include "components/proximity_auth/switches.h" | |
| 26 | 21 |
| 27 namespace { | 22 namespace { |
| 28 | 23 |
| 29 // The maximum allowed backoff interval when waiting for cryptohome to start. | 24 // The maximum allowed backoff interval when waiting for cryptohome to start. |
| 30 uint32 kMaxCryptohomeBackoffIntervalMs = 10000u; | 25 uint32 kMaxCryptohomeBackoffIntervalMs = 10000u; |
| 31 | 26 |
| 32 // If the data load fails, the initial interval after which the load will be | 27 // If the data load fails, the initial interval after which the load will be |
| 33 // retried. Further intervals will exponentially increas by factor 2. | 28 // retried. Further intervals will exponentially increas by factor 2. |
| 34 uint32 kInitialCryptohomeBackoffIntervalMs = 200u; | 29 uint32 kInitialCryptohomeBackoffIntervalMs = 200u; |
| 35 | 30 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 !user_id_.empty() && | 251 !user_id_.empty() && |
| 257 !chromeos::LoginState::Get()->IsUserLoggedIn(); | 252 !chromeos::LoginState::Get()->IsUserLoggedIn(); |
| 258 } | 253 } |
| 259 | 254 |
| 260 void EasyUnlockServiceSignin::OnWillFinalizeUnlock(bool success) { | 255 void EasyUnlockServiceSignin::OnWillFinalizeUnlock(bool success) { |
| 261 // This code path should only be exercised for the lock screen, not for the | 256 // This code path should only be exercised for the lock screen, not for the |
| 262 // sign-in screen. | 257 // sign-in screen. |
| 263 NOTREACHED(); | 258 NOTREACHED(); |
| 264 } | 259 } |
| 265 | 260 |
| 266 void EasyUnlockServiceSignin::OnSuspendDoneInternal() { | 261 void EasyUnlockServiceSignin::OnSuspendDone() { |
| 267 // Ignored. | 262 // Ignored. |
| 268 } | 263 } |
| 269 | 264 |
| 270 void EasyUnlockServiceSignin::OnScreenDidLock( | 265 void EasyUnlockServiceSignin::OnScreenDidLock( |
| 271 proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) { | 266 proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) { |
| 272 // In production code, the screen type should always be the signin screen; but | 267 // In production code, the screen type should always be the signin screen; but |
| 273 // in tests, the screen type might be different. | 268 // in tests, the screen type might be different. |
| 274 if (screen_type != | 269 if (screen_type != |
| 275 proximity_auth::ScreenlockBridge::LockHandler::SIGNIN_SCREEN) | 270 proximity_auth::ScreenlockBridge::LockHandler::SIGNIN_SCREEN) |
| 276 return; | 271 return; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 hardlock_state == EasyUnlockScreenlockStateHandler::NO_HARDLOCK) { | 375 hardlock_state == EasyUnlockScreenlockStateHandler::NO_HARDLOCK) { |
| 381 SetHardlockStateForUser(user_id, | 376 SetHardlockStateForUser(user_id, |
| 382 EasyUnlockScreenlockStateHandler::NO_PAIRING); | 377 EasyUnlockScreenlockStateHandler::NO_PAIRING); |
| 383 } | 378 } |
| 384 } | 379 } |
| 385 | 380 |
| 386 // If the fetched data belongs to the currently focused user, notify the app | 381 // If the fetched data belongs to the currently focused user, notify the app |
| 387 // that it has to refresh it's user data. | 382 // that it has to refresh it's user data. |
| 388 if (user_id == user_id_) | 383 if (user_id == user_id_) |
| 389 NotifyUserUpdated(); | 384 NotifyUserUpdated(); |
| 390 | |
| 391 if (user_id != user_id || devices.empty()) | |
| 392 return; | |
| 393 | |
| 394 // TODO(tengs): Currently, ProximityAuthSystem only supports one device. Once | |
| 395 // multiple devices are supported, we need to load all devices. | |
| 396 std::string decoded_public_key, decoded_psk, decoded_challenge; | |
| 397 proximity_auth::Base64UrlDecode(devices[0].public_key, &decoded_public_key); | |
| 398 proximity_auth::Base64UrlDecode(devices[0].psk, &decoded_psk); | |
| 399 proximity_auth::Base64UrlDecode(devices[0].challenge, &decoded_challenge); | |
| 400 | |
| 401 // TODO(tengs): We need to store the Bluetooth type with the TPM data. | |
| 402 proximity_auth::RemoteDevice::BluetoothType bluetooth_type = | |
| 403 base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 404 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery) | |
| 405 ? proximity_auth::RemoteDevice::BLUETOOTH_LE | |
| 406 : proximity_auth::RemoteDevice::BLUETOOTH_CLASSIC; | |
| 407 | |
| 408 proximity_auth::RemoteDevice remote_device( | |
| 409 user_id, std::string(), decoded_public_key, bluetooth_type, | |
| 410 devices[0].bluetooth_address, decoded_psk, decoded_challenge); | |
| 411 PA_LOG(INFO) << "Loaded Remote Device:\n" | |
| 412 << " user id: " << remote_device.user_id << "\n" | |
| 413 << " name: " << remote_device.name << "\n" | |
| 414 << " public key" << devices[0].public_key << "\n" | |
| 415 << " bt_addr:" << remote_device.bluetooth_address; | |
| 416 OnRemoteDeviceChanged(&remote_device); | |
| 417 } | 385 } |
| 418 | 386 |
| 419 const EasyUnlockServiceSignin::UserData* | 387 const EasyUnlockServiceSignin::UserData* |
| 420 EasyUnlockServiceSignin::FindLoadedDataForCurrentUser() const { | 388 EasyUnlockServiceSignin::FindLoadedDataForCurrentUser() const { |
| 421 if (user_id_.empty()) | 389 if (user_id_.empty()) |
| 422 return NULL; | 390 return NULL; |
| 423 | 391 |
| 424 std::map<std::string, UserData*>::const_iterator it = | 392 std::map<std::string, UserData*>::const_iterator it = |
| 425 user_data_.find(user_id_); | 393 user_data_.find(user_id_); |
| 426 if (it == user_data_.end()) | 394 if (it == user_data_.end()) |
| 427 return NULL; | 395 return NULL; |
| 428 if (it->second->state != USER_DATA_STATE_LOADED) | 396 if (it->second->state != USER_DATA_STATE_LOADED) |
| 429 return NULL; | 397 return NULL; |
| 430 return it->second; | 398 return it->second; |
| 431 } | 399 } |
| OLD | NEW |