| 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/extended_authenticator_impl.h" | 5 #include "chromeos/login/auth/extended_authenticator_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "chromeos/cryptohome/async_method_caller.h" | 10 #include "chromeos/cryptohome/async_method_caller.h" |
| 11 #include "chromeos/cryptohome/cryptohome_parameters.h" | 11 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 12 #include "chromeos/cryptohome/homedir_methods.h" | 12 #include "chromeos/cryptohome/homedir_methods.h" |
| 13 #include "chromeos/cryptohome/system_salt_getter.h" | 13 #include "chromeos/cryptohome/system_salt_getter.h" |
| 14 #include "chromeos/dbus/cryptohome_client.h" | 14 #include "chromeos/dbus/cryptohome_client.h" |
| 15 #include "chromeos/dbus/dbus_thread_manager.h" | 15 #include "chromeos/dbus/dbus_thread_manager.h" |
| 16 #include "chromeos/login/auth/auth_status_consumer.h" | 16 #include "chromeos/login/auth/auth_status_consumer.h" |
| 17 #include "chromeos/login/auth/key.h" | 17 #include "chromeos/login/auth/key.h" |
| 18 #include "chromeos/login/auth/user_context.h" | 18 #include "chromeos/login/auth/user_context.h" |
| 19 #include "chromeos/login_event_recorder.h" | 19 #include "chromeos/login_event_recorder.h" |
| 20 #include "components/signin/core/account_id/account_id.h" | |
| 21 #include "crypto/sha2.h" | 20 #include "crypto/sha2.h" |
| 22 #include "google_apis/gaia/gaia_auth_util.h" | 21 #include "google_apis/gaia/gaia_auth_util.h" |
| 23 | 22 |
| 24 namespace chromeos { | 23 namespace chromeos { |
| 25 | 24 |
| 26 namespace { | 25 namespace { |
| 27 | 26 |
| 28 void RecordStartMarker(const std::string& marker) { | 27 void RecordStartMarker(const std::string& marker) { |
| 29 std::string full_marker = "Cryptohome-"; | 28 std::string full_marker = "Cryptohome-"; |
| 30 full_marker.append(marker); | 29 full_marker.append(marker); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 const ResultCallback& success_callback) { | 84 const ResultCallback& success_callback) { |
| 86 RecordStartMarker("MountEx"); | 85 RecordStartMarker("MountEx"); |
| 87 | 86 |
| 88 std::string canonicalized = gaia::CanonicalizeEmail(user_id); | 87 std::string canonicalized = gaia::CanonicalizeEmail(user_id); |
| 89 cryptohome::Identification id(canonicalized); | 88 cryptohome::Identification id(canonicalized); |
| 90 cryptohome::Authorization auth(keys.front()); | 89 cryptohome::Authorization auth(keys.front()); |
| 91 cryptohome::MountParameters mount(false); | 90 cryptohome::MountParameters mount(false); |
| 92 for (size_t i = 0; i < keys.size(); i++) { | 91 for (size_t i = 0; i < keys.size(); i++) { |
| 93 mount.create_keys.push_back(keys[i]); | 92 mount.create_keys.push_back(keys[i]); |
| 94 } | 93 } |
| 95 UserContext context(AccountId::FromUserEmail(user_id)); | 94 UserContext context(user_id); |
| 96 Key key(keys.front().secret); | 95 Key key(keys.front().secret); |
| 97 key.SetLabel(keys.front().label); | 96 key.SetLabel(keys.front().label); |
| 98 context.SetKey(key); | 97 context.SetKey(key); |
| 99 | 98 |
| 100 cryptohome::HomedirMethods::GetInstance()->MountEx( | 99 cryptohome::HomedirMethods::GetInstance()->MountEx( |
| 101 id, | 100 id, |
| 102 auth, | 101 auth, |
| 103 mount, | 102 mount, |
| 104 base::Bind(&ExtendedAuthenticatorImpl::OnMountComplete, | 103 base::Bind(&ExtendedAuthenticatorImpl::OnMountComplete, |
| 105 this, | 104 this, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 it->Run(); | 179 it->Run(); |
| 181 } | 180 } |
| 182 system_salt_callbacks_.clear(); | 181 system_salt_callbacks_.clear(); |
| 183 } | 182 } |
| 184 | 183 |
| 185 void ExtendedAuthenticatorImpl::DoAuthenticateToMount( | 184 void ExtendedAuthenticatorImpl::DoAuthenticateToMount( |
| 186 const ResultCallback& success_callback, | 185 const ResultCallback& success_callback, |
| 187 const UserContext& user_context) { | 186 const UserContext& user_context) { |
| 188 RecordStartMarker("MountEx"); | 187 RecordStartMarker("MountEx"); |
| 189 | 188 |
| 190 const std::string canonicalized = | 189 std::string canonicalized = gaia::CanonicalizeEmail(user_context.GetUserID()); |
| 191 gaia::CanonicalizeEmail(user_context.GetAccountId().GetUserEmail()); | |
| 192 cryptohome::Identification id(canonicalized); | 190 cryptohome::Identification id(canonicalized); |
| 193 const Key* const key = user_context.GetKey(); | 191 const Key* const key = user_context.GetKey(); |
| 194 cryptohome::Authorization auth(key->GetSecret(), key->GetLabel()); | 192 cryptohome::Authorization auth(key->GetSecret(), key->GetLabel()); |
| 195 cryptohome::MountParameters mount(false); | 193 cryptohome::MountParameters mount(false); |
| 196 | 194 |
| 197 cryptohome::HomedirMethods::GetInstance()->MountEx( | 195 cryptohome::HomedirMethods::GetInstance()->MountEx( |
| 198 id, | 196 id, |
| 199 auth, | 197 auth, |
| 200 mount, | 198 mount, |
| 201 base::Bind(&ExtendedAuthenticatorImpl::OnMountComplete, | 199 base::Bind(&ExtendedAuthenticatorImpl::OnMountComplete, |
| 202 this, | 200 this, |
| 203 "MountEx", | 201 "MountEx", |
| 204 user_context, | 202 user_context, |
| 205 success_callback)); | 203 success_callback)); |
| 206 } | 204 } |
| 207 | 205 |
| 208 void ExtendedAuthenticatorImpl::DoAuthenticateToCheck( | 206 void ExtendedAuthenticatorImpl::DoAuthenticateToCheck( |
| 209 const base::Closure& success_callback, | 207 const base::Closure& success_callback, |
| 210 const UserContext& user_context) { | 208 const UserContext& user_context) { |
| 211 RecordStartMarker("CheckKeyEx"); | 209 RecordStartMarker("CheckKeyEx"); |
| 212 | 210 |
| 213 const std::string canonicalized = | 211 std::string canonicalized = gaia::CanonicalizeEmail(user_context.GetUserID()); |
| 214 gaia::CanonicalizeEmail(user_context.GetAccountId().GetUserEmail()); | |
| 215 cryptohome::Identification id(canonicalized); | 212 cryptohome::Identification id(canonicalized); |
| 216 const Key* const key = user_context.GetKey(); | 213 const Key* const key = user_context.GetKey(); |
| 217 cryptohome::Authorization auth(key->GetSecret(), key->GetLabel()); | 214 cryptohome::Authorization auth(key->GetSecret(), key->GetLabel()); |
| 218 | 215 |
| 219 cryptohome::HomedirMethods::GetInstance()->CheckKeyEx( | 216 cryptohome::HomedirMethods::GetInstance()->CheckKeyEx( |
| 220 id, | 217 id, |
| 221 auth, | 218 auth, |
| 222 base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, | 219 base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, |
| 223 this, | 220 this, |
| 224 "CheckKeyEx", | 221 "CheckKeyEx", |
| 225 user_context, | 222 user_context, |
| 226 success_callback)); | 223 success_callback)); |
| 227 } | 224 } |
| 228 | 225 |
| 229 void ExtendedAuthenticatorImpl::DoAddKey(const cryptohome::KeyDefinition& key, | 226 void ExtendedAuthenticatorImpl::DoAddKey(const cryptohome::KeyDefinition& key, |
| 230 bool replace_existing, | 227 bool replace_existing, |
| 231 const base::Closure& success_callback, | 228 const base::Closure& success_callback, |
| 232 const UserContext& user_context) { | 229 const UserContext& user_context) { |
| 233 RecordStartMarker("AddKeyEx"); | 230 RecordStartMarker("AddKeyEx"); |
| 234 | 231 |
| 235 const std::string canonicalized = | 232 std::string canonicalized = gaia::CanonicalizeEmail(user_context.GetUserID()); |
| 236 gaia::CanonicalizeEmail(user_context.GetAccountId().GetUserEmail()); | |
| 237 cryptohome::Identification id(canonicalized); | 233 cryptohome::Identification id(canonicalized); |
| 238 const Key* const auth_key = user_context.GetKey(); | 234 const Key* const auth_key = user_context.GetKey(); |
| 239 cryptohome::Authorization auth(auth_key->GetSecret(), auth_key->GetLabel()); | 235 cryptohome::Authorization auth(auth_key->GetSecret(), auth_key->GetLabel()); |
| 240 | 236 |
| 241 cryptohome::HomedirMethods::GetInstance()->AddKeyEx( | 237 cryptohome::HomedirMethods::GetInstance()->AddKeyEx( |
| 242 id, | 238 id, |
| 243 auth, | 239 auth, |
| 244 key, | 240 key, |
| 245 replace_existing, | 241 replace_existing, |
| 246 base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, | 242 base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, |
| 247 this, | 243 this, |
| 248 "AddKeyEx", | 244 "AddKeyEx", |
| 249 user_context, | 245 user_context, |
| 250 success_callback)); | 246 success_callback)); |
| 251 } | 247 } |
| 252 | 248 |
| 253 void ExtendedAuthenticatorImpl::DoUpdateKeyAuthorized( | 249 void ExtendedAuthenticatorImpl::DoUpdateKeyAuthorized( |
| 254 const cryptohome::KeyDefinition& key, | 250 const cryptohome::KeyDefinition& key, |
| 255 const std::string& signature, | 251 const std::string& signature, |
| 256 const base::Closure& success_callback, | 252 const base::Closure& success_callback, |
| 257 const UserContext& user_context) { | 253 const UserContext& user_context) { |
| 258 RecordStartMarker("UpdateKeyAuthorized"); | 254 RecordStartMarker("UpdateKeyAuthorized"); |
| 259 | 255 |
| 260 const std::string canonicalized = | 256 std::string canonicalized = gaia::CanonicalizeEmail(user_context.GetUserID()); |
| 261 gaia::CanonicalizeEmail(user_context.GetAccountId().GetUserEmail()); | |
| 262 cryptohome::Identification id(canonicalized); | 257 cryptohome::Identification id(canonicalized); |
| 263 const Key* const auth_key = user_context.GetKey(); | 258 const Key* const auth_key = user_context.GetKey(); |
| 264 cryptohome::Authorization auth(auth_key->GetSecret(), auth_key->GetLabel()); | 259 cryptohome::Authorization auth(auth_key->GetSecret(), auth_key->GetLabel()); |
| 265 | 260 |
| 266 cryptohome::HomedirMethods::GetInstance()->UpdateKeyEx( | 261 cryptohome::HomedirMethods::GetInstance()->UpdateKeyEx( |
| 267 id, | 262 id, |
| 268 auth, | 263 auth, |
| 269 key, | 264 key, |
| 270 signature, | 265 signature, |
| 271 base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, | 266 base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, |
| 272 this, | 267 this, |
| 273 "UpdateKeyAuthorized", | 268 "UpdateKeyAuthorized", |
| 274 user_context, | 269 user_context, |
| 275 success_callback)); | 270 success_callback)); |
| 276 } | 271 } |
| 277 | 272 |
| 278 void ExtendedAuthenticatorImpl::DoRemoveKey(const std::string& key_to_remove, | 273 void ExtendedAuthenticatorImpl::DoRemoveKey(const std::string& key_to_remove, |
| 279 const base::Closure& success_callback, | 274 const base::Closure& success_callback, |
| 280 const UserContext& user_context) { | 275 const UserContext& user_context) { |
| 281 RecordStartMarker("RemoveKeyEx"); | 276 RecordStartMarker("RemoveKeyEx"); |
| 282 | 277 |
| 283 const std::string canonicalized = | 278 std::string canonicalized = gaia::CanonicalizeEmail(user_context.GetUserID()); |
| 284 gaia::CanonicalizeEmail(user_context.GetAccountId().GetUserEmail()); | |
| 285 cryptohome::Identification id(canonicalized); | 279 cryptohome::Identification id(canonicalized); |
| 286 const Key* const auth_key = user_context.GetKey(); | 280 const Key* const auth_key = user_context.GetKey(); |
| 287 cryptohome::Authorization auth(auth_key->GetSecret(), auth_key->GetLabel()); | 281 cryptohome::Authorization auth(auth_key->GetSecret(), auth_key->GetLabel()); |
| 288 | 282 |
| 289 cryptohome::HomedirMethods::GetInstance()->RemoveKeyEx( | 283 cryptohome::HomedirMethods::GetInstance()->RemoveKeyEx( |
| 290 id, | 284 id, |
| 291 auth, | 285 auth, |
| 292 key_to_remove, | 286 key_to_remove, |
| 293 base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, | 287 base::Bind(&ExtendedAuthenticatorImpl::OnOperationComplete, |
| 294 this, | 288 this, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 if (consumer_) | 356 if (consumer_) |
| 363 consumer_->OnAuthenticationFailure(state); | 357 consumer_->OnAuthenticationFailure(state); |
| 364 | 358 |
| 365 if (old_consumer_) { | 359 if (old_consumer_) { |
| 366 AuthFailure failure(AuthFailure::UNLOCK_FAILED); | 360 AuthFailure failure(AuthFailure::UNLOCK_FAILED); |
| 367 old_consumer_->OnAuthFailure(failure); | 361 old_consumer_->OnAuthFailure(failure); |
| 368 } | 362 } |
| 369 } | 363 } |
| 370 | 364 |
| 371 } // namespace chromeos | 365 } // namespace chromeos |
| OLD | NEW |