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_regular.h" | 5 #include "chrome/browser/signin/easy_unlock_service_regular.h" |
6 | 6 |
7 #include "base/base64url.h" | 7 #include "base/base64url.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 return device_manager_.get(); | 92 return device_manager_.get(); |
93 } | 93 } |
94 | 94 |
95 proximity_auth::ProximityAuthPrefManager* | 95 proximity_auth::ProximityAuthPrefManager* |
96 EasyUnlockServiceRegular::GetProximityAuthPrefManager() { | 96 EasyUnlockServiceRegular::GetProximityAuthPrefManager() { |
97 return pref_manager_.get(); | 97 return pref_manager_.get(); |
98 } | 98 } |
99 | 99 |
100 void EasyUnlockServiceRegular::LoadRemoteDevices() { | 100 void EasyUnlockServiceRegular::LoadRemoteDevices() { |
101 if (device_manager_->unlock_keys().empty()) { | 101 if (device_manager_->unlock_keys().empty()) { |
102 SetProximityAuthDevices(GetUserEmail(), proximity_auth::RemoteDeviceList()); | 102 SetProximityAuthDevices(GetAccountId(), proximity_auth::RemoteDeviceList()); |
103 return; | 103 return; |
104 } | 104 } |
105 | 105 |
106 remote_device_loader_.reset(new proximity_auth::RemoteDeviceLoader( | 106 remote_device_loader_.reset(new proximity_auth::RemoteDeviceLoader( |
107 device_manager_->unlock_keys(), proximity_auth_client()->GetAccountId(), | 107 device_manager_->unlock_keys(), proximity_auth_client()->GetAccountId(), |
108 enrollment_manager_->GetUserPrivateKey(), | 108 enrollment_manager_->GetUserPrivateKey(), |
109 proximity_auth_client()->CreateSecureMessageDelegate(), | 109 proximity_auth_client()->CreateSecureMessageDelegate(), |
110 pref_manager_.get())); | 110 pref_manager_.get())); |
111 remote_device_loader_->Load( | 111 remote_device_loader_->Load( |
112 base::Bind(&EasyUnlockServiceRegular::OnRemoteDevicesLoaded, | 112 base::Bind(&EasyUnlockServiceRegular::OnRemoteDevicesLoaded, |
113 weak_ptr_factory_.GetWeakPtr())); | 113 weak_ptr_factory_.GetWeakPtr())); |
114 } | 114 } |
115 | 115 |
116 void EasyUnlockServiceRegular::OnRemoteDevicesLoaded( | 116 void EasyUnlockServiceRegular::OnRemoteDevicesLoaded( |
117 const proximity_auth::RemoteDeviceList& remote_devices) { | 117 const proximity_auth::RemoteDeviceList& remote_devices) { |
118 SetProximityAuthDevices(GetUserEmail(), remote_devices); | 118 SetProximityAuthDevices(GetAccountId(), remote_devices); |
119 | 119 |
120 #if defined(OS_CHROMEOS) | 120 #if defined(OS_CHROMEOS) |
121 // We need to store a copy of |remote devices_| in the TPM, so it can be | 121 // We need to store a copy of |remote devices_| in the TPM, so it can be |
122 // retrieved on the sign-in screen when a user session has not been started | 122 // retrieved on the sign-in screen when a user session has not been started |
123 // yet. | 123 // yet. |
124 scoped_ptr<base::ListValue> device_list(new base::ListValue()); | 124 scoped_ptr<base::ListValue> device_list(new base::ListValue()); |
125 for (const auto& device : remote_devices) { | 125 for (const auto& device : remote_devices) { |
126 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 126 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
127 std::string b64_public_key, b64_psk; | 127 std::string b64_public_key, b64_psk; |
128 base::Base64UrlEncode(device.public_key, | 128 base::Base64UrlEncode(device.public_key, |
(...skipping 17 matching lines...) Expand all Loading... |
146 | 146 |
147 // TODO(tengs): Rename this function after the easy_unlock app is replaced. | 147 // TODO(tengs): Rename this function after the easy_unlock app is replaced. |
148 SetRemoteDevices(*device_list); | 148 SetRemoteDevices(*device_list); |
149 #endif | 149 #endif |
150 } | 150 } |
151 | 151 |
152 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const { | 152 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const { |
153 return EasyUnlockService::TYPE_REGULAR; | 153 return EasyUnlockService::TYPE_REGULAR; |
154 } | 154 } |
155 | 155 |
156 std::string EasyUnlockServiceRegular::GetUserEmail() const { | 156 AccountId EasyUnlockServiceRegular::GetAccountId() const { |
157 const SigninManagerBase* signin_manager = | 157 const SigninManagerBase* signin_manager = |
158 SigninManagerFactory::GetForProfileIfExists(profile()); | 158 SigninManagerFactory::GetForProfileIfExists(profile()); |
159 // |profile| has to be a signed-in profile with SigninManager already | 159 // |profile| has to be a signed-in profile with SigninManager already |
160 // created. Otherwise, just crash to collect stack. | 160 // created. Otherwise, just crash to collect stack. |
161 DCHECK(signin_manager); | 161 DCHECK(signin_manager); |
162 const std::string user_email = | 162 const std::string user_email = |
163 signin_manager->GetAuthenticatedAccountInfo().email; | 163 signin_manager->GetAuthenticatedAccountInfo().email; |
164 return user_email.empty() ? user_email : gaia::CanonicalizeEmail(user_email); | 164 return user_email.empty() |
| 165 ? EmptyAccountId() |
| 166 : AccountId::FromUserEmail(gaia::CanonicalizeEmail(user_email)); |
165 } | 167 } |
166 | 168 |
167 void EasyUnlockServiceRegular::LaunchSetup() { | 169 void EasyUnlockServiceRegular::LaunchSetup() { |
168 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 170 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
169 #if defined(OS_CHROMEOS) | 171 #if defined(OS_CHROMEOS) |
170 // Force the user to reauthenticate by showing a modal overlay (similar to the | 172 // Force the user to reauthenticate by showing a modal overlay (similar to the |
171 // lock screen). The password obtained from the reauth is cached for a short | 173 // lock screen). The password obtained from the reauth is cached for a short |
172 // period of time and used to create the cryptohome keys for sign-in. | 174 // period of time and used to create the cryptohome keys for sign-in. |
173 if (short_lived_user_context_ && short_lived_user_context_->user_context()) { | 175 if (short_lived_user_context_ && short_lived_user_context_->user_context()) { |
174 OpenSetupApp(); | 176 OpenSetupApp(); |
(...skipping 30 matching lines...) Expand all Loading... |
205 base::Bind(&EasyUnlockServiceRegular::SetHardlockAfterKeyOperation, | 207 base::Bind(&EasyUnlockServiceRegular::SetHardlockAfterKeyOperation, |
206 weak_ptr_factory_.GetWeakPtr(), | 208 weak_ptr_factory_.GetWeakPtr(), |
207 EasyUnlockScreenlockStateHandler::NO_PAIRING)); | 209 EasyUnlockScreenlockStateHandler::NO_PAIRING)); |
208 } | 210 } |
209 } | 211 } |
210 | 212 |
211 void EasyUnlockServiceRegular::SetHardlockAfterKeyOperation( | 213 void EasyUnlockServiceRegular::SetHardlockAfterKeyOperation( |
212 EasyUnlockScreenlockStateHandler::HardlockState state_on_success, | 214 EasyUnlockScreenlockStateHandler::HardlockState state_on_success, |
213 bool success) { | 215 bool success) { |
214 if (success) | 216 if (success) |
215 SetHardlockStateForUser(GetUserEmail(), state_on_success); | 217 SetHardlockStateForUser(GetAccountId(), state_on_success); |
216 | 218 |
217 // Even if the refresh keys operation suceeded, we still fetch and check the | 219 // Even if the refresh keys operation suceeded, we still fetch and check the |
218 // cryptohome keys against the keys in local preferences as a sanity check. | 220 // cryptohome keys against the keys in local preferences as a sanity check. |
219 CheckCryptohomeKeysAndMaybeHardlock(); | 221 CheckCryptohomeKeysAndMaybeHardlock(); |
220 } | 222 } |
221 #endif | 223 #endif |
222 | 224 |
223 const base::DictionaryValue* EasyUnlockServiceRegular::GetPermitAccess() const { | 225 const base::DictionaryValue* EasyUnlockServiceRegular::GetPermitAccess() const { |
224 const base::DictionaryValue* pairing_dict = | 226 const base::DictionaryValue* pairing_dict = |
225 profile()->GetPrefs()->GetDictionary(prefs::kEasyUnlockPairing); | 227 profile()->GetPrefs()->GetDictionary(prefs::kEasyUnlockPairing); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 | 364 |
363 std::string EasyUnlockServiceRegular::GetChallenge() const { | 365 std::string EasyUnlockServiceRegular::GetChallenge() const { |
364 return std::string(); | 366 return std::string(); |
365 } | 367 } |
366 | 368 |
367 std::string EasyUnlockServiceRegular::GetWrappedSecret() const { | 369 std::string EasyUnlockServiceRegular::GetWrappedSecret() const { |
368 return std::string(); | 370 return std::string(); |
369 } | 371 } |
370 | 372 |
371 void EasyUnlockServiceRegular::RecordEasySignInOutcome( | 373 void EasyUnlockServiceRegular::RecordEasySignInOutcome( |
372 const std::string& user_id, | 374 const AccountId& account_id, |
373 bool success) const { | 375 bool success) const { |
374 NOTREACHED(); | 376 NOTREACHED(); |
375 } | 377 } |
376 | 378 |
377 void EasyUnlockServiceRegular::RecordPasswordLoginEvent( | 379 void EasyUnlockServiceRegular::RecordPasswordLoginEvent( |
378 const std::string& user_id) const { | 380 const AccountId& account_id) const { |
379 NOTREACHED(); | 381 NOTREACHED(); |
380 } | 382 } |
381 | 383 |
382 void EasyUnlockServiceRegular::StartAutoPairing( | 384 void EasyUnlockServiceRegular::StartAutoPairing( |
383 const AutoPairingResultCallback& callback) { | 385 const AutoPairingResultCallback& callback) { |
384 if (!auto_pairing_callback_.is_null()) { | 386 if (!auto_pairing_callback_.is_null()) { |
385 LOG(ERROR) | 387 LOG(ERROR) |
386 << "Start auto pairing when there is another auto pairing requested."; | 388 << "Start auto pairing when there is another auto pairing requested."; |
387 callback.Run(false, std::string()); | 389 callback.Run(false, std::string()); |
388 return; | 390 return; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 // If we synced remote devices while the screen was locked, we can now load | 538 // If we synced remote devices while the screen was locked, we can now load |
537 // the new remote devices. | 539 // the new remote devices. |
538 if (deferring_device_load_) { | 540 if (deferring_device_load_) { |
539 PA_LOG(INFO) << "Loading deferred devices after screen unlock."; | 541 PA_LOG(INFO) << "Loading deferred devices after screen unlock."; |
540 deferring_device_load_ = false; | 542 deferring_device_load_ = false; |
541 LoadRemoteDevices(); | 543 LoadRemoteDevices(); |
542 } | 544 } |
543 } | 545 } |
544 | 546 |
545 void EasyUnlockServiceRegular::OnFocusedUserChanged( | 547 void EasyUnlockServiceRegular::OnFocusedUserChanged( |
546 const std::string& user_id) { | 548 const AccountId& account_id) { |
547 // Nothing to do. | 549 // Nothing to do. |
548 } | 550 } |
549 | 551 |
550 void EasyUnlockServiceRegular::OnPrefsChanged() { | 552 void EasyUnlockServiceRegular::OnPrefsChanged() { |
551 SyncProfilePrefsToLocalState(); | 553 SyncProfilePrefsToLocalState(); |
552 UpdateAppState(); | 554 UpdateAppState(); |
553 } | 555 } |
554 | 556 |
555 void EasyUnlockServiceRegular::SetTurnOffFlowStatus(TurnOffFlowStatus status) { | 557 void EasyUnlockServiceRegular::SetTurnOffFlowStatus(TurnOffFlowStatus status) { |
556 turn_off_flow_status_ = status; | 558 turn_off_flow_status_ = status; |
(...skipping 25 matching lines...) Expand all Loading... |
582 // Create the dictionary of Easy Unlock preferences for the current user. The | 584 // Create the dictionary of Easy Unlock preferences for the current user. The |
583 // items in the dictionary are the same profile prefs used for Easy Unlock. | 585 // items in the dictionary are the same profile prefs used for Easy Unlock. |
584 scoped_ptr<base::DictionaryValue> user_prefs_dict( | 586 scoped_ptr<base::DictionaryValue> user_prefs_dict( |
585 new base::DictionaryValue()); | 587 new base::DictionaryValue()); |
586 user_prefs_dict->SetBooleanWithoutPathExpansion( | 588 user_prefs_dict->SetBooleanWithoutPathExpansion( |
587 prefs::kEasyUnlockProximityRequired, | 589 prefs::kEasyUnlockProximityRequired, |
588 profile_prefs->GetBoolean(prefs::kEasyUnlockProximityRequired)); | 590 profile_prefs->GetBoolean(prefs::kEasyUnlockProximityRequired)); |
589 | 591 |
590 DictionaryPrefUpdate update(local_state, | 592 DictionaryPrefUpdate update(local_state, |
591 prefs::kEasyUnlockLocalStateUserPrefs); | 593 prefs::kEasyUnlockLocalStateUserPrefs); |
592 std::string user_email = GetUserEmail(); | 594 update->SetWithoutPathExpansion(GetAccountId().GetUserEmail(), |
593 update->SetWithoutPathExpansion(user_email, user_prefs_dict.Pass()); | 595 user_prefs_dict.Pass()); |
594 } | 596 } |
595 | 597 |
596 cryptauth::GcmDeviceInfo EasyUnlockServiceRegular::GetGcmDeviceInfo() { | 598 cryptauth::GcmDeviceInfo EasyUnlockServiceRegular::GetGcmDeviceInfo() { |
597 cryptauth::GcmDeviceInfo device_info; | 599 cryptauth::GcmDeviceInfo device_info; |
598 device_info.set_long_device_id(EasyUnlockService::GetDeviceId()); | 600 device_info.set_long_device_id(EasyUnlockService::GetDeviceId()); |
599 device_info.set_device_type(cryptauth::CHROME); | 601 device_info.set_device_type(cryptauth::CHROME); |
600 device_info.set_device_software_version(version_info::GetVersionNumber()); | 602 device_info.set_device_software_version(version_info::GetVersionNumber()); |
601 google::protobuf::int64 software_version_code = | 603 google::protobuf::int64 software_version_code = |
602 proximity_auth::HashStringToInt64(version_info::GetLastChange()); | 604 proximity_auth::HashStringToInt64(version_info::GetLastChange()); |
603 device_info.set_device_software_version_code(software_version_code); | 605 device_info.set_device_software_version_code(software_version_code); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
670 PA_LOG(INFO) << "Refresh token not yet available, " | 672 PA_LOG(INFO) << "Refresh token not yet available, " |
671 << "waiting before starting CryptAuth managers"; | 673 << "waiting before starting CryptAuth managers"; |
672 token_service->AddObserver(this); | 674 token_service->AddObserver(this); |
673 } | 675 } |
674 | 676 |
675 device_manager_->AddObserver(this); | 677 device_manager_->AddObserver(this); |
676 enrollment_manager_->Start(); | 678 enrollment_manager_->Start(); |
677 device_manager_->Start(); | 679 device_manager_->Start(); |
678 } | 680 } |
679 #endif | 681 #endif |
OLD | NEW |