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.h" |
13 #include "chrome/browser/chromeos/login/user_manager.h" | 14 #include "chrome/browser/chromeos/login/user_manager.h" |
14 #include "chrome/browser/chromeos/settings/cros_settings.h" | 15 #include "chrome/browser/chromeos/settings/cros_settings.h" |
15 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 16 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 17 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
17 #include "chromeos/attestation/attestation_flow.h" | 19 #include "chromeos/attestation/attestation_flow.h" |
18 #include "chromeos/cryptohome/async_method_caller.h" | 20 #include "chromeos/cryptohome/async_method_caller.h" |
19 #include "chromeos/dbus/cryptohome_client.h" | 21 #include "chromeos/dbus/cryptohome_client.h" |
20 #include "chromeos/dbus/dbus_thread_manager.h" | 22 #include "chromeos/dbus/dbus_thread_manager.h" |
21 #include "chromeos/system/statistics_provider.h" | 23 #include "chromeos/system/statistics_provider.h" |
22 #include "components/user_prefs/pref_registry_syncable.h" | 24 #include "components/user_prefs/pref_registry_syncable.h" |
23 #include "components/user_prefs/user_prefs.h" | 25 #include "components/user_prefs/user_prefs.h" |
| 26 #include "content/public/browser/browser_context.h" |
24 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/user_metrics.h" | 28 #include "content/public/browser/user_metrics.h" |
26 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
27 | 30 |
28 namespace { | 31 namespace { |
29 // A switch which allows consent to be given on the command line. | 32 // 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). | 33 // TODO(dkrahn): Remove this when UI has been implemented (crbug.com/270908). |
31 const char kAutoApproveSwitch[] = | 34 const char kAutoApproveSwitch[] = |
32 "auto-approve-platform-verification-consent-prompts"; | 35 "auto-approve-platform-verification-consent-prompts"; |
33 | 36 |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 ReportError(callback, USER_REJECTED); | 234 ReportError(callback, USER_REJECTED); |
232 return; | 235 return; |
233 } else if (consent_response == CONSENT_RESPONSE_ALLOW) { | 236 } else if (consent_response == CONSENT_RESPONSE_ALLOW) { |
234 content::RecordAction( | 237 content::RecordAction( |
235 content::UserMetricsAction("PlatformVerificationAccepted")); | 238 content::UserMetricsAction("PlatformVerificationAccepted")); |
236 } | 239 } |
237 } | 240 } |
238 | 241 |
239 // At this point all user interaction is complete and we can proceed with the | 242 // At this point all user interaction is complete and we can proceed with the |
240 // certificate request. | 243 // certificate request. |
| 244 chromeos::User* user = GetUser(web_contents); |
| 245 if (!user) { |
| 246 ReportError(callback, INTERNAL_ERROR); |
| 247 LOG(ERROR) << "Profile does not map to a valid user."; |
| 248 return; |
| 249 } |
241 AttestationFlow::CertificateCallback certificate_callback = base::Bind( | 250 AttestationFlow::CertificateCallback certificate_callback = base::Bind( |
242 &PlatformVerificationFlow::OnCertificateReady, | 251 &PlatformVerificationFlow::OnCertificateReady, |
243 weak_factory_.GetWeakPtr(), | 252 weak_factory_.GetWeakPtr(), |
| 253 user->email(), |
244 service_id, | 254 service_id, |
245 challenge, | 255 challenge, |
246 callback); | 256 callback); |
247 attestation_flow_->GetCertificate( | 257 attestation_flow_->GetCertificate( |
248 PROFILE_CONTENT_PROTECTION_CERTIFICATE, | 258 PROFILE_CONTENT_PROTECTION_CERTIFICATE, |
249 user_manager_->GetActiveUser()->email(), | 259 user->email(), |
250 service_id, | 260 service_id, |
251 false, // Don't force a new key. | 261 false, // Don't force a new key. |
252 certificate_callback); | 262 certificate_callback); |
253 } | 263 } |
254 | 264 |
255 void PlatformVerificationFlow::OnCertificateReady( | 265 void PlatformVerificationFlow::OnCertificateReady( |
| 266 const std::string& user_id, |
256 const std::string& service_id, | 267 const std::string& service_id, |
257 const std::string& challenge, | 268 const std::string& challenge, |
258 const ChallengeCallback& callback, | 269 const ChallengeCallback& callback, |
259 bool operation_success, | 270 bool operation_success, |
260 const std::string& certificate) { | 271 const std::string& certificate) { |
261 if (!operation_success) { | 272 if (!operation_success) { |
262 LOG(WARNING) << "PlatformVerificationFlow: Failed to certify platform."; | 273 LOG(WARNING) << "PlatformVerificationFlow: Failed to certify platform."; |
263 ReportError(callback, PLATFORM_NOT_VERIFIED); | 274 ReportError(callback, PLATFORM_NOT_VERIFIED); |
264 return; | 275 return; |
265 } | 276 } |
266 cryptohome::AsyncMethodCaller::DataCallback cryptohome_callback = base::Bind( | 277 cryptohome::AsyncMethodCaller::DataCallback cryptohome_callback = base::Bind( |
267 &PlatformVerificationFlow::OnChallengeReady, | 278 &PlatformVerificationFlow::OnChallengeReady, |
268 weak_factory_.GetWeakPtr(), | 279 weak_factory_.GetWeakPtr(), |
269 certificate, | 280 certificate, |
270 challenge, | 281 challenge, |
271 callback); | 282 callback); |
272 std::string key_name = kContentProtectionKeyPrefix; | 283 std::string key_name = kContentProtectionKeyPrefix; |
273 key_name += service_id; | 284 key_name += service_id; |
274 async_caller_->TpmAttestationSignSimpleChallenge(KEY_USER, | 285 async_caller_->TpmAttestationSignSimpleChallenge(KEY_USER, |
| 286 user_id, |
275 key_name, | 287 key_name, |
276 challenge, | 288 challenge, |
277 cryptohome_callback); | 289 cryptohome_callback); |
278 } | 290 } |
279 | 291 |
280 void PlatformVerificationFlow::OnChallengeReady( | 292 void PlatformVerificationFlow::OnChallengeReady( |
281 const std::string& certificate, | 293 const std::string& certificate, |
282 const std::string& challenge, | 294 const std::string& challenge, |
283 const ChallengeCallback& callback, | 295 const ChallengeCallback& callback, |
284 bool operation_success, | 296 bool operation_success, |
(...skipping 23 matching lines...) Expand all Loading... |
308 return user_prefs::UserPrefs::Get(web_contents->GetBrowserContext()); | 320 return user_prefs::UserPrefs::Get(web_contents->GetBrowserContext()); |
309 } | 321 } |
310 | 322 |
311 const GURL& PlatformVerificationFlow::GetURL( | 323 const GURL& PlatformVerificationFlow::GetURL( |
312 content::WebContents* web_contents) { | 324 content::WebContents* web_contents) { |
313 if (!testing_url_.is_empty()) | 325 if (!testing_url_.is_empty()) |
314 return testing_url_; | 326 return testing_url_; |
315 return web_contents->GetLastCommittedURL(); | 327 return web_contents->GetLastCommittedURL(); |
316 } | 328 } |
317 | 329 |
| 330 User* PlatformVerificationFlow::GetUser(content::WebContents* web_contents) { |
| 331 if (!web_contents) |
| 332 return user_manager_->GetActiveUser(); |
| 333 return user_manager_->GetUserByProfile( |
| 334 Profile::FromBrowserContext(web_contents->GetBrowserContext())); |
| 335 } |
| 336 |
318 bool PlatformVerificationFlow::IsAttestationEnabled( | 337 bool PlatformVerificationFlow::IsAttestationEnabled( |
319 content::WebContents* web_contents) { | 338 content::WebContents* web_contents) { |
320 // Check the device policy for the feature. | 339 // Check the device policy for the feature. |
321 bool enabled_for_device = false; | 340 bool enabled_for_device = false; |
322 if (!CrosSettings::Get()->GetBoolean(kAttestationForContentProtectionEnabled, | 341 if (!CrosSettings::Get()->GetBoolean(kAttestationForContentProtectionEnabled, |
323 &enabled_for_device)) { | 342 &enabled_for_device)) { |
324 LOG(ERROR) << "Failed to get device setting."; | 343 LOG(ERROR) << "Failed to get device setting."; |
325 return false; | 344 return false; |
326 } | 345 } |
327 if (!enabled_for_device) | 346 if (!enabled_for_device) |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 bool allow_domain) { | 440 bool allow_domain) { |
422 PrefService* pref_service = GetPrefs(web_contents); | 441 PrefService* pref_service = GetPrefs(web_contents); |
423 CHECK(pref_service); | 442 CHECK(pref_service); |
424 DictionaryPrefUpdate updater(pref_service, prefs::kRAConsentDomains); | 443 DictionaryPrefUpdate updater(pref_service, prefs::kRAConsentDomains); |
425 const GURL& url = GetURL(web_contents); | 444 const GURL& url = GetURL(web_contents); |
426 updater->SetBoolean(url.host(), allow_domain); | 445 updater->SetBoolean(url.host(), allow_domain); |
427 } | 446 } |
428 | 447 |
429 } // namespace attestation | 448 } // namespace attestation |
430 } // namespace chromeos | 449 } // namespace chromeos |
OLD | NEW |