| OLD | NEW |
| 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 "components/policy/core/common/cloud/cloud_policy_client.h" | 5 #include "components/policy/core/common/cloud/cloud_policy_client.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 // Sets the client ID or generate a new one. A new one is intentionally | 124 // Sets the client ID or generate a new one. A new one is intentionally |
| 125 // generated on each new registration request in order to preserve privacy. | 125 // generated on each new registration request in order to preserve privacy. |
| 126 // Reusing IDs would mean the server could track clients by their registration | 126 // Reusing IDs would mean the server could track clients by their registration |
| 127 // attempts. | 127 // attempts. |
| 128 void CloudPolicyClient::SetClientId(const std::string& client_id) { | 128 void CloudPolicyClient::SetClientId(const std::string& client_id) { |
| 129 client_id_ = client_id.empty() ? base::GenerateGUID() : client_id; | 129 client_id_ = client_id.empty() ? base::GenerateGUID() : client_id; |
| 130 } | 130 } |
| 131 | 131 |
| 132 void CloudPolicyClient::Register(em::DeviceRegisterRequest::Type type, | 132 void CloudPolicyClient::Register(em::DeviceRegisterRequest::Type type, |
| 133 em::DeviceRegisterRequest::Flavor flavor, | 133 em::DeviceRegisterRequest::Flavor flavor, |
| 134 em::LicenseType::LicenseTypeEnum license_type, |
| 134 const std::string& auth_token, | 135 const std::string& auth_token, |
| 135 const std::string& client_id, | 136 const std::string& client_id, |
| 136 const std::string& requisition, | 137 const std::string& requisition, |
| 137 const std::string& current_state_key) { | 138 const std::string& current_state_key) { |
| 138 DCHECK(service_); | 139 DCHECK(service_); |
| 139 DCHECK(!auth_token.empty()); | 140 DCHECK(!auth_token.empty()); |
| 140 DCHECK(!is_registered()); | 141 DCHECK(!is_registered()); |
| 141 | 142 |
| 142 SetClientId(client_id); | 143 SetClientId(client_id); |
| 143 | 144 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 154 request->set_type(type); | 155 request->set_type(type); |
| 155 if (!machine_id_.empty()) | 156 if (!machine_id_.empty()) |
| 156 request->set_machine_id(machine_id_); | 157 request->set_machine_id(machine_id_); |
| 157 if (!machine_model_.empty()) | 158 if (!machine_model_.empty()) |
| 158 request->set_machine_model(machine_model_); | 159 request->set_machine_model(machine_model_); |
| 159 if (!requisition.empty()) | 160 if (!requisition.empty()) |
| 160 request->set_requisition(requisition); | 161 request->set_requisition(requisition); |
| 161 if (!current_state_key.empty()) | 162 if (!current_state_key.empty()) |
| 162 request->set_server_backed_state_key(current_state_key); | 163 request->set_server_backed_state_key(current_state_key); |
| 163 request->set_flavor(flavor); | 164 request->set_flavor(flavor); |
| 165 if (license_type != em::LicenseType::UNDEFINED) |
| 166 request->mutable_license_type()->set_license_type(license_type); |
| 164 | 167 |
| 165 policy_fetch_request_job_->SetRetryCallback( | 168 policy_fetch_request_job_->SetRetryCallback( |
| 166 base::Bind(&CloudPolicyClient::OnRetryRegister, | 169 base::Bind(&CloudPolicyClient::OnRetryRegister, |
| 167 weak_ptr_factory_.GetWeakPtr())); | 170 weak_ptr_factory_.GetWeakPtr())); |
| 168 | 171 |
| 169 policy_fetch_request_job_->Start( | 172 policy_fetch_request_job_->Start( |
| 170 base::Bind(&CloudPolicyClient::OnRegisterCompleted, | 173 base::Bind(&CloudPolicyClient::OnRegisterCompleted, |
| 171 weak_ptr_factory_.GetWeakPtr())); | 174 weak_ptr_factory_.GetWeakPtr())); |
| 172 } | 175 } |
| 173 | 176 |
| 174 void CloudPolicyClient::RegisterWithCertificate( | 177 void CloudPolicyClient::RegisterWithCertificate( |
| 175 em::DeviceRegisterRequest::Type type, | 178 em::DeviceRegisterRequest::Type type, |
| 176 em::DeviceRegisterRequest::Flavor flavor, | 179 em::DeviceRegisterRequest::Flavor flavor, |
| 180 em::LicenseType::LicenseTypeEnum license_type, |
| 177 const std::string& pem_certificate_chain, | 181 const std::string& pem_certificate_chain, |
| 178 const std::string& client_id, | 182 const std::string& client_id, |
| 179 const std::string& requisition, | 183 const std::string& requisition, |
| 180 const std::string& current_state_key) { | 184 const std::string& current_state_key) { |
| 181 DCHECK(signing_service_); | 185 DCHECK(signing_service_); |
| 182 DCHECK(service_); | 186 DCHECK(service_); |
| 183 DCHECK(!is_registered()); | 187 DCHECK(!is_registered()); |
| 184 | 188 |
| 185 SetClientId(client_id); | 189 SetClientId(client_id); |
| 186 | 190 |
| 187 em::CertificateBasedDeviceRegistrationData data; | 191 em::CertificateBasedDeviceRegistrationData data; |
| 188 data.set_certificate_type(em::CertificateBasedDeviceRegistrationData:: | 192 data.set_certificate_type(em::CertificateBasedDeviceRegistrationData:: |
| 189 ENTERPRISE_ENROLLMENT_CERTIFICATE); | 193 ENTERPRISE_ENROLLMENT_CERTIFICATE); |
| 190 data.set_device_certificate(pem_certificate_chain); | 194 data.set_device_certificate(pem_certificate_chain); |
| 191 | 195 |
| 192 em::DeviceRegisterRequest* request = data.mutable_device_register_request(); | 196 em::DeviceRegisterRequest* request = data.mutable_device_register_request(); |
| 193 if (!client_id.empty()) | 197 if (!client_id.empty()) |
| 194 request->set_reregister(true); | 198 request->set_reregister(true); |
| 195 request->set_type(type); | 199 request->set_type(type); |
| 196 if (!machine_id_.empty()) | 200 if (!machine_id_.empty()) |
| 197 request->set_machine_id(machine_id_); | 201 request->set_machine_id(machine_id_); |
| 198 if (!machine_model_.empty()) | 202 if (!machine_model_.empty()) |
| 199 request->set_machine_model(machine_model_); | 203 request->set_machine_model(machine_model_); |
| 200 if (!requisition.empty()) | 204 if (!requisition.empty()) |
| 201 request->set_requisition(requisition); | 205 request->set_requisition(requisition); |
| 202 if (!current_state_key.empty()) | 206 if (!current_state_key.empty()) |
| 203 request->set_server_backed_state_key(current_state_key); | 207 request->set_server_backed_state_key(current_state_key); |
| 204 request->set_flavor(flavor); | 208 request->set_flavor(flavor); |
| 209 if (license_type != em::LicenseType::UNDEFINED) |
| 210 request->mutable_license_type()->set_license_type(license_type); |
| 205 | 211 |
| 206 signing_service_->SignData(data.SerializeAsString(), | 212 signing_service_->SignData(data.SerializeAsString(), |
| 207 base::Bind(&CloudPolicyClient::OnRegisterWithCertificateRequestSigned, | 213 base::Bind(&CloudPolicyClient::OnRegisterWithCertificateRequestSigned, |
| 208 weak_ptr_factory_.GetWeakPtr())); | 214 weak_ptr_factory_.GetWeakPtr())); |
| 209 } | 215 } |
| 210 | 216 |
| 211 void CloudPolicyClient::OnRegisterWithCertificateRequestSigned(bool success, | 217 void CloudPolicyClient::OnRegisterWithCertificateRequestSigned(bool success, |
| 212 em::SignedData signed_data) { | 218 em::SignedData signed_data) { |
| 213 if (!success) { | 219 if (!success) { |
| 214 const em::DeviceManagementResponse response; | 220 const em::DeviceManagementResponse response; |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 for (auto& observer : observers_) | 878 for (auto& observer : observers_) |
| 873 observer.OnRobotAuthCodesFetched(this); | 879 observer.OnRobotAuthCodesFetched(this); |
| 874 } | 880 } |
| 875 | 881 |
| 876 void CloudPolicyClient::NotifyClientError() { | 882 void CloudPolicyClient::NotifyClientError() { |
| 877 for (auto& observer : observers_) | 883 for (auto& observer : observers_) |
| 878 observer.OnClientError(this); | 884 observer.OnClientError(this); |
| 879 } | 885 } |
| 880 | 886 |
| 881 } // namespace policy | 887 } // namespace policy |
| OLD | NEW |