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/auth/chrome_cryptohome_authenticator.h" | 5 #include "chrome/browser/chromeos/login/auth/chrome_cryptohome_authenticator.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "chromeos/dbus/fake_cryptohome_client.h" | 38 #include "chromeos/dbus/fake_cryptohome_client.h" |
39 #include "chromeos/login/auth/key.h" | 39 #include "chromeos/login/auth/key.h" |
40 #include "chromeos/login/auth/mock_auth_status_consumer.h" | 40 #include "chromeos/login/auth/mock_auth_status_consumer.h" |
41 #include "chromeos/login/auth/mock_url_fetchers.h" | 41 #include "chromeos/login/auth/mock_url_fetchers.h" |
42 #include "chromeos/login/auth/test_attempt_state.h" | 42 #include "chromeos/login/auth/test_attempt_state.h" |
43 #include "chromeos/login/auth/user_context.h" | 43 #include "chromeos/login/auth/user_context.h" |
44 #include "chromeos/login/login_state.h" | 44 #include "chromeos/login/login_state.h" |
45 #include "components/ownership/mock_owner_key_util.h" | 45 #include "components/ownership/mock_owner_key_util.h" |
46 #include "components/user_manager/fake_user_manager.h" | 46 #include "components/user_manager/fake_user_manager.h" |
47 #include "content/public/test/test_browser_thread_bundle.h" | 47 #include "content/public/test/test_browser_thread_bundle.h" |
48 #include "crypto/nss_key_util.h" | |
49 #include "crypto/nss_util_internal.h" | 48 #include "crypto/nss_util_internal.h" |
50 #include "crypto/scoped_test_nss_chromeos_user.h" | 49 #include "crypto/scoped_test_nss_chromeos_user.h" |
51 #include "google_apis/gaia/mock_url_fetcher_factory.h" | 50 #include "google_apis/gaia/mock_url_fetcher_factory.h" |
52 #include "net/base/net_errors.h" | 51 #include "net/base/net_errors.h" |
53 #include "net/url_request/url_request_status.h" | 52 #include "net/url_request/url_request_status.h" |
54 #include "testing/gmock/include/gmock/gmock.h" | 53 #include "testing/gmock/include/gmock/gmock.h" |
55 #include "testing/gtest/include/gtest/gtest.h" | 54 #include "testing/gtest/include/gtest/gtest.h" |
56 #include "third_party/cros_system_api/dbus/service_constants.h" | 55 #include "third_party/cros_system_api/dbus/service_constants.h" |
57 #include "url/gurl.h" | 56 #include "url/gurl.h" |
58 | 57 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 0xf3, 0xec, 0xab, 0x41, 0x57, 0x1d, 0x5f, 0xed, 0xcf, 0x09, 0xf4, 0xcc, | 111 0xf3, 0xec, 0xab, 0x41, 0x57, 0x1d, 0x5f, 0xed, 0xcf, 0x09, 0xf4, 0xcc, |
113 0xbb, 0x52, 0x52, 0xe8, 0x46, 0xf5, 0xc5, 0x01, 0xa3, 0xd8, 0x24, 0xc0, | 112 0xbb, 0x52, 0x52, 0xe8, 0x46, 0xf5, 0xc5, 0x01, 0xa3, 0xd8, 0x24, 0xc0, |
114 0x15, 0xc5, 0x65, 0x50, 0x7d, 0xbd, 0x4e, 0x81, 0xb2, 0x28, 0x38, 0xf9, | 113 0x15, 0xc5, 0x65, 0x50, 0x7d, 0xbd, 0x4e, 0x81, 0xb2, 0x28, 0x38, 0xf9, |
115 0x3d, 0x3e, 0x2a, 0x68, 0xf7, 0x02, 0x03, 0x01, 0x00, 0x01}; | 114 0x3d, 0x3e, 0x2a, 0x68, 0xf7, 0x02, 0x03, 0x01, 0x00, 0x01}; |
116 | 115 |
117 std::vector<uint8> GetOwnerPublicKey() { | 116 std::vector<uint8> GetOwnerPublicKey() { |
118 return std::vector<uint8>(kOwnerPublicKey, | 117 return std::vector<uint8>(kOwnerPublicKey, |
119 kOwnerPublicKey + arraysize(kOwnerPublicKey)); | 118 kOwnerPublicKey + arraysize(kOwnerPublicKey)); |
120 } | 119 } |
121 | 120 |
122 bool CreateOwnerKeyInSlot(PK11SlotInfo* slot) { | 121 scoped_ptr<crypto::RSAPrivateKey> CreateOwnerKeyInSlot(PK11SlotInfo* slot) { |
123 const std::vector<uint8> key(kOwnerPrivateKey, | 122 const std::vector<uint8> key(kOwnerPrivateKey, |
124 kOwnerPrivateKey + arraysize(kOwnerPrivateKey)); | 123 kOwnerPrivateKey + arraysize(kOwnerPrivateKey)); |
125 return crypto::ImportNSSKeyFromPrivateKeyInfo(slot, key, | 124 return make_scoped_ptr( |
126 true /* permanent */); | 125 crypto::RSAPrivateKey::CreateSensitiveFromPrivateKeyInfo(slot, key)); |
127 } | 126 } |
128 | 127 |
129 } // namespace | 128 } // namespace |
130 | 129 |
131 class CryptohomeAuthenticatorTest : public testing::Test { | 130 class CryptohomeAuthenticatorTest : public testing::Test { |
132 public: | 131 public: |
133 CryptohomeAuthenticatorTest() | 132 CryptohomeAuthenticatorTest() |
134 : user_context_("me@nowhere.org"), | 133 : user_context_("me@nowhere.org"), |
135 user_manager_(new user_manager::FakeUserManager()), | 134 user_manager_(new user_manager::FakeUserManager()), |
136 user_manager_enabler_(user_manager_), | 135 user_manager_enabler_(user_manager_), |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 } | 465 } |
467 | 466 |
468 // Test the case that login switches to SafeMode and the Owner logs in, which | 467 // Test the case that login switches to SafeMode and the Owner logs in, which |
469 // should lead to a successful login. | 468 // should lead to a successful login. |
470 TEST_F(CryptohomeAuthenticatorTest, ResolveOwnerNeededSuccess) { | 469 TEST_F(CryptohomeAuthenticatorTest, ResolveOwnerNeededSuccess) { |
471 crypto::ScopedTestNSSChromeOSUser test_user_db(user_context_.GetUserIDHash()); | 470 crypto::ScopedTestNSSChromeOSUser test_user_db(user_context_.GetUserIDHash()); |
472 owner_key_util_->SetPublicKey(GetOwnerPublicKey()); | 471 owner_key_util_->SetPublicKey(GetOwnerPublicKey()); |
473 | 472 |
474 crypto::ScopedPK11Slot user_slot( | 473 crypto::ScopedPK11Slot user_slot( |
475 crypto::GetPublicSlotForChromeOSUser(user_context_.GetUserIDHash())); | 474 crypto::GetPublicSlotForChromeOSUser(user_context_.GetUserIDHash())); |
476 ASSERT_TRUE(CreateOwnerKeyInSlot(user_slot.get())); | 475 CreateOwnerKeyInSlot(user_slot.get()); |
477 | 476 |
478 profile_manager_.reset( | 477 profile_manager_.reset( |
479 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 478 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
480 ASSERT_TRUE(profile_manager_->SetUp()); | 479 ASSERT_TRUE(profile_manager_->SetUp()); |
481 | 480 |
482 ExpectLoginSuccess(user_context_); | 481 ExpectLoginSuccess(user_context_); |
483 | 482 |
484 // Set up state as though a cryptohome mount attempt has occurred | 483 // Set up state as though a cryptohome mount attempt has occurred |
485 // and succeeded but we are in safe mode and the current user is not owner. | 484 // and succeeded but we are in safe mode and the current user is not owner. |
486 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); | 485 state_->PresetCryptohomeStatus(true, cryptohome::MOUNT_ERROR_NONE); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 // salt. | 772 // salt. |
774 ExpectGetKeyDataExCall( | 773 ExpectGetKeyDataExCall( |
775 make_scoped_ptr(new int64(Key::KEY_TYPE_SALTED_SHA256)), | 774 make_scoped_ptr(new int64(Key::KEY_TYPE_SALTED_SHA256)), |
776 scoped_ptr<std::string>()); | 775 scoped_ptr<std::string>()); |
777 | 776 |
778 auth_->AuthenticateToLogin(NULL, user_context_); | 777 auth_->AuthenticateToLogin(NULL, user_context_); |
779 base::RunLoop().Run(); | 778 base::RunLoop().Run(); |
780 } | 779 } |
781 | 780 |
782 } // namespace chromeos | 781 } // namespace chromeos |
OLD | NEW |