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

Side by Side Diff: chrome/browser/chromeos/attestation/platform_verification_flow.h

Issue 50093002: Added a timeout for platform verification key generation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 CHROME_BROWSER_CHROMEOS_ATTESTATION_PLATFORM_VERIFICATION_FLOW_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_ATTESTATION_PLATFORM_VERIFICATION_FLOW_H_
6 #define CHROME_BROWSER_CHROMEOS_ATTESTATION_PLATFORM_VERIFICATION_FLOW_H_ 6 #define CHROME_BROWSER_CHROMEOS_ATTESTATION_PLATFORM_VERIFICATION_FLOW_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "url/gurl.h" 14 #include "url/gurl.h"
15 15
16 class PrefService; 16 class PrefService;
17 17
18 namespace content { 18 namespace content {
19 class WebContents; 19 class WebContents;
20 } 20 }
21 21
22 namespace cryptohome { 22 namespace cryptohome {
23 class AsyncMethodCaller; 23 class AsyncMethodCaller;
(...skipping 12 matching lines...) Expand all
36 namespace attestation { 36 namespace attestation {
37 37
38 class AttestationFlow; 38 class AttestationFlow;
39 39
40 // This class allows platform verification for the content protection use case. 40 // This class allows platform verification for the content protection use case.
41 // All methods must only be called on the UI thread. Example: 41 // All methods must only be called on the UI thread. Example:
42 // PlatformVerificationFlow verifier; 42 // PlatformVerificationFlow verifier;
43 // PlatformVerificationFlow::Callback callback = base::Bind(&MyCallback); 43 // PlatformVerificationFlow::Callback callback = base::Bind(&MyCallback);
44 // verifier.ChallengePlatformKey(my_web_contents, "my_id", "some_challenge", 44 // verifier.ChallengePlatformKey(my_web_contents, "my_id", "some_challenge",
45 // callback); 45 // callback);
46 class PlatformVerificationFlow { 46 class PlatformVerificationFlow
47 : public base::RefCountedThreadSafe<PlatformVerificationFlow> {
pastarmovj 2013/10/29 09:24:29 From looking at this CL it is not obvious to me wh
Darren Krahn 2013/10/29 17:23:04 Done. It is important -- please let me know if ha
pastarmovj 2013/10/30 10:20:21 Thanks this looks reasonable to me. I think your c
47 public: 48 public:
48 enum Result { 49 enum Result {
49 SUCCESS, // The operation succeeded. 50 SUCCESS, // The operation succeeded.
50 INTERNAL_ERROR, // The operation failed unexpectedly. 51 INTERNAL_ERROR, // The operation failed unexpectedly.
51 PLATFORM_NOT_VERIFIED, // The platform cannot be verified. For example: 52 PLATFORM_NOT_VERIFIED, // The platform cannot be verified. For example:
52 // - It is not a Chrome device. 53 // - It is not a Chrome device.
53 // - It is not running a verified OS image. 54 // - It is not running a verified OS image.
54 USER_REJECTED, // The user explicitly rejected the operation. 55 USER_REJECTED, // The user explicitly rejected the operation.
55 POLICY_REJECTED, // The operation is not allowed by policy/settings. 56 POLICY_REJECTED, // The operation is not allowed by policy/settings.
57 TIMEOUT, // The operation timed out.
56 }; 58 };
57 59
58 enum ConsentType { 60 enum ConsentType {
59 CONSENT_TYPE_NONE, // No consent necessary. 61 CONSENT_TYPE_NONE, // No consent necessary.
60 CONSENT_TYPE_ATTESTATION, // Consent to use attestation. 62 CONSENT_TYPE_ATTESTATION, // Consent to use attestation.
61 CONSENT_TYPE_ALWAYS, // Consent because 'Always Ask' was requested. 63 CONSENT_TYPE_ALWAYS, // Consent because 'Always Ask' was requested.
62 }; 64 };
63 65
64 enum ConsentResponse { 66 enum ConsentResponse {
65 CONSENT_RESPONSE_NONE, 67 CONSENT_RESPONSE_NONE,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 PlatformVerificationFlow(); 106 PlatformVerificationFlow();
105 107
106 // An alternate constructor which specifies dependent objects explicitly. 108 // An alternate constructor which specifies dependent objects explicitly.
107 // This is useful in testing. The caller retains ownership of all pointers. 109 // This is useful in testing. The caller retains ownership of all pointers.
108 PlatformVerificationFlow(AttestationFlow* attestation_flow, 110 PlatformVerificationFlow(AttestationFlow* attestation_flow,
109 cryptohome::AsyncMethodCaller* async_caller, 111 cryptohome::AsyncMethodCaller* async_caller,
110 CryptohomeClient* cryptohome_client, 112 CryptohomeClient* cryptohome_client,
111 UserManager* user_manager, 113 UserManager* user_manager,
112 Delegate* delegate); 114 Delegate* delegate);
113 115
114 virtual ~PlatformVerificationFlow();
115
116 // Invokes an asynchronous operation to challenge a platform key. Any user 116 // Invokes an asynchronous operation to challenge a platform key. Any user
117 // interaction will be associated with |web_contents|. The |service_id| is an 117 // interaction will be associated with |web_contents|. The |service_id| is an
118 // arbitrary value but it should uniquely identify the origin of the request 118 // arbitrary value but it should uniquely identify the origin of the request
119 // and should not be determined by that origin; its purpose is to prevent 119 // and should not be determined by that origin; its purpose is to prevent
120 // collusion between multiple services. The |challenge| is also an arbitrary 120 // collusion between multiple services. The |challenge| is also an arbitrary
121 // value but it should be time sensitive or associated to some kind of session 121 // value but it should be time sensitive or associated to some kind of session
122 // because its purpose is to prevent certificate replay. The |callback| will 122 // because its purpose is to prevent certificate replay. The |callback| will
123 // be called when the operation completes. The duration of the operation can 123 // be called when the operation completes. The duration of the operation can
124 // vary depending on system state, hardware capabilities, and interaction with 124 // vary depending on system state, hardware capabilities, and interaction with
125 // the user. 125 // the user.
126 void ChallengePlatformKey(content::WebContents* web_contents, 126 void ChallengePlatformKey(content::WebContents* web_contents,
127 const std::string& service_id, 127 const std::string& service_id,
128 const std::string& challenge, 128 const std::string& challenge,
129 const ChallengeCallback& callback); 129 const ChallengeCallback& callback);
130 130
131 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); 131 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs);
132 132
133 void set_testing_prefs(PrefService* testing_prefs) { 133 void set_testing_prefs(PrefService* testing_prefs) {
134 testing_prefs_ = testing_prefs; 134 testing_prefs_ = testing_prefs;
135 } 135 }
136 136
137 void set_testing_url(const GURL& testing_url) { 137 void set_testing_url(const GURL& testing_url) {
138 testing_url_ = testing_url; 138 testing_url_ = testing_url;
139 } 139 }
140 140
141 void set_timeout_delay(int timeout_delay) {
142 timeout_delay_ = timeout_delay;
143 }
144
141 private: 145 private:
146 // Tracks timeout status for an asynchronous operation.
147 struct TimeoutStatus : public base::RefCountedThreadSafe<TimeoutStatus> {
148 bool finished;
149 bool timed_out;
150
151 TimeoutStatus() : finished(false), timed_out(false) {}
152
153 private:
154 friend class base::RefCountedThreadSafe<TimeoutStatus>;
155 ~TimeoutStatus() {}
156 };
157
158 // Holds the arguments of a ChallengePlatformKey call. This is convenient for
159 // use with base::Bind so we don't get too many arguments.
160 struct ChallengeContext {
161 content::WebContents* web_contents;
162 std::string service_id;
163 std::string challenge;
164 ChallengeCallback callback;
165 };
166
167 friend class base::RefCountedThreadSafe<PlatformVerificationFlow>;
168 ~PlatformVerificationFlow();
169
142 // Checks whether we need to prompt the user for consent before proceeding and 170 // Checks whether we need to prompt the user for consent before proceeding and
143 // invokes the consent UI if so. All parameters are the same as in 171 // invokes the consent UI if so. The arguments to ChallengePlatformKey are
144 // ChallengePlatformKey except for the additional |attestation_enrolled| which 172 // in |context| and |attestation_enrolled| specifies whether attestation has
145 // specifies whether attestation has been enrolled for this device. 173 // been enrolled for this device.
146 void CheckConsent(content::WebContents* web_contents, 174 void CheckConsent(const ChallengeContext& context,
147 const std::string& service_id,
148 const std::string& challenge,
149 const ChallengeCallback& callback,
150 bool attestation_enrolled); 175 bool attestation_enrolled);
151 176
152 // A callback called when the user has given their consent response. All 177 // A callback called when the user has given their consent response. The
153 // parameters are the same as in ChallengePlatformKey except for the 178 // arguments to ChallengePlatformKey are in |context|. |consent_type| and
154 // additional |consent_type| and |consent_response| which indicate the consent 179 // |consent_response| indicate the consent type and user response,
155 // type and user response, respectively. If the response indicates that the 180 // respectively. If the response indicates that the operation should proceed,
156 // operation should proceed, this method invokes a certificate request. 181 // this method invokes a certificate request.
157 void OnConsentResponse(content::WebContents* web_contents, 182 void OnConsentResponse(const ChallengeContext& context,
158 const std::string& service_id,
159 const std::string& challenge,
160 const ChallengeCallback& callback,
161 ConsentType consent_type, 183 ConsentType consent_type,
162 ConsentResponse consent_response); 184 ConsentResponse consent_response);
163 185
164 // A callback called when an attestation certificate request operation 186 // A callback called when an attestation certificate request operation
165 // completes. |service_id|, |challenge|, and |callback| are the same as in 187 // completes. The arguments to ChallengePlatformKey are in |context|.
166 // ChallengePlatformKey. |user_id| identifies the user for which the 188 // |user_id| identifies the user for which the certificate was requested.
167 // certificate was requested. |operation_success| is true iff the certificate 189 // |operation_success| is true iff the certificate request operation
168 // request operation succeeded. |certificate| holds the certificate for the 190 // succeeded. |certificate| holds the certificate for the platform key on
169 // platform key on success. If the certificate request was successful, this 191 // success. If the certificate request was successful, this method invokes a
170 // method invokes a request to sign the challenge. 192 // request to sign the challenge. If the operation timed out prior to this
171 void OnCertificateReady(const std::string& user_id, 193 // method being called, this method does nothing - notably, the callback is
172 const std::string& service_id, 194 // not invoked.
173 const std::string& challenge, 195 void OnCertificateReady(const ChallengeContext& context,
174 const ChallengeCallback& callback, 196 const std::string& user_id,
197 TimeoutStatus* timeout_status,
175 bool operation_success, 198 bool operation_success,
176 const std::string& certificate); 199 const std::string& certificate);
177 200
201 // A callback run after a constant delay to handle timeouts for lengthy
202 // certificate requests. |context.callback| will be invoked with a TIMEOUT
203 // result if the certificate request has not already finished.
204 void OnCertificateTimeout(const ChallengeContext& context,
205 TimeoutStatus* timeout_status);
206
178 // A callback called when a challenge signing request has completed. The 207 // A callback called when a challenge signing request has completed. The
179 // |certificate| is the platform certificate for the key which signed the 208 // |certificate| is the platform certificate for the key which signed the
180 // |challenge|. |callback| is the same as in ChallengePlatformKey. 209 // |challenge|. The arguments to ChallengePlatformKey are in |context|.
181 // |operation_success| is true iff the challenge signing operation was 210 // |operation_success| is true iff the challenge signing operation was
182 // successful. If it was successful, |response_data| holds the challenge 211 // successful. If it was successful, |response_data| holds the challenge
183 // response and the method will invoke |callback|. 212 // response and the method will invoke |context.callback|.
184 void OnChallengeReady(const std::string& certificate, 213 void OnChallengeReady(const ChallengeContext& context,
185 const std::string& challenge, 214 const std::string& certificate,
186 const ChallengeCallback& callback,
187 bool operation_success, 215 bool operation_success,
188 const std::string& response_data); 216 const std::string& response_data);
189 217
190 // Gets prefs associated with the given |web_contents|. If prefs have been 218 // Gets prefs associated with the given |web_contents|. If prefs have been
191 // set explicitly using set_testing_prefs(), then these are always returned. 219 // set explicitly using set_testing_prefs(), then these are always returned.
192 // If no prefs are associated with |web_contents| then NULL is returned. 220 // If no prefs are associated with |web_contents| then NULL is returned.
193 PrefService* GetPrefs(content::WebContents* web_contents); 221 PrefService* GetPrefs(content::WebContents* web_contents);
194 222
195 // Gets the URL associated with the given |web_contents|. If a URL as been 223 // Gets the URL associated with the given |web_contents|. If a URL as been
196 // set explicitly using set_testing_url(), then this value is always returned. 224 // set explicitly using set_testing_url(), then this value is always returned.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 263
236 AttestationFlow* attestation_flow_; 264 AttestationFlow* attestation_flow_;
237 scoped_ptr<AttestationFlow> default_attestation_flow_; 265 scoped_ptr<AttestationFlow> default_attestation_flow_;
238 cryptohome::AsyncMethodCaller* async_caller_; 266 cryptohome::AsyncMethodCaller* async_caller_;
239 CryptohomeClient* cryptohome_client_; 267 CryptohomeClient* cryptohome_client_;
240 UserManager* user_manager_; 268 UserManager* user_manager_;
241 Delegate* delegate_; 269 Delegate* delegate_;
242 scoped_ptr<Delegate> default_delegate_; 270 scoped_ptr<Delegate> default_delegate_;
243 PrefService* testing_prefs_; 271 PrefService* testing_prefs_;
244 GURL testing_url_; 272 GURL testing_url_;
245 273 int timeout_delay_;
246 // Note: This should remain the last member so it'll be destroyed and
247 // invalidate the weak pointers before any other members are destroyed.
248 base::WeakPtrFactory<PlatformVerificationFlow> weak_factory_;
249 274
250 DISALLOW_COPY_AND_ASSIGN(PlatformVerificationFlow); 275 DISALLOW_COPY_AND_ASSIGN(PlatformVerificationFlow);
251 }; 276 };
252 277
253 } // namespace attestation 278 } // namespace attestation
254 } // namespace chromeos 279 } // namespace chromeos
255 280
256 #endif // CHROME_BROWSER_CHROMEOS_ATTESTATION_PLATFORM_VERIFICATION_FLOW_H_ 281 #endif // CHROME_BROWSER_CHROMEOS_ATTESTATION_PLATFORM_VERIFICATION_FLOW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698