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 attestation { | 35 namespace attestation { |
29 | 36 |
30 class AttestationFlow; | 37 class AttestationFlow; |
31 | 38 |
32 // This class allows platform verification for the content protection use case. | 39 // This class allows platform verification for the content protection use case. |
(...skipping 10 matching lines...) Expand all Loading... | |
43 PLATFORM_NOT_VERIFIED, // The platform cannot be verified. For example: | 50 PLATFORM_NOT_VERIFIED, // The platform cannot be verified. For example: |
44 // - It is not a Chrome device. | 51 // - It is not a Chrome device. |
45 // - It is not running a verified OS image. | 52 // - It is not running a verified OS image. |
46 USER_REJECTED, // The user explicitly rejected the operation. | 53 USER_REJECTED, // The user explicitly rejected the operation. |
47 POLICY_REJECTED, // The operation is not allowed by policy/settings. | 54 POLICY_REJECTED, // The operation is not allowed by policy/settings. |
48 }; | 55 }; |
49 | 56 |
50 enum ConsentType { | 57 enum ConsentType { |
51 CONSENT_TYPE_NONE, // No consent necessary. | 58 CONSENT_TYPE_NONE, // No consent necessary. |
52 CONSENT_TYPE_ATTESTATION, // Consent to use attestation. | 59 CONSENT_TYPE_ATTESTATION, // Consent to use attestation. |
53 CONSENT_TYPE_ORIGIN, // Consent to proceed with an unfamiliar origin. | |
54 CONSENT_TYPE_ALWAYS, // Consent because 'Always Ask' was requested. | 60 CONSENT_TYPE_ALWAYS, // Consent because 'Always Ask' was requested. |
55 }; | 61 }; |
56 | 62 |
57 enum ConsentResponse { | 63 enum ConsentResponse { |
58 CONSENT_RESPONSE_NONE, | 64 CONSENT_RESPONSE_NONE, |
59 CONSENT_RESPONSE_ALLOW, | 65 CONSENT_RESPONSE_ALLOW, |
60 CONSENT_RESPONSE_DENY, | 66 CONSENT_RESPONSE_DENY, |
61 CONSENT_RESPONSE_ALWAYS_ASK, | 67 CONSENT_RESPONSE_ALWAYS_ASK, |
62 }; | 68 }; |
63 | 69 |
64 // An interface which allows settings and UI to be abstracted for testing | 70 // An interface which allows settings and UI to be abstracted for testing |
65 // purposes. For normal operation the default implementation should be used. | 71 // purposes. For normal operation the default implementation should be used. |
66 class Delegate { | 72 class Delegate { |
67 public: | 73 public: |
68 virtual ~Delegate() {} | 74 virtual ~Delegate() {} |
69 | 75 |
70 // This callback will be called when a user has given a |response| to a | 76 // This callback will be called when a user has given a |response| to a |
71 // consent request of the specified |type|. | 77 // consent request of the specified |type|. |
72 typedef base::Callback<void(ConsentResponse response)> ConsentCallback; | 78 typedef base::Callback<void(ConsentResponse response)> ConsentCallback; |
73 | 79 |
74 // Invokes consent UI of the given |type| within the context of | 80 // Invokes consent UI of the given |type| within the context of |
75 // |web_contents| and calls |callback| when the user responds. | 81 // |web_contents| and calls |callback| when the user responds. |
76 virtual void ShowConsentPrompt(ConsentType type, | 82 virtual void ShowConsentPrompt(ConsentType type, |
77 content::WebContents* web_contents, | 83 content::WebContents* web_contents, |
78 const ConsentCallback& callback) = 0; | 84 const ConsentCallback& callback) = 0; |
79 | |
80 // Returns true if settings indicate that attestation should be disabled. | |
81 virtual bool IsAttestationDisabled() = 0; | |
82 | |
83 // Checks if the web origin represented by |web_contents| is unfamiliar and | |
84 // requires special user consent. | |
85 virtual bool IsOriginConsentRequired( | |
86 content::WebContents* web_contents) = 0; | |
87 | |
88 // Checks if settings indicate that consent is required for the web origin | |
89 // represented by |web_contents| because the user requested to be prompted. | |
90 virtual bool IsAlwaysAskRequired(content::WebContents* web_contents) = 0; | |
91 | |
92 // Updates user settings based on their response to the consent request. | |
93 virtual bool UpdateSettings(content::WebContents* web_contents, | |
94 ConsentType consent_type, | |
95 ConsentResponse consent_response) = 0; | |
96 }; | 85 }; |
97 | 86 |
98 // This callback will be called when a challenge operation completes. If | 87 // This callback will be called when a challenge operation completes. If |
99 // |result| is SUCCESS then |challenge_response| holds the challenge response | 88 // |result| is SUCCESS then |challenge_response| holds the challenge response |
100 // as specified by the protocol. The |platform_key_certificate| is for the | 89 // as specified by the protocol. The |platform_key_certificate| is for the |
101 // key which was used to create the challenge response. This key may be | 90 // key which was used to create the challenge response. This key may be |
102 // generated on demand and is not guaranteed to persist across multiple calls | 91 // generated on demand and is not guaranteed to persist across multiple calls |
103 // to this method. Both the response and the certificate are opaque to | 92 // to this method. Both the response and the certificate are opaque to |
104 // the browser; they are intended for validation by an external application or | 93 // the browser; they are intended for validation by an external application or |
105 // service. | 94 // service. |
(...skipping 25 matching lines...) Expand all Loading... | |
131 // value but it should be time sensitive or associated to some kind of session | 120 // value but it should be time sensitive or associated to some kind of session |
132 // because its purpose is to prevent certificate replay. The |callback| will | 121 // because its purpose is to prevent certificate replay. The |callback| will |
133 // be called when the operation completes. The duration of the operation can | 122 // be called when the operation completes. The duration of the operation can |
134 // vary depending on system state, hardware capabilities, and interaction with | 123 // vary depending on system state, hardware capabilities, and interaction with |
135 // the user. | 124 // the user. |
136 void ChallengePlatformKey(content::WebContents* web_contents, | 125 void ChallengePlatformKey(content::WebContents* web_contents, |
137 const std::string& service_id, | 126 const std::string& service_id, |
138 const std::string& challenge, | 127 const std::string& challenge, |
139 const ChallengeCallback& callback); | 128 const ChallengeCallback& callback); |
140 | 129 |
130 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* prefs); | |
131 | |
132 void set_testing_prefs(PrefService* testing_prefs) { | |
Mattias Nissler (ping if slow)
2013/09/03 14:31:25
Can we replace these two by just using TestingWebC
Darren Krahn
2013/09/04 12:35:05
Ugh... really? This is likely possible but I thin
Mattias Nissler (ping if slow)
2013/09/04 16:01:44
I guess my main motivation here is to avoid litter
| |
133 testing_prefs_ = testing_prefs; | |
134 } | |
135 | |
136 void set_testing_url(const GURL& testing_url) { | |
137 testing_url_ = testing_url; | |
138 } | |
139 | |
141 private: | 140 private: |
142 // Checks whether we need to prompt the user for consent before proceeding and | 141 // 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 | 142 // invokes the consent UI if so. All parameters are the same as in |
144 // ChallengePlatformKey except for the additional |attestation_enrolled| which | 143 // ChallengePlatformKey except for the additional |attestation_enrolled| which |
145 // specifies whether attestation has been enrolled for this device. | 144 // specifies whether attestation has been enrolled for this device. |
146 void CheckConsent(content::WebContents* web_contents, | 145 void CheckConsent(content::WebContents* web_contents, |
147 const std::string& service_id, | 146 const std::string& service_id, |
148 const std::string& challenge, | 147 const std::string& challenge, |
149 const ChallengeCallback& callback, | 148 const ChallengeCallback& callback, |
150 bool attestation_enrolled); | 149 bool attestation_enrolled); |
(...skipping 26 matching lines...) Expand all Loading... | |
177 // |certificate| is the platform certificate for the key which signed the | 176 // |certificate| is the platform certificate for the key which signed the |
178 // challenge. |callback| is the same as in ChallengePlatformKey. | 177 // challenge. |callback| is the same as in ChallengePlatformKey. |
179 // |operation_success| is true iff the challenge signing operation was | 178 // |operation_success| is true iff the challenge signing operation was |
180 // successful. If it was successful, |response_data| holds the challenge | 179 // successful. If it was successful, |response_data| holds the challenge |
181 // response and the method will invoke |callback|. | 180 // response and the method will invoke |callback|. |
182 void OnChallengeReady(const std::string& certificate, | 181 void OnChallengeReady(const std::string& certificate, |
183 const ChallengeCallback& callback, | 182 const ChallengeCallback& callback, |
184 bool operation_success, | 183 bool operation_success, |
185 const std::string& response_data); | 184 const std::string& response_data); |
186 | 185 |
186 // Gets prefs associated with the given |web_contents|. If prefs have been | |
187 // set explicitly using set_testing_prefs(), then these are always returned. | |
188 // If no prefs are associated with |web_contents| then NULL is returned. | |
189 PrefService* GetPrefs(content::WebContents* web_contents); | |
190 | |
191 // Gets the URL associated with the given |web_contents|. If a URL as been | |
192 // set explicitly using set_testing_url(), then this value is always returned. | |
193 const GURL& GetURL(content::WebContents* web_contents); | |
194 | |
195 // Checks whether policy or profile settings associated with |web_contents| | |
196 // have attestation for content protection explicitly disabled. | |
197 bool IsAttestationEnabled(content::WebContents* web_contents); | |
198 | |
199 // Checks whether this is the first use on this device for the user associated | |
200 // with |web_contents|. | |
201 bool IsFirstUse(content::WebContents* web_contents); | |
202 | |
203 // Checks if settings indicate that consent is required for the web origin | |
204 // represented by |web_contents| because the user requested to be prompted. | |
205 bool IsAlwaysAskRequired(content::WebContents* web_contents); | |
206 | |
207 // Updates user settings for the profile associated with |web_contents| based | |
208 // on the |consent_response| to the request of type |consent_type|. | |
209 bool UpdateSettings(content::WebContents* web_contents, | |
210 ConsentType consent_type, | |
211 ConsentResponse consent_response); | |
212 | |
213 // Finds the domain-specific consent pref for the domain associated with | |
214 // |web_contents|. If a pref exists for the domain, returns true and sets | |
215 // |pref_value| if it is not NULL. | |
216 // | |
217 // Precondition: A valid PrefService must be available via GetPrefs(). | |
218 bool FindDomainPref(content::WebContents* web_contents, bool* pref_value); | |
219 | |
220 // Records the domain-specific consent pref for the domain associated with | |
221 // |web_contents|. The pref will be set to |allow_domain|. | |
222 // | |
223 // Precondition: A valid PrefService must be available via GetPrefs(). | |
224 void RecordDomainConsent(content::WebContents* web_contents, | |
225 bool allow_domain); | |
226 | |
187 AttestationFlow* attestation_flow_; | 227 AttestationFlow* attestation_flow_; |
188 scoped_ptr<AttestationFlow> default_attestation_flow_; | 228 scoped_ptr<AttestationFlow> default_attestation_flow_; |
189 cryptohome::AsyncMethodCaller* async_caller_; | 229 cryptohome::AsyncMethodCaller* async_caller_; |
190 CryptohomeClient* cryptohome_client_; | 230 CryptohomeClient* cryptohome_client_; |
191 UserManager* user_manager_; | 231 UserManager* user_manager_; |
192 Delegate* delegate_; | 232 Delegate* delegate_; |
193 scoped_ptr<Delegate> default_delegate_; | 233 scoped_ptr<Delegate> default_delegate_; |
234 PrefService* testing_prefs_; | |
235 GURL testing_url_; | |
194 | 236 |
195 // Note: This should remain the last member so it'll be destroyed and | 237 // Note: This should remain the last member so it'll be destroyed and |
196 // invalidate the weak pointers before any other members are destroyed. | 238 // invalidate the weak pointers before any other members are destroyed. |
197 base::WeakPtrFactory<PlatformVerificationFlow> weak_factory_; | 239 base::WeakPtrFactory<PlatformVerificationFlow> weak_factory_; |
198 | 240 |
199 DISALLOW_COPY_AND_ASSIGN(PlatformVerificationFlow); | 241 DISALLOW_COPY_AND_ASSIGN(PlatformVerificationFlow); |
200 }; | 242 }; |
201 | 243 |
202 } // namespace attestation | 244 } // namespace attestation |
203 } // namespace chromeos | 245 } // namespace chromeos |
204 | 246 |
205 #endif // CHROME_BROWSER_CHROMEOS_ATTESTATION_PLATFORM_VERIFICATION_FLOW_H_ | 247 #endif // CHROME_BROWSER_CHROMEOS_ATTESTATION_PLATFORM_VERIFICATION_FLOW_H_ |
OLD | NEW |