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

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

Issue 979273003: Simplify PlatformVerificationFlow::CheckConsent() logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months 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
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 "chrome/browser/chromeos/attestation/platform_verification_flow.h" 5 #include "chrome/browser/chromeos/attestation/platform_verification_flow.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 return; 209 return;
210 } 210 }
211 BoolDBusMethodCallback dbus_callback = base::Bind( 211 BoolDBusMethodCallback dbus_callback = base::Bind(
212 &DBusCallback, 212 &DBusCallback,
213 base::Bind(&PlatformVerificationFlow::CheckConsent, this, context), 213 base::Bind(&PlatformVerificationFlow::CheckConsent, this, context),
214 base::Bind(&ReportError, context.callback, INTERNAL_ERROR)); 214 base::Bind(&ReportError, context.callback, INTERNAL_ERROR));
215 cryptohome_client_->TpmAttestationIsEnrolled(dbus_callback); 215 cryptohome_client_->TpmAttestationIsEnrolled(dbus_callback);
216 } 216 }
217 217
218 void PlatformVerificationFlow::CheckConsent(const ChallengeContext& context, 218 void PlatformVerificationFlow::CheckConsent(const ChallengeContext& context,
219 bool attestation_enrolled) { 219 bool /* attestation_enrolled */) {
xhwang 2015/03/06 17:15:09 We can do a lot of cleanup around this. But since
220 PrefService* pref_service = delegate_->GetPrefs(context.web_contents); 220 content::WebContents* web_contents = context.web_contents;
221
222 bool enabled_for_domain = false;
ddorwin 2015/03/06 17:46:11 s/domain/origin/ The function would need to be ren
xhwang 2015/03/06 18:40:10 Done.
223 bool found =
224 GetDomainPref(delegate_->GetContentSettings(web_contents),
225 delegate_->GetURL(web_contents), &enabled_for_domain);
226 if (found && !enabled_for_domain) {
227 VLOG(1) << "Platform verification denied because the domain has been "
228 << "blocked by the user.";
229 ReportError(context.callback, USER_REJECTED);
Darren Krahn 2015/03/06 17:28:35 It seems this is the most useful when the content
xhwang 2015/03/06 18:40:10 The settings are still synced. Actually this is al
230 return;
231 }
232
233 PrefService* pref_service = delegate_->GetPrefs(web_contents);
221 if (!pref_service) { 234 if (!pref_service) {
222 LOG(ERROR) << "Failed to get user prefs."; 235 LOG(ERROR) << "Failed to get user prefs.";
223 ReportError(context.callback, INTERNAL_ERROR); 236 ReportError(context.callback, INTERNAL_ERROR);
224 return; 237 return;
225 } 238 }
226 bool consent_required = ( 239
227 // Consent required if attestation has never been enrolled on this device. 240 // Consent required if user has never given consent to attestation for content
228 !attestation_enrolled || 241 // protection on this device, or if user has never given consent for this
ddorwin 2015/03/06 17:46:11 you probably want to reverse this if you do the co
xhwang 2015/03/06 18:40:10 Done.
229 // Consent required if this is the first use of attestation for content 242 // domain.
230 // protection on this device. 243 bool consent_required =
231 !pref_service->GetBoolean(prefs::kRAConsentFirstTime) || 244 !pref_service->GetBoolean(prefs::kRAConsentGranted) || !found;
ddorwin 2015/03/06 17:46:11 nit: Swap to short circuit with the bool check
xhwang 2015/03/06 18:40:10 Done.
232 // Consent required if consent has never been given for this domain. 245
233 !GetDomainPref(delegate_->GetContentSettings(context.web_contents),
234 delegate_->GetURL(context.web_contents),
235 NULL));
236 Delegate::ConsentCallback consent_callback = base::Bind( 246 Delegate::ConsentCallback consent_callback = base::Bind(
237 &PlatformVerificationFlow::OnConsentResponse, 247 &PlatformVerificationFlow::OnConsentResponse,
238 this, 248 this,
239 context, 249 context,
240 consent_required); 250 consent_required);
241 if (consent_required) { 251 if (consent_required) {
242 // TODO(xhwang): Using delegate_->GetURL() here is not right. The consent 252 // TODO(xhwang): Using delegate_->GetURL() here is not right. The consent
243 // may be requested by a frame from a different origin. This will be solved 253 // may be requested by a frame from a different origin. This will be solved
244 // when http://crbug.com/454847 is fixed. 254 // when http://crbug.com/454847 is fixed.
245 delegate_->ShowConsentPrompt( 255 delegate_->ShowConsentPrompt(
246 context.web_contents, 256 context.web_contents,
247 delegate_->GetURL(context.web_contents).GetOrigin(), consent_callback); 257 delegate_->GetURL(context.web_contents).GetOrigin(), consent_callback);
248 } else { 258 } else {
249 consent_callback.Run(CONSENT_RESPONSE_NONE); 259 consent_callback.Run(CONSENT_RESPONSE_NONE);
250 } 260 }
251 } 261 }
252 262
253 void PlatformVerificationFlow::RegisterProfilePrefs( 263 void PlatformVerificationFlow::RegisterProfilePrefs(
254 user_prefs::PrefRegistrySyncable* prefs) { 264 user_prefs::PrefRegistrySyncable* prefs) {
255 prefs->RegisterBooleanPref(prefs::kRAConsentFirstTime, 265 prefs->RegisterBooleanPref(prefs::kRAConsentGranted, false,
ddorwin 2015/03/06 17:46:11 nit: false, // Default.
xhwang 2015/03/06 18:40:10 Done.
256 false,
257 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 266 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
258 } 267 }
259 268
260 void PlatformVerificationFlow::OnConsentResponse( 269 void PlatformVerificationFlow::OnConsentResponse(
261 const ChallengeContext& context, 270 const ChallengeContext& context,
262 bool consent_required, 271 bool consent_required,
263 ConsentResponse consent_response) { 272 ConsentResponse consent_response) {
264 if (consent_required) { 273 if (consent_required) {
265 if (consent_response == CONSENT_RESPONSE_NONE) { 274 if (consent_response == CONSENT_RESPONSE_NONE) {
266 // No user response - do not proceed and do not modify any settings. 275 // No user response - do not proceed and do not modify any settings.
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 } 442 }
434 443
435 bool PlatformVerificationFlow::UpdateSettings( 444 bool PlatformVerificationFlow::UpdateSettings(
436 content::WebContents* web_contents, 445 content::WebContents* web_contents,
437 ConsentResponse consent_response) { 446 ConsentResponse consent_response) {
438 PrefService* pref_service = delegate_->GetPrefs(web_contents); 447 PrefService* pref_service = delegate_->GetPrefs(web_contents);
439 if (!pref_service) { 448 if (!pref_service) {
440 LOG(ERROR) << "Failed to get user prefs."; 449 LOG(ERROR) << "Failed to get user prefs.";
441 return false; 450 return false;
442 } 451 }
443 pref_service->SetBoolean(prefs::kRAConsentFirstTime, true); 452
453 if (consent_response == CONSENT_RESPONSE_ALLOW)
Darren Krahn 2015/03/06 17:28:35 optional nit: Since the 'goto fail' bug I've start
xhwang 2015/03/06 18:40:10 Done.
454 pref_service->SetBoolean(prefs::kRAConsentGranted, true);
455
444 RecordDomainConsent(delegate_->GetContentSettings(web_contents), 456 RecordDomainConsent(delegate_->GetContentSettings(web_contents),
445 delegate_->GetURL(web_contents), 457 delegate_->GetURL(web_contents),
446 (consent_response == CONSENT_RESPONSE_ALLOW)); 458 (consent_response == CONSENT_RESPONSE_ALLOW));
447 return true; 459 return true;
448 } 460 }
449 461
450 bool PlatformVerificationFlow::GetDomainPref( 462 bool PlatformVerificationFlow::GetDomainPref(
451 HostContentSettingsMap* content_settings, 463 HostContentSettingsMap* content_settings,
452 const GURL& url, 464 const GURL& url,
453 bool* pref_value) { 465 bool* pref_value) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 certificate.length())); 517 certificate.length()));
506 if (!x509.get() || x509->valid_expiry().is_null()) { 518 if (!x509.get() || x509->valid_expiry().is_null()) {
507 LOG(WARNING) << "Failed to parse certificate, cannot check expiry."; 519 LOG(WARNING) << "Failed to parse certificate, cannot check expiry.";
508 return false; 520 return false;
509 } 521 }
510 return (base::Time::Now() > x509->valid_expiry()); 522 return (base::Time::Now() > x509->valid_expiry());
511 } 523 }
512 524
513 } // namespace attestation 525 } // namespace attestation
514 } // namespace chromeos 526 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/attestation/platform_verification_flow_unittest.cc » ('j') | chrome/common/pref_names.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698