| 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( | 151 cryptohome::Identification(attempt->user_context.GetUserID()), |
| 152 attempt->user_context.GetAccountId().GetUserEmail()), | 152 cryptohome::Authorization(auth_key), |
| 153 cryptohome::Authorization(auth_key), mount, | 153 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( | 269 cryptohome::Identification(attempt->user_context.GetUserID()), |
| 270 attempt->user_context.GetAccountId().GetUserEmail()), | 270 kCryptohomeGAIAKeyLabel, |
| 271 kCryptohomeGAIAKeyLabel, base::Bind(&OnGetKeyDataEx, attempt, resolver, | 271 base::Bind(&OnGetKeyDataEx, |
| 272 ephemeral, create_if_nonexistent)); | 272 attempt, |
| 273 resolver, |
| 274 ephemeral, |
| 275 create_if_nonexistent)); |
| 273 } | 276 } |
| 274 | 277 |
| 275 // Calls cryptohome's mount method for guest and also get the user hash from | 278 // Calls cryptohome's mount method for guest and also get the user hash from |
| 276 // cryptohome. | 279 // cryptohome. |
| 277 void MountGuestAndGetHash(const base::WeakPtr<AuthAttemptState>& attempt, | 280 void MountGuestAndGetHash(const base::WeakPtr<AuthAttemptState>& attempt, |
| 278 scoped_refptr<CryptohomeAuthenticator> resolver) { | 281 scoped_refptr<CryptohomeAuthenticator> resolver) { |
| 279 attempt->UsernameHashRequested(); | 282 attempt->UsernameHashRequested(); |
| 280 cryptohome::AsyncMethodCaller::GetInstance()->AsyncMountGuest( | 283 cryptohome::AsyncMethodCaller::GetInstance()->AsyncMountGuest( |
| 281 base::Bind(&TriggerResolveWithLoginTimeMarker, | 284 base::Bind(&TriggerResolveWithLoginTimeMarker, |
| 282 "CryptohomeMount-End", | 285 "CryptohomeMount-End", |
| 283 attempt, | 286 attempt, |
| 284 resolver)); | 287 resolver)); |
| 285 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( | 288 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( |
| 286 attempt->user_context.GetAccountId().GetUserEmail(), | 289 attempt->user_context.GetUserID(), |
| 287 base::Bind(&TriggerResolveHash, attempt, resolver)); | 290 base::Bind(&TriggerResolveHash, attempt, resolver)); |
| 288 } | 291 } |
| 289 | 292 |
| 290 // Calls cryptohome's MountPublic method | 293 // Calls cryptohome's MountPublic method |
| 291 void MountPublic(const base::WeakPtr<AuthAttemptState>& attempt, | 294 void MountPublic(const base::WeakPtr<AuthAttemptState>& attempt, |
| 292 scoped_refptr<CryptohomeAuthenticator> resolver, | 295 scoped_refptr<CryptohomeAuthenticator> resolver, |
| 293 int flags) { | 296 int flags) { |
| 294 cryptohome::AsyncMethodCaller::GetInstance()->AsyncMountPublic( | 297 cryptohome::AsyncMethodCaller::GetInstance()->AsyncMountPublic( |
| 295 attempt->user_context.GetAccountId().GetUserEmail(), flags, | 298 attempt->user_context.GetUserID(), |
| 299 flags, |
| 296 base::Bind(&TriggerResolveWithLoginTimeMarker, | 300 base::Bind(&TriggerResolveWithLoginTimeMarker, |
| 297 "CryptohomeMountPublic-End", attempt, resolver)); | 301 "CryptohomeMountPublic-End", |
| 302 attempt, |
| 303 resolver)); |
| 298 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( | 304 cryptohome::AsyncMethodCaller::GetInstance()->AsyncGetSanitizedUsername( |
| 299 attempt->user_context.GetAccountId().GetUserEmail(), | 305 attempt->user_context.GetUserID(), |
| 300 base::Bind(&TriggerResolveHash, attempt, resolver)); | 306 base::Bind(&TriggerResolveHash, attempt, resolver)); |
| 301 } | 307 } |
| 302 | 308 |
| 303 // Calls cryptohome's key migration method. | 309 // Calls cryptohome's key migration method. |
| 304 void Migrate(const base::WeakPtr<AuthAttemptState>& attempt, | 310 void Migrate(const base::WeakPtr<AuthAttemptState>& attempt, |
| 305 scoped_refptr<CryptohomeAuthenticator> resolver, | 311 scoped_refptr<CryptohomeAuthenticator> resolver, |
| 306 bool passing_old_hash, | 312 bool passing_old_hash, |
| 307 const std::string& old_password, | 313 const std::string& old_password, |
| 308 const std::string& system_salt) { | 314 const std::string& system_salt) { |
| 309 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( | 315 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( |
| 310 "CryptohomeMigrate-Start", false); | 316 "CryptohomeMigrate-Start", false); |
| 311 cryptohome::AsyncMethodCaller* caller = | 317 cryptohome::AsyncMethodCaller* caller = |
| 312 cryptohome::AsyncMethodCaller::GetInstance(); | 318 cryptohome::AsyncMethodCaller::GetInstance(); |
| 313 | 319 |
| 314 // TODO(bartfab): Retrieve the hashing algorithm and salt to use for |old_key| | 320 // TODO(bartfab): Retrieve the hashing algorithm and salt to use for |old_key| |
| 315 // from cryptohomed. | 321 // from cryptohomed. |
| 316 scoped_ptr<Key> old_key = | 322 scoped_ptr<Key> old_key = |
| 317 TransformKeyIfNeeded(Key(old_password), system_salt); | 323 TransformKeyIfNeeded(Key(old_password), system_salt); |
| 318 scoped_ptr<Key> new_key = | 324 scoped_ptr<Key> new_key = |
| 319 TransformKeyIfNeeded(*attempt->user_context.GetKey(), system_salt); | 325 TransformKeyIfNeeded(*attempt->user_context.GetKey(), system_salt); |
| 320 if (passing_old_hash) { | 326 if (passing_old_hash) { |
| 321 caller->AsyncMigrateKey( | 327 caller->AsyncMigrateKey(attempt->user_context.GetUserID(), |
| 322 attempt->user_context.GetAccountId().GetUserEmail(), | 328 old_key->GetSecret(), |
| 323 old_key->GetSecret(), new_key->GetSecret(), | 329 new_key->GetSecret(), |
| 324 base::Bind(&TriggerResolveWithLoginTimeMarker, "CryptohomeMount-End", | 330 base::Bind(&TriggerResolveWithLoginTimeMarker, |
| 325 attempt, resolver)); | 331 "CryptohomeMount-End", |
| 332 attempt, |
| 333 resolver)); |
| 326 } else { | 334 } else { |
| 327 caller->AsyncMigrateKey( | 335 caller->AsyncMigrateKey(attempt->user_context.GetUserID(), |
| 328 attempt->user_context.GetAccountId().GetUserEmail(), | 336 new_key->GetSecret(), |
| 329 new_key->GetSecret(), old_key->GetSecret(), | 337 old_key->GetSecret(), |
| 330 base::Bind(&TriggerResolveWithLoginTimeMarker, "CryptohomeMount-End", | 338 base::Bind(&TriggerResolveWithLoginTimeMarker, |
| 331 attempt, resolver)); | 339 "CryptohomeMount-End", |
| 340 attempt, |
| 341 resolver)); |
| 332 } | 342 } |
| 333 } | 343 } |
| 334 | 344 |
| 335 // Calls cryptohome's remove method. | 345 // Calls cryptohome's remove method. |
| 336 void Remove(const base::WeakPtr<AuthAttemptState>& attempt, | 346 void Remove(const base::WeakPtr<AuthAttemptState>& attempt, |
| 337 scoped_refptr<CryptohomeAuthenticator> resolver) { | 347 scoped_refptr<CryptohomeAuthenticator> resolver) { |
| 338 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( | 348 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( |
| 339 "CryptohomeRemove-Start", false); | 349 "CryptohomeRemove-Start", false); |
| 340 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( | 350 cryptohome::AsyncMethodCaller::GetInstance()->AsyncRemove( |
| 341 attempt->user_context.GetAccountId().GetUserEmail(), | 351 attempt->user_context.GetUserID(), |
| 342 base::Bind(&TriggerResolveWithLoginTimeMarker, "CryptohomeRemove-End", | 352 base::Bind(&TriggerResolveWithLoginTimeMarker, |
| 343 attempt, resolver)); | 353 "CryptohomeRemove-End", |
| 354 attempt, |
| 355 resolver)); |
| 344 } | 356 } |
| 345 | 357 |
| 346 // Calls cryptohome's key check method. | 358 // Calls cryptohome's key check method. |
| 347 void CheckKey(const base::WeakPtr<AuthAttemptState>& attempt, | 359 void CheckKey(const base::WeakPtr<AuthAttemptState>& attempt, |
| 348 scoped_refptr<CryptohomeAuthenticator> resolver, | 360 scoped_refptr<CryptohomeAuthenticator> resolver, |
| 349 const std::string& system_salt) { | 361 const std::string& system_salt) { |
| 350 scoped_ptr<Key> key = | 362 scoped_ptr<Key> key = |
| 351 TransformKeyIfNeeded(*attempt->user_context.GetKey(), system_salt); | 363 TransformKeyIfNeeded(*attempt->user_context.GetKey(), system_salt); |
| 352 cryptohome::AsyncMethodCaller::GetInstance()->AsyncCheckKey( | 364 cryptohome::AsyncMethodCaller::GetInstance()->AsyncCheckKey( |
| 353 attempt->user_context.GetAccountId().GetUserEmail(), key->GetSecret(), | 365 attempt->user_context.GetUserID(), |
| 366 key->GetSecret(), |
| 354 base::Bind(&TriggerResolve, attempt, resolver)); | 367 base::Bind(&TriggerResolve, attempt, resolver)); |
| 355 } | 368 } |
| 356 | 369 |
| 357 } // namespace | 370 } // namespace |
| 358 | 371 |
| 359 CryptohomeAuthenticator::CryptohomeAuthenticator( | 372 CryptohomeAuthenticator::CryptohomeAuthenticator( |
| 360 scoped_refptr<base::TaskRunner> task_runner, | 373 scoped_refptr<base::TaskRunner> task_runner, |
| 361 AuthStatusConsumer* consumer) | 374 AuthStatusConsumer* consumer) |
| 362 : Authenticator(consumer), | 375 : Authenticator(consumer), |
| 363 task_runner_(task_runner), | 376 task_runner_(task_runner), |
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 Resolve(); | 885 Resolve(); |
| 873 } | 886 } |
| 874 | 887 |
| 875 void CryptohomeAuthenticator::SetOwnerState(bool owner_check_finished, | 888 void CryptohomeAuthenticator::SetOwnerState(bool owner_check_finished, |
| 876 bool check_result) { | 889 bool check_result) { |
| 877 owner_is_verified_ = owner_check_finished; | 890 owner_is_verified_ = owner_check_finished; |
| 878 user_can_login_ = check_result; | 891 user_can_login_ = check_result; |
| 879 } | 892 } |
| 880 | 893 |
| 881 } // namespace chromeos | 894 } // namespace chromeos |
| OLD | NEW |