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 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "chromeos/chromeos_switches.h" | |
| 16 #include "chromeos/cryptohome/async_method_caller.h" | 17 #include "chromeos/cryptohome/async_method_caller.h" |
| 17 #include "chromeos/cryptohome/cryptohome_parameters.h" | 18 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 18 #include "chromeos/cryptohome/homedir_methods.h" | 19 #include "chromeos/cryptohome/homedir_methods.h" |
| 19 #include "chromeos/cryptohome/system_salt_getter.h" | 20 #include "chromeos/cryptohome/system_salt_getter.h" |
| 20 #include "chromeos/dbus/cryptohome_client.h" | 21 #include "chromeos/dbus/cryptohome_client.h" |
| 21 #include "chromeos/dbus/dbus_thread_manager.h" | 22 #include "chromeos/dbus/dbus_thread_manager.h" |
| 22 #include "chromeos/login/auth/auth_status_consumer.h" | 23 #include "chromeos/login/auth/auth_status_consumer.h" |
| 23 #include "chromeos/login/auth/key.h" | 24 #include "chromeos/login/auth/key.h" |
| 24 #include "chromeos/login/auth/user_context.h" | 25 #include "chromeos/login/auth/user_context.h" |
| 25 #include "chromeos/login/login_state.h" | 26 #include "chromeos/login/login_state.h" |
| 26 #include "chromeos/login/user_names.h" | 27 #include "chromeos/login/user_names.h" |
| 27 #include "chromeos/login_event_recorder.h" | 28 #include "chromeos/login_event_recorder.h" |
| 28 #include "components/device_event_log/device_event_log.h" | 29 #include "components/device_event_log/device_event_log.h" |
| 29 #include "components/signin/core/account_id/account_id.h" | 30 #include "components/signin/core/account_id/account_id.h" |
| 31 #include "components/user_manager/known_user.h" | |
| 30 #include "components/user_manager/user_type.h" | 32 #include "components/user_manager/user_type.h" |
| 31 #include "third_party/cros_system_api/dbus/service_constants.h" | 33 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 32 | 34 |
| 33 namespace chromeos { | 35 namespace chromeos { |
| 34 | 36 |
| 35 namespace { | 37 namespace { |
| 36 | 38 |
| 37 // The label used for the key derived from the user's GAIA credentials. | 39 // The label used for the key derived from the user's GAIA credentials. |
| 38 const char kCryptohomeGAIAKeyLabel[] = "gaia"; | 40 const char kCryptohomeGAIAKeyLabel[] = "gaia"; |
| 39 | 41 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 kCryptohomeGAIAKeyLabel, | 149 kCryptohomeGAIAKeyLabel, |
| 148 cryptohome::PRIV_DEFAULT)); | 150 cryptohome::PRIV_DEFAULT)); |
| 149 } | 151 } |
| 150 | 152 |
| 151 cryptohome::HomedirMethods::GetInstance()->MountEx( | 153 cryptohome::HomedirMethods::GetInstance()->MountEx( |
| 152 cryptohome::Identification(attempt->user_context.GetAccountId()), | 154 cryptohome::Identification(attempt->user_context.GetAccountId()), |
| 153 cryptohome::Authorization(auth_key), mount, | 155 cryptohome::Authorization(auth_key), mount, |
| 154 base::Bind(&OnMount, attempt, resolver)); | 156 base::Bind(&OnMount, attempt, resolver)); |
| 155 } | 157 } |
| 156 | 158 |
| 159 // Handle cryptohome migration status. | |
| 160 void OnCryptohomeRenamed(const base::WeakPtr<AuthAttemptState>& attempt, | |
| 161 scoped_refptr<CryptohomeAuthenticator> resolver, | |
| 162 bool ephemeral, | |
| 163 bool create_if_nonexistent, | |
| 164 bool success, | |
| 165 cryptohome::MountError return_code) { | |
| 166 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( | |
| 167 "CryptohomeRename-End", false); | |
| 168 const AccountId account_id = attempt->user_context.GetAccountId(); | |
| 169 if (success) { | |
| 170 cryptohome::SetGaiaIdMigrationStatusDone(account_id); | |
| 171 } else { | |
| 172 LOG(ERROR) << "Failed to rename cryptohome for account_id='" | |
| 173 << account_id.Serialize() << "' (return_code=" << return_code | |
| 174 << ")"; | |
| 175 } | |
| 176 | |
| 177 DoMount(attempt, resolver, ephemeral, create_if_nonexistent); | |
|
stevenjb
2016/02/26 16:48:20
Do we still want to call DoMount on failure? If so
Alexander Alekseev
2016/03/05 00:58:25
Done.
| |
| 178 } | |
| 179 | |
| 180 // This method migrates cryptohome identifier to gaia id (if needed), | |
| 181 // and then calls Mount. | |
| 182 void EnsureCryptohomeMigratedToGaiaId( | |
| 183 const base::WeakPtr<AuthAttemptState>& attempt, | |
| 184 scoped_refptr<CryptohomeAuthenticator> resolver, | |
| 185 bool ephemeral, | |
| 186 bool create_if_nonexistent) { | |
| 187 const bool is_gaiaid_migration_started = switches::IsGaiaIdMigrationStarted(); | |
| 188 if (!is_gaiaid_migration_started) { | |
| 189 DoMount(attempt, resolver, ephemeral, create_if_nonexistent); | |
| 190 return; | |
| 191 } | |
| 192 const bool already_migrated = cryptohome::GetGaiaIdMigrationStatus( | |
| 193 attempt->user_context.GetAccountId()); | |
| 194 const bool has_gaia_id = | |
| 195 !attempt->user_context.GetAccountId().GetGaiaId().empty(); | |
| 196 | |
| 197 bool need_migration = false; | |
| 198 if (!create_if_nonexistent && !already_migrated) { | |
| 199 if (has_gaia_id) { | |
| 200 need_migration = true; | |
| 201 } else { | |
| 202 LOG(WARNING) << "Account '" | |
| 203 << attempt->user_context.GetAccountId().Serialize() | |
| 204 << "' has no gaia id. Cryptohome migration skipped."; | |
| 205 } | |
| 206 } | |
| 207 if (need_migration) { | |
| 208 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( | |
| 209 "CryptohomeRename-Start", false); | |
| 210 const std::string& cryptohome_id_from = | |
| 211 attempt->user_context.GetAccountId().GetUserEmail(); // Migrated | |
| 212 const std::string cryptohome_id_to = | |
| 213 attempt->user_context.GetAccountId().GetGaiaIdKey(); | |
| 214 | |
| 215 cryptohome::HomedirMethods::GetInstance()->RenameCryptohome( | |
| 216 cryptohome::Identification::FromString(cryptohome_id_from), | |
| 217 cryptohome::Identification::FromString(cryptohome_id_to), | |
| 218 base::Bind(&OnCryptohomeRenamed, attempt, resolver, ephemeral, | |
| 219 create_if_nonexistent)); | |
| 220 return; | |
| 221 } | |
| 222 if (!already_migrated && has_gaia_id) { | |
| 223 // Mark new users migrated. | |
| 224 cryptohome::SetGaiaIdMigrationStatusDone( | |
| 225 attempt->user_context.GetAccountId()); | |
| 226 } | |
| 227 DoMount(attempt, resolver, ephemeral, create_if_nonexistent); | |
| 228 } | |
| 229 | |
| 157 // Callback invoked when the system salt has been retrieved. Transforms the key | 230 // 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 | 231 // in |attempt->user_context| using Chrome's default hashing algorithm and the |
| 159 // system salt, then calls MountEx(). | 232 // system salt, then calls MountEx(). |
| 160 void OnGetSystemSalt(const base::WeakPtr<AuthAttemptState>& attempt, | 233 void OnGetSystemSalt(const base::WeakPtr<AuthAttemptState>& attempt, |
| 161 scoped_refptr<CryptohomeAuthenticator> resolver, | 234 scoped_refptr<CryptohomeAuthenticator> resolver, |
| 162 bool ephemeral, | 235 bool ephemeral, |
| 163 bool create_if_nonexistent, | 236 bool create_if_nonexistent, |
| 164 const std::string& system_salt) { | 237 const std::string& system_salt) { |
| 165 DCHECK_EQ(Key::KEY_TYPE_PASSWORD_PLAIN, | 238 DCHECK_EQ(Key::KEY_TYPE_PASSWORD_PLAIN, |
| 166 attempt->user_context.GetKey()->GetKeyType()); | 239 attempt->user_context.GetKey()->GetKeyType()); |
| 167 | 240 |
| 168 attempt->user_context.GetKey()->Transform( | 241 attempt->user_context.GetKey()->Transform( |
| 169 Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, | 242 Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, |
| 170 system_salt); | 243 system_salt); |
| 171 | 244 |
| 172 DoMount(attempt, resolver, ephemeral, create_if_nonexistent); | 245 EnsureCryptohomeMigratedToGaiaId(attempt, resolver, ephemeral, |
| 246 create_if_nonexistent); | |
| 173 } | 247 } |
| 174 | 248 |
| 175 // Callback invoked when cryptohome's GetKeyDataEx() method has finished. | 249 // Callback invoked when cryptohome's GetKeyDataEx() method has finished. |
| 176 // * If GetKeyDataEx() returned metadata indicating the hashing algorithm and | 250 // * If GetKeyDataEx() returned metadata indicating the hashing algorithm and |
| 177 // salt that were used to generate the key for this user's cryptohome, | 251 // salt that were used to generate the key for this user's cryptohome, |
| 178 // transforms the key in |attempt->user_context| with the same parameters. | 252 // transforms the key in |attempt->user_context| with the same parameters. |
| 179 // * Otherwise, starts the retrieval of the system salt so that the key in | 253 // * Otherwise, starts the retrieval of the system salt so that the key in |
| 180 // |attempt->user_context| can be transformed with Chrome's default hashing | 254 // |attempt->user_context| can be transformed with Chrome's default hashing |
| 181 // algorithm and the system salt. | 255 // algorithm and the system salt. |
| 182 // The resulting key is then passed to cryptohome's MountEx(). | 256 // The resulting key is then passed to cryptohome's MountEx(). |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 | 295 |
| 222 if (!salt) { | 296 if (!salt) { |
| 223 LOGIN_LOG(ERROR) << "Missing salt."; | 297 LOGIN_LOG(ERROR) << "Missing salt."; |
| 224 RecordKeyErrorAndResolve(attempt, resolver); | 298 RecordKeyErrorAndResolve(attempt, resolver); |
| 225 return; | 299 return; |
| 226 } | 300 } |
| 227 | 301 |
| 228 attempt->user_context.GetKey()->Transform( | 302 attempt->user_context.GetKey()->Transform( |
| 229 static_cast<Key::KeyType>(*type), | 303 static_cast<Key::KeyType>(*type), |
| 230 *salt); | 304 *salt); |
| 231 DoMount(attempt, resolver, ephemeral, create_if_nonexistent); | 305 EnsureCryptohomeMigratedToGaiaId(attempt, resolver, ephemeral, |
| 306 create_if_nonexistent); | |
| 232 return; | 307 return; |
| 233 } | 308 } |
| 234 } else { | 309 } else { |
| 235 LOGIN_LOG(EVENT) << "GetKeyDataEx() returned " << key_definitions.size() | 310 LOGIN_LOG(EVENT) << "GetKeyDataEx() returned " << key_definitions.size() |
| 236 << " entries."; | 311 << " entries."; |
| 237 } | 312 } |
| 238 } | 313 } |
| 239 | 314 |
| 240 SystemSaltGetter::Get()->GetSystemSalt(base::Bind(&OnGetSystemSalt, | 315 SystemSaltGetter::Get()->GetSystemSalt(base::Bind(&OnGetSystemSalt, |
| 241 attempt, | 316 attempt, |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 254 // transformed accordingly before calling MountEx(). | 329 // transformed accordingly before calling MountEx(). |
| 255 void StartMount(const base::WeakPtr<AuthAttemptState>& attempt, | 330 void StartMount(const base::WeakPtr<AuthAttemptState>& attempt, |
| 256 scoped_refptr<CryptohomeAuthenticator> resolver, | 331 scoped_refptr<CryptohomeAuthenticator> resolver, |
| 257 bool ephemeral, | 332 bool ephemeral, |
| 258 bool create_if_nonexistent) { | 333 bool create_if_nonexistent) { |
| 259 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( | 334 chromeos::LoginEventRecorder::Get()->AddLoginTimeMarker( |
| 260 "CryptohomeMount-Start", false); | 335 "CryptohomeMount-Start", false); |
| 261 | 336 |
| 262 if (attempt->user_context.GetKey()->GetKeyType() != | 337 if (attempt->user_context.GetKey()->GetKeyType() != |
| 263 Key::KEY_TYPE_PASSWORD_PLAIN) { | 338 Key::KEY_TYPE_PASSWORD_PLAIN) { |
| 264 DoMount(attempt, resolver, ephemeral, create_if_nonexistent); | 339 EnsureCryptohomeMigratedToGaiaId(attempt, resolver, ephemeral, |
| 340 create_if_nonexistent); | |
| 265 return; | 341 return; |
| 266 } | 342 } |
| 267 | 343 |
| 268 cryptohome::HomedirMethods::GetInstance()->GetKeyDataEx( | 344 cryptohome::HomedirMethods::GetInstance()->GetKeyDataEx( |
| 269 cryptohome::Identification(attempt->user_context.GetAccountId()), | 345 cryptohome::Identification(attempt->user_context.GetAccountId()), |
| 270 kCryptohomeGAIAKeyLabel, base::Bind(&OnGetKeyDataEx, attempt, resolver, | 346 kCryptohomeGAIAKeyLabel, base::Bind(&OnGetKeyDataEx, attempt, resolver, |
| 271 ephemeral, create_if_nonexistent)); | 347 ephemeral, create_if_nonexistent)); |
| 272 } | 348 } |
| 273 | 349 |
| 274 // Calls cryptohome's mount method for guest and also get the user hash from | 350 // Calls cryptohome's mount method for guest and also get the user hash from |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 870 Resolve(); | 946 Resolve(); |
| 871 } | 947 } |
| 872 | 948 |
| 873 void CryptohomeAuthenticator::SetOwnerState(bool owner_check_finished, | 949 void CryptohomeAuthenticator::SetOwnerState(bool owner_check_finished, |
| 874 bool check_result) { | 950 bool check_result) { |
| 875 owner_is_verified_ = owner_check_finished; | 951 owner_is_verified_ = owner_check_finished; |
| 876 user_can_login_ = check_result; | 952 user_can_login_ = check_result; |
| 877 } | 953 } |
| 878 | 954 |
| 879 } // namespace chromeos | 955 } // namespace chromeos |
| OLD | NEW |