Chromium Code Reviews| 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" | 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 void set_testing_prefs(PrefService* testing_prefs) { |
| 134 testing_prefs_ = testing_prefs; | 130 testing_prefs_ = testing_prefs; |
| 135 } | 131 } |
| 136 | 132 |
| 137 void set_testing_url(const GURL& testing_url) { | 133 void set_testing_url(const GURL& testing_url) { |
| 138 testing_url_ = testing_url; | 134 testing_url_ = testing_url; |
| 139 } | 135 } |
| 140 | 136 |
| 137 void set_testing_content_settings(HostContentSettingsMap* settings) { | |
| 138 testing_content_settings_ = settings; | |
| 139 } | |
|
Jun Mukai
2013/10/29 00:26:51
Could this be private?
Darren Krahn
2013/10/29 17:37:30
Actually, given I needed to 'friend' the test fixt
| |
| 140 | |
| 141 private: | 141 private: |
| 142 friend class PlatformVerificationFlowTest; | |
| 143 | |
| 142 // Checks whether we need to prompt the user for consent before proceeding and | 144 // 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 | 145 // invokes the consent UI if so. All parameters are the same as in |
| 144 // ChallengePlatformKey except for the additional |attestation_enrolled| which | 146 // ChallengePlatformKey except for the additional |attestation_enrolled| which |
| 145 // specifies whether attestation has been enrolled for this device. | 147 // specifies whether attestation has been enrolled for this device. |
| 146 void CheckConsent(content::WebContents* web_contents, | 148 void CheckConsent(content::WebContents* web_contents, |
| 147 const std::string& service_id, | 149 const std::string& service_id, |
| 148 const std::string& challenge, | 150 const std::string& challenge, |
| 149 const ChallengeCallback& callback, | 151 const ChallengeCallback& callback, |
| 150 bool attestation_enrolled); | 152 bool attestation_enrolled); |
| 151 | 153 |
| 152 // A callback called when the user has given their consent response. All | 154 // A callback called when the user has given their consent response. All |
| 153 // parameters are the same as in ChallengePlatformKey except for the | 155 // parameters are the same as in ChallengePlatformKey except for the |
| 154 // additional |consent_type| and |consent_response| which indicate the consent | 156 // additional |consent_required| and |consent_response| which indicate that |
| 155 // type and user response, respectively. If the response indicates that the | 157 // user interaction was required and the user response, respectively. If the |
| 156 // operation should proceed, this method invokes a certificate request. | 158 // response indicates that the operation should proceed, this method invokes a |
| 159 // certificate request. | |
| 157 void OnConsentResponse(content::WebContents* web_contents, | 160 void OnConsentResponse(content::WebContents* web_contents, |
| 158 const std::string& service_id, | 161 const std::string& service_id, |
| 159 const std::string& challenge, | 162 const std::string& challenge, |
| 160 const ChallengeCallback& callback, | 163 const ChallengeCallback& callback, |
| 161 ConsentType consent_type, | 164 bool consent_required, |
| 162 ConsentResponse consent_response); | 165 ConsentResponse consent_response); |
| 163 | 166 |
| 164 // A callback called when an attestation certificate request operation | 167 // A callback called when an attestation certificate request operation |
| 165 // completes. |service_id|, |challenge|, and |callback| are the same as in | 168 // completes. |service_id|, |challenge|, and |callback| are the same as in |
| 166 // ChallengePlatformKey. |user_id| identifies the user for which the | 169 // ChallengePlatformKey. |user_id| identifies the user for which the |
| 167 // certificate was requested. |operation_success| is true iff the certificate | 170 // certificate was requested. |operation_success| is true iff the certificate |
| 168 // request operation succeeded. |certificate| holds the certificate for the | 171 // request operation succeeded. |certificate| holds the certificate for the |
| 169 // platform key on success. If the certificate request was successful, this | 172 // platform key on success. If the certificate request was successful, this |
| 170 // method invokes a request to sign the challenge. | 173 // method invokes a request to sign the challenge. |
| 171 void OnCertificateReady(const std::string& user_id, | 174 void OnCertificateReady(const std::string& user_id, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 194 | 197 |
| 195 // Gets the URL associated with the given |web_contents|. If a URL as been | 198 // 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. | 199 // set explicitly using set_testing_url(), then this value is always returned. |
| 197 const GURL& GetURL(content::WebContents* web_contents); | 200 const GURL& GetURL(content::WebContents* web_contents); |
| 198 | 201 |
| 199 // Gets the user associated with the given |web_contents|. NULL may be | 202 // 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 | 203 // returned. If |web_contents| is NULL (e.g. during testing), then the |
| 201 // current active user will be returned. | 204 // current active user will be returned. |
| 202 User* GetUser(content::WebContents* web_contents); | 205 User* GetUser(content::WebContents* web_contents); |
| 203 | 206 |
| 207 // Gets the content settings map associated with the given |web_contents|. If | |
| 208 // |testing_content_settings_| is set, then this is always returned. | |
| 209 HostContentSettingsMap* GetContentSettings( | |
| 210 content::WebContents* web_contents); | |
| 211 | |
| 204 // Checks whether policy or profile settings associated with |web_contents| | 212 // Checks whether policy or profile settings associated with |web_contents| |
| 205 // have attestation for content protection explicitly disabled. | 213 // have attestation for content protection explicitly disabled. |
| 206 bool IsAttestationEnabled(content::WebContents* web_contents); | 214 bool IsAttestationEnabled(content::WebContents* web_contents); |
| 207 | 215 |
| 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 | 216 // Updates user settings for the profile associated with |web_contents| based |
| 217 // on the |consent_response| to the request of type |consent_type|. | 217 // on the |consent_response| to the request of type |consent_type|. |
| 218 bool UpdateSettings(content::WebContents* web_contents, | 218 bool UpdateSettings(content::WebContents* web_contents, |
| 219 ConsentType consent_type, | |
| 220 ConsentResponse consent_response); | 219 ConsentResponse consent_response); |
| 221 | 220 |
| 222 // Finds the domain-specific consent pref for the domain associated with | 221 // 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 | 222 // a pref exists for the domain, returns true and sets |pref_value| if it is |
| 224 // |pref_value| if it is not NULL. | 223 // not NULL. |
| 225 // | 224 bool GetDomainPref(HostContentSettingsMap* content_settings, |
| 226 // Precondition: A valid PrefService must be available via GetPrefs(). | 225 const GURL& url, |
| 227 bool GetDomainPref(content::WebContents* web_contents, bool* pref_value); | 226 bool* pref_value); |
| 228 | 227 |
| 229 // Records the domain-specific consent pref for the domain associated with | 228 // Records the domain-specific consent pref in |content_settings| for |url|. |
| 230 // |web_contents|. The pref will be set to |allow_domain|. | 229 // The pref will be set to |allow_domain|. |
| 231 // | 230 void RecordDomainConsent(HostContentSettingsMap* content_settings, |
| 232 // Precondition: A valid PrefService must be available via GetPrefs(). | 231 const GURL& url, |
| 233 void RecordDomainConsent(content::WebContents* web_contents, | |
| 234 bool allow_domain); | 232 bool allow_domain); |
| 235 | 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_ |
| OLD | NEW |