OLD | NEW |
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" |
| 15 |
| 16 class PrefService; |
14 | 17 |
15 namespace content { | 18 namespace content { |
16 class WebContents; | 19 class WebContents; |
17 } | 20 } |
18 | 21 |
19 namespace cryptohome { | 22 namespace cryptohome { |
20 class AsyncMethodCaller; | 23 class AsyncMethodCaller; |
21 } | 24 } |
22 | 25 |
| 26 namespace user_prefs { |
| 27 class PrefRegistrySyncable; |
| 28 } |
| 29 |
23 namespace chromeos { | 30 namespace chromeos { |
24 | 31 |
25 class CryptohomeClient; | 32 class CryptohomeClient; |
26 class UserManager; | 33 class UserManager; |
27 | 34 |
28 namespace system { | 35 namespace system { |
29 class StatisticsProvider; | 36 class StatisticsProvider; |
30 } | 37 } |
31 | 38 |
32 namespace attestation { | 39 namespace attestation { |
(...skipping 14 matching lines...) Expand all Loading... |
47 PLATFORM_NOT_VERIFIED, // The platform cannot be verified. For example: | 54 PLATFORM_NOT_VERIFIED, // The platform cannot be verified. For example: |
48 // - It is not a Chrome device. | 55 // - It is not a Chrome device. |
49 // - It is not running a verified OS image. | 56 // - It is not running a verified OS image. |
50 USER_REJECTED, // The user explicitly rejected the operation. | 57 USER_REJECTED, // The user explicitly rejected the operation. |
51 POLICY_REJECTED, // The operation is not allowed by policy/settings. | 58 POLICY_REJECTED, // The operation is not allowed by policy/settings. |
52 }; | 59 }; |
53 | 60 |
54 enum ConsentType { | 61 enum ConsentType { |
55 CONSENT_TYPE_NONE, // No consent necessary. | 62 CONSENT_TYPE_NONE, // No consent necessary. |
56 CONSENT_TYPE_ATTESTATION, // Consent to use attestation. | 63 CONSENT_TYPE_ATTESTATION, // Consent to use attestation. |
57 CONSENT_TYPE_ORIGIN, // Consent to proceed with an unfamiliar origin. | |
58 CONSENT_TYPE_ALWAYS, // Consent because 'Always Ask' was requested. | 64 CONSENT_TYPE_ALWAYS, // Consent because 'Always Ask' was requested. |
59 }; | 65 }; |
60 | 66 |
61 enum ConsentResponse { | 67 enum ConsentResponse { |
62 CONSENT_RESPONSE_NONE, | 68 CONSENT_RESPONSE_NONE, |
63 CONSENT_RESPONSE_ALLOW, | 69 CONSENT_RESPONSE_ALLOW, |
64 CONSENT_RESPONSE_DENY, | 70 CONSENT_RESPONSE_DENY, |
65 CONSENT_RESPONSE_ALWAYS_ASK, | 71 CONSENT_RESPONSE_ALWAYS_ASK, |
66 }; | 72 }; |
67 | 73 |
68 // An interface which allows settings and UI to be abstracted for testing | 74 // An interface which allows settings and UI to be abstracted for testing |
69 // purposes. For normal operation the default implementation should be used. | 75 // purposes. For normal operation the default implementation should be used. |
70 class Delegate { | 76 class Delegate { |
71 public: | 77 public: |
72 virtual ~Delegate() {} | 78 virtual ~Delegate() {} |
73 | 79 |
74 // This callback will be called when a user has given a |response| to a | 80 // This callback will be called when a user has given a |response| to a |
75 // consent request of the specified |type|. | 81 // consent request of the specified |type|. |
76 typedef base::Callback<void(ConsentResponse response)> ConsentCallback; | 82 typedef base::Callback<void(ConsentResponse response)> ConsentCallback; |
77 | 83 |
78 // Invokes consent UI of the given |type| within the context of | 84 // Invokes consent UI of the given |type| within the context of |
79 // |web_contents| and calls |callback| when the user responds. | 85 // |web_contents| and calls |callback| when the user responds. |
80 virtual void ShowConsentPrompt(ConsentType type, | 86 virtual void ShowConsentPrompt(ConsentType type, |
81 content::WebContents* web_contents, | 87 content::WebContents* web_contents, |
82 const ConsentCallback& callback) = 0; | 88 const ConsentCallback& callback) = 0; |
83 | |
84 // Returns true if settings indicate that attestation should be disabled. | |
85 virtual bool IsAttestationDisabled() = 0; | |
86 | |
87 // Checks if the web origin represented by |web_contents| is unfamiliar and | |
88 // requires special user consent. | |
89 virtual bool IsOriginConsentRequired( | |
90 content::WebContents* web_contents) = 0; | |
91 | |
92 // Checks if settings indicate that consent is required for the web origin | |
93 // represented by |web_contents| because the user requested to be prompted. | |
94 virtual bool IsAlwaysAskRequired(content::WebContents* web_contents) = 0; | |
95 | |
96 // Updates user settings based on their response to the consent request. | |
97 virtual bool UpdateSettings(content::WebContents* web_contents, | |
98 ConsentType consent_type, | |
99 ConsentResponse consent_response) = 0; | |
100 }; | 89 }; |
101 | 90 |
102 // This callback will be called when a challenge operation completes. If | 91 // This callback will be called when a challenge operation completes. If |
103 // |result| is SUCCESS then |challenge_response| holds the challenge response | 92 // |result| is SUCCESS then |challenge_response| holds the challenge response |
104 // as specified by the protocol. The |platform_key_certificate| is for the | 93 // as specified by the protocol. The |platform_key_certificate| is for the |
105 // key which was used to create the challenge response. This key may be | 94 // key which was used to create the challenge response. This key may be |
106 // generated on demand and is not guaranteed to persist across multiple calls | 95 // generated on demand and is not guaranteed to persist across multiple calls |
107 // to this method. Both the response and the certificate are opaque to | 96 // to this method. Both the response and the certificate are opaque to |
108 // the browser; they are intended for validation by an external application or | 97 // the browser; they are intended for validation by an external application or |
109 // service. | 98 // service. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 const std::string& challenge, | 132 const std::string& challenge, |
144 const ChallengeCallback& callback); | 133 const ChallengeCallback& callback); |
145 | 134 |
146 // Performs a quick check to see if platform verification is reasonably | 135 // Performs a quick check to see if platform verification is reasonably |
147 // expected to succeed. The result of the check will be sent to the given | 136 // expected to succeed. The result of the check will be sent to the given |
148 // |callback|. If the |result| is true, then platform verification is | 137 // |callback|. If the |result| is true, then platform verification is |
149 // expected to succeed. However, this result is not authoritative either true | 138 // expected to succeed. However, this result is not authoritative either true |
150 // or false. If an error occurs, |result| will be false. | 139 // or false. If an error occurs, |result| will be false. |
151 void CheckPlatformState(const base::Callback<void(bool result)>& callback); | 140 void CheckPlatformState(const base::Callback<void(bool result)>& callback); |
152 | 141 |
| 142 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); |
| 143 |
| 144 void set_testing_prefs(PrefService* testing_prefs) { |
| 145 testing_prefs_ = testing_prefs; |
| 146 } |
| 147 |
| 148 void set_testing_url(const GURL& testing_url) { |
| 149 testing_url_ = testing_url; |
| 150 } |
| 151 |
153 private: | 152 private: |
154 // Checks whether we need to prompt the user for consent before proceeding and | 153 // Checks whether we need to prompt the user for consent before proceeding and |
155 // invokes the consent UI if so. All parameters are the same as in | 154 // invokes the consent UI if so. All parameters are the same as in |
156 // ChallengePlatformKey except for the additional |attestation_enrolled| which | 155 // ChallengePlatformKey except for the additional |attestation_enrolled| which |
157 // specifies whether attestation has been enrolled for this device. | 156 // specifies whether attestation has been enrolled for this device. |
158 void CheckConsent(content::WebContents* web_contents, | 157 void CheckConsent(content::WebContents* web_contents, |
159 const std::string& service_id, | 158 const std::string& service_id, |
160 const std::string& challenge, | 159 const std::string& challenge, |
161 const ChallengeCallback& callback, | 160 const ChallengeCallback& callback, |
162 bool attestation_enrolled); | 161 bool attestation_enrolled); |
(...skipping 26 matching lines...) Expand all Loading... |
189 // |certificate| is the platform certificate for the key which signed the | 188 // |certificate| is the platform certificate for the key which signed the |
190 // challenge. |callback| is the same as in ChallengePlatformKey. | 189 // challenge. |callback| is the same as in ChallengePlatformKey. |
191 // |operation_success| is true iff the challenge signing operation was | 190 // |operation_success| is true iff the challenge signing operation was |
192 // successful. If it was successful, |response_data| holds the challenge | 191 // successful. If it was successful, |response_data| holds the challenge |
193 // response and the method will invoke |callback|. | 192 // response and the method will invoke |callback|. |
194 void OnChallengeReady(const std::string& certificate, | 193 void OnChallengeReady(const std::string& certificate, |
195 const ChallengeCallback& callback, | 194 const ChallengeCallback& callback, |
196 bool operation_success, | 195 bool operation_success, |
197 const std::string& response_data); | 196 const std::string& response_data); |
198 | 197 |
| 198 // Gets prefs associated with the given |web_contents|. If prefs have been |
| 199 // set explicitly using set_testing_prefs(), then these are always returned. |
| 200 // If no prefs are associated with |web_contents| then NULL is returned. |
| 201 PrefService* GetPrefs(content::WebContents* web_contents); |
| 202 |
| 203 // Gets the URL associated with the given |web_contents|. If a URL as been |
| 204 // set explicitly using set_testing_url(), then this value is always returned. |
| 205 const GURL& GetURL(content::WebContents* web_contents); |
| 206 |
| 207 // Checks whether policy or profile settings associated with |web_contents| |
| 208 // have attestation for content protection explicitly disabled. |
| 209 bool IsAttestationEnabled(content::WebContents* web_contents); |
| 210 |
| 211 // Checks whether this is the first use on this device for the user associated |
| 212 // with |web_contents|. |
| 213 bool IsFirstUse(content::WebContents* web_contents); |
| 214 |
| 215 // Checks if settings indicate that consent is required for the web origin |
| 216 // represented by |web_contents| because the user requested to be prompted. |
| 217 bool IsAlwaysAskRequired(content::WebContents* web_contents); |
| 218 |
| 219 // Updates user settings for the profile associated with |web_contents| based |
| 220 // on the |consent_response| to the request of type |consent_type|. |
| 221 bool UpdateSettings(content::WebContents* web_contents, |
| 222 ConsentType consent_type, |
| 223 ConsentResponse consent_response); |
| 224 |
| 225 // Finds the domain-specific consent pref for the domain associated with |
| 226 // |web_contents|. If a pref exists for the domain, returns true and sets |
| 227 // |pref_value| if it is not NULL. |
| 228 // |
| 229 // Precondition: A valid PrefService must be available via GetPrefs(). |
| 230 bool GetDomainPref(content::WebContents* web_contents, bool* pref_value); |
| 231 |
| 232 // Records the domain-specific consent pref for the domain associated with |
| 233 // |web_contents|. The pref will be set to |allow_domain|. |
| 234 // |
| 235 // Precondition: A valid PrefService must be available via GetPrefs(). |
| 236 void RecordDomainConsent(content::WebContents* web_contents, |
| 237 bool allow_domain); |
| 238 |
199 AttestationFlow* attestation_flow_; | 239 AttestationFlow* attestation_flow_; |
200 scoped_ptr<AttestationFlow> default_attestation_flow_; | 240 scoped_ptr<AttestationFlow> default_attestation_flow_; |
201 cryptohome::AsyncMethodCaller* async_caller_; | 241 cryptohome::AsyncMethodCaller* async_caller_; |
202 CryptohomeClient* cryptohome_client_; | 242 CryptohomeClient* cryptohome_client_; |
203 UserManager* user_manager_; | 243 UserManager* user_manager_; |
204 system::StatisticsProvider* statistics_provider_; | 244 system::StatisticsProvider* statistics_provider_; |
205 Delegate* delegate_; | 245 Delegate* delegate_; |
206 scoped_ptr<Delegate> default_delegate_; | 246 scoped_ptr<Delegate> default_delegate_; |
| 247 PrefService* testing_prefs_; |
| 248 GURL testing_url_; |
207 | 249 |
208 // Note: This should remain the last member so it'll be destroyed and | 250 // Note: This should remain the last member so it'll be destroyed and |
209 // invalidate the weak pointers before any other members are destroyed. | 251 // invalidate the weak pointers before any other members are destroyed. |
210 base::WeakPtrFactory<PlatformVerificationFlow> weak_factory_; | 252 base::WeakPtrFactory<PlatformVerificationFlow> weak_factory_; |
211 | 253 |
212 DISALLOW_COPY_AND_ASSIGN(PlatformVerificationFlow); | 254 DISALLOW_COPY_AND_ASSIGN(PlatformVerificationFlow); |
213 }; | 255 }; |
214 | 256 |
215 } // namespace attestation | 257 } // namespace attestation |
216 } // namespace chromeos | 258 } // namespace chromeos |
217 | 259 |
218 #endif // CHROME_BROWSER_CHROMEOS_ATTESTATION_PLATFORM_VERIFICATION_FLOW_H_ | 260 #endif // CHROME_BROWSER_CHROMEOS_ATTESTATION_PLATFORM_VERIFICATION_FLOW_H_ |
OLD | NEW |