| 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 "chrome/browser/chromeos/login/easy_unlock/easy_unlock_create_keys_oper
ation.h" | 5 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_create_keys_oper
ation.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 kEasyUnlockKeyPrivileges); | 347 kEasyUnlockKeyPrivileges); |
| 348 key_def.revision = kEasyUnlockKeyRevision; | 348 key_def.revision = kEasyUnlockKeyRevision; |
| 349 key_def.provider_data.push_back(cryptohome::KeyDefinition::ProviderData( | 349 key_def.provider_data.push_back(cryptohome::KeyDefinition::ProviderData( |
| 350 kEasyUnlockKeyMetaNameBluetoothAddress, device->bluetooth_address)); | 350 kEasyUnlockKeyMetaNameBluetoothAddress, device->bluetooth_address)); |
| 351 key_def.provider_data.push_back(cryptohome::KeyDefinition::ProviderData( | 351 key_def.provider_data.push_back(cryptohome::KeyDefinition::ProviderData( |
| 352 kEasyUnlockKeyMetaNamePsk, device->psk)); | 352 kEasyUnlockKeyMetaNamePsk, device->psk)); |
| 353 key_def.provider_data.push_back(cryptohome::KeyDefinition::ProviderData( | 353 key_def.provider_data.push_back(cryptohome::KeyDefinition::ProviderData( |
| 354 kEasyUnlockKeyMetaNamePubKey, device->public_key)); | 354 kEasyUnlockKeyMetaNamePubKey, device->public_key)); |
| 355 key_def.provider_data.push_back(cryptohome::KeyDefinition::ProviderData( | 355 key_def.provider_data.push_back(cryptohome::KeyDefinition::ProviderData( |
| 356 kEasyUnlockKeyMetaNameChallenge, device->challenge)); | 356 kEasyUnlockKeyMetaNameChallenge, device->challenge)); |
| 357 // TODO(xiyuan): Store wrapped secret when all pieces are in place. | |
| 358 key_def.provider_data.push_back(cryptohome::KeyDefinition::ProviderData( | 357 key_def.provider_data.push_back(cryptohome::KeyDefinition::ProviderData( |
| 359 kEasyUnlockKeyMetaNameWrappedSecret, challenge_creator_->user_key())); | 358 kEasyUnlockKeyMetaNameWrappedSecret, device->wrapped_secret)); |
| 360 | 359 |
| 361 // Add cryptohome key. | 360 // Add cryptohome key. |
| 362 std::string canonicalized = | 361 std::string canonicalized = |
| 363 gaia::CanonicalizeEmail(user_context_.GetUserID()); | 362 gaia::CanonicalizeEmail(user_context_.GetUserID()); |
| 364 cryptohome::Identification id(canonicalized); | 363 cryptohome::Identification id(canonicalized); |
| 365 const Key* const auth_key = user_context_.GetKey(); | 364 const Key* const auth_key = user_context_.GetKey(); |
| 366 cryptohome::Authorization auth(auth_key->GetSecret(), auth_key->GetLabel()); | 365 cryptohome::Authorization auth(auth_key->GetSecret(), auth_key->GetLabel()); |
| 367 cryptohome::HomedirMethods::GetInstance()->AddKeyEx( | 366 cryptohome::HomedirMethods::GetInstance()->AddKeyEx( |
| 368 id, | 367 id, |
| 369 auth, | 368 auth, |
| 370 key_def, | 369 key_def, |
| 371 true, // clobber | 370 true, // clobber |
| 372 base::Bind(&EasyUnlockCreateKeysOperation::OnKeyCreated, | 371 base::Bind(&EasyUnlockCreateKeysOperation::OnKeyCreated, |
| 373 weak_ptr_factory_.GetWeakPtr(), | 372 weak_ptr_factory_.GetWeakPtr(), |
| 374 index)); | 373 index, |
| 374 user_key)); |
| 375 } | 375 } |
| 376 | 376 |
| 377 void EasyUnlockCreateKeysOperation::OnKeyCreated( | 377 void EasyUnlockCreateKeysOperation::OnKeyCreated( |
| 378 size_t index, | 378 size_t index, |
| 379 const Key& user_key, |
| 379 bool success, | 380 bool success, |
| 380 cryptohome::MountError return_code) { | 381 cryptohome::MountError return_code) { |
| 381 DCHECK_EQ(key_creation_index_, index); | 382 DCHECK_EQ(key_creation_index_, index); |
| 382 | 383 |
| 383 if (!success) { | 384 if (!success) { |
| 384 LOG(ERROR) << "Easy unlock failed to create key, code=" << return_code; | 385 LOG(ERROR) << "Easy unlock failed to create key, code=" << return_code; |
| 385 callback_.Run(false); | 386 callback_.Run(false); |
| 386 return; | 387 return; |
| 387 } | 388 } |
| 388 | 389 |
| 390 // If the key associated with the current context changed (i.e. in the case |
| 391 // the current signin flow was Easy signin), update the user context. |
| 392 if (user_context_.GetAuthFlow() == UserContext::AUTH_FLOW_EASY_UNLOCK && |
| 393 user_context_.GetKey()->GetLabel() == |
| 394 EasyUnlockKeyManager::GetKeyLabel(key_creation_index_)) { |
| 395 user_context_.SetKey(user_key); |
| 396 } |
| 397 |
| 389 ++key_creation_index_; | 398 ++key_creation_index_; |
| 390 CreateKeyForDeviceAtIndex(key_creation_index_); | 399 CreateKeyForDeviceAtIndex(key_creation_index_); |
| 391 } | 400 } |
| 392 | 401 |
| 393 } // namespace chromeos | 402 } // namespace chromeos |
| OLD | NEW |