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

Side by Side Diff: chromeos/attestation/attestation_flow.h

Issue 2529743002: Wait for the attestation to be ready (TPM being prepared for attestation) before trying to enroll. (Closed)
Patch Set: AttestationFlow supports a timeout. Created 4 years 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 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"
14 #include "chromeos/attestation/attestation_constants.h" 15 #include "chromeos/attestation/attestation_constants.h"
15 #include "chromeos/chromeos_export.h" 16 #include "chromeos/chromeos_export.h"
16 #include "chromeos/dbus/dbus_method_call_status.h" 17 #include "chromeos/dbus/dbus_method_call_status.h"
18 #include "net/base/backoff_entry.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
23 namespace base {
24
25 class OneShotTimer;
26
27 } // namespace base
28
21 namespace cryptohome { 29 namespace cryptohome {
22 30
23 class AsyncMethodCaller; 31 class AsyncMethodCaller;
24 32
25 } // namespace cryptohome 33 } // namespace cryptohome
26 34
27 namespace chromeos { 35 namespace chromeos {
28 36
29 class CryptohomeClient; 37 class CryptohomeClient;
30 38
(...skipping 10 matching lines...) Expand all
41 virtual void SendCertificateRequest(const std::string& request, 49 virtual void SendCertificateRequest(const std::string& request,
42 const DataCallback& on_response) = 0; 50 const DataCallback& on_response) = 0;
43 virtual PrivacyCAType GetType(); 51 virtual PrivacyCAType GetType();
44 }; 52 };
45 53
46 // Implements the message flow for Chrome OS attestation tasks. Generally this 54 // Implements the message flow for Chrome OS attestation tasks. Generally this
47 // consists of coordinating messages between the Chrome OS attestation service 55 // consists of coordinating messages between the Chrome OS attestation service
48 // and the Chrome OS Privacy CA server. Sample usage: 56 // and the Chrome OS Privacy CA server. Sample usage:
49 // AttestationFlow flow(AsyncMethodCaller::GetInstance(), 57 // AttestationFlow flow(AsyncMethodCaller::GetInstance(),
50 // DBusThreadManager::Get().GetCryptohomeClient(), 58 // DBusThreadManager::Get().GetCryptohomeClient(),
51 // std::move(my_server_proxy)); 59 // std::move(my_server_proxy),
60 // base::TimeDelta::Max());
52 // AttestationFlow::CertificateCallback callback = base::Bind(&MyCallback); 61 // AttestationFlow::CertificateCallback callback = base::Bind(&MyCallback);
53 // flow.GetCertificate(ENTERPRISE_USER_CERTIFICATE, false, callback); 62 // flow.GetCertificate(ENTERPRISE_USER_CERTIFICATE, false, callback);
54 class CHROMEOS_EXPORT AttestationFlow { 63 class CHROMEOS_EXPORT AttestationFlow {
55 public: 64 public:
56 typedef base::Callback<void(bool success, 65 typedef base::Callback<void(bool success,
57 const std::string& pem_certificate_chain)> 66 const std::string& pem_certificate_chain)>
58 CertificateCallback; 67 CertificateCallback;
59 68
60 // Returns the attestation key type for a given |certificate_profile|. 69 // Returns the attestation key type for a given |certificate_profile|.
61 // 70 //
(...skipping 10 matching lines...) Expand all
72 // certificate_profile - Specifies what kind of certificate the key is for. 81 // certificate_profile - Specifies what kind of certificate the key is for.
73 // request_origin - For content protection profiles, certificate requests 82 // request_origin - For content protection profiles, certificate requests
74 // are origin-specific. This string must uniquely identify 83 // are origin-specific. This string must uniquely identify
75 // the origin of the request. 84 // the origin of the request.
76 static std::string GetKeyNameForProfile( 85 static std::string GetKeyNameForProfile(
77 AttestationCertificateProfile certificate_profile, 86 AttestationCertificateProfile certificate_profile,
78 const std::string& request_origin); 87 const std::string& request_origin);
79 88
80 AttestationFlow(cryptohome::AsyncMethodCaller* async_caller, 89 AttestationFlow(cryptohome::AsyncMethodCaller* async_caller,
81 CryptohomeClient* cryptohome_client, 90 CryptohomeClient* cryptohome_client,
82 std::unique_ptr<ServerProxy> server_proxy); 91 std::unique_ptr<ServerProxy> server_proxy,
92 base::TimeDelta preparedness_timeout);
83 virtual ~AttestationFlow(); 93 virtual ~AttestationFlow();
84 94
85 // Gets an attestation certificate for a hardware-protected key. If a key for 95 // 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 96 // 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 97 // 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 98 // the key. If the key already exists and |force_new_key| is false, the
89 // existing certificate is returned. 99 // existing certificate is returned.
90 // 100 //
91 // Parameters 101 // Parameters
92 // certificate_profile - Specifies what kind of certificate should be 102 // certificate_profile - Specifies what kind of certificate should be
93 // requested from the CA. 103 // requested from the CA.
94 // account_id - Identifies the currently active user. This is ignored when 104 // account_id - Identifies the currently active user. This is ignored when
95 // using the enterprise machine cert profile. 105 // using the enterprise machine cert profile.
96 // request_origin - For content protection profiles, certificate requests 106 // request_origin - For content protection profiles, certificate requests
97 // are origin-specific. This string must uniquely identify 107 // are origin-specific. This string must uniquely identify
98 // the origin of the request. 108 // the origin of the request.
99 // force_new_key - If set to true, a new key will be generated even if a key 109 // 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 110 // already exists for the profile. The new key will replace
101 // the existing key on success. 111 // the existing key on success.
102 // callback - A callback which will be called when the operation completes. 112 // callback - A callback which will be called when the operation completes.
103 // On success |result| will be true and |data| will contain the 113 // On success |result| will be true and |data| will contain the
104 // PCA-issued certificate chain in PEM format. 114 // PCA-issued certificate chain in PEM format.
105 virtual void GetCertificate(AttestationCertificateProfile certificate_profile, 115 virtual void GetCertificate(AttestationCertificateProfile certificate_profile,
106 const AccountId& account_id, 116 const AccountId& account_id,
107 const std::string& request_origin, 117 const std::string& request_origin,
108 bool force_new_key, 118 bool force_new_key,
109 const CertificateCallback& callback); 119 const CertificateCallback& callback);
110 120
121 // Sets the retry timer for tests.
122 void SetRetryTimerForTest(std::unique_ptr<base::OneShotTimer> retry_timer);
123
111 private: 124 private:
112 // Asynchronously initiates the attestation enrollment flow. 125 // Asynchronously initiates the attestation enrollment flow.
126 // If attestation is not ready yet, retry as needed.
113 // 127 //
114 // Parameters 128 // Parameters
115 // on_failure - Called if any failure occurs. 129 // on_failure - Called if any failure occurs.
130 // next_task - Called on successful enrollment.
131 void InitiateEnroll(const base::Closure& on_failure,
132 const base::Closure& next_task);
133
134 // Called when atestation is not prepared yet, to re-initiate enrollment
135 // after a delay.
136 //
137 // Parameters
138 // on_failure - Called if any failure occurs.
139 // next_task - Called on successful enrollment.
140 void RetryInitiateEnroll(const base::Closure& on_failure,
141 const base::Closure& next_task);
142
143 // Called when attestation is prepared, to start the actual enrollment flow.
144 //
145 // Parameters
146 // on_failure - Called if any failure occurs.
116 // next_task - Called on successful enrollment. 147 // next_task - Called on successful enrollment.
117 void StartEnroll(const base::Closure& on_failure, 148 void StartEnroll(const base::Closure& on_failure,
118 const base::Closure& next_task); 149 const base::Closure& next_task);
119 150
120 // Called when the attestation daemon has finished creating an enrollment 151 // Called when the attestation daemon has finished creating an enrollment
121 // request for the Privacy CA. The request is asynchronously forwarded as-is 152 // request for the Privacy CA. The request is asynchronously forwarded as-is
122 // to the PCA. 153 // to the PCA.
123 // 154 //
124 // Parameters 155 // Parameters
125 // on_failure - Called if any failure occurs. 156 // on_failure - Called if any failure occurs.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // callback - Called when the operation completes. 251 // callback - Called when the operation completes.
221 void GetExistingCertificate(AttestationKeyType key_type, 252 void GetExistingCertificate(AttestationKeyType key_type,
222 const AccountId& account_id, 253 const AccountId& account_id,
223 const std::string& key_name, 254 const std::string& key_name,
224 const CertificateCallback& callback); 255 const CertificateCallback& callback);
225 256
226 cryptohome::AsyncMethodCaller* async_caller_; 257 cryptohome::AsyncMethodCaller* async_caller_;
227 CryptohomeClient* cryptohome_client_; 258 CryptohomeClient* cryptohome_client_;
228 std::unique_ptr<ServerProxy> server_proxy_; 259 std::unique_ptr<ServerProxy> server_proxy_;
229 260
261 base::TimeDelta preparedness_timeout_;
262 std::unique_ptr<base::OneShotTimer> retry_timer_;
The one and only Dr. Crash 2016/12/02 06:59:34 Note that the use we make of all of these is very
263 net::BackoffEntry retry_backoff_;
264
230 base::WeakPtrFactory<AttestationFlow> weak_factory_; 265 base::WeakPtrFactory<AttestationFlow> weak_factory_;
231 266
232 DISALLOW_COPY_AND_ASSIGN(AttestationFlow); 267 DISALLOW_COPY_AND_ASSIGN(AttestationFlow);
233 }; 268 };
234 269
235 } // namespace attestation 270 } // namespace attestation
236 } // namespace chromeos 271 } // namespace chromeos
237 272
238 #endif // CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_ 273 #endif // CHROMEOS_ATTESTATION_ATTESTATION_FLOW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698