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

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: use base::Timer 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 "base/time/time.h"
15 #include "base/timer/timer.h"
14 #include "url/gurl.h" 16 #include "url/gurl.h"
15 17
16 class PrefService; 18 class PrefService;
17 19
18 namespace content { 20 namespace content {
19 class WebContents; 21 class WebContents;
20 } 22 }
21 23
22 namespace cryptohome { 24 namespace cryptohome {
23 class AsyncMethodCaller; 25 class AsyncMethodCaller;
24 } 26 }
25 27
26 namespace user_prefs { 28 namespace user_prefs {
27 class PrefRegistrySyncable; 29 class PrefRegistrySyncable;
28 } 30 }
29 31
30 namespace chromeos { 32 namespace chromeos {
31 33
32 class CryptohomeClient; 34 class CryptohomeClient;
33 class UserManager; 35 class UserManager;
34 class User; 36 class User;
35 37
36 namespace attestation { 38 namespace attestation {
37 39
38 class AttestationFlow; 40 class AttestationFlow;
39 41
40 // This class allows platform verification for the content protection use case. 42 // This class allows platform verification for the content protection use case.
41 // All methods must only be called on the UI thread. Example: 43 // All methods must only be called on the UI thread. Example:
42 // PlatformVerificationFlow verifier; 44 // scoped_refptr<PlatformVerificationFlow> verifier =
45 // new PlatformVerificationFlow();
43 // PlatformVerificationFlow::Callback callback = base::Bind(&MyCallback); 46 // PlatformVerificationFlow::Callback callback = base::Bind(&MyCallback);
44 // verifier.ChallengePlatformKey(my_web_contents, "my_id", "some_challenge", 47 // verifier->ChallengePlatformKey(my_web_contents, "my_id", "some_challenge",
45 // callback); 48 // callback);
46 class PlatformVerificationFlow { 49 //
50 // This class is RefCountedThreadSafe because it may need to outlive its caller.
51 // The attestation flow that needs to happen to establish a certified platform
52 // key may take minutes on some hardware. This class will timeout after a much
53 // shorter time so the caller can proceed without platform verification but it
54 // is important that the pending operation be allowed to finish. If the
55 // attestation flow is aborted at any stage, it will need to start over. If we
56 // use weak pointers, the attestation flow will stop when the next callback is
57 // run. So we need the instance to stay alive until the platform key is fully
58 // certified so the next time ChallegePlatformKey() is invoked it will be quick.
59 class PlatformVerificationFlow
60 : public base::RefCountedThreadSafe<PlatformVerificationFlow> {
47 public: 61 public:
48 enum Result { 62 enum Result {
49 SUCCESS, // The operation succeeded. 63 SUCCESS, // The operation succeeded.
50 INTERNAL_ERROR, // The operation failed unexpectedly. 64 INTERNAL_ERROR, // The operation failed unexpectedly.
51 PLATFORM_NOT_VERIFIED, // The platform cannot be verified. For example: 65 PLATFORM_NOT_VERIFIED, // The platform cannot be verified. For example:
52 // - It is not a Chrome device. 66 // - It is not a Chrome device.
53 // - It is not running a verified OS image. 67 // - It is not running a verified OS image.
54 USER_REJECTED, // The user explicitly rejected the operation. 68 USER_REJECTED, // The user explicitly rejected the operation.
55 POLICY_REJECTED, // The operation is not allowed by policy/settings. 69 POLICY_REJECTED, // The operation is not allowed by policy/settings.
70 TIMEOUT, // The operation timed out.
56 }; 71 };
57 72
58 enum ConsentType { 73 enum ConsentType {
59 CONSENT_TYPE_NONE, // No consent necessary. 74 CONSENT_TYPE_NONE, // No consent necessary.
60 CONSENT_TYPE_ATTESTATION, // Consent to use attestation. 75 CONSENT_TYPE_ATTESTATION, // Consent to use attestation.
61 CONSENT_TYPE_ALWAYS, // Consent because 'Always Ask' was requested. 76 CONSENT_TYPE_ALWAYS, // Consent because 'Always Ask' was requested.
62 }; 77 };
63 78
64 enum ConsentResponse { 79 enum ConsentResponse {
65 CONSENT_RESPONSE_NONE, 80 CONSENT_RESPONSE_NONE,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 PlatformVerificationFlow(); 119 PlatformVerificationFlow();
105 120
106 // An alternate constructor which specifies dependent objects explicitly. 121 // An alternate constructor which specifies dependent objects explicitly.
107 // This is useful in testing. The caller retains ownership of all pointers. 122 // This is useful in testing. The caller retains ownership of all pointers.
108 PlatformVerificationFlow(AttestationFlow* attestation_flow, 123 PlatformVerificationFlow(AttestationFlow* attestation_flow,
109 cryptohome::AsyncMethodCaller* async_caller, 124 cryptohome::AsyncMethodCaller* async_caller,
110 CryptohomeClient* cryptohome_client, 125 CryptohomeClient* cryptohome_client,
111 UserManager* user_manager, 126 UserManager* user_manager,
112 Delegate* delegate); 127 Delegate* delegate);
113 128
114 virtual ~PlatformVerificationFlow();
115
116 // Invokes an asynchronous operation to challenge a platform key. Any user 129 // Invokes an asynchronous operation to challenge a platform key. Any user
117 // interaction will be associated with |web_contents|. The |service_id| is an 130 // 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 131 // 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 132 // and should not be determined by that origin; its purpose is to prevent
120 // collusion between multiple services. The |challenge| is also an arbitrary 133 // 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 134 // 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 135 // because its purpose is to prevent certificate replay. The |callback| will
123 // be called when the operation completes. The duration of the operation can 136 // be called when the operation completes. The duration of the operation can
124 // vary depending on system state, hardware capabilities, and interaction with 137 // vary depending on system state, hardware capabilities, and interaction with
125 // the user. 138 // the user.
126 void ChallengePlatformKey(content::WebContents* web_contents, 139 void ChallengePlatformKey(content::WebContents* web_contents,
127 const std::string& service_id, 140 const std::string& service_id,
128 const std::string& challenge, 141 const std::string& challenge,
129 const ChallengeCallback& callback); 142 const ChallengeCallback& callback);
130 143
131 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); 144 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs);
132 145
133 void set_testing_prefs(PrefService* testing_prefs) { 146 void set_testing_prefs(PrefService* testing_prefs) {
134 testing_prefs_ = testing_prefs; 147 testing_prefs_ = testing_prefs;
135 } 148 }
136 149
137 void set_testing_url(const GURL& testing_url) { 150 void set_testing_url(const GURL& testing_url) {
138 testing_url_ = testing_url; 151 testing_url_ = testing_url;
139 } 152 }
140 153
154 void set_timeout_delay(const base::TimeDelta& timeout_delay) {
155 timeout_delay_ = timeout_delay;
156 }
157
141 private: 158 private:
159 // Holds the arguments of a ChallengePlatformKey call. This is convenient for
160 // use with base::Bind so we don't get too many arguments.
161 struct ChallengeContext {
162 content::WebContents* web_contents;
163 std::string service_id;
164 std::string challenge;
165 ChallengeCallback callback;
166 };
167
168 friend class base::RefCountedThreadSafe<PlatformVerificationFlow>;
169 ~PlatformVerificationFlow();
170
142 // Checks whether we need to prompt the user for consent before proceeding and 171 // 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 172 // invokes the consent UI if so. The arguments to ChallengePlatformKey are
144 // ChallengePlatformKey except for the additional |attestation_enrolled| which 173 // in |context| and |attestation_enrolled| specifies whether attestation has
145 // specifies whether attestation has been enrolled for this device. 174 // been enrolled for this device.
146 void CheckConsent(content::WebContents* web_contents, 175 void CheckConsent(const ChallengeContext& context,
147 const std::string& service_id,
148 const std::string& challenge,
149 const ChallengeCallback& callback,
150 bool attestation_enrolled); 176 bool attestation_enrolled);
151 177
152 // A callback called when the user has given their consent response. All 178 // A callback called when the user has given their consent response. The
153 // parameters are the same as in ChallengePlatformKey except for the 179 // arguments to ChallengePlatformKey are in |context|. |consent_type| and
154 // additional |consent_type| and |consent_response| which indicate the consent 180 // |consent_response| indicate the consent type and user response,
155 // type and user response, respectively. If the response indicates that the 181 // respectively. If the response indicates that the operation should proceed,
156 // operation should proceed, this method invokes a certificate request. 182 // this method invokes a certificate request.
157 void OnConsentResponse(content::WebContents* web_contents, 183 void OnConsentResponse(const ChallengeContext& context,
158 const std::string& service_id,
159 const std::string& challenge,
160 const ChallengeCallback& callback,
161 ConsentType consent_type, 184 ConsentType consent_type,
162 ConsentResponse consent_response); 185 ConsentResponse consent_response);
163 186
164 // A callback called when an attestation certificate request operation 187 // A callback called when an attestation certificate request operation
165 // completes. |service_id|, |challenge|, and |callback| are the same as in 188 // completes. The arguments to ChallengePlatformKey are in |context|.
166 // ChallengePlatformKey. |user_id| identifies the user for which the 189 // |user_id| identifies the user for which the certificate was requested.
167 // certificate was requested. |operation_success| is true iff the certificate 190 // |operation_success| is true iff the certificate request operation
168 // request operation succeeded. |certificate| holds the certificate for the 191 // succeeded. |certificate| holds the certificate for the platform key on
169 // platform key on success. If the certificate request was successful, this 192 // success. If the certificate request was successful, this method invokes a
170 // method invokes a request to sign the challenge. 193 // request to sign the challenge. If the operation timed out prior to this
171 void OnCertificateReady(const std::string& user_id, 194 // method being called, this method does nothing - notably, the callback is
172 const std::string& service_id, 195 // not invoked.
173 const std::string& challenge, 196 void OnCertificateReady(const ChallengeContext& context,
174 const ChallengeCallback& callback, 197 const std::string& user_id,
198 scoped_ptr<base::Timer> timer,
175 bool operation_success, 199 bool operation_success,
176 const std::string& certificate); 200 const std::string& certificate);
177 201
202 // A callback run after a constant delay to handle timeouts for lengthy
203 // certificate requests. |context.callback| will be invoked with a TIMEOUT
204 // result.
205 void OnCertificateTimeout(const ChallengeContext& context);
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 base::TimeDelta 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