Chromium Code Reviews| 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 #ifndef COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ | 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ |
| 6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ | 6 #define COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/callback.h" | 17 #include "base/callback.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/scoped_vector.h" | 19 #include "base/memory/scoped_vector.h" |
| 20 #include "base/observer_list.h" | 20 #include "base/observer_list.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 22 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 22 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 23 #include "components/policy/core/common/remote_commands/remote_command_job.h" | 23 #include "components/policy/core/common/remote_commands/remote_command_job.h" |
| 24 #include "components/policy/policy_export.h" | 24 #include "components/policy/policy_export.h" |
| 25 #include "policy/proto/device_management_backend.pb.h" | 25 #include "policy/proto/device_management_backend.pb.h" |
| 26 | 26 |
| 27 namespace cryptohome { | |
| 28 class AsyncMethodCaller; | |
| 29 } | |
| 30 | |
| 27 namespace net { | 31 namespace net { |
| 28 class URLRequestContextGetter; | 32 class URLRequestContextGetter; |
| 29 } | 33 } |
| 30 | 34 |
| 31 namespace policy { | 35 namespace policy { |
| 32 | 36 |
| 33 class DeviceManagementRequestJob; | 37 class DeviceManagementRequestJob; |
| 34 class DeviceManagementService; | 38 class DeviceManagementService; |
| 35 | 39 |
| 36 // Implements the core logic required to talk to the device management service. | 40 // Implements the core logic required to talk to the device management service. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 | 76 |
| 73 // Called when a request for device robot OAuth2 authorization tokens | 77 // Called when a request for device robot OAuth2 authorization tokens |
| 74 // returns successfully. Only occurs during enrollment. Optional | 78 // returns successfully. Only occurs during enrollment. Optional |
| 75 // (default implementation is a noop). | 79 // (default implementation is a noop). |
| 76 virtual void OnRobotAuthCodesFetched(CloudPolicyClient* client); | 80 virtual void OnRobotAuthCodesFetched(CloudPolicyClient* client); |
| 77 | 81 |
| 78 // Indicates there's been an error in a previously-issued request. | 82 // Indicates there's been an error in a previously-issued request. |
| 79 virtual void OnClientError(CloudPolicyClient* client) = 0; | 83 virtual void OnClientError(CloudPolicyClient* client) = 0; |
| 80 }; | 84 }; |
| 81 | 85 |
| 86 // Data signing interface. | |
| 87 class POLICY_EXPORT SigningService { | |
| 88 public: | |
| 89 typedef base::Callback<void(bool success, | |
| 90 enterprise_management::SignedData signed_data)> | |
| 91 SigningCallback; | |
|
pastarmovj
2016/08/22 15:09:43
nit: please add a new line between the two.
The one and only Dr. Crash
2016/08/22 16:00:02
Done.
| |
| 92 virtual void SignData(const std::string& data, | |
|
pastarmovj
2016/08/22 15:09:43
Please document this function so that whoever need
The one and only Dr. Crash
2016/08/22 16:00:02
Done.
| |
| 93 SigningCallback callback) = 0; | |
| 94 }; | |
| 95 | |
| 82 // |provider| and |service| are weak pointers and it's the caller's | 96 // |provider| and |service| are weak pointers and it's the caller's |
| 83 // responsibility to keep them valid for the lifetime of CloudPolicyClient. | 97 // responsibility to keep them valid for the lifetime of CloudPolicyClient. |
| 84 // |verification_key_hash| contains an identifier telling the DMServer which | 98 // |verification_key_hash| contains an identifier telling the DMServer which |
| 85 // verification key to use. | 99 // verification key to use. The |signing_service| is used to sign sensitive |
| 100 // requests. | |
| 86 CloudPolicyClient( | 101 CloudPolicyClient( |
|
pastarmovj
2016/08/22 15:09:43
Just thinking aloud here... could the signing serv
The one and only Dr. Crash
2016/08/22 16:00:01
I think the constructor patterns fits the code sty
| |
| 87 const std::string& machine_id, | 102 const std::string& machine_id, |
| 88 const std::string& machine_model, | 103 const std::string& machine_model, |
| 104 const std::string& verification_key_hash, | |
| 105 DeviceManagementService* service, | |
| 106 scoped_refptr<net::URLRequestContextGetter> request_context, | |
| 107 SigningService* signing_service); | |
| 108 // Constructs a client without signing support. | |
| 109 CloudPolicyClient( | |
| 110 const std::string& machine_id, | |
| 111 const std::string& machine_model, | |
| 89 const std::string& verification_key_hash, | 112 const std::string& verification_key_hash, |
| 90 DeviceManagementService* service, | 113 DeviceManagementService* service, |
| 91 scoped_refptr<net::URLRequestContextGetter> request_context); | 114 scoped_refptr<net::URLRequestContextGetter> request_context); |
| 92 virtual ~CloudPolicyClient(); | 115 virtual ~CloudPolicyClient(); |
| 93 | 116 |
| 94 // Sets the DMToken, thereby establishing a registration with the server. A | 117 // Sets the DMToken, thereby establishing a registration with the server. A |
| 95 // policy fetch is not automatically issued but can be requested by calling | 118 // policy fetch is not automatically issued but can be requested by calling |
| 96 // FetchPolicy(). | 119 // FetchPolicy(). |
| 97 virtual void SetupRegistration(const std::string& dm_token, | 120 virtual void SetupRegistration(const std::string& dm_token, |
| 98 const std::string& client_id); | 121 const std::string& client_id); |
| 99 | 122 |
| 100 // Attempts to register with the device management service. Results in a | 123 // Attempts to register with the device management service. Results in a |
| 101 // registration change or error notification. | 124 // registration change or error notification. |
| 102 virtual void Register( | 125 virtual void Register( |
| 103 enterprise_management::DeviceRegisterRequest::Type registration_type, | 126 enterprise_management::DeviceRegisterRequest::Type registration_type, |
| 104 enterprise_management::DeviceRegisterRequest::Flavor flavor, | 127 enterprise_management::DeviceRegisterRequest::Flavor flavor, |
| 105 const std::string& auth_token, | 128 const std::string& auth_token, |
| 106 const std::string& client_id, | 129 const std::string& client_id, |
| 107 const std::string& requisition, | 130 const std::string& requisition, |
| 108 const std::string& current_state_key); | 131 const std::string& current_state_key); |
| 109 | 132 |
| 133 // Attempts to register with the device management service using a | |
| 134 // registration certificate. Results in a registration change or | |
| 135 // error notification. | |
| 136 virtual void RegisterWithCertificate( | |
| 137 enterprise_management::DeviceRegisterRequest::Type registration_type, | |
| 138 enterprise_management::DeviceRegisterRequest::Flavor flavor, | |
| 139 const std::string& pem_certificate_chain, | |
| 140 const std::string& client_id, | |
| 141 const std::string& requisition, | |
| 142 const std::string& current_state_key); | |
| 143 | |
| 110 // Sets information about a policy invalidation. Subsequent fetch operations | 144 // Sets information about a policy invalidation. Subsequent fetch operations |
| 111 // will use the given info, and callers can use fetched_invalidation_version | 145 // will use the given info, and callers can use fetched_invalidation_version |
| 112 // to determine which version of policy was fetched. | 146 // to determine which version of policy was fetched. |
| 113 void SetInvalidationInfo(int64_t version, const std::string& payload); | 147 void SetInvalidationInfo(int64_t version, const std::string& payload); |
| 114 | 148 |
| 115 // Requests a policy fetch. The client being registered is a prerequisite to | 149 // Requests a policy fetch. The client being registered is a prerequisite to |
| 116 // this operation and this call will CHECK if the client is not in registered | 150 // this operation and this call will CHECK if the client is not in registered |
| 117 // state. FetchPolicy() triggers a policy fetch from the cloud. A policy | 151 // state. FetchPolicy() triggers a policy fetch from the cloud. A policy |
| 118 // change notification is reported to the observers and the new policy blob | 152 // change notification is reported to the observers and the new policy blob |
| 119 // can be retrieved once the policy fetch operation completes. In case of | 153 // can be retrieved once the policy fetch operation completes. In case of |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 // Returns the number of active requests. | 296 // Returns the number of active requests. |
| 263 int GetActiveRequestCountForTest() const; | 297 int GetActiveRequestCountForTest() const; |
| 264 | 298 |
| 265 protected: | 299 protected: |
| 266 // A set of (policy type, settings entity ID) pairs to fetch. | 300 // A set of (policy type, settings entity ID) pairs to fetch. |
| 267 typedef std::set<std::pair<std::string, std::string>> PolicyTypeSet; | 301 typedef std::set<std::pair<std::string, std::string>> PolicyTypeSet; |
| 268 | 302 |
| 269 // Callback for retries of registration requests. | 303 // Callback for retries of registration requests. |
| 270 void OnRetryRegister(DeviceManagementRequestJob* job); | 304 void OnRetryRegister(DeviceManagementRequestJob* job); |
| 271 | 305 |
| 306 // Callback for siganture of requests. | |
| 307 void OnRegisterWithCertificateRequestSigned(bool success, | |
| 308 enterprise_management::SignedData signed_data); | |
| 309 | |
| 272 // Callback for registration requests. | 310 // Callback for registration requests. |
| 273 void OnRegisterCompleted( | 311 void OnRegisterCompleted( |
| 274 DeviceManagementStatus status, | 312 DeviceManagementStatus status, |
| 275 int net_error, | 313 int net_error, |
| 276 const enterprise_management::DeviceManagementResponse& response); | 314 const enterprise_management::DeviceManagementResponse& response); |
| 277 | 315 |
| 278 // Callback for policy fetch requests. | 316 // Callback for policy fetch requests. |
| 279 void OnPolicyFetchCompleted( | 317 void OnPolicyFetchCompleted( |
| 280 DeviceManagementStatus status, | 318 DeviceManagementStatus status, |
| 281 int net_error, | 319 int net_error, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 // Information for the latest policy invalidation received. | 407 // Information for the latest policy invalidation received. |
| 370 int64_t invalidation_version_; | 408 int64_t invalidation_version_; |
| 371 std::string invalidation_payload_; | 409 std::string invalidation_payload_; |
| 372 | 410 |
| 373 // The invalidation version used for the most recent fetch operation. | 411 // The invalidation version used for the most recent fetch operation. |
| 374 int64_t fetched_invalidation_version_; | 412 int64_t fetched_invalidation_version_; |
| 375 | 413 |
| 376 // Used for issuing requests to the cloud. | 414 // Used for issuing requests to the cloud. |
| 377 DeviceManagementService* service_; | 415 DeviceManagementService* service_; |
| 378 | 416 |
| 417 // Used for signing requests. | |
| 418 SigningService* signing_service_; | |
| 419 | |
| 379 // Only one outstanding policy fetch is allowed, so this is tracked in | 420 // Only one outstanding policy fetch is allowed, so this is tracked in |
| 380 // its own member variable. | 421 // its own member variable. |
| 381 std::unique_ptr<DeviceManagementRequestJob> policy_fetch_request_job_; | 422 std::unique_ptr<DeviceManagementRequestJob> policy_fetch_request_job_; |
| 382 | 423 |
| 383 // All of the outstanding non-policy-fetch request jobs. These jobs are | 424 // All of the outstanding non-policy-fetch request jobs. These jobs are |
| 384 // silently cancelled if Unregister() is called. | 425 // silently cancelled if Unregister() is called. |
| 385 ScopedVector<DeviceManagementRequestJob> request_jobs_; | 426 ScopedVector<DeviceManagementRequestJob> request_jobs_; |
| 386 | 427 |
| 387 // The policy responses returned by the last policy fetch operation. | 428 // The policy responses returned by the last policy fetch operation. |
| 388 ResponseMap responses_; | 429 ResponseMap responses_; |
| 389 DeviceManagementStatus status_; | 430 DeviceManagementStatus status_; |
| 390 | 431 |
| 391 base::ObserverList<Observer, true> observers_; | 432 base::ObserverList<Observer, true> observers_; |
| 392 scoped_refptr<net::URLRequestContextGetter> request_context_; | 433 scoped_refptr<net::URLRequestContextGetter> request_context_; |
| 393 | 434 |
| 394 private: | 435 private: |
| 436 void SetClientId(const std::string& client_id); | |
| 437 | |
| 395 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient); | 438 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient); |
| 396 }; | 439 }; |
| 397 | 440 |
| 398 } // namespace policy | 441 } // namespace policy |
| 399 | 442 |
| 400 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ | 443 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ |
| OLD | NEW |