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

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

Issue 31043008: Changed platform verification user consent logic to be per-domain. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix browser_tests 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/attestation/platform_verification_flow.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "url/gurl.h" 14 #include "url/gurl.h"
15 15
16 class HostContentSettingsMap;
16 class PrefService; 17 class PrefService;
17 18
18 namespace content { 19 namespace content {
19 class WebContents; 20 class WebContents;
20 } 21 }
21 22
22 namespace cryptohome { 23 namespace cryptohome {
23 class AsyncMethodCaller; 24 class AsyncMethodCaller;
24 } 25 }
25 26
26 namespace user_prefs { 27 namespace user_prefs {
27 class PrefRegistrySyncable; 28 class PrefRegistrySyncable;
28 } 29 }
29 30
30 namespace chromeos { 31 namespace chromeos {
31 32
32 class CryptohomeClient; 33 class CryptohomeClient;
33 class UserManager; 34 class UserManager;
34 class User; 35 class User;
35 36
36 namespace attestation { 37 namespace attestation {
37 38
38 class AttestationFlow; 39 class AttestationFlow;
40 class PlatformVerificationFlowTest;
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 // PlatformVerificationFlow verifier;
43 // PlatformVerificationFlow::Callback callback = base::Bind(&MyCallback); 45 // PlatformVerificationFlow::Callback callback = base::Bind(&MyCallback);
44 // verifier.ChallengePlatformKey(my_web_contents, "my_id", "some_challenge", 46 // verifier.ChallengePlatformKey(my_web_contents, "my_id", "some_challenge",
45 // callback); 47 // callback);
46 class PlatformVerificationFlow { 48 class PlatformVerificationFlow {
47 public: 49 public:
48 enum Result { 50 enum Result {
49 SUCCESS, // The operation succeeded. 51 SUCCESS, // The operation succeeded.
50 INTERNAL_ERROR, // The operation failed unexpectedly. 52 INTERNAL_ERROR, // The operation failed unexpectedly.
51 PLATFORM_NOT_VERIFIED, // The platform cannot be verified. For example: 53 PLATFORM_NOT_VERIFIED, // The platform cannot be verified. For example:
52 // - It is not a Chrome device. 54 // - It is not a Chrome device.
53 // - It is not running a verified OS image. 55 // - It is not running a verified OS image.
54 USER_REJECTED, // The user explicitly rejected the operation. 56 USER_REJECTED, // The user explicitly rejected the operation.
55 POLICY_REJECTED, // The operation is not allowed by policy/settings. 57 POLICY_REJECTED, // The operation is not allowed by policy/settings.
56 }; 58 };
57 59
58 enum ConsentType {
59 CONSENT_TYPE_NONE, // No consent necessary.
60 CONSENT_TYPE_ATTESTATION, // Consent to use attestation.
61 CONSENT_TYPE_ALWAYS, // Consent because 'Always Ask' was requested.
62 };
63
64 enum ConsentResponse { 60 enum ConsentResponse {
65 CONSENT_RESPONSE_NONE, 61 CONSENT_RESPONSE_NONE,
66 CONSENT_RESPONSE_ALLOW, 62 CONSENT_RESPONSE_ALLOW,
67 CONSENT_RESPONSE_DENY, 63 CONSENT_RESPONSE_DENY,
68 CONSENT_RESPONSE_ALWAYS_ASK,
69 }; 64 };
70 65
71 // An interface which allows settings and UI to be abstracted for testing 66 // An interface which allows settings and UI to be abstracted for testing
72 // purposes. For normal operation the default implementation should be used. 67 // purposes. For normal operation the default implementation should be used.
73 class Delegate { 68 class Delegate {
74 public: 69 public:
75 virtual ~Delegate() {} 70 virtual ~Delegate() {}
76 71
77 // This callback will be called when a user has given a |response| to a 72 // This callback will be called when a user has given a |response| to a
78 // consent request of the specified |type|. 73 // consent request of the specified |type|.
79 typedef base::Callback<void(ConsentResponse response)> ConsentCallback; 74 typedef base::Callback<void(ConsentResponse response)> ConsentCallback;
80 75
81 // Invokes consent UI of the given |type| within the context of 76 // Invokes consent UI within the context of |web_contents| and calls
82 // |web_contents| and calls |callback| when the user responds. 77 // |callback| when the user responds.
83 virtual void ShowConsentPrompt(ConsentType type, 78 // Precondition: The last committed URL for |web_contents| has a valid
84 content::WebContents* web_contents, 79 // origin.
80 virtual void ShowConsentPrompt(content::WebContents* web_contents,
85 const ConsentCallback& callback) = 0; 81 const ConsentCallback& callback) = 0;
86 }; 82 };
87 83
88 // This callback will be called when a challenge operation completes. If 84 // This callback will be called when a challenge operation completes. If
89 // |result| is SUCCESS then |signed_data| holds the data which was signed 85 // |result| is SUCCESS then |signed_data| holds the data which was signed
90 // by the platform key (this is the original challenge appended with a random 86 // by the platform key (this is the original challenge appended with a random
91 // nonce) and |signature| holds the RSA-PKCS1-v1.5 signature. The 87 // nonce) and |signature| holds the RSA-PKCS1-v1.5 signature. The
92 // |platform_key_certificate| certifies the key used to generate the 88 // |platform_key_certificate| certifies the key used to generate the
93 // signature. This key may be generated on demand and is not guaranteed to 89 // signature. This key may be generated on demand and is not guaranteed to
94 // persist across multiple calls to this method. The browser does not check 90 // persist across multiple calls to this method. The browser does not check
(...skipping 28 matching lines...) Expand all
123 // be called when the operation completes. The duration of the operation can 119 // be called when the operation completes. The duration of the operation can
124 // vary depending on system state, hardware capabilities, and interaction with 120 // vary depending on system state, hardware capabilities, and interaction with
125 // the user. 121 // the user.
126 void ChallengePlatformKey(content::WebContents* web_contents, 122 void ChallengePlatformKey(content::WebContents* web_contents,
127 const std::string& service_id, 123 const std::string& service_id,
128 const std::string& challenge, 124 const std::string& challenge,
129 const ChallengeCallback& callback); 125 const ChallengeCallback& callback);
130 126
131 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); 127 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs);
132 128
133 void set_testing_prefs(PrefService* testing_prefs) { 129 private:
134 testing_prefs_ = testing_prefs; 130 friend class PlatformVerificationFlowTest;
135 }
136 131
137 void set_testing_url(const GURL& testing_url) {
138 testing_url_ = testing_url;
139 }
140
141 private:
142 // Checks whether we need to prompt the user for consent before proceeding and 132 // 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 133 // invokes the consent UI if so. All parameters are the same as in
144 // ChallengePlatformKey except for the additional |attestation_enrolled| which 134 // ChallengePlatformKey except for the additional |attestation_enrolled| which
145 // specifies whether attestation has been enrolled for this device. 135 // specifies whether attestation has been enrolled for this device.
146 void CheckConsent(content::WebContents* web_contents, 136 void CheckConsent(content::WebContents* web_contents,
147 const std::string& service_id, 137 const std::string& service_id,
148 const std::string& challenge, 138 const std::string& challenge,
149 const ChallengeCallback& callback, 139 const ChallengeCallback& callback,
150 bool attestation_enrolled); 140 bool attestation_enrolled);
151 141
152 // A callback called when the user has given their consent response. All 142 // A callback called when the user has given their consent response. All
153 // parameters are the same as in ChallengePlatformKey except for the 143 // parameters are the same as in ChallengePlatformKey except for the
154 // additional |consent_type| and |consent_response| which indicate the consent 144 // additional |consent_required| and |consent_response| which indicate that
155 // type and user response, respectively. If the response indicates that the 145 // user interaction was required and the user response, respectively. If the
156 // operation should proceed, this method invokes a certificate request. 146 // response indicates that the operation should proceed, this method invokes a
147 // certificate request.
157 void OnConsentResponse(content::WebContents* web_contents, 148 void OnConsentResponse(content::WebContents* web_contents,
158 const std::string& service_id, 149 const std::string& service_id,
159 const std::string& challenge, 150 const std::string& challenge,
160 const ChallengeCallback& callback, 151 const ChallengeCallback& callback,
161 ConsentType consent_type, 152 bool consent_required,
162 ConsentResponse consent_response); 153 ConsentResponse consent_response);
163 154
164 // A callback called when an attestation certificate request operation 155 // A callback called when an attestation certificate request operation
165 // completes. |service_id|, |challenge|, and |callback| are the same as in 156 // completes. |service_id|, |challenge|, and |callback| are the same as in
166 // ChallengePlatformKey. |user_id| identifies the user for which the 157 // ChallengePlatformKey. |user_id| identifies the user for which the
167 // certificate was requested. |operation_success| is true iff the certificate 158 // certificate was requested. |operation_success| is true iff the certificate
168 // request operation succeeded. |certificate| holds the certificate for the 159 // request operation succeeded. |certificate| holds the certificate for the
169 // platform key on success. If the certificate request was successful, this 160 // platform key on success. If the certificate request was successful, this
170 // method invokes a request to sign the challenge. 161 // method invokes a request to sign the challenge.
171 void OnCertificateReady(const std::string& user_id, 162 void OnCertificateReady(const std::string& user_id,
(...skipping 22 matching lines...) Expand all
194 185
195 // Gets the URL associated with the given |web_contents|. If a URL as been 186 // 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. 187 // set explicitly using set_testing_url(), then this value is always returned.
197 const GURL& GetURL(content::WebContents* web_contents); 188 const GURL& GetURL(content::WebContents* web_contents);
198 189
199 // Gets the user associated with the given |web_contents|. NULL may be 190 // Gets the user associated with the given |web_contents|. NULL may be
200 // returned. If |web_contents| is NULL (e.g. during testing), then the 191 // returned. If |web_contents| is NULL (e.g. during testing), then the
201 // current active user will be returned. 192 // current active user will be returned.
202 User* GetUser(content::WebContents* web_contents); 193 User* GetUser(content::WebContents* web_contents);
203 194
195 // Gets the content settings map associated with the given |web_contents|. If
196 // |testing_content_settings_| is set, then this is always returned.
197 HostContentSettingsMap* GetContentSettings(
198 content::WebContents* web_contents);
199
204 // Checks whether policy or profile settings associated with |web_contents| 200 // Checks whether policy or profile settings associated with |web_contents|
205 // have attestation for content protection explicitly disabled. 201 // have attestation for content protection explicitly disabled.
206 bool IsAttestationEnabled(content::WebContents* web_contents); 202 bool IsAttestationEnabled(content::WebContents* web_contents);
207 203
208 // Checks whether this is the first use on this device for the user associated
209 // with |web_contents|.
210 bool IsFirstUse(content::WebContents* web_contents);
211
212 // Checks if settings indicate that consent is required for the web origin
213 // represented by |web_contents| because the user requested to be prompted.
214 bool IsAlwaysAskRequired(content::WebContents* web_contents);
215
216 // Updates user settings for the profile associated with |web_contents| based 204 // Updates user settings for the profile associated with |web_contents| based
217 // on the |consent_response| to the request of type |consent_type|. 205 // on the |consent_response| to the request of type |consent_type|.
218 bool UpdateSettings(content::WebContents* web_contents, 206 bool UpdateSettings(content::WebContents* web_contents,
219 ConsentType consent_type,
220 ConsentResponse consent_response); 207 ConsentResponse consent_response);
221 208
222 // Finds the domain-specific consent pref for the domain associated with 209 // Finds the domain-specific consent pref in |content_settings| for |url|. If
223 // |web_contents|. If a pref exists for the domain, returns true and sets 210 // a pref exists for the domain, returns true and sets |pref_value| if it is
224 // |pref_value| if it is not NULL. 211 // not NULL.
225 // 212 bool GetDomainPref(HostContentSettingsMap* content_settings,
226 // Precondition: A valid PrefService must be available via GetPrefs(). 213 const GURL& url,
227 bool GetDomainPref(content::WebContents* web_contents, bool* pref_value); 214 bool* pref_value);
228 215
229 // Records the domain-specific consent pref for the domain associated with 216 // Records the domain-specific consent pref in |content_settings| for |url|.
230 // |web_contents|. The pref will be set to |allow_domain|. 217 // The pref will be set to |allow_domain|.
231 // 218 void RecordDomainConsent(HostContentSettingsMap* content_settings,
232 // Precondition: A valid PrefService must be available via GetPrefs(). 219 const GURL& url,
233 void RecordDomainConsent(content::WebContents* web_contents,
234 bool allow_domain); 220 bool allow_domain);
235 221
222 void set_testing_prefs(PrefService* testing_prefs) {
223 testing_prefs_ = testing_prefs;
224 }
225
226 void set_testing_url(const GURL& testing_url) {
227 testing_url_ = testing_url;
228 }
229
230 void set_testing_content_settings(HostContentSettingsMap* settings) {
231 testing_content_settings_ = settings;
232 }
233
236 AttestationFlow* attestation_flow_; 234 AttestationFlow* attestation_flow_;
237 scoped_ptr<AttestationFlow> default_attestation_flow_; 235 scoped_ptr<AttestationFlow> default_attestation_flow_;
238 cryptohome::AsyncMethodCaller* async_caller_; 236 cryptohome::AsyncMethodCaller* async_caller_;
239 CryptohomeClient* cryptohome_client_; 237 CryptohomeClient* cryptohome_client_;
240 UserManager* user_manager_; 238 UserManager* user_manager_;
241 Delegate* delegate_; 239 Delegate* delegate_;
242 scoped_ptr<Delegate> default_delegate_; 240 scoped_ptr<Delegate> default_delegate_;
243 PrefService* testing_prefs_; 241 PrefService* testing_prefs_;
244 GURL testing_url_; 242 GURL testing_url_;
243 HostContentSettingsMap* testing_content_settings_;
245 244
246 // Note: This should remain the last member so it'll be destroyed and 245 // Note: This should remain the last member so it'll be destroyed and
247 // invalidate the weak pointers before any other members are destroyed. 246 // invalidate the weak pointers before any other members are destroyed.
248 base::WeakPtrFactory<PlatformVerificationFlow> weak_factory_; 247 base::WeakPtrFactory<PlatformVerificationFlow> weak_factory_;
249 248
250 DISALLOW_COPY_AND_ASSIGN(PlatformVerificationFlow); 249 DISALLOW_COPY_AND_ASSIGN(PlatformVerificationFlow);
251 }; 250 };
252 251
253 } // namespace attestation 252 } // namespace attestation
254 } // namespace chromeos 253 } // namespace chromeos
255 254
256 #endif // CHROME_BROWSER_CHROMEOS_ATTESTATION_PLATFORM_VERIFICATION_FLOW_H_ 255 #endif // CHROME_BROWSER_CHROMEOS_ATTESTATION_PLATFORM_VERIFICATION_FLOW_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/attestation/platform_verification_flow.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698