| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h" | 5 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/base64url.h" | 9 #include "base/base64url.h" |
| 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/time/clock.h" | 11 #include "base/time/clock.h" |
| 11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 12 #include "components/prefs/pref_registry_simple.h" | 13 #include "components/prefs/pref_registry_simple.h" |
| 13 #include "components/prefs/pref_service.h" | 14 #include "components/prefs/pref_service.h" |
| 14 #include "components/proximity_auth/cryptauth/cryptauth_enroller.h" | 15 #include "components/proximity_auth/cryptauth/cryptauth_enroller.h" |
| 15 #include "components/proximity_auth/cryptauth/pref_names.h" | 16 #include "components/proximity_auth/cryptauth/pref_names.h" |
| 16 #include "components/proximity_auth/cryptauth/secure_message_delegate.h" | 17 #include "components/proximity_auth/cryptauth/secure_message_delegate.h" |
| 17 #include "components/proximity_auth/cryptauth/sync_scheduler_impl.h" | 18 #include "components/proximity_auth/cryptauth/sync_scheduler_impl.h" |
| 18 #include "components/proximity_auth/logging/logging.h" | 19 #include "components/proximity_auth/logging/logging.h" |
| 19 | 20 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 37 const double kEnrollmentMaxJitterRatio = 0.2; | 38 const double kEnrollmentMaxJitterRatio = 0.2; |
| 38 | 39 |
| 39 // The value of the device_software_package field in the device info uploaded | 40 // The value of the device_software_package field in the device info uploaded |
| 40 // during enrollment. This value must be the same as the app id used for GCM | 41 // during enrollment. This value must be the same as the app id used for GCM |
| 41 // registration. | 42 // registration. |
| 42 const char kDeviceSoftwarePackage[] = "com.google.chrome.cryptauth"; | 43 const char kDeviceSoftwarePackage[] = "com.google.chrome.cryptauth"; |
| 43 | 44 |
| 44 } // namespace | 45 } // namespace |
| 45 | 46 |
| 46 CryptAuthEnrollmentManager::CryptAuthEnrollmentManager( | 47 CryptAuthEnrollmentManager::CryptAuthEnrollmentManager( |
| 47 scoped_ptr<base::Clock> clock, | 48 std::unique_ptr<base::Clock> clock, |
| 48 scoped_ptr<CryptAuthEnrollerFactory> enroller_factory, | 49 std::unique_ptr<CryptAuthEnrollerFactory> enroller_factory, |
| 49 scoped_ptr<SecureMessageDelegate> secure_message_delegate, | 50 std::unique_ptr<SecureMessageDelegate> secure_message_delegate, |
| 50 const cryptauth::GcmDeviceInfo& device_info, | 51 const cryptauth::GcmDeviceInfo& device_info, |
| 51 CryptAuthGCMManager* gcm_manager, | 52 CryptAuthGCMManager* gcm_manager, |
| 52 PrefService* pref_service) | 53 PrefService* pref_service) |
| 53 : clock_(std::move(clock)), | 54 : clock_(std::move(clock)), |
| 54 enroller_factory_(std::move(enroller_factory)), | 55 enroller_factory_(std::move(enroller_factory)), |
| 55 secure_message_delegate_(std::move(secure_message_delegate)), | 56 secure_message_delegate_(std::move(secure_message_delegate)), |
| 56 device_info_(device_info), | 57 device_info_(device_info), |
| 57 gcm_manager_(gcm_manager), | 58 gcm_manager_(gcm_manager), |
| 58 pref_service_(pref_service), | 59 pref_service_(pref_service), |
| 59 weak_ptr_factory_(this) {} | 60 weak_ptr_factory_(this) {} |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 151 |
| 151 pref_service_->SetBoolean(prefs::kCryptAuthEnrollmentIsRecoveringFromFailure, | 152 pref_service_->SetBoolean(prefs::kCryptAuthEnrollmentIsRecoveringFromFailure, |
| 152 !success); | 153 !success); |
| 153 | 154 |
| 154 sync_request_->OnDidComplete(success); | 155 sync_request_->OnDidComplete(success); |
| 155 cryptauth_enroller_.reset(); | 156 cryptauth_enroller_.reset(); |
| 156 sync_request_.reset(); | 157 sync_request_.reset(); |
| 157 FOR_EACH_OBSERVER(Observer, observers_, OnEnrollmentFinished(success)); | 158 FOR_EACH_OBSERVER(Observer, observers_, OnEnrollmentFinished(success)); |
| 158 } | 159 } |
| 159 | 160 |
| 160 scoped_ptr<SyncScheduler> CryptAuthEnrollmentManager::CreateSyncScheduler() { | 161 std::unique_ptr<SyncScheduler> |
| 161 return make_scoped_ptr(new SyncSchedulerImpl( | 162 CryptAuthEnrollmentManager::CreateSyncScheduler() { |
| 163 return base::WrapUnique(new SyncSchedulerImpl( |
| 162 this, base::TimeDelta::FromDays(kEnrollmentRefreshPeriodDays), | 164 this, base::TimeDelta::FromDays(kEnrollmentRefreshPeriodDays), |
| 163 base::TimeDelta::FromMinutes(kEnrollmentBaseRecoveryPeriodMinutes), | 165 base::TimeDelta::FromMinutes(kEnrollmentBaseRecoveryPeriodMinutes), |
| 164 kEnrollmentMaxJitterRatio, "CryptAuth Enrollment")); | 166 kEnrollmentMaxJitterRatio, "CryptAuth Enrollment")); |
| 165 } | 167 } |
| 166 | 168 |
| 167 std::string CryptAuthEnrollmentManager::GetUserPublicKey() { | 169 std::string CryptAuthEnrollmentManager::GetUserPublicKey() { |
| 168 std::string public_key; | 170 std::string public_key; |
| 169 if (!base::Base64UrlDecode( | 171 if (!base::Base64UrlDecode( |
| 170 pref_service_->GetString(prefs::kCryptAuthEnrollmentUserPublicKey), | 172 pref_service_->GetString(prefs::kCryptAuthEnrollmentUserPublicKey), |
| 171 base::Base64UrlDecodePolicy::REQUIRE_PADDING, &public_key)) { | 173 base::Base64UrlDecodePolicy::REQUIRE_PADDING, &public_key)) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 } else { | 222 } else { |
| 221 OnEnrollmentFinished(false); | 223 OnEnrollmentFinished(false); |
| 222 } | 224 } |
| 223 } | 225 } |
| 224 | 226 |
| 225 void CryptAuthEnrollmentManager::OnReenrollMessage() { | 227 void CryptAuthEnrollmentManager::OnReenrollMessage() { |
| 226 ForceEnrollmentNow(cryptauth::INVOCATION_REASON_SERVER_INITIATED); | 228 ForceEnrollmentNow(cryptauth::INVOCATION_REASON_SERVER_INITIATED); |
| 227 } | 229 } |
| 228 | 230 |
| 229 void CryptAuthEnrollmentManager::OnSyncRequested( | 231 void CryptAuthEnrollmentManager::OnSyncRequested( |
| 230 scoped_ptr<SyncScheduler::SyncRequest> sync_request) { | 232 std::unique_ptr<SyncScheduler::SyncRequest> sync_request) { |
| 231 FOR_EACH_OBSERVER(Observer, observers_, OnEnrollmentStarted()); | 233 FOR_EACH_OBSERVER(Observer, observers_, OnEnrollmentStarted()); |
| 232 | 234 |
| 233 sync_request_ = std::move(sync_request); | 235 sync_request_ = std::move(sync_request); |
| 234 if (gcm_manager_->GetRegistrationId().empty() || | 236 if (gcm_manager_->GetRegistrationId().empty() || |
| 235 pref_service_->GetInteger(prefs::kCryptAuthEnrollmentReason) == | 237 pref_service_->GetInteger(prefs::kCryptAuthEnrollmentReason) == |
| 236 cryptauth::INVOCATION_REASON_MANUAL) { | 238 cryptauth::INVOCATION_REASON_MANUAL) { |
| 237 gcm_manager_->RegisterWithGCM(); | 239 gcm_manager_->RegisterWithGCM(); |
| 238 } else { | 240 } else { |
| 239 DoCryptAuthEnrollment(); | 241 DoCryptAuthEnrollment(); |
| 240 } | 242 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 << device_info.gcm_registration_id(); | 293 << device_info.gcm_registration_id(); |
| 292 | 294 |
| 293 cryptauth_enroller_ = enroller_factory_->CreateInstance(); | 295 cryptauth_enroller_ = enroller_factory_->CreateInstance(); |
| 294 cryptauth_enroller_->Enroll( | 296 cryptauth_enroller_->Enroll( |
| 295 GetUserPublicKey(), GetUserPrivateKey(), device_info, invocation_reason, | 297 GetUserPublicKey(), GetUserPrivateKey(), device_info, invocation_reason, |
| 296 base::Bind(&CryptAuthEnrollmentManager::OnEnrollmentFinished, | 298 base::Bind(&CryptAuthEnrollmentManager::OnEnrollmentFinished, |
| 297 weak_ptr_factory_.GetWeakPtr())); | 299 weak_ptr_factory_.GetWeakPtr())); |
| 298 } | 300 } |
| 299 | 301 |
| 300 } // namespace proximity_auth | 302 } // namespace proximity_auth |
| OLD | NEW |