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

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: Use the new attestation enrollment flavors. 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 using SigningCallback = base::Callback<void(bool success,
90 enterprise_management::SignedData signed_data)>;
91
92 // Signs |data| and calls |callback| with the signed data.
93 virtual void SignData(const std::string& data,
94 const SigningCallback& callback) = 0;
95 };
96
82 // |provider| and |service| are weak pointers and it's the caller's 97 // |provider| and |service| are weak pointers and it's the caller's
83 // responsibility to keep them valid for the lifetime of CloudPolicyClient. 98 // responsibility to keep them valid for the lifetime of CloudPolicyClient.
84 // |verification_key_hash| contains an identifier telling the DMServer which 99 // |verification_key_hash| contains an identifier telling the DMServer which
85 // verification key to use. 100 // verification key to use. The |signing_service| is used to sign sensitive
101 // requests.
86 CloudPolicyClient( 102 CloudPolicyClient(
87 const std::string& machine_id, 103 const std::string& machine_id,
88 const std::string& machine_model, 104 const std::string& machine_model,
89 const std::string& verification_key_hash, 105 const std::string& verification_key_hash,
90 DeviceManagementService* service, 106 DeviceManagementService* service,
91 scoped_refptr<net::URLRequestContextGetter> request_context); 107 scoped_refptr<net::URLRequestContextGetter> request_context,
108 SigningService* signing_service);
92 virtual ~CloudPolicyClient(); 109 virtual ~CloudPolicyClient();
93 110
94 // Sets the DMToken, thereby establishing a registration with the server. A 111 // Sets the DMToken, thereby establishing a registration with the server. A
95 // policy fetch is not automatically issued but can be requested by calling 112 // policy fetch is not automatically issued but can be requested by calling
96 // FetchPolicy(). 113 // FetchPolicy().
97 virtual void SetupRegistration(const std::string& dm_token, 114 virtual void SetupRegistration(const std::string& dm_token,
98 const std::string& client_id); 115 const std::string& client_id);
99 116
100 // Attempts to register with the device management service. Results in a 117 // Attempts to register with the device management service. Results in a
101 // registration change or error notification. 118 // registration change or error notification.
102 virtual void Register( 119 virtual void Register(
103 enterprise_management::DeviceRegisterRequest::Type registration_type, 120 enterprise_management::DeviceRegisterRequest::Type registration_type,
104 enterprise_management::DeviceRegisterRequest::Flavor flavor, 121 enterprise_management::DeviceRegisterRequest::Flavor flavor,
105 const std::string& auth_token, 122 const std::string& auth_token,
106 const std::string& client_id, 123 const std::string& client_id,
107 const std::string& requisition, 124 const std::string& requisition,
108 const std::string& current_state_key); 125 const std::string& current_state_key);
109 126
127 // Attempts to register with the device management service using a
128 // registration certificate. Results in a registration change or
129 // error notification.
130 virtual void RegisterWithCertificate(
131 enterprise_management::DeviceRegisterRequest::Type registration_type,
132 enterprise_management::DeviceRegisterRequest::Flavor flavor,
133 const std::string& pem_certificate_chain,
134 const std::string& client_id,
135 const std::string& requisition,
136 const std::string& current_state_key);
137
110 // Sets information about a policy invalidation. Subsequent fetch operations 138 // Sets information about a policy invalidation. Subsequent fetch operations
111 // will use the given info, and callers can use fetched_invalidation_version 139 // will use the given info, and callers can use fetched_invalidation_version
112 // to determine which version of policy was fetched. 140 // to determine which version of policy was fetched.
113 void SetInvalidationInfo(int64_t version, const std::string& payload); 141 void SetInvalidationInfo(int64_t version, const std::string& payload);
114 142
115 // Requests a policy fetch. The client being registered is a prerequisite to 143 // 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 144 // 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 145 // state. FetchPolicy() triggers a policy fetch from the cloud. A policy
118 // change notification is reported to the observers and the new policy blob 146 // 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 147 // 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. 290 // Returns the number of active requests.
263 int GetActiveRequestCountForTest() const; 291 int GetActiveRequestCountForTest() const;
264 292
265 protected: 293 protected:
266 // A set of (policy type, settings entity ID) pairs to fetch. 294 // A set of (policy type, settings entity ID) pairs to fetch.
267 typedef std::set<std::pair<std::string, std::string>> PolicyTypeSet; 295 typedef std::set<std::pair<std::string, std::string>> PolicyTypeSet;
268 296
269 // Callback for retries of registration requests. 297 // Callback for retries of registration requests.
270 void OnRetryRegister(DeviceManagementRequestJob* job); 298 void OnRetryRegister(DeviceManagementRequestJob* job);
271 299
300 // Callback for siganture of requests.
301 void OnRegisterWithCertificateRequestSigned(bool success,
302 enterprise_management::SignedData signed_data);
303
272 // Callback for registration requests. 304 // Callback for registration requests.
273 void OnRegisterCompleted( 305 void OnRegisterCompleted(
274 DeviceManagementStatus status, 306 DeviceManagementStatus status,
275 int net_error, 307 int net_error,
276 const enterprise_management::DeviceManagementResponse& response); 308 const enterprise_management::DeviceManagementResponse& response);
277 309
278 // Callback for policy fetch requests. 310 // Callback for policy fetch requests.
279 void OnPolicyFetchCompleted( 311 void OnPolicyFetchCompleted(
280 DeviceManagementStatus status, 312 DeviceManagementStatus status,
281 int net_error, 313 int net_error,
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 void NotifyClientError(); 383 void NotifyClientError();
352 384
353 // Data necessary for constructing policy requests. 385 // Data necessary for constructing policy requests.
354 const std::string machine_id_; 386 const std::string machine_id_;
355 const std::string machine_model_; 387 const std::string machine_model_;
356 const std::string verification_key_hash_; 388 const std::string verification_key_hash_;
357 PolicyTypeSet types_to_fetch_; 389 PolicyTypeSet types_to_fetch_;
358 std::vector<std::string> state_keys_to_upload_; 390 std::vector<std::string> state_keys_to_upload_;
359 391
360 std::string dm_token_; 392 std::string dm_token_;
361 DeviceMode device_mode_; 393 DeviceMode device_mode_ = DEVICE_MODE_NOT_SET;
362 std::string client_id_; 394 std::string client_id_;
363 bool submit_machine_id_; 395 bool submit_machine_id_ = false;
364 base::Time last_policy_timestamp_; 396 base::Time last_policy_timestamp_;
365 int public_key_version_; 397 int public_key_version_ = -1;
366 bool public_key_version_valid_; 398 bool public_key_version_valid_ = false;
367 std::string robot_api_auth_code_; 399 std::string robot_api_auth_code_;
368 400
369 // Information for the latest policy invalidation received. 401 // Information for the latest policy invalidation received.
370 int64_t invalidation_version_; 402 int64_t invalidation_version_ = 0;
371 std::string invalidation_payload_; 403 std::string invalidation_payload_;
372 404
373 // The invalidation version used for the most recent fetch operation. 405 // The invalidation version used for the most recent fetch operation.
374 int64_t fetched_invalidation_version_; 406 int64_t fetched_invalidation_version_ = 0;
375 407
376 // Used for issuing requests to the cloud. 408 // Used for issuing requests to the cloud.
377 DeviceManagementService* service_; 409 DeviceManagementService* service_;
achuithb 2016/08/24 21:46:18 = nullptr
The one and only Dr. Crash 2016/08/24 22:17:52 Done.
378 410
411 // Used for signing requests.
412 SigningService* signing_service_;
achuithb 2016/08/24 21:46:17 = nullptr;
The one and only Dr. Crash 2016/08/24 22:17:52 Done.
413
379 // Only one outstanding policy fetch is allowed, so this is tracked in 414 // Only one outstanding policy fetch is allowed, so this is tracked in
380 // its own member variable. 415 // its own member variable.
381 std::unique_ptr<DeviceManagementRequestJob> policy_fetch_request_job_; 416 std::unique_ptr<DeviceManagementRequestJob> policy_fetch_request_job_;
382 417
383 // All of the outstanding non-policy-fetch request jobs. These jobs are 418 // All of the outstanding non-policy-fetch request jobs. These jobs are
384 // silently cancelled if Unregister() is called. 419 // silently cancelled if Unregister() is called.
385 ScopedVector<DeviceManagementRequestJob> request_jobs_; 420 ScopedVector<DeviceManagementRequestJob> request_jobs_;
386 421
387 // The policy responses returned by the last policy fetch operation. 422 // The policy responses returned by the last policy fetch operation.
388 ResponseMap responses_; 423 ResponseMap responses_;
389 DeviceManagementStatus status_; 424 DeviceManagementStatus status_ = DM_STATUS_SUCCESS;
390 425
391 base::ObserverList<Observer, true> observers_; 426 base::ObserverList<Observer, true> observers_;
392 scoped_refptr<net::URLRequestContextGetter> request_context_; 427 scoped_refptr<net::URLRequestContextGetter> request_context_;
393 428
394 private: 429 private:
430 void SetClientId(const std::string& client_id);
431
432 // Used to create tasks which run delayed on the UI thread.
433 base::WeakPtrFactory<CloudPolicyClient> weak_ptr_factory_;
434
395 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient); 435 DISALLOW_COPY_AND_ASSIGN(CloudPolicyClient);
396 }; 436 };
397 437
398 } // namespace policy 438 } // namespace policy
399 439
400 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_ 440 #endif // COMPONENTS_POLICY_CORE_COMMON_CLOUD_CLOUD_POLICY_CLIENT_H_
OLDNEW
« no previous file with comments | « components/policy/core/browser/cloud/message_util.cc ('k') | components/policy/core/common/cloud/cloud_policy_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698