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 | 8 |
| 9 #include "base/basictypes.h" |
9 #include "base/command_line.h" | 10 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
11 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/memory/scoped_vector.h" |
13 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/run_loop.h" |
14 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
15 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
16 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" | 19 #include "chrome/browser/chromeos/login/users/fake_user_manager.h" |
17 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 20 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
18 #include "chrome/browser/chromeos/ownership/owner_settings_service.h" | 21 #include "chrome/browser/chromeos/ownership/owner_settings_service.h" |
19 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" | 22 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" |
20 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 23 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
21 #include "chrome/browser/chromeos/settings/cros_settings.h" | 24 #include "chrome/browser/chromeos/settings/cros_settings.h" |
22 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | 25 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
23 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | 26 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
24 #include "chrome/test/base/testing_browser_process.h" | 27 #include "chrome/test/base/testing_browser_process.h" |
25 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" |
26 #include "chrome/test/base/testing_profile_manager.h" | 29 #include "chrome/test/base/testing_profile_manager.h" |
27 #include "chromeos/chromeos_switches.h" | 30 #include "chromeos/chromeos_switches.h" |
28 #include "chromeos/cryptohome/cryptohome_parameters.h" | 31 #include "chromeos/cryptohome/cryptohome_parameters.h" |
29 #include "chromeos/cryptohome/homedir_methods.h" | 32 #include "chromeos/cryptohome/homedir_methods.h" |
30 #include "chromeos/cryptohome/mock_async_method_caller.h" | 33 #include "chromeos/cryptohome/mock_async_method_caller.h" |
31 #include "chromeos/cryptohome/mock_homedir_methods.h" | 34 #include "chromeos/cryptohome/mock_homedir_methods.h" |
32 #include "chromeos/cryptohome/system_salt_getter.h" | 35 #include "chromeos/cryptohome/system_salt_getter.h" |
33 #include "chromeos/dbus/cros_disks_client.h" | 36 #include "chromeos/dbus/cros_disks_client.h" |
| 37 #include "chromeos/dbus/cryptohome/rpc.pb.h" |
34 #include "chromeos/dbus/dbus_thread_manager.h" | 38 #include "chromeos/dbus/dbus_thread_manager.h" |
35 #include "chromeos/dbus/fake_cryptohome_client.h" | 39 #include "chromeos/dbus/fake_cryptohome_client.h" |
36 #include "chromeos/login/auth/key.h" | 40 #include "chromeos/login/auth/key.h" |
37 #include "chromeos/login/auth/mock_auth_status_consumer.h" | 41 #include "chromeos/login/auth/mock_auth_status_consumer.h" |
38 #include "chromeos/login/auth/mock_url_fetchers.h" | 42 #include "chromeos/login/auth/mock_url_fetchers.h" |
39 #include "chromeos/login/auth/test_attempt_state.h" | 43 #include "chromeos/login/auth/test_attempt_state.h" |
40 #include "chromeos/login/auth/user_context.h" | 44 #include "chromeos/login/auth/user_context.h" |
41 #include "components/ownership/mock_owner_key_util.h" | 45 #include "components/ownership/mock_owner_key_util.h" |
42 #include "content/public/test/test_browser_thread_bundle.h" | 46 #include "content/public/test/test_browser_thread_bundle.h" |
43 #include "crypto/nss_util_internal.h" | 47 #include "crypto/nss_util_internal.h" |
44 #include "crypto/scoped_test_nss_chromeos_user.h" | 48 #include "crypto/scoped_test_nss_chromeos_user.h" |
45 #include "google_apis/gaia/mock_url_fetcher_factory.h" | 49 #include "google_apis/gaia/mock_url_fetcher_factory.h" |
46 #include "net/base/net_errors.h" | 50 #include "net/base/net_errors.h" |
47 #include "net/url_request/url_request_status.h" | 51 #include "net/url_request/url_request_status.h" |
48 #include "testing/gmock/include/gmock/gmock.h" | 52 #include "testing/gmock/include/gmock/gmock.h" |
49 #include "testing/gtest/include/gtest/gtest.h" | 53 #include "testing/gtest/include/gtest/gtest.h" |
50 #include "third_party/cros_system_api/dbus/service_constants.h" | 54 #include "third_party/cros_system_api/dbus/service_constants.h" |
51 #include "url/gurl.h" | 55 #include "url/gurl.h" |
52 | 56 |
53 using ::testing::Invoke; | 57 using ::testing::Invoke; |
54 using ::testing::Return; | 58 using ::testing::Return; |
| 59 using ::testing::WithArg; |
55 using ::testing::_; | 60 using ::testing::_; |
56 | 61 |
57 namespace chromeos { | 62 namespace chromeos { |
58 | 63 |
59 namespace { | 64 namespace { |
60 | 65 |
| 66 // Label under which the user's key is stored. |
| 67 const char kCryptohomeGAIAKeyLabel[] = "gaia"; |
| 68 |
| 69 // Salt used by pre-hashed key. |
| 70 const char kSalt[] = "SALT $$"; |
| 71 |
61 // An owner key in PKCS#8 PrivateKeyInfo for testing owner checks. | 72 // An owner key in PKCS#8 PrivateKeyInfo for testing owner checks. |
62 const uint8 kOwnerPrivateKey[] = { | 73 const uint8 kOwnerPrivateKey[] = { |
63 0x30, 0x82, 0x01, 0x53, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, | 74 0x30, 0x82, 0x01, 0x53, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, |
64 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, | 75 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, |
65 0x01, 0x3d, 0x30, 0x82, 0x01, 0x39, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, | 76 0x01, 0x3d, 0x30, 0x82, 0x01, 0x39, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, |
66 0xb4, 0xf5, 0xab, 0xfe, 0xd8, 0xf1, 0xcb, 0x5f, 0x8f, 0x48, 0x3e, 0xdf, | 77 0xb4, 0xf5, 0xab, 0xfe, 0xd8, 0xf1, 0xcb, 0x5f, 0x8f, 0x48, 0x3e, 0xdf, |
67 0x40, 0x8e, 0x2b, 0x15, 0x43, 0x6c, 0x67, 0x74, 0xa2, 0xcb, 0xe4, 0xf3, | 78 0x40, 0x8e, 0x2b, 0x15, 0x43, 0x6c, 0x67, 0x74, 0xa2, 0xcb, 0xe4, 0xf3, |
68 0xec, 0xab, 0x41, 0x57, 0x1d, 0x5f, 0xed, 0xcf, 0x09, 0xf4, 0xcc, 0xbb, | 79 0xec, 0xab, 0x41, 0x57, 0x1d, 0x5f, 0xed, 0xcf, 0x09, 0xf4, 0xcc, 0xbb, |
69 0x52, 0x52, 0xe8, 0x46, 0xf5, 0xc5, 0x01, 0xa3, 0xd8, 0x24, 0xc0, 0x15, | 80 0x52, 0x52, 0xe8, 0x46, 0xf5, 0xc5, 0x01, 0xa3, 0xd8, 0x24, 0xc0, 0x15, |
70 0xc5, 0x65, 0x50, 0x7d, 0xbd, 0x4e, 0x81, 0xb2, 0x28, 0x38, 0xf9, 0x3d, | 81 0xc5, 0x65, 0x50, 0x7d, 0xbd, 0x4e, 0x81, 0xb2, 0x28, 0x38, 0xf9, 0x3d, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 mock_homedir_methods_(NULL), | 136 mock_homedir_methods_(NULL), |
126 owner_key_util_(new ownership::MockOwnerKeyUtil) { | 137 owner_key_util_(new ownership::MockOwnerKeyUtil) { |
127 user_context_.SetKey(Key("fakepass")); | 138 user_context_.SetKey(Key("fakepass")); |
128 user_context_.SetUserIDHash("me_nowhere_com_hash"); | 139 user_context_.SetUserIDHash("me_nowhere_com_hash"); |
129 const user_manager::User* user = | 140 const user_manager::User* user = |
130 user_manager_->AddUser(user_context_.GetUserID()); | 141 user_manager_->AddUser(user_context_.GetUserID()); |
131 profile_.set_profile_name(user_context_.GetUserID()); | 142 profile_.set_profile_name(user_context_.GetUserID()); |
132 | 143 |
133 ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, &profile_); | 144 ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, &profile_); |
134 | 145 |
135 transformed_key_ = *user_context_.GetKey(); | 146 CreateTransformedKey(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, |
136 transformed_key_.Transform(Key::KEY_TYPE_SALTED_SHA256_TOP_HALF, | 147 SystemSaltGetter::ConvertRawSaltToHexString( |
137 SystemSaltGetter::ConvertRawSaltToHexString( | 148 FakeCryptohomeClient::GetStubSystemSalt())); |
138 FakeCryptohomeClient::GetStubSystemSalt())); | |
139 } | 149 } |
140 | 150 |
141 virtual ~CryptohomeAuthenticatorTest() {} | 151 virtual ~CryptohomeAuthenticatorTest() {} |
142 | 152 |
143 virtual void SetUp() { | 153 virtual void SetUp() { |
144 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kLoginManager); | 154 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kLoginManager); |
145 | 155 |
146 mock_caller_ = new cryptohome::MockAsyncMethodCaller; | 156 mock_caller_ = new cryptohome::MockAsyncMethodCaller; |
147 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_); | 157 cryptohome::AsyncMethodCaller::InitializeForTesting(mock_caller_); |
148 mock_homedir_methods_ = new cryptohome::MockHomedirMethods; | 158 mock_homedir_methods_ = new cryptohome::MockHomedirMethods; |
(...skipping 17 matching lines...) Expand all Loading... |
166 OwnerSettingsService::SetOwnerKeyUtilForTesting(NULL); | 176 OwnerSettingsService::SetOwnerKeyUtilForTesting(NULL); |
167 SystemSaltGetter::Shutdown(); | 177 SystemSaltGetter::Shutdown(); |
168 DBusThreadManager::Shutdown(); | 178 DBusThreadManager::Shutdown(); |
169 | 179 |
170 cryptohome::AsyncMethodCaller::Shutdown(); | 180 cryptohome::AsyncMethodCaller::Shutdown(); |
171 mock_caller_ = NULL; | 181 mock_caller_ = NULL; |
172 cryptohome::HomedirMethods::Shutdown(); | 182 cryptohome::HomedirMethods::Shutdown(); |
173 mock_homedir_methods_ = NULL; | 183 mock_homedir_methods_ = NULL; |
174 } | 184 } |
175 | 185 |
| 186 void CreateTransformedKey(Key::KeyType type, const std::string& salt) { |
| 187 user_context_with_transformed_key_ = user_context_; |
| 188 user_context_with_transformed_key_.GetKey()->Transform(type, salt); |
| 189 transformed_key_ = *user_context_with_transformed_key_.GetKey(); |
| 190 } |
| 191 |
176 base::FilePath PopulateTempFile(const char* data, int data_len) { | 192 base::FilePath PopulateTempFile(const char* data, int data_len) { |
177 base::FilePath out; | 193 base::FilePath out; |
178 FILE* tmp_file = base::CreateAndOpenTemporaryFile(&out); | 194 FILE* tmp_file = base::CreateAndOpenTemporaryFile(&out); |
179 EXPECT_NE(tmp_file, static_cast<FILE*>(NULL)); | 195 EXPECT_NE(tmp_file, static_cast<FILE*>(NULL)); |
180 EXPECT_EQ(base::WriteFile(out, data, data_len), data_len); | 196 EXPECT_EQ(base::WriteFile(out, data, data_len), data_len); |
181 EXPECT_TRUE(base::CloseFile(tmp_file)); | 197 EXPECT_TRUE(base::CloseFile(tmp_file)); |
182 return out; | 198 return out; |
183 } | 199 } |
184 | 200 |
185 // Allow test to fail and exit gracefully, even if OnAuthFailure() | 201 // Allow test to fail and exit gracefully, even if OnAuthFailure() |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 .WillOnce(Invoke(MockAuthStatusConsumer::OnGuestSuccessQuit)) | 249 .WillOnce(Invoke(MockAuthStatusConsumer::OnGuestSuccessQuit)) |
234 .RetiresOnSaturation(); | 250 .RetiresOnSaturation(); |
235 } | 251 } |
236 | 252 |
237 void ExpectPasswordChange() { | 253 void ExpectPasswordChange() { |
238 EXPECT_CALL(consumer_, OnPasswordChangeDetected()) | 254 EXPECT_CALL(consumer_, OnPasswordChangeDetected()) |
239 .WillOnce(Invoke(MockAuthStatusConsumer::OnMigrateQuit)) | 255 .WillOnce(Invoke(MockAuthStatusConsumer::OnMigrateQuit)) |
240 .RetiresOnSaturation(); | 256 .RetiresOnSaturation(); |
241 } | 257 } |
242 | 258 |
| 259 void ExpectGetKeyDataExCall(scoped_ptr<int64> key_type, |
| 260 scoped_ptr<std::string> salt) { |
| 261 key_data_.clear(); |
| 262 key_data_.push_back(new cryptohome::RetrievedKeyData( |
| 263 cryptohome::RetrievedKeyData::TYPE_PASSWORD, |
| 264 kCryptohomeGAIAKeyLabel, |
| 265 1)); |
| 266 key_data_.front()->privileges = cryptohome::PRIV_DEFAULT; |
| 267 key_data_.front()->authorization_types.push_back( |
| 268 cryptohome::RetrievedKeyData::AUTHORIZATION_TYPE_HMACSHA256); |
| 269 if (key_type) { |
| 270 scoped_ptr<cryptohome::RetrievedKeyData::ProviderData> provider_data( |
| 271 new cryptohome::RetrievedKeyData::ProviderData("type")); |
| 272 provider_data->number = key_type.Pass(); |
| 273 key_data_.front()->provider_data.push_back(provider_data.release()); |
| 274 } |
| 275 if (salt) { |
| 276 scoped_ptr<cryptohome::RetrievedKeyData::ProviderData> provider_data( |
| 277 new cryptohome::RetrievedKeyData::ProviderData("salt")); |
| 278 provider_data->bytes = salt.Pass(); |
| 279 key_data_.front()->provider_data.push_back(provider_data.release()); |
| 280 } |
| 281 EXPECT_CALL(*mock_homedir_methods_, GetKeyDataEx( |
| 282 cryptohome::Identification(user_context_.GetUserID()), |
| 283 kCryptohomeGAIAKeyLabel, |
| 284 _)) |
| 285 .WillOnce(WithArg<2>(Invoke( |
| 286 this, |
| 287 &CryptohomeAuthenticatorTest::InvokeGetDataExCallback))); |
| 288 } |
| 289 |
| 290 void ExpectMountExCall(bool expect_create_attempt) { |
| 291 const cryptohome::KeyDefinition auth_key(transformed_key_.GetSecret(), |
| 292 std::string(), |
| 293 cryptohome::PRIV_DEFAULT); |
| 294 cryptohome::MountParameters mount(false /* ephemeral */); |
| 295 if (expect_create_attempt) { |
| 296 mount.create_keys.push_back(cryptohome::KeyDefinition( |
| 297 transformed_key_.GetSecret(), |
| 298 kCryptohomeGAIAKeyLabel, |
| 299 cryptohome::PRIV_DEFAULT)); |
| 300 } |
| 301 EXPECT_CALL(*mock_homedir_methods_, |
| 302 MountEx(cryptohome::Identification(user_context_.GetUserID()), |
| 303 cryptohome::Authorization(auth_key), |
| 304 mount, |
| 305 _)) |
| 306 .Times(1) |
| 307 .RetiresOnSaturation(); |
| 308 } |
| 309 |
243 void RunResolve(CryptohomeAuthenticator* auth) { | 310 void RunResolve(CryptohomeAuthenticator* auth) { |
244 auth->Resolve(); | 311 auth->Resolve(); |
245 base::MessageLoop::current()->RunUntilIdle(); | 312 base::MessageLoop::current()->RunUntilIdle(); |
246 } | 313 } |
247 | 314 |
248 void SetAttemptState(CryptohomeAuthenticator* auth, TestAttemptState* state) { | 315 void SetAttemptState(CryptohomeAuthenticator* auth, TestAttemptState* state) { |
249 auth->set_attempt_state(state); | 316 auth->set_attempt_state(state); |
250 } | 317 } |
251 | 318 |
252 CryptohomeAuthenticator::AuthState SetAndResolveState( | 319 CryptohomeAuthenticator::AuthState SetAndResolveState( |
253 CryptohomeAuthenticator* auth, | 320 CryptohomeAuthenticator* auth, |
254 TestAttemptState* state) { | 321 TestAttemptState* state) { |
255 auth->set_attempt_state(state); | 322 auth->set_attempt_state(state); |
256 return auth->ResolveState(); | 323 return auth->ResolveState(); |
257 } | 324 } |
258 | 325 |
259 void SetOwnerState(bool owner_check_finished, bool check_result) { | 326 void SetOwnerState(bool owner_check_finished, bool check_result) { |
260 auth_->SetOwnerState(owner_check_finished, check_result); | 327 auth_->SetOwnerState(owner_check_finished, check_result); |
261 } | 328 } |
262 | 329 |
263 content::TestBrowserThreadBundle thread_bundle_; | 330 content::TestBrowserThreadBundle thread_bundle_; |
264 | 331 |
265 UserContext user_context_; | 332 UserContext user_context_; |
| 333 UserContext user_context_with_transformed_key_; |
266 Key transformed_key_; | 334 Key transformed_key_; |
267 | 335 |
| 336 ScopedVector<cryptohome::RetrievedKeyData> key_data_; |
| 337 |
268 ScopedDeviceSettingsTestHelper device_settings_test_helper_; | 338 ScopedDeviceSettingsTestHelper device_settings_test_helper_; |
269 ScopedTestCrosSettings test_cros_settings_; | 339 ScopedTestCrosSettings test_cros_settings_; |
270 | 340 |
271 TestingProfile profile_; | 341 TestingProfile profile_; |
272 scoped_ptr<TestingProfileManager> profile_manager_; | 342 scoped_ptr<TestingProfileManager> profile_manager_; |
273 FakeUserManager* user_manager_; | 343 FakeUserManager* user_manager_; |
274 ScopedUserManagerEnabler user_manager_enabler_; | 344 ScopedUserManagerEnabler user_manager_enabler_; |
275 | 345 |
276 cryptohome::MockAsyncMethodCaller* mock_caller_; | 346 cryptohome::MockAsyncMethodCaller* mock_caller_; |
277 cryptohome::MockHomedirMethods* mock_homedir_methods_; | 347 cryptohome::MockHomedirMethods* mock_homedir_methods_; |
278 | 348 |
279 MockAuthStatusConsumer consumer_; | 349 MockAuthStatusConsumer consumer_; |
280 | 350 |
281 scoped_refptr<CryptohomeAuthenticator> auth_; | 351 scoped_refptr<CryptohomeAuthenticator> auth_; |
282 scoped_ptr<TestAttemptState> state_; | 352 scoped_ptr<TestAttemptState> state_; |
283 FakeCryptohomeClient* fake_cryptohome_client_; | 353 FakeCryptohomeClient* fake_cryptohome_client_; |
284 | 354 |
285 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_; | 355 scoped_refptr<ownership::MockOwnerKeyUtil> owner_key_util_; |
| 356 |
| 357 private: |
| 358 void InvokeGetDataExCallback( |
| 359 const cryptohome::HomedirMethods::GetKeyDataCallback& callback) { |
| 360 callback.Run(true /* success */, |
| 361 cryptohome::MOUNT_ERROR_NONE, |
| 362 key_data_.Pass()); |
| 363 } |
286 }; | 364 }; |
287 | 365 |
288 TEST_F(CryptohomeAuthenticatorTest, OnAuthSuccess) { | 366 TEST_F(CryptohomeAuthenticatorTest, OnAuthSuccess) { |
289 EXPECT_CALL(consumer_, OnAuthSuccess(user_context_)) | 367 EXPECT_CALL(consumer_, OnAuthSuccess(user_context_)) |
290 .Times(1) | 368 .Times(1) |
291 .RetiresOnSaturation(); | 369 .RetiresOnSaturation(); |
292 | 370 |
293 SetAttemptState(auth_.get(), state_.release()); | 371 SetAttemptState(auth_.get(), state_.release()); |
294 auth_->OnAuthSuccess(); | 372 auth_->OnAuthSuccess(); |
295 } | 373 } |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 // Set up mock async method caller to respond as though a tmpfs mount | 604 // Set up mock async method caller to respond as though a tmpfs mount |
527 // attempt has occurred and failed. | 605 // attempt has occurred and failed. |
528 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE); | 606 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE); |
529 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_)).Times(1).RetiresOnSaturation(); | 607 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_)).Times(1).RetiresOnSaturation(); |
530 | 608 |
531 auth_->LoginRetailMode(); | 609 auth_->LoginRetailMode(); |
532 base::MessageLoop::current()->Run(); | 610 base::MessageLoop::current()->Run(); |
533 } | 611 } |
534 | 612 |
535 TEST_F(CryptohomeAuthenticatorTest, DriveDataResync) { | 613 TEST_F(CryptohomeAuthenticatorTest, DriveDataResync) { |
536 UserContext expected_user_context(user_context_); | 614 UserContext expected_user_context(user_context_with_transformed_key_); |
537 expected_user_context.SetUserIDHash( | 615 expected_user_context.SetUserIDHash( |
538 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); | 616 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); |
539 ExpectLoginSuccess(expected_user_context); | 617 ExpectLoginSuccess(expected_user_context); |
540 FailOnLoginFailure(); | 618 FailOnLoginFailure(); |
541 | 619 |
542 // Set up mock async method caller to respond successfully to a cryptohome | 620 // Set up mock async method caller to respond successfully to a cryptohome |
543 // remove attempt. | 621 // remove attempt. |
544 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 622 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
545 EXPECT_CALL(*mock_caller_, AsyncRemove(user_context_.GetUserID(), _)) | 623 EXPECT_CALL(*mock_caller_, AsyncRemove(user_context_.GetUserID(), _)) |
546 .Times(1) | 624 .Times(1) |
547 .RetiresOnSaturation(); | 625 .RetiresOnSaturation(); |
548 | 626 |
549 // Set up mock homedir methods to respond successfully to a cryptohome create | 627 // Set up mock homedir methods to respond successfully to a cryptohome create |
550 // attempt. | 628 // attempt. |
551 const cryptohome::KeyDefinition auth_key(transformed_key_.GetSecret(), | 629 ExpectGetKeyDataExCall(scoped_ptr<int64>(), scoped_ptr<std::string>()); |
552 std::string(), | 630 ExpectMountExCall(true /* expect_create_attempt */); |
553 cryptohome::PRIV_DEFAULT); | |
554 cryptohome::MountParameters mount(false /* ephemeral */); | |
555 mount.create_keys.push_back(cryptohome::KeyDefinition( | |
556 transformed_key_.GetSecret(), | |
557 "gaia", | |
558 cryptohome::PRIV_DEFAULT)); | |
559 EXPECT_CALL(*mock_homedir_methods_, | |
560 MountEx(cryptohome::Identification(user_context_.GetUserID()), | |
561 cryptohome::Authorization(auth_key), | |
562 mount, | |
563 _)) | |
564 .Times(1); | |
565 | 631 |
566 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); | 632 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); |
567 SetAttemptState(auth_.get(), state_.release()); | 633 SetAttemptState(auth_.get(), state_.release()); |
568 | 634 |
569 auth_->ResyncEncryptedData(); | 635 auth_->ResyncEncryptedData(); |
570 base::MessageLoop::current()->Run(); | 636 base::MessageLoop::current()->Run(); |
571 } | 637 } |
572 | 638 |
573 TEST_F(CryptohomeAuthenticatorTest, DriveResyncFail) { | 639 TEST_F(CryptohomeAuthenticatorTest, DriveResyncFail) { |
574 FailOnLoginSuccess(); | 640 FailOnLoginSuccess(); |
(...skipping 16 matching lines...) Expand all Loading... |
591 ExpectPasswordChange(); | 657 ExpectPasswordChange(); |
592 | 658 |
593 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); | 659 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); |
594 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); | 660 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); |
595 SetAttemptState(auth_.get(), state_.release()); | 661 SetAttemptState(auth_.get(), state_.release()); |
596 | 662 |
597 RunResolve(auth_.get()); | 663 RunResolve(auth_.get()); |
598 } | 664 } |
599 | 665 |
600 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecover) { | 666 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecover) { |
601 UserContext expected_user_context(user_context_); | 667 UserContext expected_user_context(user_context_with_transformed_key_); |
602 expected_user_context.SetUserIDHash( | 668 expected_user_context.SetUserIDHash( |
603 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); | 669 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); |
604 ExpectLoginSuccess(expected_user_context); | 670 ExpectLoginSuccess(expected_user_context); |
605 FailOnLoginFailure(); | 671 FailOnLoginFailure(); |
606 | 672 |
607 // Set up mock async method caller to respond successfully to a key migration. | 673 // Set up mock async method caller to respond successfully to a key migration. |
608 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 674 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
609 EXPECT_CALL( | 675 EXPECT_CALL( |
610 *mock_caller_, | 676 *mock_caller_, |
611 AsyncMigrateKey( | 677 AsyncMigrateKey( |
612 user_context_.GetUserID(), _, transformed_key_.GetSecret(), _)) | 678 user_context_.GetUserID(), _, transformed_key_.GetSecret(), _)) |
613 .Times(1) | 679 .Times(1) |
614 .RetiresOnSaturation(); | 680 .RetiresOnSaturation(); |
615 | 681 |
616 // Set up mock homedir methods to respond successfully to a cryptohome mount | 682 // Set up mock homedir methods to respond successfully to a cryptohome mount |
617 // attempt. | 683 // attempt. |
618 const cryptohome::KeyDefinition auth_key(transformed_key_.GetSecret(), | 684 ExpectGetKeyDataExCall(scoped_ptr<int64>(), scoped_ptr<std::string>()); |
619 std::string(), | 685 ExpectMountExCall(false /* expect_create_attempt */); |
620 cryptohome::PRIV_DEFAULT); | |
621 EXPECT_CALL(*mock_homedir_methods_, | |
622 MountEx(cryptohome::Identification(user_context_.GetUserID()), | |
623 cryptohome::Authorization(auth_key), | |
624 cryptohome::MountParameters(false /* ephemeral */), | |
625 _)); | |
626 | 686 |
627 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); | 687 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); |
628 SetAttemptState(auth_.get(), state_.release()); | 688 SetAttemptState(auth_.get(), state_.release()); |
629 | 689 |
630 auth_->RecoverEncryptedData(std::string()); | 690 auth_->RecoverEncryptedData(std::string()); |
631 base::MessageLoop::current()->Run(); | 691 base::MessageLoop::current()->Run(); |
632 } | 692 } |
633 | 693 |
634 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecoverButFail) { | 694 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecoverButFail) { |
635 FailOnLoginSuccess(); | 695 FailOnLoginSuccess(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 // an online auth attempt has completed successfully. | 729 // an online auth attempt has completed successfully. |
670 state_->PresetCryptohomeStatus(false, | 730 state_->PresetCryptohomeStatus(false, |
671 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); | 731 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); |
672 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); | 732 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); |
673 | 733 |
674 EXPECT_EQ(CryptohomeAuthenticator::CREATE_NEW, | 734 EXPECT_EQ(CryptohomeAuthenticator::CREATE_NEW, |
675 SetAndResolveState(auth_.get(), state_.release())); | 735 SetAndResolveState(auth_.get(), state_.release())); |
676 } | 736 } |
677 | 737 |
678 TEST_F(CryptohomeAuthenticatorTest, DriveCreateForNewUser) { | 738 TEST_F(CryptohomeAuthenticatorTest, DriveCreateForNewUser) { |
679 UserContext expected_user_context(user_context_); | 739 UserContext expected_user_context(user_context_with_transformed_key_); |
680 expected_user_context.SetUserIDHash( | 740 expected_user_context.SetUserIDHash( |
681 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); | 741 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); |
682 ExpectLoginSuccess(expected_user_context); | 742 ExpectLoginSuccess(expected_user_context); |
683 FailOnLoginFailure(); | 743 FailOnLoginFailure(); |
684 | 744 |
685 // Set up mock homedir methods to respond successfully to a cryptohome create | 745 // Set up mock homedir methods to respond successfully to a cryptohome create |
686 // attempt. | 746 // attempt. |
687 const cryptohome::KeyDefinition auth_key(transformed_key_.GetSecret(), | 747 ExpectGetKeyDataExCall(scoped_ptr<int64>(), scoped_ptr<std::string>()); |
688 std::string(), | 748 ExpectMountExCall(true /* expect_create_attempt */); |
689 cryptohome::PRIV_DEFAULT); | |
690 cryptohome::MountParameters mount(false /* ephemeral */); | |
691 mount.create_keys.push_back(cryptohome::KeyDefinition( | |
692 transformed_key_.GetSecret(), | |
693 "gaia", | |
694 cryptohome::PRIV_DEFAULT)); | |
695 EXPECT_CALL(*mock_homedir_methods_, | |
696 MountEx(cryptohome::Identification(user_context_.GetUserID()), | |
697 cryptohome::Authorization(auth_key), | |
698 mount, | |
699 _)); | |
700 | 749 |
701 // Set up state as though a cryptohome mount attempt has occurred | 750 // Set up state as though a cryptohome mount attempt has occurred |
702 // and been rejected because the user doesn't exist; additionally, | 751 // and been rejected because the user doesn't exist; additionally, |
703 // an online auth attempt has completed successfully. | 752 // an online auth attempt has completed successfully. |
704 state_->PresetCryptohomeStatus(false, | 753 state_->PresetCryptohomeStatus(false, |
705 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); | 754 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); |
706 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); | 755 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); |
707 SetAttemptState(auth_.get(), state_.release()); | 756 SetAttemptState(auth_.get(), state_.release()); |
708 | 757 |
709 RunResolve(auth_.get()); | 758 RunResolve(auth_.get()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 // key-check attempt. | 791 // key-check attempt. |
743 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 792 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
744 EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _)) | 793 EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _)) |
745 .Times(1) | 794 .Times(1) |
746 .RetiresOnSaturation(); | 795 .RetiresOnSaturation(); |
747 | 796 |
748 auth_->AuthenticateToUnlock(user_context_); | 797 auth_->AuthenticateToUnlock(user_context_); |
749 base::MessageLoop::current()->Run(); | 798 base::MessageLoop::current()->Run(); |
750 } | 799 } |
751 | 800 |
| 801 TEST_F(CryptohomeAuthenticatorTest, DriveLoginWithPreHashedPassword) { |
| 802 CreateTransformedKey(Key::KEY_TYPE_SALTED_SHA256, kSalt); |
| 803 |
| 804 UserContext expected_user_context(user_context_with_transformed_key_); |
| 805 expected_user_context.SetUserIDHash( |
| 806 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); |
| 807 ExpectLoginSuccess(expected_user_context); |
| 808 FailOnLoginFailure(); |
| 809 |
| 810 // Set up mock homedir methods to respond with key metadata indicating that a |
| 811 // pre-hashed key was used to create the cryptohome and allow a successful |
| 812 // mount when this pre-hashed key is used. |
| 813 |
| 814 ExpectGetKeyDataExCall( |
| 815 make_scoped_ptr(new int64(Key::KEY_TYPE_SALTED_SHA256)), |
| 816 make_scoped_ptr(new std::string(kSalt))); |
| 817 ExpectMountExCall(false /* expect_create_attempt */); |
| 818 |
| 819 auth_->AuthenticateToLogin(NULL, user_context_); |
| 820 base::RunLoop().Run(); |
| 821 } |
| 822 |
| 823 TEST_F(CryptohomeAuthenticatorTest, FailLoginWithMissingSalt) { |
| 824 CreateTransformedKey(Key::KEY_TYPE_SALTED_SHA256, kSalt); |
| 825 |
| 826 FailOnLoginSuccess(); |
| 827 ExpectLoginFailure(AuthFailure(AuthFailure::COULD_NOT_MOUNT_CRYPTOHOME)); |
| 828 |
| 829 // Set up mock homedir methods to respond with key metadata indicating that a |
| 830 // pre-hashed key was used to create the cryptohome but without the required |
| 831 // salt. |
| 832 ExpectGetKeyDataExCall( |
| 833 make_scoped_ptr(new int64(Key::KEY_TYPE_SALTED_SHA256)), |
| 834 scoped_ptr<std::string>()); |
| 835 |
| 836 auth_->AuthenticateToLogin(NULL, user_context_); |
| 837 base::RunLoop().Run(); |
| 838 } |
| 839 |
752 } // namespace chromeos | 840 } // namespace chromeos |
OLD | NEW |