Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(547)

Side by Side Diff: chrome/browser/chromeos/attestation/platform_verification_flow_unittest.cc

Issue 31043008: Changed platform verification user consent logic to be per-domain. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/prefs/pref_registry_simple.h" 9 #include "base/prefs/pref_registry_simple.h"
10 #include "base/prefs/testing_pref_service.h" 10 #include "base/prefs/testing_pref_service.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "chrome/browser/chromeos/attestation/attestation_signed_data.pb.h" 12 #include "chrome/browser/chromeos/attestation/attestation_signed_data.pb.h"
13 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h" 13 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h"
14 #include "chrome/browser/chromeos/login/mock_user_manager.h" 14 #include "chrome/browser/chromeos/login/mock_user_manager.h"
15 #include "chrome/browser/chromeos/settings/cros_settings.h" 15 #include "chrome/browser/chromeos/settings/cros_settings.h"
16 #include "chrome/browser/chromeos/settings/device_settings_service.h" 16 #include "chrome/browser/chromeos/settings/device_settings_service.h"
17 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" 17 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
18 #include "chrome/browser/prefs/scoped_user_pref_update.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "chromeos/attestation/mock_attestation_flow.h" 20 #include "chromeos/attestation/mock_attestation_flow.h"
20 #include "chromeos/cryptohome/mock_async_method_caller.h" 21 #include "chromeos/cryptohome/mock_async_method_caller.h"
21 #include "chromeos/dbus/fake_cryptohome_client.h" 22 #include "chromeos/dbus/fake_cryptohome_client.h"
22 #include "chromeos/settings/cros_settings_names.h" 23 #include "chromeos/settings/cros_settings_names.h"
23 #include "content/public/test/test_browser_thread.h" 24 #include "content/public/test/test_browser_thread.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 26
26 using testing::_; 27 using testing::_;
27 using testing::DoAll; 28 using testing::DoAll;
28 using testing::Invoke; 29 using testing::Invoke;
29 using testing::Return; 30 using testing::Return;
30 using testing::SetArgumentPointee; 31 using testing::SetArgumentPointee;
31 using testing::StrictMock; 32 using testing::StrictMock;
32 using testing::WithArgs; 33 using testing::WithArgs;
33 34
34 namespace chromeos { 35 namespace chromeos {
35 namespace attestation { 36 namespace attestation {
36 37
37 namespace { 38 namespace {
38 39
39 const char kTestID[] = "test_id"; 40 const char kTestID[] = "test_id";
40 const char kTestChallenge[] = "test_challenge"; 41 const char kTestChallenge[] = "test_challenge";
41 const char kTestSignedData[] = "test_challenge_with_salt"; 42 const char kTestSignedData[] = "test_challenge_with_salt";
42 const char kTestSignature[] = "test_signature"; 43 const char kTestSignature[] = "test_signature";
43 const char kTestCertificate[] = "test_certificate"; 44 const char kTestCertificate[] = "test_certificate";
44 const char kTestEmail[] = "test_email@chromium.org"; 45 const char kTestEmail[] = "test_email@chromium.org";
45 const char kTestURL[] = "http://mytestdomain/test"; 46 const char kTestURL[] = "http://mytestdomain/test";
46 const char kTestDomain[] = "mytestdomain"; 47 const char kTestURLSecure[] = "https://mytestdomain/test";
48 const char kTestDomain[] = "http://mytestdomain/";
47 49
48 class FakeDelegate : public PlatformVerificationFlow::Delegate { 50 class FakeDelegate : public PlatformVerificationFlow::Delegate {
49 public: 51 public:
50 FakeDelegate() : response_(PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW), 52 FakeDelegate() : response_(PlatformVerificationFlow::CONSENT_RESPONSE_ALLOW),
51 num_consent_calls_(0) {} 53 num_consent_calls_(0) {}
52 virtual ~FakeDelegate() {} 54 virtual ~FakeDelegate() {}
53 55
54 virtual void ShowConsentPrompt( 56 virtual void ShowConsentPrompt(
55 PlatformVerificationFlow::ConsentType type,
56 content::WebContents* web_contents, 57 content::WebContents* web_contents,
57 const PlatformVerificationFlow::Delegate::ConsentCallback& callback) 58 const PlatformVerificationFlow::Delegate::ConsentCallback& callback)
58 OVERRIDE { 59 OVERRIDE {
59 num_consent_calls_++; 60 num_consent_calls_++;
60 callback.Run(response_); 61 callback.Run(response_);
61 } 62 }
62 63
63 void set_response(PlatformVerificationFlow::ConsentResponse response) { 64 void set_response(PlatformVerificationFlow::ConsentResponse response) {
64 response_ = response; 65 response_ = response;
65 } 66 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 &fake_delegate_)); 138 &fake_delegate_));
138 139
139 // Create callbacks for tests to use with verifier_. 140 // Create callbacks for tests to use with verifier_.
140 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback, 141 callback_ = base::Bind(&PlatformVerificationFlowTest::FakeChallengeCallback,
141 base::Unretained(this)); 142 base::Unretained(this));
142 143
143 // Configure the test pref service. 144 // Configure the test pref service.
144 pref_service_.registry()->RegisterBooleanPref(prefs::kEnableDRM, true); 145 pref_service_.registry()->RegisterBooleanPref(prefs::kEnableDRM, true);
145 pref_service_.registry()->RegisterBooleanPref(prefs::kRAConsentFirstTime, 146 pref_service_.registry()->RegisterBooleanPref(prefs::kRAConsentFirstTime,
146 true); 147 true);
147 pref_service_.registry()->RegisterBooleanPref(prefs::kRAConsentAlways,
148 false);
149 pref_service_.registry()->RegisterDictionaryPref(prefs::kRAConsentDomains); 148 pref_service_.registry()->RegisterDictionaryPref(prefs::kRAConsentDomains);
150 verifier_->set_testing_prefs(&pref_service_); 149 verifier_->set_testing_prefs(&pref_service_);
151 150
152 // Configure the global cros_settings. 151 // Configure the global cros_settings.
153 CrosSettings* cros_settings = CrosSettings::Get(); 152 CrosSettings* cros_settings = CrosSettings::Get();
154 device_settings_provider_ = 153 device_settings_provider_ =
155 cros_settings->GetProvider(kAttestationForContentProtectionEnabled); 154 cros_settings->GetProvider(kAttestationForContentProtectionEnabled);
156 cros_settings->RemoveSettingsProvider(device_settings_provider_); 155 cros_settings->RemoveSettingsProvider(device_settings_provider_);
157 cros_settings->AddSettingsProvider(&stub_settings_provider_); 156 cros_settings->AddSettingsProvider(&stub_settings_provider_);
158 cros_settings->SetBoolean(kAttestationForContentProtectionEnabled, true); 157 cros_settings->SetBoolean(kAttestationForContentProtectionEnabled, true);
(...skipping 26 matching lines...) Expand all
185 std::string expected_key_name = std::string(kContentProtectionKeyPrefix) + 184 std::string expected_key_name = std::string(kContentProtectionKeyPrefix) +
186 std::string(kTestID); 185 std::string(kTestID);
187 EXPECT_CALL(mock_async_caller_, 186 EXPECT_CALL(mock_async_caller_,
188 TpmAttestationSignSimpleChallenge(KEY_USER, kTestEmail, 187 TpmAttestationSignSimpleChallenge(KEY_USER, kTestEmail,
189 expected_key_name, 188 expected_key_name,
190 kTestChallenge, _)) 189 kTestChallenge, _))
191 .WillRepeatedly(WithArgs<4>(Invoke( 190 .WillRepeatedly(WithArgs<4>(Invoke(
192 this, &PlatformVerificationFlowTest::FakeSignChallenge))); 191 this, &PlatformVerificationFlowTest::FakeSignChallenge)));
193 } 192 }
194 193
194 void SetUserConsent(const std::string& domain, bool allow) {
195 DictionaryPrefUpdate updater(&pref_service_, prefs::kRAConsentDomains);
196 updater->SetBoolean(domain, allow);
197 }
198
195 void FakeGetCertificate( 199 void FakeGetCertificate(
196 const AttestationFlow::CertificateCallback& callback) { 200 const AttestationFlow::CertificateCallback& callback) {
197 base::MessageLoop::current()->PostTask(FROM_HERE, 201 base::MessageLoop::current()->PostTask(FROM_HERE,
198 base::Bind(callback, 202 base::Bind(callback,
199 certificate_success_, 203 certificate_success_,
200 kTestCertificate)); 204 kTestCertificate));
201 } 205 }
202 206
203 void FakeSignChallenge( 207 void FakeSignChallenge(
204 const cryptohome::AsyncMethodCaller::DataCallback& callback) { 208 const cryptohome::AsyncMethodCaller::DataCallback& callback) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 255
252 // Callback functions and data. 256 // Callback functions and data.
253 PlatformVerificationFlow::ChallengeCallback callback_; 257 PlatformVerificationFlow::ChallengeCallback callback_;
254 PlatformVerificationFlow::Result result_; 258 PlatformVerificationFlow::Result result_;
255 std::string challenge_salt_; 259 std::string challenge_salt_;
256 std::string challenge_signature_; 260 std::string challenge_signature_;
257 std::string certificate_; 261 std::string certificate_;
258 }; 262 };
259 263
260 TEST_F(PlatformVerificationFlowTest, SuccessNoConsent) { 264 TEST_F(PlatformVerificationFlowTest, SuccessNoConsent) {
265 SetUserConsent(kTestDomain, true);
261 // Make sure the call will fail if consent is requested. 266 // Make sure the call will fail if consent is requested.
262 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); 267 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY);
263 ExpectAttestationFlow(); 268 ExpectAttestationFlow();
264 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 269 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
265 base::RunLoop().RunUntilIdle(); 270 base::RunLoop().RunUntilIdle();
266 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); 271 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_);
267 EXPECT_EQ(kTestSignedData, challenge_salt_); 272 EXPECT_EQ(kTestSignedData, challenge_salt_);
268 EXPECT_EQ(kTestSignature, challenge_signature_); 273 EXPECT_EQ(kTestSignature, challenge_signature_);
269 EXPECT_EQ(kTestCertificate, certificate_); 274 EXPECT_EQ(kTestCertificate, certificate_);
270 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); 275 EXPECT_EQ(0, fake_delegate_.num_consent_calls());
271 } 276 }
272 277
273 TEST_F(PlatformVerificationFlowTest, SuccessWithAlwaysAskConsent) {
274 pref_service_.SetUserPref(prefs::kRAConsentAlways,
275 new base::FundamentalValue(true));
276 ExpectAttestationFlow();
277 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
278 base::RunLoop().RunUntilIdle();
279 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_);
280 EXPECT_EQ(kTestSignedData, challenge_salt_);
281 EXPECT_EQ(kTestSignature, challenge_signature_);
282 EXPECT_EQ(kTestCertificate, certificate_);
283 EXPECT_EQ(1, fake_delegate_.num_consent_calls());
284 }
285
286 TEST_F(PlatformVerificationFlowTest, SuccessWithAttestationConsent) { 278 TEST_F(PlatformVerificationFlowTest, SuccessWithAttestationConsent) {
279 SetUserConsent(kTestDomain, true);
287 fake_cryptohome_client_.set_attestation_enrolled(false); 280 fake_cryptohome_client_.set_attestation_enrolled(false);
288 ExpectAttestationFlow(); 281 ExpectAttestationFlow();
289 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 282 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
290 base::RunLoop().RunUntilIdle(); 283 base::RunLoop().RunUntilIdle();
291 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); 284 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_);
292 EXPECT_EQ(kTestSignedData, challenge_salt_); 285 EXPECT_EQ(kTestSignedData, challenge_salt_);
293 EXPECT_EQ(kTestSignature, challenge_signature_); 286 EXPECT_EQ(kTestSignature, challenge_signature_);
294 EXPECT_EQ(kTestCertificate, certificate_); 287 EXPECT_EQ(kTestCertificate, certificate_);
295 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); 288 EXPECT_EQ(1, fake_delegate_.num_consent_calls());
296 } 289 }
297 290
298 TEST_F(PlatformVerificationFlowTest, SuccessWithFirstTimeConsent) { 291 TEST_F(PlatformVerificationFlowTest, SuccessWithFirstTimeConsent) {
292 SetUserConsent(kTestDomain, true);
299 pref_service_.SetUserPref(prefs::kRAConsentFirstTime, 293 pref_service_.SetUserPref(prefs::kRAConsentFirstTime,
300 new base::FundamentalValue(false)); 294 new base::FundamentalValue(false));
301 ExpectAttestationFlow(); 295 ExpectAttestationFlow();
302 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 296 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
303 base::RunLoop().RunUntilIdle(); 297 base::RunLoop().RunUntilIdle();
304 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_); 298 EXPECT_EQ(PlatformVerificationFlow::SUCCESS, result_);
305 EXPECT_EQ(kTestSignedData, challenge_salt_); 299 EXPECT_EQ(kTestSignedData, challenge_salt_);
306 EXPECT_EQ(kTestSignature, challenge_signature_); 300 EXPECT_EQ(kTestSignature, challenge_signature_);
307 EXPECT_EQ(kTestCertificate, certificate_); 301 EXPECT_EQ(kTestCertificate, certificate_);
308 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); 302 EXPECT_EQ(1, fake_delegate_.num_consent_calls());
309 } 303 }
310 304
311 TEST_F(PlatformVerificationFlowTest, ConsentRejected) { 305 TEST_F(PlatformVerificationFlowTest, ConsentRejected) {
312 pref_service_.SetUserPref(prefs::kRAConsentAlways,
313 new base::FundamentalValue(true));
314 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY); 306 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY);
315 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 307 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
316 base::RunLoop().RunUntilIdle(); 308 base::RunLoop().RunUntilIdle();
317 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); 309 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_);
318 EXPECT_EQ(1, fake_delegate_.num_consent_calls()); 310 EXPECT_EQ(1, fake_delegate_.num_consent_calls());
319 } 311 }
320 312
321 TEST_F(PlatformVerificationFlowTest, FeatureDisabled) { 313 TEST_F(PlatformVerificationFlowTest, FeatureDisabled) {
322 CrosSettings::Get()->SetBoolean(kAttestationForContentProtectionEnabled, 314 CrosSettings::Get()->SetBoolean(kAttestationForContentProtectionEnabled,
323 false); 315 false);
324 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 316 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
325 base::RunLoop().RunUntilIdle(); 317 base::RunLoop().RunUntilIdle();
326 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); 318 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_);
327 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); 319 EXPECT_EQ(0, fake_delegate_.num_consent_calls());
328 } 320 }
329 321
330 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUser) { 322 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUser) {
331 pref_service_.SetUserPref(prefs::kEnableDRM, 323 pref_service_.SetUserPref(prefs::kEnableDRM,
332 new base::FundamentalValue(false)); 324 new base::FundamentalValue(false));
333 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 325 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
334 base::RunLoop().RunUntilIdle(); 326 base::RunLoop().RunUntilIdle();
335 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); 327 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_);
336 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); 328 EXPECT_EQ(0, fake_delegate_.num_consent_calls());
337 } 329 }
338 330
339 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUserForDomain) { 331 TEST_F(PlatformVerificationFlowTest, FeatureDisabledByUserForDomain) {
340 base::DictionaryValue* domains = new base::DictionaryValue(); 332 SetUserConsent(kTestDomain, false);
341 domains->SetBoolean(kTestDomain, false);
342 pref_service_.SetUserPref(prefs::kRAConsentDomains, domains);
343 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 333 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
344 base::RunLoop().RunUntilIdle(); 334 base::RunLoop().RunUntilIdle();
345 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_); 335 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_);
346 EXPECT_EQ(0, fake_delegate_.num_consent_calls()); 336 EXPECT_EQ(0, fake_delegate_.num_consent_calls());
347 } 337 }
348 338
349 TEST_F(PlatformVerificationFlowTest, NotVerified) { 339 TEST_F(PlatformVerificationFlowTest, NotVerified) {
350 certificate_success_ = false; 340 certificate_success_ = false;
351 ExpectAttestationFlow(); 341 ExpectAttestationFlow();
352 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 342 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
(...skipping 11 matching lines...) Expand all
364 354
365 TEST_F(PlatformVerificationFlowTest, DBusFailure) { 355 TEST_F(PlatformVerificationFlowTest, DBusFailure) {
366 fake_cryptohome_client_.set_call_status(DBUS_METHOD_CALL_FAILURE); 356 fake_cryptohome_client_.set_call_status(DBUS_METHOD_CALL_FAILURE);
367 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 357 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
368 base::RunLoop().RunUntilIdle(); 358 base::RunLoop().RunUntilIdle();
369 EXPECT_EQ(PlatformVerificationFlow::INTERNAL_ERROR, result_); 359 EXPECT_EQ(PlatformVerificationFlow::INTERNAL_ERROR, result_);
370 } 360 }
371 361
372 TEST_F(PlatformVerificationFlowTest, ConsentNoResponse) { 362 TEST_F(PlatformVerificationFlowTest, ConsentNoResponse) {
373 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_NONE); 363 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_NONE);
374 pref_service_.SetUserPref(prefs::kRAConsentAlways,
375 new base::FundamentalValue(true));
376 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_); 364 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
377 base::RunLoop().RunUntilIdle(); 365 base::RunLoop().RunUntilIdle();
378 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_); 366 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_);
379 } 367 }
380 368
369 TEST_F(PlatformVerificationFlowTest, ConsentPerScheme) {
370 fake_delegate_.set_response(PlatformVerificationFlow::CONSENT_RESPONSE_DENY);
371 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
372 base::RunLoop().RunUntilIdle();
373 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_);
374 // Call again and expect denial based on previous response.
375 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
376 base::RunLoop().RunUntilIdle();
377 EXPECT_EQ(PlatformVerificationFlow::POLICY_REJECTED, result_);
378 // Call with a different scheme and expect another consent prompt.
379 verifier_->set_testing_url(GURL(kTestURLSecure));
380 verifier_->ChallengePlatformKey(NULL, kTestID, kTestChallenge, callback_);
381 base::RunLoop().RunUntilIdle();
382 EXPECT_EQ(PlatformVerificationFlow::USER_REJECTED, result_);
383 EXPECT_EQ(2, fake_delegate_.num_consent_calls());
384 }
385
381 } // namespace attestation 386 } // namespace attestation
382 } // namespace chromeos 387 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698