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/mock_owner_key_util.h" | 26 #include "chrome/browser/chromeos/settings/mock_owner_key_util.h" |
24 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | 27 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
25 #include "chrome/test/base/testing_browser_process.h" | 28 #include "chrome/test/base/testing_browser_process.h" |
26 #include "chrome/test/base/testing_profile.h" | 29 #include "chrome/test/base/testing_profile.h" |
27 #include "chrome/test/base/testing_profile_manager.h" | 30 #include "chrome/test/base/testing_profile_manager.h" |
28 #include "chromeos/chromeos_switches.h" | 31 #include "chromeos/chromeos_switches.h" |
29 #include "chromeos/cryptohome/cryptohome_parameters.h" | 32 #include "chromeos/cryptohome/cryptohome_parameters.h" |
30 #include "chromeos/cryptohome/homedir_methods.h" | 33 #include "chromeos/cryptohome/homedir_methods.h" |
31 #include "chromeos/cryptohome/mock_async_method_caller.h" | 34 #include "chromeos/cryptohome/mock_async_method_caller.h" |
32 #include "chromeos/cryptohome/mock_homedir_methods.h" | 35 #include "chromeos/cryptohome/mock_homedir_methods.h" |
33 #include "chromeos/cryptohome/system_salt_getter.h" | 36 #include "chromeos/cryptohome/system_salt_getter.h" |
34 #include "chromeos/dbus/cros_disks_client.h" | 37 #include "chromeos/dbus/cros_disks_client.h" |
38 #include "chromeos/dbus/cryptohome/rpc.pb.h" | |
35 #include "chromeos/dbus/dbus_thread_manager.h" | 39 #include "chromeos/dbus/dbus_thread_manager.h" |
36 #include "chromeos/dbus/fake_cryptohome_client.h" | 40 #include "chromeos/dbus/fake_cryptohome_client.h" |
37 #include "chromeos/login/auth/key.h" | 41 #include "chromeos/login/auth/key.h" |
38 #include "chromeos/login/auth/mock_auth_status_consumer.h" | 42 #include "chromeos/login/auth/mock_auth_status_consumer.h" |
39 #include "chromeos/login/auth/mock_url_fetchers.h" | 43 #include "chromeos/login/auth/mock_url_fetchers.h" |
40 #include "chromeos/login/auth/test_attempt_state.h" | 44 #include "chromeos/login/auth/test_attempt_state.h" |
41 #include "chromeos/login/auth/user_context.h" | 45 #include "chromeos/login/auth/user_context.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 MockOwnerKeyUtil) { | 137 owner_key_util_(new 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 .Times(1) | |
Darren Krahn
2014/08/28 17:52:52
nit: This can be removed. WillOnce() implies Times
bartfab (slow)
2014/08/29 08:30:02
Done.
| |
286 .WillOnce(WithArg<2>(Invoke( | |
287 this, | |
288 &CryptohomeAuthenticatorTest::InvokeGetDataExCallback))); | |
289 } | |
290 | |
291 void ExpectMountExCall(bool expect_create_attempt) { | |
292 const cryptohome::KeyDefinition auth_key(transformed_key_.GetSecret(), | |
293 std::string(), | |
294 cryptohome::PRIV_DEFAULT); | |
295 cryptohome::MountParameters mount(false /* ephemeral */); | |
296 if (expect_create_attempt) { | |
297 mount.create_keys.push_back(cryptohome::KeyDefinition( | |
298 transformed_key_.GetSecret(), | |
299 kCryptohomeGAIAKeyLabel, | |
300 cryptohome::PRIV_DEFAULT)); | |
301 } | |
302 EXPECT_CALL(*mock_homedir_methods_, | |
303 MountEx(cryptohome::Identification(user_context_.GetUserID()), | |
304 cryptohome::Authorization(auth_key), | |
305 mount, | |
306 _)) | |
307 .Times(1) | |
308 .RetiresOnSaturation(); | |
309 } | |
310 | |
243 void RunResolve(CryptohomeAuthenticator* auth) { | 311 void RunResolve(CryptohomeAuthenticator* auth) { |
244 auth->Resolve(); | 312 auth->Resolve(); |
245 base::MessageLoop::current()->RunUntilIdle(); | 313 base::MessageLoop::current()->RunUntilIdle(); |
246 } | 314 } |
247 | 315 |
248 void SetAttemptState(CryptohomeAuthenticator* auth, TestAttemptState* state) { | 316 void SetAttemptState(CryptohomeAuthenticator* auth, TestAttemptState* state) { |
249 auth->set_attempt_state(state); | 317 auth->set_attempt_state(state); |
250 } | 318 } |
251 | 319 |
252 CryptohomeAuthenticator::AuthState SetAndResolveState( | 320 CryptohomeAuthenticator::AuthState SetAndResolveState( |
253 CryptohomeAuthenticator* auth, | 321 CryptohomeAuthenticator* auth, |
254 TestAttemptState* state) { | 322 TestAttemptState* state) { |
255 auth->set_attempt_state(state); | 323 auth->set_attempt_state(state); |
256 return auth->ResolveState(); | 324 return auth->ResolveState(); |
257 } | 325 } |
258 | 326 |
259 void SetOwnerState(bool owner_check_finished, bool check_result) { | 327 void SetOwnerState(bool owner_check_finished, bool check_result) { |
260 auth_->SetOwnerState(owner_check_finished, check_result); | 328 auth_->SetOwnerState(owner_check_finished, check_result); |
261 } | 329 } |
262 | 330 |
263 content::TestBrowserThreadBundle thread_bundle_; | 331 content::TestBrowserThreadBundle thread_bundle_; |
264 | 332 |
265 UserContext user_context_; | 333 UserContext user_context_; |
334 UserContext user_context_with_transformed_key_; | |
266 Key transformed_key_; | 335 Key transformed_key_; |
267 | 336 |
337 ScopedVector<cryptohome::RetrievedKeyData> key_data_; | |
338 | |
268 ScopedDeviceSettingsTestHelper device_settings_test_helper_; | 339 ScopedDeviceSettingsTestHelper device_settings_test_helper_; |
269 ScopedTestCrosSettings test_cros_settings_; | 340 ScopedTestCrosSettings test_cros_settings_; |
270 | 341 |
271 TestingProfile profile_; | 342 TestingProfile profile_; |
272 scoped_ptr<TestingProfileManager> profile_manager_; | 343 scoped_ptr<TestingProfileManager> profile_manager_; |
273 FakeUserManager* user_manager_; | 344 FakeUserManager* user_manager_; |
274 ScopedUserManagerEnabler user_manager_enabler_; | 345 ScopedUserManagerEnabler user_manager_enabler_; |
275 | 346 |
276 cryptohome::MockAsyncMethodCaller* mock_caller_; | 347 cryptohome::MockAsyncMethodCaller* mock_caller_; |
277 cryptohome::MockHomedirMethods* mock_homedir_methods_; | 348 cryptohome::MockHomedirMethods* mock_homedir_methods_; |
278 | 349 |
279 MockAuthStatusConsumer consumer_; | 350 MockAuthStatusConsumer consumer_; |
280 | 351 |
281 scoped_refptr<CryptohomeAuthenticator> auth_; | 352 scoped_refptr<CryptohomeAuthenticator> auth_; |
282 scoped_ptr<TestAttemptState> state_; | 353 scoped_ptr<TestAttemptState> state_; |
283 FakeCryptohomeClient* fake_cryptohome_client_; | 354 FakeCryptohomeClient* fake_cryptohome_client_; |
284 | 355 |
285 scoped_refptr<MockOwnerKeyUtil> owner_key_util_; | 356 scoped_refptr<MockOwnerKeyUtil> owner_key_util_; |
357 | |
358 private: | |
359 void InvokeGetDataExCallback( | |
360 const cryptohome::HomedirMethods::GetKeyDataCallback& callback) { | |
361 callback.Run(true /* success */, | |
362 cryptohome::MOUNT_ERROR_NONE, | |
363 key_data_.Pass()); | |
364 } | |
286 }; | 365 }; |
287 | 366 |
288 TEST_F(CryptohomeAuthenticatorTest, OnAuthSuccess) { | 367 TEST_F(CryptohomeAuthenticatorTest, OnAuthSuccess) { |
289 EXPECT_CALL(consumer_, OnAuthSuccess(user_context_)) | 368 EXPECT_CALL(consumer_, OnAuthSuccess(user_context_)) |
290 .Times(1) | 369 .Times(1) |
291 .RetiresOnSaturation(); | 370 .RetiresOnSaturation(); |
292 | 371 |
293 SetAttemptState(auth_.get(), state_.release()); | 372 SetAttemptState(auth_.get(), state_.release()); |
294 auth_->OnAuthSuccess(); | 373 auth_->OnAuthSuccess(); |
295 } | 374 } |
(...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 | 605 // Set up mock async method caller to respond as though a tmpfs mount |
527 // attempt has occurred and failed. | 606 // attempt has occurred and failed. |
528 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE); | 607 mock_caller_->SetUp(false, cryptohome::MOUNT_ERROR_NONE); |
529 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_)).Times(1).RetiresOnSaturation(); | 608 EXPECT_CALL(*mock_caller_, AsyncMountGuest(_)).Times(1).RetiresOnSaturation(); |
530 | 609 |
531 auth_->LoginRetailMode(); | 610 auth_->LoginRetailMode(); |
532 base::MessageLoop::current()->Run(); | 611 base::MessageLoop::current()->Run(); |
533 } | 612 } |
534 | 613 |
535 TEST_F(CryptohomeAuthenticatorTest, DriveDataResync) { | 614 TEST_F(CryptohomeAuthenticatorTest, DriveDataResync) { |
536 UserContext expected_user_context(user_context_); | 615 UserContext expected_user_context(user_context_with_transformed_key_); |
537 expected_user_context.SetUserIDHash( | 616 expected_user_context.SetUserIDHash( |
538 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); | 617 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); |
539 ExpectLoginSuccess(expected_user_context); | 618 ExpectLoginSuccess(expected_user_context); |
540 FailOnLoginFailure(); | 619 FailOnLoginFailure(); |
541 | 620 |
542 // Set up mock async method caller to respond successfully to a cryptohome | 621 // Set up mock async method caller to respond successfully to a cryptohome |
543 // remove attempt. | 622 // remove attempt. |
544 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 623 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
545 EXPECT_CALL(*mock_caller_, AsyncRemove(user_context_.GetUserID(), _)) | 624 EXPECT_CALL(*mock_caller_, AsyncRemove(user_context_.GetUserID(), _)) |
546 .Times(1) | 625 .Times(1) |
547 .RetiresOnSaturation(); | 626 .RetiresOnSaturation(); |
548 | 627 |
549 // Set up mock homedir methods to respond successfully to a cryptohome create | 628 // Set up mock homedir methods to respond successfully to a cryptohome create |
550 // attempt. | 629 // attempt. |
551 const cryptohome::KeyDefinition auth_key(transformed_key_.GetSecret(), | 630 ExpectGetKeyDataExCall(scoped_ptr<int64>(), scoped_ptr<std::string>()); |
552 std::string(), | 631 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 | 632 |
566 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); | 633 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); |
567 SetAttemptState(auth_.get(), state_.release()); | 634 SetAttemptState(auth_.get(), state_.release()); |
568 | 635 |
569 auth_->ResyncEncryptedData(); | 636 auth_->ResyncEncryptedData(); |
570 base::MessageLoop::current()->Run(); | 637 base::MessageLoop::current()->Run(); |
571 } | 638 } |
572 | 639 |
573 TEST_F(CryptohomeAuthenticatorTest, DriveResyncFail) { | 640 TEST_F(CryptohomeAuthenticatorTest, DriveResyncFail) { |
574 FailOnLoginSuccess(); | 641 FailOnLoginSuccess(); |
(...skipping 16 matching lines...) Expand all Loading... | |
591 ExpectPasswordChange(); | 658 ExpectPasswordChange(); |
592 | 659 |
593 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); | 660 state_->PresetCryptohomeStatus(false, cryptohome::MOUNT_ERROR_KEY_FAILURE); |
594 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); | 661 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); |
595 SetAttemptState(auth_.get(), state_.release()); | 662 SetAttemptState(auth_.get(), state_.release()); |
596 | 663 |
597 RunResolve(auth_.get()); | 664 RunResolve(auth_.get()); |
598 } | 665 } |
599 | 666 |
600 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecover) { | 667 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecover) { |
601 UserContext expected_user_context(user_context_); | 668 UserContext expected_user_context(user_context_with_transformed_key_); |
602 expected_user_context.SetUserIDHash( | 669 expected_user_context.SetUserIDHash( |
603 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); | 670 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); |
604 ExpectLoginSuccess(expected_user_context); | 671 ExpectLoginSuccess(expected_user_context); |
605 FailOnLoginFailure(); | 672 FailOnLoginFailure(); |
606 | 673 |
607 // Set up mock async method caller to respond successfully to a key migration. | 674 // Set up mock async method caller to respond successfully to a key migration. |
608 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 675 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
609 EXPECT_CALL( | 676 EXPECT_CALL( |
610 *mock_caller_, | 677 *mock_caller_, |
611 AsyncMigrateKey( | 678 AsyncMigrateKey( |
612 user_context_.GetUserID(), _, transformed_key_.GetSecret(), _)) | 679 user_context_.GetUserID(), _, transformed_key_.GetSecret(), _)) |
613 .Times(1) | 680 .Times(1) |
614 .RetiresOnSaturation(); | 681 .RetiresOnSaturation(); |
615 | 682 |
616 // Set up mock homedir methods to respond successfully to a cryptohome mount | 683 // Set up mock homedir methods to respond successfully to a cryptohome mount |
617 // attempt. | 684 // attempt. |
618 const cryptohome::KeyDefinition auth_key(transformed_key_.GetSecret(), | 685 ExpectGetKeyDataExCall(scoped_ptr<int64>(), scoped_ptr<std::string>()); |
619 std::string(), | 686 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 | 687 |
627 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); | 688 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); |
628 SetAttemptState(auth_.get(), state_.release()); | 689 SetAttemptState(auth_.get(), state_.release()); |
629 | 690 |
630 auth_->RecoverEncryptedData(std::string()); | 691 auth_->RecoverEncryptedData(std::string()); |
631 base::MessageLoop::current()->Run(); | 692 base::MessageLoop::current()->Run(); |
632 } | 693 } |
633 | 694 |
634 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecoverButFail) { | 695 TEST_F(CryptohomeAuthenticatorTest, DriveDataRecoverButFail) { |
635 FailOnLoginSuccess(); | 696 FailOnLoginSuccess(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
669 // an online auth attempt has completed successfully. | 730 // an online auth attempt has completed successfully. |
670 state_->PresetCryptohomeStatus(false, | 731 state_->PresetCryptohomeStatus(false, |
671 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); | 732 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); |
672 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); | 733 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); |
673 | 734 |
674 EXPECT_EQ(CryptohomeAuthenticator::CREATE_NEW, | 735 EXPECT_EQ(CryptohomeAuthenticator::CREATE_NEW, |
675 SetAndResolveState(auth_.get(), state_.release())); | 736 SetAndResolveState(auth_.get(), state_.release())); |
676 } | 737 } |
677 | 738 |
678 TEST_F(CryptohomeAuthenticatorTest, DriveCreateForNewUser) { | 739 TEST_F(CryptohomeAuthenticatorTest, DriveCreateForNewUser) { |
679 UserContext expected_user_context(user_context_); | 740 UserContext expected_user_context(user_context_with_transformed_key_); |
680 expected_user_context.SetUserIDHash( | 741 expected_user_context.SetUserIDHash( |
681 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); | 742 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); |
682 ExpectLoginSuccess(expected_user_context); | 743 ExpectLoginSuccess(expected_user_context); |
683 FailOnLoginFailure(); | 744 FailOnLoginFailure(); |
684 | 745 |
685 // Set up mock homedir methods to respond successfully to a cryptohome create | 746 // Set up mock homedir methods to respond successfully to a cryptohome create |
686 // attempt. | 747 // attempt. |
687 const cryptohome::KeyDefinition auth_key(transformed_key_.GetSecret(), | 748 ExpectGetKeyDataExCall(scoped_ptr<int64>(), scoped_ptr<std::string>()); |
688 std::string(), | 749 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 | 750 |
701 // Set up state as though a cryptohome mount attempt has occurred | 751 // Set up state as though a cryptohome mount attempt has occurred |
702 // and been rejected because the user doesn't exist; additionally, | 752 // and been rejected because the user doesn't exist; additionally, |
703 // an online auth attempt has completed successfully. | 753 // an online auth attempt has completed successfully. |
704 state_->PresetCryptohomeStatus(false, | 754 state_->PresetCryptohomeStatus(false, |
705 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); | 755 cryptohome::MOUNT_ERROR_USER_DOES_NOT_EXIST); |
706 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); | 756 state_->PresetOnlineLoginStatus(AuthFailure::AuthFailureNone()); |
707 SetAttemptState(auth_.get(), state_.release()); | 757 SetAttemptState(auth_.get(), state_.release()); |
708 | 758 |
709 RunResolve(auth_.get()); | 759 RunResolve(auth_.get()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
742 // key-check attempt. | 792 // key-check attempt. |
743 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); | 793 mock_caller_->SetUp(true, cryptohome::MOUNT_ERROR_NONE); |
744 EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _)) | 794 EXPECT_CALL(*mock_caller_, AsyncCheckKey(user_context_.GetUserID(), _, _)) |
745 .Times(1) | 795 .Times(1) |
746 .RetiresOnSaturation(); | 796 .RetiresOnSaturation(); |
747 | 797 |
748 auth_->AuthenticateToUnlock(user_context_); | 798 auth_->AuthenticateToUnlock(user_context_); |
749 base::MessageLoop::current()->Run(); | 799 base::MessageLoop::current()->Run(); |
750 } | 800 } |
751 | 801 |
802 TEST_F(CryptohomeAuthenticatorTest, DriveLoginWithPreHashedPassword) { | |
803 CreateTransformedKey(Key::KEY_TYPE_SALTED_SHA256, kSalt); | |
804 | |
805 UserContext expected_user_context(user_context_with_transformed_key_); | |
806 expected_user_context.SetUserIDHash( | |
807 cryptohome::MockAsyncMethodCaller::kFakeSanitizedUsername); | |
808 ExpectLoginSuccess(expected_user_context); | |
809 FailOnLoginFailure(); | |
810 | |
811 // Set up mock homedir methods to respond with key metadata indicating that a | |
812 // pre-hashed key was used to create the cryptohome and allow a successful | |
813 // mount when this pre-hashed key is used. | |
814 | |
815 ExpectGetKeyDataExCall( | |
816 make_scoped_ptr(new int64(Key::KEY_TYPE_SALTED_SHA256)), | |
817 make_scoped_ptr(new std::string(kSalt))); | |
818 ExpectMountExCall(false /* expect_create_attempt */); | |
819 | |
820 auth_->AuthenticateToLogin(NULL, user_context_); | |
821 base::RunLoop().Run(); | |
822 } | |
823 | |
824 TEST_F(CryptohomeAuthenticatorTest, FailLoginWithMissingSalt) { | |
825 CreateTransformedKey(Key::KEY_TYPE_SALTED_SHA256, kSalt); | |
826 | |
827 FailOnLoginSuccess(); | |
828 ExpectLoginFailure(AuthFailure(AuthFailure::COULD_NOT_MOUNT_CRYPTOHOME)); | |
829 | |
830 // Set up mock homedir methods to respond with key metadata indicating that a | |
831 // pre-hashed key was used to create the cryptohome but without the required | |
832 // salt. | |
833 ExpectGetKeyDataExCall( | |
834 make_scoped_ptr(new int64(Key::KEY_TYPE_SALTED_SHA256)), | |
835 scoped_ptr<std::string>()); | |
836 | |
837 auth_->AuthenticateToLogin(NULL, user_context_); | |
838 base::RunLoop().Run(); | |
839 } | |
840 | |
752 } // namespace chromeos | 841 } // namespace chromeos |
OLD | NEW |