| 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 "chromeos/login/auth/cryptohome_authenticator.h" | 5 #include "chromeos/login/auth/cryptohome_authenticator.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 cryptohome::PRIV_DEFAULT); | 141 cryptohome::PRIV_DEFAULT); |
| 142 cryptohome::MountParameters mount(ephemeral); | 142 cryptohome::MountParameters mount(ephemeral); |
| 143 if (create_if_nonexistent) { | 143 if (create_if_nonexistent) { |
| 144 mount.create_keys.push_back(cryptohome::KeyDefinition( | 144 mount.create_keys.push_back(cryptohome::KeyDefinition( |
| 145 key->GetSecret(), | 145 key->GetSecret(), |
| 146 kCryptohomeGAIAKeyLabel, | 146 kCryptohomeGAIAKeyLabel, |
| 147 cryptohome::PRIV_DEFAULT)); | 147 cryptohome::PRIV_DEFAULT)); |
| 148 } | 148 } |
| 149 | 149 |
| 150 cryptohome::HomedirMethods::GetInstance()->MountEx( | 150 cryptohome::HomedirMethods::GetInstance()->MountEx( |
| 151 cryptohome::Identification(attempt->user_context.GetUserID()), | 151 cryptohome::Identification( |
| 152 cryptohome::Authorization(auth_key), | 152 attempt->user_context.GetAccountId().GetUserEmail()), |
| 153 mount, | 153 cryptohome::Authorization(auth_key), mount, |
| 154 base::Bind(&OnMount, attempt, resolver)); | 154 base::Bind(&OnMount, attempt, resolver)); |
| 155 } | 155 } |
| 156 | 156 |
| 157 // Callback invoked when the system salt has been retrieved. Transforms the key | 157 // Callback invoked when the system salt has been retrieved. Transforms the key |
| 158 // in |attempt->user_context| using Chrome's default hashing algorithm and the | 158 // in |attempt->user_context| using Chrome's default hashing algorithm and the |
| 159 // system salt, then calls MountEx(). | 159 // system salt, then calls MountEx(). |
| 160 void OnGetSystemSalt(const base::WeakPtr<AuthAttemptState>& attempt, | 160 void OnGetSystemSalt(const base::WeakPtr<AuthAttemptState>& attempt, |
| 161 scoped_refptr<CryptohomeAuthenticator> resolver, | 161 scoped_refptr<CryptohomeAuthenticator> resolver, |
| 162 bool ephemeral, | 162 bool ephemeral, |
| 163 bool create_if_nonexistent, | 163 bool create_if_nonexistent, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( | 259 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( |
| 260 "CryptohomeMount-Start", false); | 260 "CryptohomeMount-Start", false); |
| 261 | 261 |
| 262 if (attempt->user_context.GetKey()->GetKeyType() != | 262 if (attempt->user_context.GetKey()->GetKeyType() != |
| 263 Key::KEY_TYPE_PASSWORD_PLAIN) { | 263 Key::KEY_TYPE_PASSWORD_PLAIN) { |
| 264 DoMount(attempt, resolver, ephemeral, create_if_nonexistent); | 264 DoMount(attempt, resolver, ephemeral, create_if_nonexistent); |
| 265 return; | 265 return; |
| 266 } | 266 } |
| 267 | 267 |
| 268 cryptohome::HomedirMethods::GetInstance()->GetKeyDataEx( | 268 cryptohome::HomedirMethods::GetInstance()->GetKeyDataEx( |
| 269 cryptohome::Identification(attempt->user_context.GetUserID()), | 269 cryptohome::Identification( |
| 270 kCryptohomeGAIAKeyLabel, | 270 attempt->user_context.GetAccountId().GetUserEmail()), |
| 271 base::Bind(&OnGetKeyDataEx, | 271 kCryptohomeGAIAKeyLabel, base::Bind(&OnGetKeyDataEx, attempt, resolver, |
| 272 attempt, | 272 ephemeral, create_if_nonexistent)); |
| 273 resolver, | |
| 274 ephemeral, | |
| 275 create_if_nonexistent)); | |
| 276 } | 273 } |
| 277 | 274 |
| 278 // Calls cryptohome's mount method for guest and also get the user hash from | 275 // Calls cryptohome's mount method for guest and also get the user hash from |
| 279 // cryptohome. | 276 // cryptohome. |
| 280 void MountGuestAndGetHash(const base::WeakPtr<AuthAttemptState>& attempt, | 277 void MountGuestAndGetHash(const base::WeakPtr<AuthAttemptState>& attempt, |
| 281 scoped_refptr<CryptohomeAuthenticator> resolver) { | 278 scoped_refptr<CryptohomeAuthenticator> resolver) { |
| 282 attempt->UsernameHashRequested(); | 279 attempt->UsernameHashRequested(); |
| 283 cryptohome::AsyncMethodCaller::GetInstance()->AsyncMountGuest( | 280 cryptohome::AsyncMethodCaller::GetInstance()->AsyncMountGuest( |
| 284 base::Bind(&TriggerResolveWithLoginTimeMarker, | 281 base::Bind(&TriggerResolveWithLoginTimeMarker, |
| 285 "CryptohomeMount-End", | 282 "CryptohomeMount-End", |
| 286 attempt, | 283 attempt, |
| 287 resolver)); | 284 resolver)); |
| 288 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( | 285 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( |
| 289 attempt->user_context.GetUserID(), | 286 attempt->user_context.GetAccountId().GetUserEmail(), |
| 290 base::Bind(&TriggerResolveHash, attempt, resolver)); | 287 base::Bind(&TriggerResolveHash, attempt, resolver)); |
| 291 } | 288 } |
| 292 | 289 |
| 293 // Calls cryptohome's MountPublic method | 290 // Calls cryptohome's MountPublic method |
| 294 void MountPublic(const base::WeakPtr<AuthAttemptState>& attempt, | 291 void MountPublic(const base::WeakPtr<AuthAttemptState>& attempt, |
| 295 scoped_refptr<CryptohomeAuthenticator> resolver, | 292 scoped_refptr<CryptohomeAuthenticator> resolver, |
| 296 int flags) { | 293 int flags) { |
| 297 cryptohome::AsyncMethodCaller::GetInstance()->AsyncMountPublic( | 294 cryptohome::AsyncMethodCaller::GetInstance()->AsyncMountPublic( |
| 298 attempt->user_context.GetUserID(), | 295 attempt->user_context.GetAccountId().GetUserEmail(), flags, |
| 299 flags, | |
| 300 base::Bind(&TriggerResolveWithLoginTimeMarker, | 296 base::Bind(&TriggerResolveWithLoginTimeMarker, |
| 301 "CryptohomeMountPublic-End", | 297 "CryptohomeMountPublic-End", attempt, resolver)); |
| 302 attempt, | |
| 303 resolver)); | |
| 304 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( | 298 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( |
| 305 attempt->user_context.GetUserID(), | 299 attempt->user_context.GetAccountId().GetUserEmail(), |
| 306 base::Bind(&TriggerResolveHash, attempt, resolver)); | 300 base::Bind(&TriggerResolveHash, attempt, resolver)); |
| 307 } | 301 } |
| 308 | 302 |
| 309 // Calls cryptohome's key migration method. | 303 // Calls cryptohome's key migration method. |
| 310 void Migrate(const base::WeakPtr<AuthAttemptState>& attempt, | 304 void Migrate(const base::WeakPtr<AuthAttemptState>& attempt, |
| 311 scoped_refptr<CryptohomeAuthenticator> resolver, | 305 scoped_refptr<CryptohomeAuthenticator> resolver, |
| 312 bool passing_old_hash, | 306 bool passing_old_hash, |
| 313 const std::string& old_password, | 307 const std::string& old_password, |
| 314 const std::string& system_salt) { | 308 const std::string& system_salt) { |
| 315 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( | 309 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( |
| 316 "CryptohomeMigrate-Start", false); | 310 "CryptohomeMigrate-Start", false); |
| 317 cryptohome::AsyncMethodCaller* caller = | 311 cryptohome::AsyncMethodCaller* caller = |
| 318 cryptohome::AsyncMethodCaller::GetInstance(); | 312 cryptohome::AsyncMethodCaller::GetInstance(); |
| 319 | 313 |
| 320 // TODO(bartfab): Retrieve the hashing algorithm and salt to use for |old_key| | 314 // TODO(bartfab): Retrieve the hashing algorithm and salt to use for |old_key| |
| 321 // from cryptohomed. | 315 // from cryptohomed. |
| 322 scoped_ptr<Key> old_key = | 316 scoped_ptr<Key> old_key = |
| 323 TransformKeyIfNeeded(Key(old_password), system_salt); | 317 TransformKeyIfNeeded(Key(old_password), system_salt); |
| 324 scoped_ptr<Key> new_key = | 318 scoped_ptr<Key> new_key = |
| 325 TransformKeyIfNeeded(*attempt->user_context.GetKey(), system_salt); | 319 TransformKeyIfNeeded(*attempt->user_context.GetKey(), system_salt); |
| 326 if (passing_old_hash) { | 320 if (passing_old_hash) { |
| 327 caller->AsyncMigrateKey(attempt->user_context.GetUserID(), | 321 caller->AsyncMigrateKey( |
| 328 old_key->GetSecret(), | 322 attempt->user_context.GetAccountId().GetUserEmail(), |
| 329 new_key->GetSecret(), | 323 old_key->GetSecret(), new_key->GetSecret(), |
| 330 base::Bind(&TriggerResolveWithLoginTimeMarker, | 324 base::Bind(&TriggerResolveWithLoginTimeMarker, "CryptohomeMount-End", |
| 331 "CryptohomeMount-End", | 325 attempt, resolver)); |
| 332 attempt, | |
| 333 resolver)); | |
| 334 } else { | 326 } else { |
| 335 caller->AsyncMigrateKey(attempt->user_context.GetUserID(), | 327 caller->AsyncMigrateKey( |
| 336 new_key->GetSecret(), | 328 attempt->user_context.GetAccountId().GetUserEmail(), |
| 337 old_key->GetSecret(), | 329 new_key->GetSecret(), old_key->GetSecret(), |
| 338 base::Bind(&TriggerResolveWithLoginTimeMarker, | 330 base::Bind(&TriggerResolveWithLoginTimeMarker, "CryptohomeMount-End", |
| 339 "CryptohomeMount-End", | 331 attempt, resolver)); |
| 340 attempt, | |
| 341 resolver)); | |
| 342 } | 332 } |
| 343 } | 333 } |
| 344 | 334 |
| 345 // Calls cryptohome's remove method. | 335 // Calls cryptohome's remove method. |
| 346 void Remove(const base::WeakPtr<AuthAttemptState>& attempt, | 336 void Remove(const base::WeakPtr<AuthAttemptState>& attempt, |
| 347 scoped_refptr<CryptohomeAuthenticator> resolver) { | 337 scoped_refptr<CryptohomeAuthenticator> resolver) { |
| 348 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( | 338 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( |
| 349 "CryptohomeRemove-Start", false); | 339 "CryptohomeRemove-Start", false); |
| 350 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( | 340 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( |
| 351 attempt->user_context.GetUserID(), | 341 attempt->user_context.GetAccountId().GetUserEmail(), |
| 352 base::Bind(&TriggerResolveWithLoginTimeMarker, | 342 base::Bind(&TriggerResolveWithLoginTimeMarker, "CryptohomeRemove-End", |
| 353 "CryptohomeRemove-End", | 343 attempt, resolver)); |
| 354 attempt, | |
| 355 resolver)); | |
| 356 } | 344 } |
| 357 | 345 |
| 358 // Calls cryptohome's key check method. | 346 // Calls cryptohome's key check method. |
| 359 void CheckKey(const base::WeakPtr<AuthAttemptState>& attempt, | 347 void CheckKey(const base::WeakPtr<AuthAttemptState>& attempt, |
| 360 scoped_refptr<CryptohomeAuthenticator> resolver, | 348 scoped_refptr<CryptohomeAuthenticator> resolver, |
| 361 const std::string& system_salt) { | 349 const std::string& system_salt) { |
| 362 scoped_ptr<Key> key = | 350 scoped_ptr<Key> key = |
| 363 TransformKeyIfNeeded(*attempt->user_context.GetKey(), system_salt); | 351 TransformKeyIfNeeded(*attempt->user_context.GetKey(), system_salt); |
| 364 cryptohome::AsyncMethodCaller::GetInstance()->AsyncCheckKey( | 352 cryptohome::AsyncMethodCaller::GetInstance()->AsyncCheckKey( |
| 365 attempt->user_context.GetUserID(), | 353 attempt->user_context.GetAccountId().GetUserEmail(), key->GetSecret(), |
| 366 key->GetSecret(), | |
| 367 base::Bind(&TriggerResolve, attempt, resolver)); | 354 base::Bind(&TriggerResolve, attempt, resolver)); |
| 368 } | 355 } |
| 369 | 356 |
| 370 } // namespace | 357 } // namespace |
| 371 | 358 |
| 372 CryptohomeAuthenticator::CryptohomeAuthenticator( | 359 CryptohomeAuthenticator::CryptohomeAuthenticator( |
| 373 scoped_refptr<base::TaskRunner> task_runner, | 360 scoped_refptr<base::TaskRunner> task_runner, |
| 374 AuthStatusConsumer* consumer) | 361 AuthStatusConsumer* consumer) |
| 375 : Authenticator(consumer), | 362 : Authenticator(consumer), |
| 376 task_runner_(task_runner), | 363 task_runner_(task_runner), |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 Resolve(); | 872 Resolve(); |
| 886 } | 873 } |
| 887 | 874 |
| 888 void CryptohomeAuthenticator::SetOwnerState(bool owner_check_finished, | 875 void CryptohomeAuthenticator::SetOwnerState(bool owner_check_finished, |
| 889 bool check_result) { | 876 bool check_result) { |
| 890 owner_is_verified_ = owner_check_finished; | 877 owner_is_verified_ = owner_check_finished; |
| 891 user_can_login_ = check_result; | 878 user_can_login_ = check_result; |
| 892 } | 879 } |
| 893 | 880 |
| 894 } // namespace chromeos | 881 } // namespace chromeos |
| OLD | NEW |