Chromium Code Reviews| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 resolver->Resolve(); | 142 resolver->Resolve(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 // Calls cryptohome's MountEx() method. The key in |attempt->user_context| must | 145 // Calls cryptohome's MountEx() method. The key in |attempt->user_context| must |
| 146 // not be a plain text password. If the user provided a plain text password, | 146 // not be a plain text password. If the user provided a plain text password, |
| 147 // that password must be transformed to another key type (by salted hashing) | 147 // that password must be transformed to another key type (by salted hashing) |
| 148 // before calling this method. | 148 // before calling this method. |
| 149 void DoMount(const base::WeakPtr<AuthAttemptState>& attempt, | 149 void DoMount(const base::WeakPtr<AuthAttemptState>& attempt, |
| 150 scoped_refptr<CryptohomeAuthenticator> resolver, | 150 scoped_refptr<CryptohomeAuthenticator> resolver, |
| 151 bool ephemeral, | 151 bool ephemeral, |
| 152 bool create_if_nonexistent) { | 152 bool create_if_nonexistent, |
| 153 bool force_dircrypto_if_available) { | |
|
xiyuan
2017/04/05 21:15:11
I don't think we need this extra arg. |attempt| ho
fukino
2017/04/06 14:22:17
Done.
I didn't noticed that we can use |attempt|.
| |
| 153 const Key* key = attempt->user_context.GetKey(); | 154 const Key* key = attempt->user_context.GetKey(); |
| 154 // If the |key| is a plain text password, crash rather than attempting to | 155 // If the |key| is a plain text password, crash rather than attempting to |
| 155 // mount the cryptohome with a plain text password. | 156 // mount the cryptohome with a plain text password. |
| 156 CHECK_NE(Key::KEY_TYPE_PASSWORD_PLAIN, key->GetKeyType()); | 157 CHECK_NE(Key::KEY_TYPE_PASSWORD_PLAIN, key->GetKeyType()); |
| 157 | 158 |
| 158 // Set state that username_hash is requested here so that test implementation | 159 // Set state that username_hash is requested here so that test implementation |
| 159 // that returns directly would not generate 2 OnLoginSucces() calls. | 160 // that returns directly would not generate 2 OnLoginSucces() calls. |
| 160 attempt->UsernameHashRequested(); | 161 attempt->UsernameHashRequested(); |
| 161 | 162 |
| 162 // Set the authentication's key label to an empty string, which is a wildcard | 163 // Set the authentication's key label to an empty string, which is a wildcard |
| 163 // allowing any key to match. This is necessary because cryptohomes created by | 164 // allowing any key to match. This is necessary because cryptohomes created by |
| 164 // Chrome OS M38 and older will have a legacy key with no label while those | 165 // Chrome OS M38 and older will have a legacy key with no label while those |
| 165 // created by Chrome OS M39 and newer will have a key with the label | 166 // created by Chrome OS M39 and newer will have a key with the label |
| 166 // kCryptohomeGAIAKeyLabel. | 167 // kCryptohomeGAIAKeyLabel. |
| 167 const cryptohome::KeyDefinition auth_key(key->GetSecret(), | 168 const cryptohome::KeyDefinition auth_key(key->GetSecret(), |
| 168 std::string(), | 169 std::string(), |
| 169 cryptohome::PRIV_DEFAULT); | 170 cryptohome::PRIV_DEFAULT); |
| 170 cryptohome::MountParameters mount(ephemeral); | 171 cryptohome::MountParameters mount(ephemeral); |
| 171 if (create_if_nonexistent) { | 172 if (create_if_nonexistent) { |
| 172 mount.create_keys.push_back(cryptohome::KeyDefinition( | 173 mount.create_keys.push_back(cryptohome::KeyDefinition( |
| 173 key->GetSecret(), | 174 key->GetSecret(), |
| 174 kCryptohomeGAIAKeyLabel, | 175 kCryptohomeGAIAKeyLabel, |
| 175 cryptohome::PRIV_DEFAULT)); | 176 cryptohome::PRIV_DEFAULT)); |
| 176 } | 177 } |
| 178 mount.force_dircrypto_if_available = force_dircrypto_if_available; | |
| 177 | 179 |
| 178 cryptohome::HomedirMethods::GetInstance()->MountEx( | 180 cryptohome::HomedirMethods::GetInstance()->MountEx( |
| 179 cryptohome::Identification(attempt->user_context.GetAccountId()), | 181 cryptohome::Identification(attempt->user_context.GetAccountId()), |
| 180 cryptohome::Authorization(auth_key), mount, | 182 cryptohome::Authorization(auth_key), mount, |
| 181 base::Bind(&OnMount, attempt, resolver)); | 183 base::Bind(&OnMount, attempt, resolver)); |
| 182 } | 184 } |
| 183 | 185 |
| 184 // Handle cryptohome migration status. | 186 // Handle cryptohome migration status. |
| 185 void OnCryptohomeRenamed(const base::WeakPtr<AuthAttemptState>& attempt, | 187 void OnCryptohomeRenamed(const base::WeakPtr<AuthAttemptState>& attempt, |
| 186 scoped_refptr<CryptohomeAuthenticator> resolver, | 188 scoped_refptr<CryptohomeAuthenticator> resolver, |
| 187 bool ephemeral, | 189 bool ephemeral, |
| 188 bool create_if_nonexistent, | 190 bool create_if_nonexistent, |
| 191 bool force_dircrypto_if_available, | |
| 189 bool success, | 192 bool success, |
| 190 cryptohome::MountError return_code) { | 193 cryptohome::MountError return_code) { |
| 191 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( | 194 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( |
| 192 "CryptohomeRename-End", false); | 195 "CryptohomeRename-End", false); |
| 193 const AccountId account_id = attempt->user_context.GetAccountId(); | 196 const AccountId account_id = attempt->user_context.GetAccountId(); |
| 194 if (success) { | 197 if (success) { |
| 195 cryptohome::SetGaiaIdMigrationStatusDone(account_id); | 198 cryptohome::SetGaiaIdMigrationStatusDone(account_id); |
| 196 UMACryptohomeMigrationToGaiaId(CryptohomeMigrationToGaiaId::SUCCESS); | 199 UMACryptohomeMigrationToGaiaId(CryptohomeMigrationToGaiaId::SUCCESS); |
| 197 } else { | 200 } else { |
| 198 LOG(ERROR) << "Failed to rename cryptohome for account_id='" | 201 LOG(ERROR) << "Failed to rename cryptohome for account_id='" |
| 199 << account_id.Serialize() << "' (return_code=" << return_code | 202 << account_id.Serialize() << "' (return_code=" << return_code |
| 200 << ")"; | 203 << ")"; |
| 201 // If rename fails, we can still use legacy cryptohome identifier. | 204 // If rename fails, we can still use legacy cryptohome identifier. |
| 202 // Proceed to DoMount. | 205 // Proceed to DoMount. |
| 203 UMACryptohomeMigrationToGaiaId(CryptohomeMigrationToGaiaId::FAILURE); | 206 UMACryptohomeMigrationToGaiaId(CryptohomeMigrationToGaiaId::FAILURE); |
| 204 } | 207 } |
| 205 DoMount(attempt, resolver, ephemeral, create_if_nonexistent); | 208 DoMount(attempt, resolver, ephemeral, create_if_nonexistent, |
| 209 force_dircrypto_if_available); | |
| 206 } | 210 } |
| 207 | 211 |
| 208 // This method migrates cryptohome identifier to gaia id (if needed), | 212 // This method migrates cryptohome identifier to gaia id (if needed), |
| 209 // and then calls Mount. | 213 // and then calls Mount. |
| 210 void EnsureCryptohomeMigratedToGaiaId( | 214 void EnsureCryptohomeMigratedToGaiaId( |
| 211 const base::WeakPtr<AuthAttemptState>& attempt, | 215 const base::WeakPtr<AuthAttemptState>& attempt, |
| 212 scoped_refptr<CryptohomeAuthenticator> resolver, | 216 scoped_refptr<CryptohomeAuthenticator> resolver, |
| 213 bool ephemeral, | 217 bool ephemeral, |
| 214 bool create_if_nonexistent) { | 218 bool create_if_nonexistent, |
| 219 bool force_dircrypto_if_available) { | |
| 215 if (attempt->user_context.GetAccountId().GetAccountType() == | 220 if (attempt->user_context.GetAccountId().GetAccountType() == |
| 216 AccountType::ACTIVE_DIRECTORY) { | 221 AccountType::ACTIVE_DIRECTORY) { |
| 217 cryptohome::SetGaiaIdMigrationStatusDone( | 222 cryptohome::SetGaiaIdMigrationStatusDone( |
| 218 attempt->user_context.GetAccountId()); | 223 attempt->user_context.GetAccountId()); |
| 219 } | 224 } |
| 220 const bool is_gaiaid_migration_started = switches::IsGaiaIdMigrationStarted(); | 225 const bool is_gaiaid_migration_started = switches::IsGaiaIdMigrationStarted(); |
| 221 if (!is_gaiaid_migration_started) { | 226 if (!is_gaiaid_migration_started) { |
| 222 UMACryptohomeMigrationToGaiaId(CryptohomeMigrationToGaiaId::NOT_STARTED); | 227 UMACryptohomeMigrationToGaiaId(CryptohomeMigrationToGaiaId::NOT_STARTED); |
| 223 DoMount(attempt, resolver, ephemeral, create_if_nonexistent); | 228 DoMount(attempt, resolver, ephemeral, create_if_nonexistent, |
| 229 force_dircrypto_if_available); | |
| 224 return; | 230 return; |
| 225 } | 231 } |
| 226 const bool already_migrated = cryptohome::GetGaiaIdMigrationStatus( | 232 const bool already_migrated = cryptohome::GetGaiaIdMigrationStatus( |
| 227 attempt->user_context.GetAccountId()); | 233 attempt->user_context.GetAccountId()); |
| 228 const bool has_account_key = | 234 const bool has_account_key = |
| 229 attempt->user_context.GetAccountId().HasAccountIdKey(); | 235 attempt->user_context.GetAccountId().HasAccountIdKey(); |
| 230 | 236 |
| 231 bool need_migration = false; | 237 bool need_migration = false; |
| 232 if (!create_if_nonexistent && !already_migrated) { | 238 if (!create_if_nonexistent && !already_migrated) { |
| 233 if (has_account_key) { | 239 if (has_account_key) { |
| 234 need_migration = true; | 240 need_migration = true; |
| 235 } else { | 241 } else { |
| 236 LOG(WARNING) << "Account '" | 242 LOG(WARNING) << "Account '" |
| 237 << attempt->user_context.GetAccountId().Serialize() | 243 << attempt->user_context.GetAccountId().Serialize() |
| 238 << "' has no gaia id. Cryptohome migration skipped."; | 244 << "' has no gaia id. Cryptohome migration skipped."; |
| 239 } | 245 } |
| 240 } | 246 } |
| 241 if (need_migration) { | 247 if (need_migration) { |
| 242 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( | 248 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( |
| 243 "CryptohomeRename-Start", false); | 249 "CryptohomeRename-Start", false); |
| 244 const std::string& cryptohome_id_from = | 250 const std::string& cryptohome_id_from = |
| 245 attempt->user_context.GetAccountId().GetUserEmail(); // Migrated | 251 attempt->user_context.GetAccountId().GetUserEmail(); // Migrated |
| 246 const std::string cryptohome_id_to = | 252 const std::string cryptohome_id_to = |
| 247 attempt->user_context.GetAccountId().GetAccountIdKey(); | 253 attempt->user_context.GetAccountId().GetAccountIdKey(); |
| 248 | 254 |
| 249 cryptohome::HomedirMethods::GetInstance()->RenameCryptohome( | 255 cryptohome::HomedirMethods::GetInstance()->RenameCryptohome( |
| 250 cryptohome::Identification::FromString(cryptohome_id_from), | 256 cryptohome::Identification::FromString(cryptohome_id_from), |
| 251 cryptohome::Identification::FromString(cryptohome_id_to), | 257 cryptohome::Identification::FromString(cryptohome_id_to), |
| 252 base::Bind(&OnCryptohomeRenamed, attempt, resolver, ephemeral, | 258 base::Bind(&OnCryptohomeRenamed, attempt, resolver, ephemeral, |
| 253 create_if_nonexistent)); | 259 create_if_nonexistent, force_dircrypto_if_available)); |
| 254 return; | 260 return; |
| 255 } | 261 } |
| 256 if (!already_migrated && has_account_key) { | 262 if (!already_migrated && has_account_key) { |
| 257 // Mark new users migrated. | 263 // Mark new users migrated. |
| 258 cryptohome::SetGaiaIdMigrationStatusDone( | 264 cryptohome::SetGaiaIdMigrationStatusDone( |
| 259 attempt->user_context.GetAccountId()); | 265 attempt->user_context.GetAccountId()); |
| 260 } | 266 } |
| 261 if (already_migrated) { | 267 if (already_migrated) { |
| 262 UMACryptohomeMigrationToGaiaId( | 268 UMACryptohomeMigrationToGaiaId( |
| 263 CryptohomeMigrationToGaiaId::ALREADY_MIGRATED); | 269 CryptohomeMigrationToGaiaId::ALREADY_MIGRATED); |
| 264 } | 270 } |
| 265 | 271 |
| 266 DoMount(attempt, resolver, ephemeral, create_if_nonexistent); | 272 DoMount(attempt, resolver, ephemeral, create_if_nonexistent, |
| 273 force_dircrypto_if_available); | |
| 267 } | 274 } |
| 268 | 275 |
| 269 // Callback invoked when the system salt has been retrieved. Transforms the key | 276 // Callback invoked when the system salt has been retrieved. Transforms the key |
| 270 // in |attempt->user_context| using Chrome's default hashing algorithm and the | 277 // in |attempt->user_context| using Chrome's default hashing algorithm and the |
| 271 // system salt, then calls MountEx(). | 278 // system salt, then calls MountEx(). |
| 272 void OnGetSystemSalt(const base::WeakPtr<AuthAttemptState>& attempt, | 279 void OnGetSystemSalt(const base::WeakPtr<AuthAttemptState>& attempt, |
| 273 scoped_refptr<CryptohomeAuthenticator> resolver, | 280 scoped_refptr<CryptohomeAuthenticator> resolver, |
| 274 bool ephemeral, | 281 bool ephemeral, |
| 275 bool create_if_nonexistent, | 282 bool create_if_nonexistent, |
| 283 bool force_dircrypto_if_available, | |
| 276 const std::string& system_salt) { | 284 const std::string& system_salt) { |
| 277 DCHECK_EQ(Key::KEY_TYPE_PASSWORD_PLAIN, | 285 DCHECK_EQ(Key::KEY_TYPE_PASSWORD_PLAIN, |
| 278 attempt->user_context.GetKey()->GetKeyType()); | 286 attempt->user_context.GetKey()->GetKeyType()); |
| 279 | 287 |
| 280 attempt->user_context.GetKey()->Transform( | 288 attempt->user_context.GetKey()->Transform( |
| 281 Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, | 289 Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, |
| 282 system_salt); | 290 system_salt); |
| 283 | 291 |
| 284 EnsureCryptohomeMigratedToGaiaId(attempt, resolver, ephemeral, | 292 EnsureCryptohomeMigratedToGaiaId(attempt, resolver, ephemeral, |
| 285 create_if_nonexistent); | 293 create_if_nonexistent, |
| 294 force_dircrypto_if_available); | |
| 286 } | 295 } |
| 287 | 296 |
| 288 // Callback invoked when cryptohome's GetKeyDataEx() method has finished. | 297 // Callback invoked when cryptohome's GetKeyDataEx() method has finished. |
| 289 // * If GetKeyDataEx() returned metadata indicating the hashing algorithm and | 298 // * If GetKeyDataEx() returned metadata indicating the hashing algorithm and |
| 290 // salt that were used to generate the key for this user's cryptohome, | 299 // salt that were used to generate the key for this user's cryptohome, |
| 291 // transforms the key in |attempt->user_context| with the same parameters. | 300 // transforms the key in |attempt->user_context| with the same parameters. |
| 292 // * Otherwise, starts the retrieval of the system salt so that the key in | 301 // * Otherwise, starts the retrieval of the system salt so that the key in |
| 293 // |attempt->user_context| can be transformed with Chrome's default hashing | 302 // |attempt->user_context| can be transformed with Chrome's default hashing |
| 294 // algorithm and the system salt. | 303 // algorithm and the system salt. |
| 295 // The resulting key is then passed to cryptohome's MountEx(). | 304 // The resulting key is then passed to cryptohome's MountEx(). |
| 296 void OnGetKeyDataEx( | 305 void OnGetKeyDataEx( |
| 297 const base::WeakPtr<AuthAttemptState>& attempt, | 306 const base::WeakPtr<AuthAttemptState>& attempt, |
| 298 scoped_refptr<CryptohomeAuthenticator> resolver, | 307 scoped_refptr<CryptohomeAuthenticator> resolver, |
| 299 bool ephemeral, | 308 bool ephemeral, |
| 300 bool create_if_nonexistent, | 309 bool create_if_nonexistent, |
| 310 bool force_dircrypto_if_available, | |
| 301 bool success, | 311 bool success, |
| 302 cryptohome::MountError return_code, | 312 cryptohome::MountError return_code, |
| 303 const std::vector<cryptohome::KeyDefinition>& key_definitions) { | 313 const std::vector<cryptohome::KeyDefinition>& key_definitions) { |
| 304 if (success) { | 314 if (success) { |
| 305 if (key_definitions.size() == 1) { | 315 if (key_definitions.size() == 1) { |
| 306 const cryptohome::KeyDefinition& key_definition = key_definitions.front(); | 316 const cryptohome::KeyDefinition& key_definition = key_definitions.front(); |
| 307 DCHECK_EQ(kCryptohomeGAIAKeyLabel, key_definition.label); | 317 DCHECK_EQ(kCryptohomeGAIAKeyLabel, key_definition.label); |
| 308 | 318 |
| 309 // Extract the key type and salt from |key_definition|, if present. | 319 // Extract the key type and salt from |key_definition|, if present. |
| 310 std::unique_ptr<int64_t> type; | 320 std::unique_ptr<int64_t> type; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 335 if (!salt) { | 345 if (!salt) { |
| 336 LOGIN_LOG(ERROR) << "Missing salt."; | 346 LOGIN_LOG(ERROR) << "Missing salt."; |
| 337 RecordKeyErrorAndResolve(attempt, resolver); | 347 RecordKeyErrorAndResolve(attempt, resolver); |
| 338 return; | 348 return; |
| 339 } | 349 } |
| 340 | 350 |
| 341 attempt->user_context.GetKey()->Transform( | 351 attempt->user_context.GetKey()->Transform( |
| 342 static_cast<Key::KeyType>(*type), | 352 static_cast<Key::KeyType>(*type), |
| 343 *salt); | 353 *salt); |
| 344 EnsureCryptohomeMigratedToGaiaId(attempt, resolver, ephemeral, | 354 EnsureCryptohomeMigratedToGaiaId(attempt, resolver, ephemeral, |
| 345 create_if_nonexistent); | 355 create_if_nonexistent, |
| 356 force_dircrypto_if_available); | |
| 346 return; | 357 return; |
| 347 } | 358 } |
| 348 } else { | 359 } else { |
| 349 LOGIN_LOG(EVENT) << "GetKeyDataEx() returned " << key_definitions.size() | 360 LOGIN_LOG(EVENT) << "GetKeyDataEx() returned " << key_definitions.size() |
| 350 << " entries."; | 361 << " entries."; |
| 351 } | 362 } |
| 352 } | 363 } |
| 353 | 364 |
| 354 SystemSaltGetter::Get()->GetSystemSalt(base::Bind(&OnGetSystemSalt, | 365 SystemSaltGetter::Get()->GetSystemSalt( |
| 355 attempt, | 366 base::Bind(&OnGetSystemSalt, attempt, resolver, ephemeral, |
| 356 resolver, | 367 create_if_nonexistent, force_dircrypto_if_available)); |
| 357 ephemeral, | |
| 358 create_if_nonexistent)); | |
| 359 } | 368 } |
| 360 | 369 |
| 361 // Starts the process that will mount a user's cryptohome. | 370 // Starts the process that will mount a user's cryptohome. |
| 362 // * If the key in |attempt->user_context| is not a plain text password, | 371 // * If the key in |attempt->user_context| is not a plain text password, |
| 363 // cryptohome's MountEx() method is called directly with the key. | 372 // cryptohome's MountEx() method is called directly with the key. |
| 364 // * Otherwise, the key must be transformed (by salted hashing) before being | 373 // * Otherwise, the key must be transformed (by salted hashing) before being |
| 365 // passed to MountEx(). In that case, cryptohome's GetKeyDataEx() method is | 374 // passed to MountEx(). In that case, cryptohome's GetKeyDataEx() method is |
| 366 // called to retrieve metadata indicating the hashing algorithm and salt that | 375 // called to retrieve metadata indicating the hashing algorithm and salt that |
| 367 // were used to generate the key for this user's cryptohome and the key is | 376 // were used to generate the key for this user's cryptohome and the key is |
| 368 // transformed accordingly before calling MountEx(). | 377 // transformed accordingly before calling MountEx(). |
| 369 void StartMount(const base::WeakPtr<AuthAttemptState>& attempt, | 378 void StartMount(const base::WeakPtr<AuthAttemptState>& attempt, |
| 370 scoped_refptr<CryptohomeAuthenticator> resolver, | 379 scoped_refptr<CryptohomeAuthenticator> resolver, |
| 371 bool ephemeral, | 380 bool ephemeral, |
| 372 bool create_if_nonexistent) { | 381 bool create_if_nonexistent, |
| 382 bool force_dircrypto_if_available) { | |
| 373 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( | 383 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( |
| 374 "CryptohomeMount-Start", false); | 384 "CryptohomeMount-Start", false); |
| 375 | 385 |
| 376 if (attempt->user_context.GetKey()->GetKeyType() != | 386 if (attempt->user_context.GetKey()->GetKeyType() != |
| 377 Key::KEY_TYPE_PASSWORD_PLAIN) { | 387 Key::KEY_TYPE_PASSWORD_PLAIN) { |
| 378 EnsureCryptohomeMigratedToGaiaId(attempt, resolver, ephemeral, | 388 EnsureCryptohomeMigratedToGaiaId(attempt, resolver, ephemeral, |
| 379 create_if_nonexistent); | 389 create_if_nonexistent, |
| 390 force_dircrypto_if_available); | |
| 380 return; | 391 return; |
| 381 } | 392 } |
| 382 | 393 |
| 383 cryptohome::HomedirMethods::GetInstance()->GetKeyDataEx( | 394 cryptohome::HomedirMethods::GetInstance()->GetKeyDataEx( |
| 384 cryptohome::Identification(attempt->user_context.GetAccountId()), | 395 cryptohome::Identification(attempt->user_context.GetAccountId()), |
| 385 kCryptohomeGAIAKeyLabel, base::Bind(&OnGetKeyDataEx, attempt, resolver, | 396 kCryptohomeGAIAKeyLabel, |
| 386 ephemeral, create_if_nonexistent)); | 397 base::Bind(&OnGetKeyDataEx, attempt, resolver, ephemeral, |
| 398 create_if_nonexistent, force_dircrypto_if_available)); | |
| 387 } | 399 } |
| 388 | 400 |
| 389 // Calls cryptohome's mount method for guest and also get the user hash from | 401 // Calls cryptohome's mount method for guest and also get the user hash from |
| 390 // cryptohome. | 402 // cryptohome. |
| 391 void MountGuestAndGetHash(const base::WeakPtr<AuthAttemptState>& attempt, | 403 void MountGuestAndGetHash(const base::WeakPtr<AuthAttemptState>& attempt, |
| 392 scoped_refptr<CryptohomeAuthenticator> resolver) { | 404 scoped_refptr<CryptohomeAuthenticator> resolver) { |
| 393 attempt->UsernameHashRequested(); | 405 attempt->UsernameHashRequested(); |
| 394 cryptohome::AsyncMethodCaller::GetInstance()->AsyncMountGuest( | 406 cryptohome::AsyncMethodCaller::GetInstance()->AsyncMountGuest( |
| 395 base::Bind(&TriggerResolveWithLoginTimeMarker, | 407 base::Bind(&TriggerResolveWithLoginTimeMarker, |
| 396 "CryptohomeMount-End", | 408 "CryptohomeMount-End", |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 authentication_context_ = context; | 506 authentication_context_ = context; |
| 495 current_state_.reset(new AuthAttemptState(user_context, | 507 current_state_.reset(new AuthAttemptState(user_context, |
| 496 false, // unlock | 508 false, // unlock |
| 497 false, // online_complete | 509 false, // online_complete |
| 498 !IsKnownUser(user_context))); | 510 !IsKnownUser(user_context))); |
| 499 // Reset the verified flag. | 511 // Reset the verified flag. |
| 500 owner_is_verified_ = false; | 512 owner_is_verified_ = false; |
| 501 | 513 |
| 502 StartMount(current_state_->AsWeakPtr(), | 514 StartMount(current_state_->AsWeakPtr(), |
| 503 scoped_refptr<CryptohomeAuthenticator>(this), | 515 scoped_refptr<CryptohomeAuthenticator>(this), |
| 504 false /* ephemeral */, false /* create_if_nonexistent */); | 516 false /* ephemeral */, false /* create_if_nonexistent */, |
| 517 user_context.IsForcingDircrypto()); | |
| 505 } | 518 } |
| 506 | 519 |
| 507 void CryptohomeAuthenticator::CompleteLogin(content::BrowserContext* context, | 520 void CryptohomeAuthenticator::CompleteLogin(content::BrowserContext* context, |
| 508 const UserContext& user_context) { | 521 const UserContext& user_context) { |
| 509 DCHECK(user_context.GetUserType() == user_manager::USER_TYPE_REGULAR || | 522 DCHECK(user_context.GetUserType() == user_manager::USER_TYPE_REGULAR || |
| 510 user_context.GetUserType() == | 523 user_context.GetUserType() == |
| 511 user_manager::USER_TYPE_ACTIVE_DIRECTORY); | 524 user_manager::USER_TYPE_ACTIVE_DIRECTORY); |
| 512 authentication_context_ = context; | 525 authentication_context_ = context; |
| 513 current_state_.reset(new AuthAttemptState(user_context, | 526 current_state_.reset(new AuthAttemptState(user_context, |
| 514 true, // unlock | 527 true, // unlock |
| 515 false, // online_complete | 528 false, // online_complete |
| 516 !IsKnownUser(user_context))); | 529 !IsKnownUser(user_context))); |
| 517 | 530 |
| 518 // Reset the verified flag. | 531 // Reset the verified flag. |
| 519 owner_is_verified_ = false; | 532 owner_is_verified_ = false; |
| 520 | 533 |
| 521 StartMount(current_state_->AsWeakPtr(), | 534 StartMount(current_state_->AsWeakPtr(), |
| 522 scoped_refptr<CryptohomeAuthenticator>(this), | 535 scoped_refptr<CryptohomeAuthenticator>(this), |
| 523 false /* ephemeral */, false /* create_if_nonexistent */); | 536 false /* ephemeral */, false /* create_if_nonexistent */, |
| 537 user_context.IsForcingDircrypto()); | |
| 524 | 538 |
| 525 // For login completion from extension, we just need to resolve the current | 539 // For login completion from extension, we just need to resolve the current |
| 526 // auth attempt state, the rest of OAuth related tasks will be done in | 540 // auth attempt state, the rest of OAuth related tasks will be done in |
| 527 // parallel. | 541 // parallel. |
| 528 task_runner_->PostTask( | 542 task_runner_->PostTask( |
| 529 FROM_HERE, | 543 FROM_HERE, |
| 530 base::Bind(&CryptohomeAuthenticator::ResolveLoginCompletionStatus, this)); | 544 base::Bind(&CryptohomeAuthenticator::ResolveLoginCompletionStatus, this)); |
| 531 } | 545 } |
| 532 | 546 |
| 533 void CryptohomeAuthenticator::AuthenticateToUnlock( | 547 void CryptohomeAuthenticator::AuthenticateToUnlock( |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 550 DCHECK_EQ(user_manager::USER_TYPE_SUPERVISED, user_context.GetUserType()); | 564 DCHECK_EQ(user_manager::USER_TYPE_SUPERVISED, user_context.GetUserType()); |
| 551 | 565 |
| 552 // TODO(nkostylev): Pass proper value for |user_is_new| or remove (not used). | 566 // TODO(nkostylev): Pass proper value for |user_is_new| or remove (not used). |
| 553 current_state_.reset(new AuthAttemptState(user_context, | 567 current_state_.reset(new AuthAttemptState(user_context, |
| 554 false, // unlock | 568 false, // unlock |
| 555 false, // online_complete | 569 false, // online_complete |
| 556 false)); // user_is_new | 570 false)); // user_is_new |
| 557 remove_user_data_on_failure_ = false; | 571 remove_user_data_on_failure_ = false; |
| 558 StartMount(current_state_->AsWeakPtr(), | 572 StartMount(current_state_->AsWeakPtr(), |
| 559 scoped_refptr<CryptohomeAuthenticator>(this), | 573 scoped_refptr<CryptohomeAuthenticator>(this), |
| 560 false /* ephemeral */, false /* create_if_nonexistent */); | 574 false /* ephemeral */, false /* create_if_nonexistent */, |
| 575 user_context.IsForcingDircrypto()); | |
| 561 } | 576 } |
| 562 | 577 |
| 563 void CryptohomeAuthenticator::LoginOffTheRecord() { | 578 void CryptohomeAuthenticator::LoginOffTheRecord() { |
| 564 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 579 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 565 current_state_.reset( | 580 current_state_.reset( |
| 566 new AuthAttemptState(UserContext(user_manager::USER_TYPE_GUEST, | 581 new AuthAttemptState(UserContext(user_manager::USER_TYPE_GUEST, |
| 567 user_manager::GuestAccountId()), | 582 user_manager::GuestAccountId()), |
| 568 false, // unlock | 583 false, // unlock |
| 569 false, // online_complete | 584 false, // online_complete |
| 570 false)); // user_is_new | 585 false)); // user_is_new |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 581 | 596 |
| 582 current_state_.reset( | 597 current_state_.reset( |
| 583 new AuthAttemptState(user_context, | 598 new AuthAttemptState(user_context, |
| 584 false, // unlock | 599 false, // unlock |
| 585 false, // online_complete | 600 false, // online_complete |
| 586 false)); // user_is_new | 601 false)); // user_is_new |
| 587 remove_user_data_on_failure_ = false; | 602 remove_user_data_on_failure_ = false; |
| 588 ephemeral_mount_attempted_ = true; | 603 ephemeral_mount_attempted_ = true; |
| 589 StartMount(current_state_->AsWeakPtr(), | 604 StartMount(current_state_->AsWeakPtr(), |
| 590 scoped_refptr<CryptohomeAuthenticator>(this), true /* ephemeral */, | 605 scoped_refptr<CryptohomeAuthenticator>(this), true /* ephemeral */, |
| 591 true /* create_if_nonexistent */); | 606 true /* create_if_nonexistent */, |
| 607 user_context.IsForcingDircrypto()); | |
|
fukino
2017/04/05 15:59:56
If the cryptohome is ephemeral, IsForcingDircrypto
xiyuan
2017/04/05 21:15:11
IMHO, not making much sense to force dircrypto for
fukino
2017/04/06 14:22:17
I updated the code to use the UserContext in AuthA
| |
| 592 } | 608 } |
| 593 | 609 |
| 594 void CryptohomeAuthenticator::LoginAsKioskAccount( | 610 void CryptohomeAuthenticator::LoginAsKioskAccount( |
| 595 const AccountId& app_account_id, | 611 const AccountId& app_account_id, |
| 596 bool use_guest_mount) { | 612 bool use_guest_mount) { |
| 597 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 613 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 598 | 614 |
| 599 const AccountId& account_id = | 615 const AccountId& account_id = |
| 600 use_guest_mount ? user_manager::GuestAccountId() : app_account_id; | 616 use_guest_mount ? user_manager::GuestAccountId() : app_account_id; |
| 601 current_state_.reset(new AuthAttemptState( | 617 current_state_.reset(new AuthAttemptState( |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 793 base::Bind(&CryptohomeAuthenticator::OnAuthFailure, | 809 base::Bind(&CryptohomeAuthenticator::OnAuthFailure, |
| 794 this, | 810 this, |
| 795 *delayed_login_failure_)); | 811 *delayed_login_failure_)); |
| 796 break; | 812 break; |
| 797 case CREATE_NEW: | 813 case CREATE_NEW: |
| 798 create_if_nonexistent = true; | 814 create_if_nonexistent = true; |
| 799 case RECOVER_MOUNT: | 815 case RECOVER_MOUNT: |
| 800 current_state_->ResetCryptohomeStatus(); | 816 current_state_->ResetCryptohomeStatus(); |
| 801 StartMount(current_state_->AsWeakPtr(), | 817 StartMount(current_state_->AsWeakPtr(), |
| 802 scoped_refptr<CryptohomeAuthenticator>(this), | 818 scoped_refptr<CryptohomeAuthenticator>(this), |
| 803 false /*ephemeral*/, create_if_nonexistent); | 819 false /*ephemeral*/, create_if_nonexistent, |
| 820 false /*force_dircrypto_if_available*/); | |
| 804 break; | 821 break; |
| 805 case NEED_OLD_PW: | 822 case NEED_OLD_PW: |
| 806 task_runner_->PostTask( | 823 task_runner_->PostTask( |
| 807 FROM_HERE, | 824 FROM_HERE, |
| 808 base::Bind(&CryptohomeAuthenticator::OnPasswordChangeDetected, this)); | 825 base::Bind(&CryptohomeAuthenticator::OnPasswordChangeDetected, this)); |
| 809 break; | 826 break; |
| 810 case ONLINE_FAILED: | 827 case ONLINE_FAILED: |
| 811 case NEED_NEW_PW: | 828 case NEED_NEW_PW: |
| 812 case HAVE_NEW_PW: | 829 case HAVE_NEW_PW: |
| 813 NOTREACHED() << "Using obsolete ClientLogin code path."; | 830 NOTREACHED() << "Using obsolete ClientLogin code path."; |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1023 Resolve(); | 1040 Resolve(); |
| 1024 } | 1041 } |
| 1025 | 1042 |
| 1026 void CryptohomeAuthenticator::SetOwnerState(bool owner_check_finished, | 1043 void CryptohomeAuthenticator::SetOwnerState(bool owner_check_finished, |
| 1027 bool check_result) { | 1044 bool check_result) { |
| 1028 owner_is_verified_ = owner_check_finished; | 1045 owner_is_verified_ = owner_check_finished; |
| 1029 user_can_login_ = check_result; | 1046 user_can_login_ = check_result; |
| 1030 } | 1047 } |
| 1031 | 1048 |
| 1032 } // namespace chromeos | 1049 } // namespace chromeos |
| OLD | NEW |