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

Side by Side Diff: chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper_impl.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/enterprise_enrollment_helper_ impl.h" 5 #include "chrome/browser/chromeos/login/enrollment/enterprise_enrollment_helper_ impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 namespace chromeos { 66 namespace chromeos {
67 67
68 EnterpriseEnrollmentHelperImpl::EnterpriseEnrollmentHelperImpl( 68 EnterpriseEnrollmentHelperImpl::EnterpriseEnrollmentHelperImpl(
69 EnrollmentStatusConsumer* status_consumer, 69 EnrollmentStatusConsumer* status_consumer,
70 const policy::EnrollmentConfig& enrollment_config, 70 const policy::EnrollmentConfig& enrollment_config,
71 const std::string& enrolling_user_domain) 71 const std::string& enrolling_user_domain)
72 : EnterpriseEnrollmentHelper(status_consumer), 72 : EnterpriseEnrollmentHelper(status_consumer),
73 enrollment_config_(enrollment_config), 73 enrollment_config_(enrollment_config),
74 enrolling_user_domain_(enrolling_user_domain), 74 enrolling_user_domain_(enrolling_user_domain),
75 started_(false), 75 started_oauth_(false),
76 finished_(false), 76 finished_oauth_(false),
77 success_(false), 77 success_(false),
78 auth_data_cleared_(false), 78 auth_data_cleared_(false),
79 weak_ptr_factory_(this) { 79 weak_ptr_factory_(this) {
80 // Init the TPM if it has not been done until now (in debug build we might 80 // Init the TPM if it has not been done until now (in debug build we might
81 // have not done that yet). 81 // have not done that yet).
82 DBusThreadManager::Get()->GetCryptohomeClient()->TpmCanAttemptOwnership( 82 DBusThreadManager::Get()->GetCryptohomeClient()->TpmCanAttemptOwnership(
83 EmptyVoidDBusMethodCallback()); 83 EmptyVoidDBusMethodCallback());
84 } 84 }
85 85
86 EnterpriseEnrollmentHelperImpl::~EnterpriseEnrollmentHelperImpl() { 86 EnterpriseEnrollmentHelperImpl::~EnterpriseEnrollmentHelperImpl() {
87 DCHECK(g_browser_process->IsShuttingDown() || !started_ || 87 DCHECK(g_browser_process->IsShuttingDown() || !started_oauth_ ||
88 (finished_ && (success_ || auth_data_cleared_))); 88 (finished_oauth_ && (success_ || auth_data_cleared_)));
89 } 89 }
90 90
91 void EnterpriseEnrollmentHelperImpl::EnrollUsingAuthCode( 91 void EnterpriseEnrollmentHelperImpl::EnrollUsingAuthCode(
92 const std::string& auth_code, 92 const std::string& auth_code,
93 bool fetch_additional_token) { 93 bool fetch_additional_token) {
94 DCHECK(!started_); 94 DCHECK(!started_oauth_);
95 started_ = true; 95 started_oauth_ = true;
96 oauth_fetcher_.reset(policy::PolicyOAuth2TokenFetcher::CreateInstance()); 96 oauth_fetcher_.reset(policy::PolicyOAuth2TokenFetcher::CreateInstance());
97 oauth_fetcher_->StartWithAuthCode( 97 oauth_fetcher_->StartWithAuthCode(
98 auth_code, g_browser_process->system_request_context(), 98 auth_code, g_browser_process->system_request_context(),
99 base::Bind(&EnterpriseEnrollmentHelperImpl::OnTokenFetched, 99 base::Bind(&EnterpriseEnrollmentHelperImpl::OnTokenFetched,
100 weak_ptr_factory_.GetWeakPtr(), 100 weak_ptr_factory_.GetWeakPtr(),
101 fetch_additional_token /* is_additional_token */)); 101 fetch_additional_token /* is_additional_token */));
102 } 102 }
103 103
104 void EnterpriseEnrollmentHelperImpl::EnrollUsingToken( 104 void EnterpriseEnrollmentHelperImpl::EnrollUsingToken(
105 const std::string& token) { 105 const std::string& token) {
106 DCHECK(!started_); 106 DCHECK(!started_oauth_);
107 started_ = true; 107 started_oauth_ = true;
108 DoEnrollUsingToken(token); 108 DoEnroll(token);
109 }
110
111 void EnterpriseEnrollmentHelperImpl::EnrollUsingAttestation() {
112 DCHECK(enrollment_config_.mode ==
pastarmovj 2016/08/19 10:29:18 I wonder if this should not even be a CHECK. Could
The one and only Dr. Crash 2016/08/19 17:49:29 Sounds reasonable.
113 policy::EnrollmentConfig::MODE_ATTESTATION ||
114 enrollment_config_.mode ==
115 policy::EnrollmentConfig::MODE_ATTESTATION_FORCED);
116 DoEnroll("");
109 } 117 }
110 118
111 void EnterpriseEnrollmentHelperImpl::ClearAuth(const base::Closure& callback) { 119 void EnterpriseEnrollmentHelperImpl::ClearAuth(const base::Closure& callback) {
112 // Do not revoke the additional token if enrollment has finished 120 if (started_oauth_) {
113 // successfully. 121 // Do not revoke the additional token if enrollment has finished
114 if (!success_ && additional_token_.length()) 122 // successfully.
115 (new TokenRevoker())->Start(additional_token_); 123 if (!success_ && additional_token_.length())
124 (new TokenRevoker())->Start(additional_token_);
116 125
117 if (oauth_fetcher_) { 126 if (oauth_fetcher_) {
118 if (!oauth_fetcher_->OAuth2AccessToken().empty()) 127 if (!oauth_fetcher_->OAuth2AccessToken().empty())
119 (new TokenRevoker())->Start(oauth_fetcher_->OAuth2AccessToken()); 128 (new TokenRevoker())->Start(oauth_fetcher_->OAuth2AccessToken());
120 129
121 if (!oauth_fetcher_->OAuth2RefreshToken().empty()) 130 if (!oauth_fetcher_->OAuth2RefreshToken().empty())
122 (new TokenRevoker())->Start(oauth_fetcher_->OAuth2RefreshToken()); 131 (new TokenRevoker())->Start(oauth_fetcher_->OAuth2RefreshToken());
123 132
124 oauth_fetcher_.reset(); 133 oauth_fetcher_.reset();
125 } else if (oauth_token_.length()) { 134 } else if (oauth_token_.length()) {
126 // EnrollUsingToken was called. 135 // EnrollUsingToken was called.
127 (new TokenRevoker())->Start(oauth_token_); 136 (new TokenRevoker())->Start(oauth_token_);
137 }
128 } 138 }
129 139
130 chromeos::ProfileHelper::Get()->ClearSigninProfile( 140 chromeos::ProfileHelper::Get()->ClearSigninProfile(
131 base::Bind(&EnterpriseEnrollmentHelperImpl::OnSigninProfileCleared, 141 base::Bind(&EnterpriseEnrollmentHelperImpl::OnSigninProfileCleared,
132 weak_ptr_factory_.GetWeakPtr(), callback)); 142 weak_ptr_factory_.GetWeakPtr(), callback));
133 } 143 }
134 144
135 void EnterpriseEnrollmentHelperImpl::DoEnrollUsingToken( 145 void EnterpriseEnrollmentHelperImpl::DoEnroll(const std::string& token) {
136 const std::string& token) {
137 DCHECK(token == oauth_token_ || oauth_token_.empty()); 146 DCHECK(token == oauth_token_ || oauth_token_.empty());
138 oauth_token_ = token; 147 oauth_token_ = token;
139 policy::BrowserPolicyConnectorChromeOS* connector = 148 policy::BrowserPolicyConnectorChromeOS* connector =
140 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 149 g_browser_process->platform_part()->browser_policy_connector_chromeos();
141 if (connector->IsEnterpriseManaged() && 150 if (connector->IsEnterpriseManaged() &&
142 connector->GetEnterpriseDomain() != enrolling_user_domain_) { 151 connector->GetEnterpriseDomain() != enrolling_user_domain_) {
143 LOG(ERROR) << "Trying to re-enroll to a different domain than " 152 LOG(ERROR) << "Trying to re-enroll to a different domain than "
144 << connector->GetEnterpriseDomain(); 153 << connector->GetEnterpriseDomain();
145 UMA(policy::kMetricEnrollmentPrecheckDomainMismatch); 154 UMA(policy::kMetricEnrollmentPrecheckDomainMismatch);
146 finished_ = true; 155 finished_oauth_ = true;
147 status_consumer()->OnOtherError(OTHER_ERROR_DOMAIN_MISMATCH); 156 status_consumer()->OnOtherError(OTHER_ERROR_DOMAIN_MISMATCH);
148 return; 157 return;
149 } 158 }
150 159
151 policy::DeviceCloudPolicyInitializer::AllowedDeviceModes device_modes; 160 policy::DeviceCloudPolicyInitializer::AllowedDeviceModes device_modes;
152 device_modes[policy::DEVICE_MODE_ENTERPRISE] = true; 161 device_modes[policy::DEVICE_MODE_ENTERPRISE] = true;
153 connector->ScheduleServiceInitialization(0); 162 connector->ScheduleServiceInitialization(0);
154 163
155 policy::DeviceCloudPolicyInitializer* dcp_initializer = 164 policy::DeviceCloudPolicyInitializer* dcp_initializer =
156 connector->GetDeviceCloudPolicyInitializer(); 165 connector->GetDeviceCloudPolicyInitializer();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 &EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUploadCompleted, 202 &EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUploadCompleted,
194 weak_ptr_factory_.GetWeakPtr())); 203 weak_ptr_factory_.GetWeakPtr()));
195 } 204 }
196 205
197 void EnterpriseEnrollmentHelperImpl::OnTokenFetched( 206 void EnterpriseEnrollmentHelperImpl::OnTokenFetched(
198 bool is_additional_token, 207 bool is_additional_token,
199 const std::string& token, 208 const std::string& token,
200 const GoogleServiceAuthError& error) { 209 const GoogleServiceAuthError& error) {
201 if (error.state() != GoogleServiceAuthError::NONE) { 210 if (error.state() != GoogleServiceAuthError::NONE) {
202 ReportAuthStatus(error); 211 ReportAuthStatus(error);
203 finished_ = true; 212 finished_oauth_ = true;
204 status_consumer()->OnAuthError(error); 213 status_consumer()->OnAuthError(error);
205 return; 214 return;
206 } 215 }
207 216
208 if (!is_additional_token) { 217 if (!is_additional_token) {
209 DoEnrollUsingToken(token); 218 EnrollUsingToken(token);
210 return; 219 return;
211 } 220 }
212 221
213 additional_token_ = token; 222 additional_token_ = token;
214 std::string refresh_token = oauth_fetcher_->OAuth2RefreshToken(); 223 std::string refresh_token = oauth_fetcher_->OAuth2RefreshToken();
215 oauth_fetcher_.reset(policy::PolicyOAuth2TokenFetcher::CreateInstance()); 224 oauth_fetcher_.reset(policy::PolicyOAuth2TokenFetcher::CreateInstance());
216 oauth_fetcher_->StartWithRefreshToken( 225 oauth_fetcher_->StartWithRefreshToken(
217 refresh_token, g_browser_process->system_request_context(), 226 refresh_token, g_browser_process->system_request_context(),
218 base::Bind(&EnterpriseEnrollmentHelperImpl::OnTokenFetched, 227 base::Bind(&EnterpriseEnrollmentHelperImpl::OnTokenFetched,
219 weak_ptr_factory_.GetWeakPtr(), 228 weak_ptr_factory_.GetWeakPtr(),
220 false /* is_additional_token */)); 229 false /* is_additional_token */));
221 } 230 }
222 231
223 void EnterpriseEnrollmentHelperImpl::OnEnrollmentFinished( 232 void EnterpriseEnrollmentHelperImpl::OnEnrollmentFinished(
224 policy::EnrollmentStatus status) { 233 policy::EnrollmentStatus status) {
225 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed. 234 // TODO(pbond): remove this LOG once http://crbug.com/586961 is fixed.
226 LOG(WARNING) << "Enrollment finished"; 235 LOG(WARNING) << "Enrollment finished";
227 ReportEnrollmentStatus(status); 236 ReportEnrollmentStatus(status);
228 finished_ = true; 237 if (started_oauth_) {
238 finished_oauth_ = true;
239 }
229 if (status.status() == policy::EnrollmentStatus::STATUS_SUCCESS) { 240 if (status.status() == policy::EnrollmentStatus::STATUS_SUCCESS) {
230 success_ = true; 241 success_ = true;
231 StartupUtils::MarkOobeCompleted(); 242 StartupUtils::MarkOobeCompleted();
232 status_consumer()->OnDeviceEnrolled(additional_token_); 243 status_consumer()->OnDeviceEnrolled(additional_token_);
233 } else { 244 } else {
234 status_consumer()->OnEnrollmentError(status); 245 status_consumer()->OnEnrollmentError(status);
235 } 246 }
236 } 247 }
237 248
238 void EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUpdatePermission( 249 void EnterpriseEnrollmentHelperImpl::OnDeviceAttributeUpdatePermission(
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 EnrollmentUMA(sample, enrollment_config_.mode); 427 EnrollmentUMA(sample, enrollment_config_.mode);
417 } 428 }
418 429
419 void EnterpriseEnrollmentHelperImpl::OnSigninProfileCleared( 430 void EnterpriseEnrollmentHelperImpl::OnSigninProfileCleared(
420 const base::Closure& callback) { 431 const base::Closure& callback) {
421 auth_data_cleared_ = true; 432 auth_data_cleared_ = true;
422 callback.Run(); 433 callback.Run();
423 } 434 }
424 435
425 } // namespace chromeos 436 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698