| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/enterprise_enrollment_screen.h" | 5 #include "chrome/browser/chromeos/login/enterprise_enrollment_screen.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 10 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
| 9 #include "chrome/browser/chromeos/login/screen_observer.h" | 11 #include "chrome/browser/chromeos/login/screen_observer.h" |
| 10 #include "chrome/browser/policy/browser_policy_connector.h" | 12 #include "chrome/browser/policy/browser_policy_connector.h" |
| 11 #include "chrome/common/net/gaia/gaia_constants.h" | 13 #include "chrome/common/net/gaia/gaia_constants.h" |
| 12 | 14 |
| 13 namespace chromeos { | 15 namespace chromeos { |
| 14 | 16 |
| 17 // Retry for lockbox initialization every 500ms. |
| 18 const int kLockboxRetryIntervalMs = 500; |
| 19 |
| 15 EnterpriseEnrollmentScreen::EnterpriseEnrollmentScreen( | 20 EnterpriseEnrollmentScreen::EnterpriseEnrollmentScreen( |
| 16 WizardScreenDelegate* delegate) | 21 WizardScreenDelegate* delegate) |
| 17 : ViewScreen<EnterpriseEnrollmentView>(delegate) {} | 22 : ViewScreen<EnterpriseEnrollmentView>(delegate), |
| 23 ALLOW_THIS_IN_INITIALIZER_LIST(runnable_method_factory_(this)) {} |
| 18 | 24 |
| 19 EnterpriseEnrollmentScreen::~EnterpriseEnrollmentScreen() {} | 25 EnterpriseEnrollmentScreen::~EnterpriseEnrollmentScreen() {} |
| 20 | 26 |
| 21 void EnterpriseEnrollmentScreen::Authenticate(const std::string& user, | 27 void EnterpriseEnrollmentScreen::Authenticate(const std::string& user, |
| 22 const std::string& password, | 28 const std::string& password, |
| 23 const std::string& captcha, | 29 const std::string& captcha, |
| 24 const std::string& access_code) { | 30 const std::string& access_code) { |
| 25 captcha_token_.clear(); | 31 captcha_token_.clear(); |
| 26 user_ = user; | 32 user_ = user; |
| 27 auth_fetcher_.reset( | 33 auth_fetcher_.reset( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 50 } | 56 } |
| 51 | 57 |
| 52 void EnterpriseEnrollmentScreen::CloseConfirmation() { | 58 void EnterpriseEnrollmentScreen::CloseConfirmation() { |
| 53 auth_fetcher_.reset(); | 59 auth_fetcher_.reset(); |
| 54 ScreenObserver* observer = delegate()->GetObserver(this); | 60 ScreenObserver* observer = delegate()->GetObserver(this); |
| 55 observer->OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_COMPLETED); | 61 observer->OnExit(ScreenObserver::ENTERPRISE_ENROLLMENT_COMPLETED); |
| 56 } | 62 } |
| 57 | 63 |
| 58 void EnterpriseEnrollmentScreen::OnClientLoginSuccess( | 64 void EnterpriseEnrollmentScreen::OnClientLoginSuccess( |
| 59 const ClientLoginResult& result) { | 65 const ClientLoginResult& result) { |
| 60 auth_fetcher_->StartIssueAuthToken(result.sid, result.lsid, | 66 WriteLockboxData(result); |
| 61 GaiaConstants::kDeviceManagementService); | |
| 62 } | 67 } |
| 63 | 68 |
| 64 void EnterpriseEnrollmentScreen::OnClientLoginFailure( | 69 void EnterpriseEnrollmentScreen::OnClientLoginFailure( |
| 65 const GoogleServiceAuthError& error) { | 70 const GoogleServiceAuthError& error) { |
| 66 HandleAuthError(error); | 71 HandleAuthError(error); |
| 67 } | 72 } |
| 68 | 73 |
| 69 void EnterpriseEnrollmentScreen::OnIssueAuthTokenSuccess( | 74 void EnterpriseEnrollmentScreen::OnIssueAuthTokenSuccess( |
| 70 const std::string& service, | 75 const std::string& service, |
| 71 const std::string& auth_token) { | 76 const std::string& auth_token) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 // fall through. | 175 // fall through. |
| 171 case GoogleServiceAuthError::REQUEST_CANCELED: | 176 case GoogleServiceAuthError::REQUEST_CANCELED: |
| 172 LOG(ERROR) << "Unexpected GAIA auth error: " << error.state(); | 177 LOG(ERROR) << "Unexpected GAIA auth error: " << error.state(); |
| 173 view()->ShowFatalAuthError(); | 178 view()->ShowFatalAuthError(); |
| 174 return; | 179 return; |
| 175 } | 180 } |
| 176 | 181 |
| 177 NOTREACHED() << error.state(); | 182 NOTREACHED() << error.state(); |
| 178 } | 183 } |
| 179 | 184 |
| 185 void EnterpriseEnrollmentScreen::WriteLockboxData( |
| 186 const ClientLoginResult& result) { |
| 187 // Since this method is also called directly. |
| 188 runnable_method_factory_.RevokeAll(); |
| 189 |
| 190 chromeos::CryptohomeLibrary* cryptohome = |
| 191 chromeos::CrosLibrary::Get()->GetCryptohomeLibrary(); |
| 192 if (!cryptohome->InstallAttributesIsReady()) { |
| 193 // Lockbox is not read yet, reschedule pulling. |
| 194 LOG(WARNING) << "Lockbox is not ready yet will retry in " |
| 195 << kLockboxRetryIntervalMs << "ms."; |
| 196 MessageLoop::current()->PostDelayedTask( |
| 197 FROM_HERE, |
| 198 runnable_method_factory_.NewRunnableMethod( |
| 199 &EnterpriseEnrollmentScreen::WriteLockboxData, result), |
| 200 kLockboxRetryIntervalMs); |
| 201 } else { |
| 202 // Set values in the lockbox and lock it. |
| 203 if (!cryptohome->InstallAttributesIsFirstInstall()) { |
| 204 LOG(ERROR) << "Enrollment can not proceed because the lockbox " |
| 205 << "has been altered already!"; |
| 206 view()->ShowFatalEnrollmentError(); |
| 207 } |
| 208 DCHECK(cryptohome->InstallAttributesIsFirstInstall()); |
| 209 cryptohome->InstallAttributesSet("enterprise.owned", "true"); |
| 210 cryptohome->InstallAttributesSet("enterprise.user", user_); |
| 211 DCHECK(cryptohome->InstallAttributesCount() == 2); |
| 212 cryptohome->InstallAttributesFinalize(); |
| 213 if (cryptohome->InstallAttributesIsFirstInstall()) { |
| 214 LOG(ERROR) << "Enrollment can not proceed because the lockbox " |
| 215 << "can not be sealed!"; |
| 216 view()->ShowFatalEnrollmentError(); |
| 217 } else { |
| 218 auth_fetcher_->StartIssueAuthToken( |
| 219 result.sid, result.lsid, GaiaConstants::kDeviceManagementService); |
| 220 } |
| 221 } |
| 222 } |
| 223 |
| 180 } // namespace chromeos | 224 } // namespace chromeos |
| OLD | NEW |