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

Side by Side Diff: components/policy/core/common/cloud/cloud_policy_client.h

Issue 2261763002: Device enterprise registration with a certificate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed more feedback. 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 (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
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,
achuithb 2016/08/23 18:40:28 use using here instead. https://groups.google.com/
The one and only Dr. Crash 2016/08/24 05:53:44 Done.
90 enterprise_management::SignedData signed_data)>
91 SigningCallback;
92
93 // Signs |data| and calls |callback| with the signed data.
94 virtual void SignData(const std::string& data,
95 SigningCallback callback) = 0;
achuithb 2016/08/23 18:40:28 pass const reference instead.
The one and only Dr. Crash 2016/08/24 05:53:44 Done.
96 };
97
82 // |provider| and |service| are weak pointers and it's the caller's 98 // |provider| and |service| are weak pointers and it's the caller's
83 // responsibility to keep them valid for the lifetime of CloudPolicyClient. 99 // responsibility to keep them valid for the lifetime of CloudPolicyClient.
84 // |verification_key_hash| contains an identifier telling the DMServer which 100 // |verification_key_hash| contains an identifier telling the DMServer which
85 // verification key to use. 101 // verification key to use. The |signing_service| is used to sign sensitive
102 // requests.
86 CloudPolicyClient( 103 CloudPolicyClient(
87 const std::string& machine_id, 104 const std::string& machine_id,
88 const std::string& machine_model, 105 const std::string& machine_model,
106 const std::string& verification_key_hash,
107 DeviceManagementService* service,
108 scoped_refptr<net::URLRequestContextGetter> request_context,
109 SigningService* signing_service);
110 // Constructs a client without signing support.
111 CloudPolicyClient(
achuithb 2016/08/23 18:40:28 we don't prefer multiple ctors. Please just use th
The one and only Dr. Crash 2016/08/24 05:53:44 Done.
112 const std::string& machine_id,
113 const std::string& machine_model,
89 const std::string& verification_key_hash, 114 const std::string& verification_key_hash,
90 DeviceManagementService* service, 115 DeviceManagementService* service,
91 scoped_refptr<net::URLRequestContextGetter> request_context); 116 scoped_refptr<net::URLRequestContextGetter> request_context);
92 virtual ~CloudPolicyClient(); 117 virtual ~CloudPolicyClient();
93 118
94 // Sets the DMToken, thereby establishing a registration with the server. A 119 // Sets the DMToken, thereby establishing a registration with the server. A
95 // policy fetch is not automatically issued but can be requested by calling 120 // policy fetch is not automatically issued but can be requested by calling
96 // FetchPolicy(). 121 // FetchPolicy().
97 virtual void SetupRegistration(const std::string& dm_token, 122 virtual void SetupRegistration(const std::string& dm_token,
98 const std::string& client_id); 123 const std::string& client_id);
99 124
100 // Attempts to register with the device management service. Results in a 125 // Attempts to register with the device management service. Results in a
101 // registration change or error notification. 126 // registration change or error notification.
102 virtual void Register( 127 virtual void Register(
103 enterprise_management::DeviceRegisterRequest::Type registration_type, 128 enterprise_management::DeviceRegisterRequest::Type registration_type,
104 enterprise_management::DeviceRegisterRequest::Flavor flavor, 129 enterprise_management::DeviceRegisterRequest::Flavor flavor,
105 const std::string& auth_token, 130 const std::string& auth_token,
106 const std::string& client_id, 131 const std::string& client_id,
107 const std::string& requisition, 132 const std::string& requisition,
108 const std::string& current_state_key); 133 const std::string& current_state_key);
109 134
135 // Attempts to register with the device management service using a
136 // registration certificate. Results in a registration change or
137 // error notification.
138 virtual void RegisterWithCertificate(
139 enterprise_management::DeviceRegisterRequest::Type registration_type,
140 enterprise_management::DeviceRegisterRequest::Flavor flavor,
141 const std::string& pem_certificate_chain,
142 const std::string& client_id,
143 const std::string& requisition,
144 const std::string& current_state_key);
145
110 // Sets information about a policy invalidation. Subsequent fetch operations 146 // Sets information about a policy invalidation. Subsequent fetch operations
111 // will use the given info, and callers can use fetched_invalidation_version 147 // will use the given info, and callers can use fetched_invalidation_version
112 // to determine which version of policy was fetched. 148 // to determine which version of policy was fetched.
113 void SetInvalidationInfo(int64_t version, const std::string& payload); 149 void SetInvalidationInfo(int64_t version, const std::string& payload);
114 150
115 // Requests a policy fetch. The client being registered is a prerequisite to 151 // 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 152 // 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 153 // state. FetchPolicy() triggers a policy fetch from the cloud. A policy
118 // change notification is reported to the observers and the new policy blob 154 // 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 155 // can be retrieved once the policy fetch operation completes. In case of
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 // Returns the number of active requests. 298 // Returns the number of active requests.
263 int GetActiveRequestCountForTest() const; 299 int GetActiveRequestCountForTest() const;
264 300
265 protected: 301 protected:
266 // A set of (policy type, settings entity ID) pairs to fetch. 302 // A set of (policy type, settings entity ID) pairs to fetch.
267 typedef std::set<std::pair<std::string, std::string>> PolicyTypeSet; 303 typedef std::set<std::pair<std::string, std::string>> PolicyTypeSet;
268 304
269 // Callback for retries of registration requests. 305 // Callback for retries of registration requests.
270 void OnRetryRegister(DeviceManagementRequestJob* job); 306 void OnRetryRegister(DeviceManagementRequestJob* job);
271 307
308 // Callback for siganture of requests.
309 void OnRegisterWithCertificateRequestSigned(bool success,
310 enterprise_management::SignedData signed_data);
311
272 // Callback for registration requests. 312 // Callback for registration requests.
273 void OnRegisterCompleted( 313 void OnRegisterCompleted(
274 DeviceManagementStatus status, 314 DeviceManagementStatus status,
275 int net_error, 315 int net_error,
276 const enterprise_management::DeviceManagementResponse& response); 316 const enterprise_management::DeviceManagementResponse& response);
277 317
278 // Callback for policy fetch requests. 318 // Callback for policy fetch requests.
279 void OnPolicyFetchCompleted( 319 void OnPolicyFetchCompleted(
280 DeviceManagementStatus status, 320 DeviceManagementStatus status,
281 int net_error, 321 int net_error,
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 // Information for the latest policy invalidation received. 409 // Information for the latest policy invalidation received.
370 int64_t invalidation_version_; 410 int64_t invalidation_version_;
371 std::string invalidation_payload_; 411 std::string invalidation_payload_;
372 412
373 // The invalidation version used for the most recent fetch operation. 413 // The invalidation version used for the most recent fetch operation.
374 int64_t fetched_invalidation_version_; 414 int64_t fetched_invalidation_version_;
375 415
376 // Used for issuing requests to the cloud. 416 // Used for issuing requests to the cloud.
377 DeviceManagementService* service_; 417 DeviceManagementService* service_;
378 418
419 // Used for signing requests.
420 SigningService* signing_service_;
421
379 // Only one outstanding policy fetch is allowed, so this is tracked in 422 // Only one outstanding policy fetch is allowed, so this is tracked in
380 // its own member variable. 423 // its own member variable.
381 std::unique_ptr<DeviceManagementRequestJob> policy_fetch_request_job_; 424 std::unique_ptr<DeviceManagementRequestJob> policy_fetch_request_job_;
382 425
383 // All of the outstanding non-policy-fetch request jobs. These jobs are 426 // All of the outstanding non-policy-fetch request jobs. These jobs are
384 // silently cancelled if Unregister() is called. 427 // silently cancelled if Unregister() is called.
385 ScopedVector<DeviceManagementRequestJob> request_jobs_; 428 ScopedVector<DeviceManagementRequestJob> request_jobs_;
386 429
387 // The policy responses returned by the last policy fetch operation. 430 // The policy responses returned by the last policy fetch operation.
388 ResponseMap responses_; 431 ResponseMap responses_;
389 DeviceManagementStatus status_; 432 DeviceManagementStatus status_;
390 433
391 base::ObserverList<Observer, true> observers_; 434 base::ObserverList<Observer, true> observers_;
392 scoped_refptr<net::URLRequestContextGetter> request_context_; 435 scoped_refptr<net::URLRequestContextGetter> request_context_;
393 436
394 private: 437 private:
438 void SetClientId(const std::string& client_id);
439
395 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient); 440 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient);
396 }; 441 };
397 442
398 } // namespace policy 443 } // namespace policy
399 444
400 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ 445 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698