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 CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_ | 5 #ifndef CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_ |
6 #define CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_ | 6 #define CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/time/time.h" | |
15 #include "base/timer/timer.h" | |
14 #include "chromeos/attestation/attestation_constants.h" | 16 #include "chromeos/attestation/attestation_constants.h" |
15 #include "chromeos/chromeos_export.h" | 17 #include "chromeos/chromeos_export.h" |
16 #include "chromeos/dbus/dbus_method_call_status.h" | 18 #include "chromeos/dbus/dbus_method_call_status.h" |
17 #include "third_party/cros_system_api/dbus/service_constants.h" | 19 #include "third_party/cros_system_api/dbus/service_constants.h" |
18 | 20 |
19 class AccountId; | 21 class AccountId; |
20 | 22 |
21 namespace cryptohome { | 23 namespace cryptohome { |
22 | 24 |
23 class AsyncMethodCaller; | 25 class AsyncMethodCaller; |
(...skipping 15 matching lines...) Expand all Loading... | |
39 virtual void SendEnrollRequest(const std::string& request, | 41 virtual void SendEnrollRequest(const std::string& request, |
40 const DataCallback& on_response) = 0; | 42 const DataCallback& on_response) = 0; |
41 virtual void SendCertificateRequest(const std::string& request, | 43 virtual void SendCertificateRequest(const std::string& request, |
42 const DataCallback& on_response) = 0; | 44 const DataCallback& on_response) = 0; |
43 virtual PrivacyCAType GetType(); | 45 virtual PrivacyCAType GetType(); |
44 }; | 46 }; |
45 | 47 |
46 // Implements the message flow for Chrome OS attestation tasks. Generally this | 48 // Implements the message flow for Chrome OS attestation tasks. Generally this |
47 // consists of coordinating messages between the Chrome OS attestation service | 49 // consists of coordinating messages between the Chrome OS attestation service |
48 // and the Chrome OS Privacy CA server. Sample usage: | 50 // and the Chrome OS Privacy CA server. Sample usage: |
51 // | |
49 // AttestationFlow flow(AsyncMethodCaller::GetInstance(), | 52 // AttestationFlow flow(AsyncMethodCaller::GetInstance(), |
50 // DBusThreadManager::Get().GetCryptohomeClient(), | 53 // DBusThreadManager::Get().GetCryptohomeClient(), |
51 // std::move(my_server_proxy)); | 54 // std::move(my_server_proxy)); |
52 // AttestationFlow::CertificateCallback callback = base::Bind(&MyCallback); | 55 // AttestationFlow::CertificateCallback callback = base::Bind(&MyCallback); |
53 // flow.GetCertificate(ENTERPRISE_USER_CERTIFICATE, false, callback); | 56 // flow.GetCertificate(ENTERPRISE_USER_CERTIFICATE, false, callback); |
57 // | |
58 // This class is not thread safe. | |
54 class CHROMEOS_EXPORT AttestationFlow { | 59 class CHROMEOS_EXPORT AttestationFlow { |
55 public: | 60 public: |
56 typedef base::Callback<void(bool success, | 61 typedef base::Callback<void(bool success, |
57 const std::string& pem_certificate_chain)> | 62 const std::string& pem_certificate_chain)> |
58 CertificateCallback; | 63 CertificateCallback; |
59 | 64 |
60 // Returns the attestation key type for a given |certificate_profile|. | 65 // Returns the attestation key type for a given |certificate_profile|. |
61 // | 66 // |
62 // Parameters | 67 // Parameters |
63 // certificate_profile - Specifies what kind of certificate the key is for. | 68 // certificate_profile - Specifies what kind of certificate the key is for. |
(...skipping 11 matching lines...) Expand all Loading... | |
75 // the origin of the request. | 80 // the origin of the request. |
76 static std::string GetKeyNameForProfile( | 81 static std::string GetKeyNameForProfile( |
77 AttestationCertificateProfile certificate_profile, | 82 AttestationCertificateProfile certificate_profile, |
78 const std::string& request_origin); | 83 const std::string& request_origin); |
79 | 84 |
80 AttestationFlow(cryptohome::AsyncMethodCaller* async_caller, | 85 AttestationFlow(cryptohome::AsyncMethodCaller* async_caller, |
81 CryptohomeClient* cryptohome_client, | 86 CryptohomeClient* cryptohome_client, |
82 std::unique_ptr<ServerProxy> server_proxy); | 87 std::unique_ptr<ServerProxy> server_proxy); |
83 virtual ~AttestationFlow(); | 88 virtual ~AttestationFlow(); |
84 | 89 |
90 // Sets the timeout for attestation to be ready. | |
91 void SetReadyTimeout(base::TimeDelta ready_timeout) { | |
Darren Krahn
2016/12/08 18:06:06
set_ready_timeout()
The one and only Dr. Crash
2016/12/13 22:37:17
Done.
| |
92 ready_timeout_ = ready_timeout; | |
93 } | |
94 // Gets the timeout for attestation to be ready. | |
95 base::TimeDelta GetReadyTimeout() const { return ready_timeout_; } | |
Darren Krahn
2016/12/08 18:06:06
ready_timeout()
The one and only Dr. Crash
2016/12/13 22:37:17
Done.
| |
96 | |
97 // Sets the retry delay. | |
98 void SetRetryDelay(base::TimeDelta retry_delay) { | |
Darren Krahn
2016/12/08 18:06:06
set_retry_delay()
The one and only Dr. Crash
2016/12/13 22:37:17
Done.
| |
99 retry_delay_ = retry_delay; | |
100 } | |
101 | |
102 // Returns the retry delay. | |
103 base::TimeDelta GetRetryDelay() { return retry_delay_; } | |
Darren Krahn
2016/12/08 18:06:06
retry_delay()
The one and only Dr. Crash
2016/12/13 22:37:17
Done.
| |
104 | |
85 // Gets an attestation certificate for a hardware-protected key. If a key for | 105 // Gets an attestation certificate for a hardware-protected key. If a key for |
86 // the given profile does not exist, it will be generated and a certificate | 106 // the given profile does not exist, it will be generated and a certificate |
87 // request will be made to the Chrome OS Privacy CA to issue a certificate for | 107 // request will be made to the Chrome OS Privacy CA to issue a certificate for |
88 // the key. If the key already exists and |force_new_key| is false, the | 108 // the key. If the key already exists and |force_new_key| is false, the |
89 // existing certificate is returned. | 109 // existing certificate is returned. |
90 // | 110 // |
91 // Parameters | 111 // Parameters |
92 // certificate_profile - Specifies what kind of certificate should be | 112 // certificate_profile - Specifies what kind of certificate should be |
93 // requested from the CA. | 113 // requested from the CA. |
94 // account_id - Identifies the currently active user. This is ignored when | 114 // account_id - Identifies the currently active user. This is ignored when |
95 // using the enterprise machine cert profile. | 115 // using the enterprise machine cert profile. |
96 // request_origin - For content protection profiles, certificate requests | 116 // request_origin - For content protection profiles, certificate requests |
97 // are origin-specific. This string must uniquely identify | 117 // are origin-specific. This string must uniquely identify |
98 // the origin of the request. | 118 // the origin of the request. |
99 // force_new_key - If set to true, a new key will be generated even if a key | 119 // force_new_key - If set to true, a new key will be generated even if a key |
100 // already exists for the profile. The new key will replace | 120 // already exists for the profile. The new key will replace |
101 // the existing key on success. | 121 // the existing key on success. |
102 // callback - A callback which will be called when the operation completes. | 122 // callback - A callback which will be called when the operation completes. |
103 // On success |result| will be true and |data| will contain the | 123 // On success |result| will be true and |data| will contain the |
104 // PCA-issued certificate chain in PEM format. | 124 // PCA-issued certificate chain in PEM format. |
105 virtual void GetCertificate(AttestationCertificateProfile certificate_profile, | 125 virtual void GetCertificate(AttestationCertificateProfile certificate_profile, |
106 const AccountId& account_id, | 126 const AccountId& account_id, |
107 const std::string& request_origin, | 127 const std::string& request_origin, |
108 bool force_new_key, | 128 bool force_new_key, |
109 const CertificateCallback& callback); | 129 const CertificateCallback& callback); |
110 | 130 |
111 private: | 131 private: |
112 // Asynchronously initiates the attestation enrollment flow. | 132 // Initiates enrollment. |
113 // | 133 // |
114 // Parameters | 134 // Parameters |
115 // on_failure - Called if any failure occurs. | 135 // on_failure - Called if any failure occurs. |
136 // next_task - Called on successful enrollment. | |
137 void InitiateEnroll(const base::Closure& on_failure, | |
138 const base::Closure& next_task); | |
139 | |
140 // Asynchronously waits for attestation to be ready and start enrollment once | |
141 // it is. If attestation is not ready by the time the flow's timeout is | |
142 // reached, fail. | |
143 // | |
144 // Parameters | |
145 // retries_left - Number of retries left (-1 for infinite retries). | |
146 // on_failure - Called if any failure occurs. | |
147 // next_task - Called on successful enrollment. | |
148 void WaitForAttestationReadyAndStartEnroll(base::TimeTicks end_time, | |
149 const base::Closure& on_failure, | |
150 const base::Closure& next_task); | |
151 | |
152 // Called when attestation is prepared, to start the actual enrollment flow. | |
153 // | |
154 // Parameters | |
155 // on_failure - Called if any failure occurs. | |
116 // next_task - Called on successful enrollment. | 156 // next_task - Called on successful enrollment. |
117 void StartEnroll(const base::Closure& on_failure, | 157 void StartEnroll(const base::Closure& on_failure, |
118 const base::Closure& next_task); | 158 const base::Closure& next_task); |
119 | 159 |
120 // Called when the attestation daemon has finished creating an enrollment | 160 // Called when the attestation daemon has finished creating an enrollment |
121 // request for the Privacy CA. The request is asynchronously forwarded as-is | 161 // request for the Privacy CA. The request is asynchronously forwarded as-is |
122 // to the PCA. | 162 // to the PCA. |
123 // | 163 // |
124 // Parameters | 164 // Parameters |
125 // on_failure - Called if any failure occurs. | 165 // on_failure - Called if any failure occurs. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
216 // Parameters | 256 // Parameters |
217 // key_type - The type of the key for which a certificate is requested. | 257 // key_type - The type of the key for which a certificate is requested. |
218 // account_id - Identifies the active user. | 258 // account_id - Identifies the active user. |
219 // key_name - The name of the key for which a certificate is requested. | 259 // key_name - The name of the key for which a certificate is requested. |
220 // callback - Called when the operation completes. | 260 // callback - Called when the operation completes. |
221 void GetExistingCertificate(AttestationKeyType key_type, | 261 void GetExistingCertificate(AttestationKeyType key_type, |
222 const AccountId& account_id, | 262 const AccountId& account_id, |
223 const std::string& key_name, | 263 const std::string& key_name, |
224 const CertificateCallback& callback); | 264 const CertificateCallback& callback); |
225 | 265 |
266 // Checks whether attestation is ready. If not, reschedules a check after | |
267 // a delay unless we are out of retries, in which case we run |on_failure|. | |
268 // runs |on_giving_up|, otherwise runs |on_retrying| after a delay. | |
Darren Krahn
2016/12/08 18:06:06
on_giving_up and on_retrying are not defined
The one and only Dr. Crash
2016/12/13 22:37:17
Yes I went back to original names. Fixing document
| |
269 // | |
270 // Parameters | |
271 // retries_left - Number of retries left (-1 for infinite retries). | |
272 // on_failure - Called if any failure occurs. | |
273 // next_task - Called on successful enrollment. | |
274 void CheckAttestationReadyAndReschedule(base::TimeTicks end_time, | |
275 const base::Closure& on_failure, | |
276 const base::Closure& next_task); | |
277 | |
226 cryptohome::AsyncMethodCaller* async_caller_; | 278 cryptohome::AsyncMethodCaller* async_caller_; |
227 CryptohomeClient* cryptohome_client_; | 279 CryptohomeClient* cryptohome_client_; |
228 std::unique_ptr<ServerProxy> server_proxy_; | 280 std::unique_ptr<ServerProxy> server_proxy_; |
229 | 281 |
282 base::TimeDelta ready_timeout_; | |
283 base::TimeDelta retry_delay_; | |
284 | |
230 base::WeakPtrFactory<AttestationFlow> weak_factory_; | 285 base::WeakPtrFactory<AttestationFlow> weak_factory_; |
231 | 286 |
232 DISALLOW_COPY_AND_ASSIGN(AttestationFlow); | 287 DISALLOW_COPY_AND_ASSIGN(AttestationFlow); |
233 }; | 288 }; |
234 | 289 |
235 } // namespace attestation | 290 } // namespace attestation |
236 } // namespace chromeos | 291 } // namespace chromeos |
237 | 292 |
238 #endif // CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_ | 293 #endif // CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_ |
OLD | NEW |