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

Side by Side Diff: chrome/browser/chromeos/login/enrollment/enrollment_screen.cc

Issue 2186623002: Minimal attestation-based enrollment flow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Made ZTE independent of enterprise enrollment. Created 4 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/enrollment/enrollment_screen.h" 5 #include "chrome/browser/chromeos/login/enrollment/enrollment_screen.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/timer/elapsed_timer.h" 12 #include "base/timer/elapsed_timer.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/browser_process_platform_part.h" 14 #include "chrome/browser/browser_process_platform_part.h"
15 #include "chrome/browser/chromeos/login/enrollment/enrollment_uma.h" 15 #include "chrome/browser/chromeos/login/enrollment/enrollment_uma.h"
16 #include "chrome/browser/chromeos/login/screen_manager.h" 16 #include "chrome/browser/chromeos/login/screen_manager.h"
17 #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h" 17 #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h"
18 #include "chrome/browser/chromeos/login/startup_utils.h" 18 #include "chrome/browser/chromeos/login/startup_utils.h"
19 #include "chrome/browser/chromeos/login/wizard_controller.h" 19 #include "chrome/browser/chromeos/login/wizard_controller.h"
20 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 20 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
21 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" 21 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h"
22 #include "chrome/browser/chromeos/profiles/profile_helper.h" 22 #include "chrome/browser/chromeos/profiles/profile_helper.h"
23 #include "chromeos/dbus/cryptohome_client.h" 23 #include "chromeos/dbus/cryptohome_client.h"
24 #include "chromeos/dbus/dbus_method_call_status.h" 24 #include "chromeos/dbus/dbus_method_call_status.h"
25 #include "chromeos/dbus/dbus_thread_manager.h" 25 #include "chromeos/dbus/dbus_thread_manager.h"
26 #include "components/pairing/controller_pairing_controller.h" 26 #include "components/pairing/controller_pairing_controller.h"
27 #include "google_apis/gaia/gaia_auth_util.h" 27 #include "google_apis/gaia/gaia_auth_util.h"
28 28
29 using namespace pairing_chromeos; 29 using namespace pairing_chromeos;
30 using policy::EnrollmentConfig;
30 31
31 // Do not change the UMA histogram parameters without renaming the histograms! 32 // Do not change the UMA histogram parameters without renaming the histograms!
32 #define UMA_ENROLLMENT_TIME(histogram_name, elapsed_timer) \ 33 #define UMA_ENROLLMENT_TIME(histogram_name, elapsed_timer) \
33 do { \ 34 do { \
34 UMA_HISTOGRAM_CUSTOM_TIMES( \ 35 UMA_HISTOGRAM_CUSTOM_TIMES( \
35 (histogram_name), \ 36 (histogram_name), \
36 (elapsed_timer)->Elapsed(), \ 37 (elapsed_timer)->Elapsed(), \
37 base::TimeDelta::FromMilliseconds(100) /* min */, \ 38 base::TimeDelta::FromMilliseconds(100) /* min */, \
38 base::TimeDelta::FromMinutes(15) /* max */, \ 39 base::TimeDelta::FromMinutes(15) /* max */, \
39 100 /* bucket_count */); \ 40 100 /* bucket_count */); \
(...skipping 16 matching lines...) Expand all
56 EnrollmentScreen* EnrollmentScreen::Get(ScreenManager* manager) { 57 EnrollmentScreen* EnrollmentScreen::Get(ScreenManager* manager) {
57 return static_cast<EnrollmentScreen*>( 58 return static_cast<EnrollmentScreen*>(
58 manager->GetScreen(WizardController::kEnrollmentScreenName)); 59 manager->GetScreen(WizardController::kEnrollmentScreenName));
59 } 60 }
60 61
61 EnrollmentScreen::EnrollmentScreen(BaseScreenDelegate* base_screen_delegate, 62 EnrollmentScreen::EnrollmentScreen(BaseScreenDelegate* base_screen_delegate,
62 EnrollmentScreenActor* actor) 63 EnrollmentScreenActor* actor)
63 : BaseScreen(base_screen_delegate), 64 : BaseScreen(base_screen_delegate),
64 shark_controller_(NULL), 65 shark_controller_(NULL),
65 actor_(actor), 66 actor_(actor),
67 current_auth_(AUTH_OAUTH),
68 last_auth_(AUTH_OAUTH),
66 enrollment_failed_once_(false), 69 enrollment_failed_once_(false),
67 weak_ptr_factory_(this) { 70 weak_ptr_factory_(this) {}
68 }
69 71
70 EnrollmentScreen::~EnrollmentScreen() { 72 EnrollmentScreen::~EnrollmentScreen() {
71 DCHECK(!enrollment_helper_ || g_browser_process->IsShuttingDown()); 73 DCHECK(!enrollment_helper_ || g_browser_process->IsShuttingDown());
72 } 74 }
73 75
74 void EnrollmentScreen::SetParameters( 76 void EnrollmentScreen::SetParameters(
75 const policy::EnrollmentConfig& enrollment_config, 77 const policy::EnrollmentConfig& enrollment_config,
76 pairing_chromeos::ControllerPairingController* shark_controller) { 78 pairing_chromeos::ControllerPairingController* shark_controller) {
77 enrollment_config_ = enrollment_config; 79 enrollment_config_ = enrollment_config;
80 switch (enrollment_config_.auth_mechanism) {
81 case EnrollmentConfig::AUTH_MECHANISM_INTERACTIVE:
82 current_auth_ = AUTH_OAUTH;
83 last_auth_ = AUTH_OAUTH;
84 break;
85 case EnrollmentConfig::AUTH_MECHANISM_ATTESTATION:
86 current_auth_ = AUTH_ATTESTATION;
87 last_auth_ = AUTH_ATTESTATION;
88 break;
89 case EnrollmentConfig::AUTH_MECHANISM_BEST_AVAILABLE:
90 current_auth_ = AUTH_ATTESTATION;
91 last_auth_ = AUTH_OAUTH;
92 break;
93 }
78 shark_controller_ = shark_controller; 94 shark_controller_ = shark_controller;
79 actor_->SetParameters(this, enrollment_config_); 95 SetConfig();
96 }
97
98 void EnrollmentScreen::SetConfig() {
99 config_ = enrollment_config_;
100 if (current_auth_ == AUTH_ATTESTATION) {
101 if (last_auth_ == current_auth_) {
102 config_.mode = policy::EnrollmentConfig::MODE_ATTESTATION;
103 } else {
104 config_.mode = policy::EnrollmentConfig::MODE_ATTESTATION_FORCED;
105 }
106 }
107 actor_->SetParameters(this, config_);
108 enrollment_helper_ = nullptr;
109 }
110
111 bool EnrollmentScreen::AdvanceToNextAuth() {
112 if (current_auth_ == last_auth_) {
pastarmovj 2016/08/19 10:29:18 This looks like too much of a boilerplate for jugg
The one and only Dr. Crash 2016/08/19 17:49:29 I like that.
113 return false;
114 }
115 switch (current_auth_) {
116 case AUTH_ATTESTATION:
117 current_auth_ = AUTH_OAUTH;
118 if (enrollment_config_.should_enroll_interactively()) {
119 SetConfig();
120 return true;
121 } else {
122 return false;
123 }
124 case AUTH_OAUTH:
125 return false;
126 }
127 return false;
80 } 128 }
81 129
82 void EnrollmentScreen::CreateEnrollmentHelper() { 130 void EnrollmentScreen::CreateEnrollmentHelper() {
83 DCHECK(!enrollment_helper_); 131 if (!enrollment_helper_) {
84 enrollment_helper_ = EnterpriseEnrollmentHelper::Create( 132 enrollment_helper_ = EnterpriseEnrollmentHelper::Create(
85 this, enrollment_config_, enrolling_user_domain_); 133 this, config_, enrolling_user_domain_);
134 }
86 } 135 }
87 136
88 void EnrollmentScreen::ClearAuth(const base::Closure& callback) { 137 void EnrollmentScreen::ClearAuth(const base::Closure& callback) {
89 if (!enrollment_helper_) { 138 if (!enrollment_helper_) {
90 callback.Run(); 139 callback.Run();
91 return; 140 return;
92 } 141 }
93 enrollment_helper_->ClearAuth(base::Bind(&EnrollmentScreen::OnAuthCleared, 142 enrollment_helper_->ClearAuth(base::Bind(&EnrollmentScreen::OnAuthCleared,
94 weak_ptr_factory_.GetWeakPtr(), 143 weak_ptr_factory_.GetWeakPtr(),
95 callback)); 144 callback));
96 } 145 }
97 146
98 void EnrollmentScreen::OnAuthCleared(const base::Closure& callback) { 147 void EnrollmentScreen::OnAuthCleared(const base::Closure& callback) {
99 enrollment_helper_.reset(); 148 enrollment_helper_ = nullptr;
100 callback.Run(); 149 callback.Run();
101 } 150 }
102 151
103 void EnrollmentScreen::PrepareToShow() { 152 void EnrollmentScreen::PrepareToShow() {
104 actor_->PrepareToShow(); 153 actor_->PrepareToShow();
105 } 154 }
106 155
107 void EnrollmentScreen::Show() { 156 void EnrollmentScreen::Show() {
108 UMA(policy::kMetricEnrollmentTriggered); 157 UMA(policy::kMetricEnrollmentTriggered);
158 switch (current_auth_) {
159 case AUTH_OAUTH:
160 ShowInteractiveScreen();
161 break;
162 case AUTH_ATTESTATION:
163 AuthenticateUsingAttestation();
164 break;
165 }
166 }
167
168 void EnrollmentScreen::ShowInteractiveScreen() {
109 ClearAuth(base::Bind(&EnrollmentScreen::ShowSigninScreen, 169 ClearAuth(base::Bind(&EnrollmentScreen::ShowSigninScreen,
110 weak_ptr_factory_.GetWeakPtr())); 170 weak_ptr_factory_.GetWeakPtr()));
111 } 171 }
112 172
113 void EnrollmentScreen::Hide() { 173 void EnrollmentScreen::Hide() {
114 actor_->Hide(); 174 actor_->Hide();
115 weak_ptr_factory_.InvalidateWeakPtrs(); 175 weak_ptr_factory_.InvalidateWeakPtrs();
116 } 176 }
117 177
118 std::string EnrollmentScreen::GetName() const { 178 std::string EnrollmentScreen::GetName() const {
119 return WizardController::kEnrollmentScreenName; 179 return WizardController::kEnrollmentScreenName;
120 } 180 }
121 181
182 void EnrollmentScreen::AuthenticateUsingAttestation() {
183 VLOG(1) << "Authenticating using attestation.";
184 elapsed_timer_.reset(new base::ElapsedTimer());
185 actor_->Show();
186 actor_->ShowEnrollmentSpinnerScreen();
187 CreateEnrollmentHelper();
188 enrollment_helper_->EnrollUsingAttestation();
189 }
190
122 void EnrollmentScreen::OnLoginDone(const std::string& user, 191 void EnrollmentScreen::OnLoginDone(const std::string& user,
123 const std::string& auth_code) { 192 const std::string& auth_code) {
124 LOG_IF(ERROR, auth_code.empty()) << "Auth code is empty."; 193 LOG_IF(ERROR, auth_code.empty()) << "Auth code is empty.";
125 elapsed_timer_.reset(new base::ElapsedTimer()); 194 elapsed_timer_.reset(new base::ElapsedTimer());
126 enrolling_user_domain_ = gaia::ExtractDomainName(user); 195 enrolling_user_domain_ = gaia::ExtractDomainName(user);
127 196
128 UMA(enrollment_failed_once_ ? policy::kMetricEnrollmentRestarted 197 UMA(enrollment_failed_once_ ? policy::kMetricEnrollmentRestarted
129 : policy::kMetricEnrollmentStarted); 198 : policy::kMetricEnrollmentStarted);
130 199
131 actor_->ShowEnrollmentSpinnerScreen(); 200 actor_->ShowEnrollmentSpinnerScreen();
132 CreateEnrollmentHelper(); 201 CreateEnrollmentHelper();
133 enrollment_helper_->EnrollUsingAuthCode( 202 enrollment_helper_->EnrollUsingAuthCode(
134 auth_code, shark_controller_ != NULL /* fetch_additional_token */); 203 auth_code, shark_controller_ != NULL /* fetch_additional_token */);
135 } 204 }
136 205
137 void EnrollmentScreen::OnRetry() { 206 void EnrollmentScreen::OnRetry() {
138 ClearAuth(base::Bind(&EnrollmentScreen::ShowSigninScreen, 207 Show();
139 weak_ptr_factory_.GetWeakPtr()));
140 } 208 }
141 209
142 void EnrollmentScreen::OnCancel() { 210 void EnrollmentScreen::OnCancel() {
211 if (AdvanceToNextAuth()) {
212 Show();
213 return;
214 }
215
143 UMA(policy::kMetricEnrollmentCancelled); 216 UMA(policy::kMetricEnrollmentCancelled);
144 if (elapsed_timer_) 217 if (elapsed_timer_)
145 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeCancel, elapsed_timer_); 218 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeCancel, elapsed_timer_);
146 219
147 const BaseScreenDelegate::ExitCodes exit_code = 220 const BaseScreenDelegate::ExitCodes exit_code =
148 enrollment_config_.is_forced() 221 config_.is_forced() ? BaseScreenDelegate::ENTERPRISE_ENROLLMENT_BACK
149 ? BaseScreenDelegate::ENTERPRISE_ENROLLMENT_BACK 222 : BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED;
150 : BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED;
151 ClearAuth( 223 ClearAuth(
152 base::Bind(&EnrollmentScreen::Finish, base::Unretained(this), exit_code)); 224 base::Bind(&EnrollmentScreen::Finish, base::Unretained(this), exit_code));
153 } 225 }
154 226
155 void EnrollmentScreen::OnConfirmationClosed() { 227 void EnrollmentScreen::OnConfirmationClosed() {
156 ClearAuth(base::Bind(&EnrollmentScreen::Finish, base::Unretained(this), 228 ClearAuth(base::Bind(&EnrollmentScreen::Finish, base::Unretained(this),
157 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED)); 229 BaseScreenDelegate::ENTERPRISE_ENROLLMENT_COMPLETED));
158 } 230 }
159 231
160 void EnrollmentScreen::OnAuthError(const GoogleServiceAuthError& error) { 232 void EnrollmentScreen::OnAuthError(const GoogleServiceAuthError& error) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 } 317 }
246 318
247 void EnrollmentScreen::ShowEnrollmentStatusOnSuccess() { 319 void EnrollmentScreen::ShowEnrollmentStatusOnSuccess() {
248 if (elapsed_timer_) 320 if (elapsed_timer_)
249 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeSuccess, elapsed_timer_); 321 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeSuccess, elapsed_timer_);
250 actor_->ShowEnrollmentStatus(policy::EnrollmentStatus::ForStatus( 322 actor_->ShowEnrollmentStatus(policy::EnrollmentStatus::ForStatus(
251 policy::EnrollmentStatus::STATUS_SUCCESS)); 323 policy::EnrollmentStatus::STATUS_SUCCESS));
252 } 324 }
253 325
254 void EnrollmentScreen::UMA(policy::MetricEnrollment sample) { 326 void EnrollmentScreen::UMA(policy::MetricEnrollment sample) {
255 EnrollmentUMA(sample, enrollment_config_.mode); 327 EnrollmentUMA(sample, config_.mode);
256 } 328 }
257 329
258 void EnrollmentScreen::ShowSigninScreen() { 330 void EnrollmentScreen::ShowSigninScreen() {
259 actor_->Show(); 331 actor_->Show();
260 actor_->ShowSigninScreen(); 332 actor_->ShowSigninScreen();
261 } 333 }
262 334
263 void EnrollmentScreen::OnAnyEnrollmentError() { 335 void EnrollmentScreen::OnAnyEnrollmentError() {
264 enrollment_failed_once_ = true; 336 enrollment_failed_once_ = true;
337 // TODO(drcrash): Maybe create multiple metrics for attestation vs oauth?
265 if (elapsed_timer_) 338 if (elapsed_timer_)
266 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeFailure, elapsed_timer_); 339 UMA_ENROLLMENT_TIME(kMetricEnrollmentTimeFailure, elapsed_timer_);
267 } 340 }
268 341
269 } // namespace chromeos 342 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698