| OLD | NEW |
| 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 "platform_verification_flow.h" | 5 #include "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/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/chromeos/attestation/attestation_ca_client.h" | 10 #include "chrome/browser/chromeos/attestation/attestation_ca_client.h" |
| 11 #include "chrome/browser/chromeos/attestation/attestation_signed_data.pb.h" | 11 #include "chrome/browser/chromeos/attestation/attestation_signed_data.pb.h" |
| 12 #include "chrome/browser/chromeos/attestation/platform_verification_dialog.h" | 12 #include "chrome/browser/chromeos/attestation/platform_verification_dialog.h" |
| 13 #include "chrome/browser/chromeos/login/user_manager.h" | 13 #include "chrome/browser/chromeos/login/user_manager.h" |
| 14 #include "chrome/browser/chromeos/settings/cros_settings.h" | 14 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 15 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 15 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "chromeos/attestation/attestation_flow.h" | 17 #include "chromeos/attestation/attestation_flow.h" |
| 18 #include "chromeos/cryptohome/async_method_caller.h" | 18 #include "chromeos/cryptohome/async_method_caller.h" |
| 19 #include "chromeos/dbus/cryptohome_client.h" | 19 #include "chromeos/dbus/cryptohome_client.h" |
| 20 #include "chromeos/dbus/dbus_thread_manager.h" | 20 #include "chromeos/dbus/dbus_thread_manager.h" |
| 21 #include "chromeos/system/statistics_provider.h" | |
| 22 #include "components/user_prefs/pref_registry_syncable.h" | 21 #include "components/user_prefs/pref_registry_syncable.h" |
| 23 #include "components/user_prefs/user_prefs.h" | 22 #include "components/user_prefs/user_prefs.h" |
| 24 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/user_metrics.h" | 24 #include "content/public/browser/user_metrics.h" |
| 26 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 27 | 26 |
| 28 namespace { | 27 namespace { |
| 29 // A switch which allows consent to be given on the command line. | 28 // A switch which allows consent to be given on the command line. |
| 30 // TODO(dkrahn): Remove this when UI has been implemented (crbug.com/270908). | 29 // TODO(dkrahn): Remove this when UI has been implemented (crbug.com/270908). |
| 31 const char kAutoApproveSwitch[] = | 30 const char kAutoApproveSwitch[] = |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 76 |
| 78 private: | 77 private: |
| 79 DISALLOW_COPY_AND_ASSIGN(DefaultDelegate); | 78 DISALLOW_COPY_AND_ASSIGN(DefaultDelegate); |
| 80 }; | 79 }; |
| 81 | 80 |
| 82 PlatformVerificationFlow::PlatformVerificationFlow() | 81 PlatformVerificationFlow::PlatformVerificationFlow() |
| 83 : attestation_flow_(NULL), | 82 : attestation_flow_(NULL), |
| 84 async_caller_(cryptohome::AsyncMethodCaller::GetInstance()), | 83 async_caller_(cryptohome::AsyncMethodCaller::GetInstance()), |
| 85 cryptohome_client_(DBusThreadManager::Get()->GetCryptohomeClient()), | 84 cryptohome_client_(DBusThreadManager::Get()->GetCryptohomeClient()), |
| 86 user_manager_(UserManager::Get()), | 85 user_manager_(UserManager::Get()), |
| 87 statistics_provider_(system::StatisticsProvider::GetInstance()), | |
| 88 delegate_(NULL), | 86 delegate_(NULL), |
| 89 testing_prefs_(NULL), | 87 testing_prefs_(NULL), |
| 90 weak_factory_(this) { | 88 weak_factory_(this) { |
| 91 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 89 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 92 scoped_ptr<ServerProxy> attestation_ca_client(new AttestationCAClient()); | 90 scoped_ptr<ServerProxy> attestation_ca_client(new AttestationCAClient()); |
| 93 default_attestation_flow_.reset(new AttestationFlow( | 91 default_attestation_flow_.reset(new AttestationFlow( |
| 94 async_caller_, | 92 async_caller_, |
| 95 cryptohome_client_, | 93 cryptohome_client_, |
| 96 attestation_ca_client.Pass())); | 94 attestation_ca_client.Pass())); |
| 97 attestation_flow_ = default_attestation_flow_.get(); | 95 attestation_flow_ = default_attestation_flow_.get(); |
| 98 default_delegate_.reset(new DefaultDelegate()); | 96 default_delegate_.reset(new DefaultDelegate()); |
| 99 delegate_ = default_delegate_.get(); | 97 delegate_ = default_delegate_.get(); |
| 100 } | 98 } |
| 101 | 99 |
| 102 PlatformVerificationFlow::PlatformVerificationFlow( | 100 PlatformVerificationFlow::PlatformVerificationFlow( |
| 103 AttestationFlow* attestation_flow, | 101 AttestationFlow* attestation_flow, |
| 104 cryptohome::AsyncMethodCaller* async_caller, | 102 cryptohome::AsyncMethodCaller* async_caller, |
| 105 CryptohomeClient* cryptohome_client, | 103 CryptohomeClient* cryptohome_client, |
| 106 UserManager* user_manager, | 104 UserManager* user_manager, |
| 107 system::StatisticsProvider* statistics_provider, | |
| 108 Delegate* delegate) | 105 Delegate* delegate) |
| 109 : attestation_flow_(attestation_flow), | 106 : attestation_flow_(attestation_flow), |
| 110 async_caller_(async_caller), | 107 async_caller_(async_caller), |
| 111 cryptohome_client_(cryptohome_client), | 108 cryptohome_client_(cryptohome_client), |
| 112 user_manager_(user_manager), | 109 user_manager_(user_manager), |
| 113 statistics_provider_(statistics_provider), | |
| 114 delegate_(delegate), | 110 delegate_(delegate), |
| 115 testing_prefs_(NULL), | 111 testing_prefs_(NULL), |
| 116 weak_factory_(this) { | 112 weak_factory_(this) { |
| 117 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 113 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 118 } | 114 } |
| 119 | 115 |
| 120 PlatformVerificationFlow::~PlatformVerificationFlow() { | 116 PlatformVerificationFlow::~PlatformVerificationFlow() { |
| 121 } | 117 } |
| 122 | 118 |
| 123 void PlatformVerificationFlow::ChallengePlatformKey( | 119 void PlatformVerificationFlow::ChallengePlatformKey( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 136 base::Bind(&PlatformVerificationFlow::CheckConsent, | 132 base::Bind(&PlatformVerificationFlow::CheckConsent, |
| 137 weak_factory_.GetWeakPtr(), | 133 weak_factory_.GetWeakPtr(), |
| 138 web_contents, | 134 web_contents, |
| 139 service_id, | 135 service_id, |
| 140 challenge, | 136 challenge, |
| 141 callback), | 137 callback), |
| 142 base::Bind(&ReportError, callback, INTERNAL_ERROR)); | 138 base::Bind(&ReportError, callback, INTERNAL_ERROR)); |
| 143 cryptohome_client_->TpmAttestationIsEnrolled(dbus_callback); | 139 cryptohome_client_->TpmAttestationIsEnrolled(dbus_callback); |
| 144 } | 140 } |
| 145 | 141 |
| 146 void PlatformVerificationFlow::CheckPlatformState( | |
| 147 const base::Callback<void(bool result)>& callback) { | |
| 148 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 149 std::string stat_value; | |
| 150 if (!statistics_provider_->GetMachineStatistic(system::kDevSwitchBootMode, | |
| 151 &stat_value)) { | |
| 152 LOG(ERROR) << __func__ << ": Failed to get boot mode statistic."; | |
| 153 callback.Run(false); | |
| 154 return; | |
| 155 } | |
| 156 if (stat_value != "0") { | |
| 157 LOG(INFO) << __func__ << ": Statistic indicates developer mode."; | |
| 158 callback.Run(false); | |
| 159 return; | |
| 160 } | |
| 161 BoolDBusMethodCallback dbus_callback = base::Bind( | |
| 162 &DBusCallback, | |
| 163 callback, | |
| 164 base::Bind(callback, false)); | |
| 165 cryptohome_client_->TpmAttestationIsPrepared(dbus_callback); | |
| 166 } | |
| 167 | |
| 168 void PlatformVerificationFlow::CheckConsent(content::WebContents* web_contents, | 142 void PlatformVerificationFlow::CheckConsent(content::WebContents* web_contents, |
| 169 const std::string& service_id, | 143 const std::string& service_id, |
| 170 const std::string& challenge, | 144 const std::string& challenge, |
| 171 const ChallengeCallback& callback, | 145 const ChallengeCallback& callback, |
| 172 bool attestation_enrolled) { | 146 bool attestation_enrolled) { |
| 173 ConsentType consent_type = CONSENT_TYPE_NONE; | 147 ConsentType consent_type = CONSENT_TYPE_NONE; |
| 174 if (!attestation_enrolled || IsFirstUse(web_contents)) { | 148 if (!attestation_enrolled || IsFirstUse(web_contents)) { |
| 175 consent_type = CONSENT_TYPE_ATTESTATION; | 149 consent_type = CONSENT_TYPE_ATTESTATION; |
| 176 } else if (IsAlwaysAskRequired(web_contents)) { | 150 } else if (IsAlwaysAskRequired(web_contents)) { |
| 177 consent_type = CONSENT_TYPE_ALWAYS; | 151 consent_type = CONSENT_TYPE_ALWAYS; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 bool allow_domain) { | 395 bool allow_domain) { |
| 422 PrefService* pref_service = GetPrefs(web_contents); | 396 PrefService* pref_service = GetPrefs(web_contents); |
| 423 CHECK(pref_service); | 397 CHECK(pref_service); |
| 424 DictionaryPrefUpdate updater(pref_service, prefs::kRAConsentDomains); | 398 DictionaryPrefUpdate updater(pref_service, prefs::kRAConsentDomains); |
| 425 const GURL& url = GetURL(web_contents); | 399 const GURL& url = GetURL(web_contents); |
| 426 updater->SetBoolean(url.host(), allow_domain); | 400 updater->SetBoolean(url.host(), allow_domain); |
| 427 } | 401 } |
| 428 | 402 |
| 429 } // namespace attestation | 403 } // namespace attestation |
| 430 } // namespace chromeos | 404 } // namespace chromeos |
| OLD | NEW |