Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_CERTIFICATE_PROVIDER_CERTIFICATE_PROVIDER_SERVIC E_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_CERTIFICATE_PROVIDER_SERVIC E_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_CERTIFICATE_PROVIDER_SERVIC E_H_ | 6 #define CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_CERTIFICATE_PROVIDER_SERVIC E_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/callback.h" | |
| 15 #include "base/callback_forward.h" | 16 #include "base/callback_forward.h" |
| 16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 17 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
| 19 #include "base/threading/thread_checker.h" | 20 #include "base/threading/thread_checker.h" |
| 20 #include "chrome/browser/chromeos/certificate_provider/certificate_info.h" | 21 #include "chrome/browser/chromeos/certificate_provider/certificate_info.h" |
| 21 #include "chrome/browser/chromeos/certificate_provider/certificate_requests.h" | 22 #include "chrome/browser/chromeos/certificate_provider/certificate_requests.h" |
| 22 #include "chrome/browser/chromeos/certificate_provider/sign_requests.h" | 23 #include "chrome/browser/chromeos/certificate_provider/sign_requests.h" |
| 23 #include "chrome/browser/chromeos/certificate_provider/thread_safe_certificate_m ap.h" | 24 #include "chrome/browser/chromeos/certificate_provider/thread_safe_certificate_m ap.h" |
| 25 #include "chrome/browser/chromeos/ui/request_pin_view.h" | |
| 24 #include "components/keyed_service/core/keyed_service.h" | 26 #include "components/keyed_service/core/keyed_service.h" |
| 25 #include "net/cert/x509_certificate.h" | 27 #include "net/cert/x509_certificate.h" |
| 26 #include "net/ssl/ssl_private_key.h" | 28 #include "net/ssl/ssl_private_key.h" |
| 27 | 29 |
| 28 namespace chromeos { | 30 namespace chromeos { |
| 29 | 31 |
| 30 class CertificateProvider; | 32 class CertificateProvider; |
| 31 | 33 |
| 34 enum RequestPinResponse { SUCCESS, INVALID_ID, OTHER_FLOW_IN_PROGRESS }; | |
| 35 | |
| 32 // A keyed service that manages registrations of extensions as certificate | 36 // A keyed service that manages registrations of extensions as certificate |
| 33 // providers. It exposes all certificates that are provided by extensions | 37 // providers. It exposes all certificates that are provided by extensions |
| 34 // through a |CertificateProvider| object that can be created using | 38 // through a |CertificateProvider| object that can be created using |
| 35 // |CreateCertificateProvider()|. Private key handles are exposed through | 39 // |CreateCertificateProvider()|. Private key handles are exposed through |
| 36 // net::ClientKeyStore. Sign operations are routed to the extension that exposed | 40 // net::ClientKeyStore. Sign operations are routed to the extension that exposed |
| 37 // the certificate. | 41 // the certificate. |
| 38 // | 42 // |
| 39 // The typical order of execution is as follows: | 43 // The typical order of execution is as follows: |
| 40 // 1. HTTPS server requests client certs or | 44 // 1. HTTPS server requests client certs or |
| 41 // chrome.platformKeys.selectClientCertificates is called. | 45 // chrome.platformKeys.selectClientCertificates is called. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 // call its |GetCertificates()|. The returned provider is valid even after the | 147 // call its |GetCertificates()|. The returned provider is valid even after the |
| 144 // destruction of this service. | 148 // destruction of this service. |
| 145 // The returned provider can be used on any thread. | 149 // The returned provider can be used on any thread. |
| 146 std::unique_ptr<CertificateProvider> CreateCertificateProvider(); | 150 std::unique_ptr<CertificateProvider> CreateCertificateProvider(); |
| 147 | 151 |
| 148 // Must be called if extension with id |extension_id| is unloaded and cannot | 152 // Must be called if extension with id |extension_id| is unloaded and cannot |
| 149 // serve certificates anymore. This should be called everytime the | 153 // serve certificates anymore. This should be called everytime the |
| 150 // corresponding notification of the ExtensionRegistry is triggered. | 154 // corresponding notification of the ExtensionRegistry is triggered. |
| 151 void OnExtensionUnloaded(const std::string& extension_id); | 155 void OnExtensionUnloaded(const std::string& extension_id); |
| 152 | 156 |
| 157 // The user provided input to dialog. |closed| tells whether the dialog was | |
| 158 // closed by the user without providing any input. | |
| 159 void OnPinDialogInput(const std::string& extension_id, const bool closed); | |
| 160 | |
| 161 // This callback function is called by the view when user closes the PIN | |
| 162 // dialog while the last input is still processing at extension side. |value| | |
| 163 // is not used, but checked that it's empty. | |
| 164 void OnFlowInterrupted(const base::string16& value); | |
| 165 | |
| 166 // Returns whether the last PIN dialog from this extension was closed by the | |
| 167 // user. | |
| 168 bool LastPinDialogClosed(const std::string& extension_id); | |
| 169 | |
| 170 // Updates the existing dialog with new error message. Uses callback with | |
| 171 // empty string when user closes the dialog. Returns whether the provided | |
| 172 // extension_id matches the extension owning the active dialog. | |
| 173 bool UpdatePinDialog(const std::string& extension_id, | |
| 174 const base::string16& error_message, | |
| 175 const bool accept_input, | |
| 176 const RequestPinView::RequestPinCallback& callback); | |
| 177 | |
| 178 // Creates a new RequestPinView object and displays it in a dialog or reuses | |
| 179 // the old dialog if active one exists just updating the parameters. Returns | |
| 180 // SUCCESS if the dialog is displayed and extension owns it. Otherwise the | |
| 181 // the specific error is returned. | |
|
stevenjb
2016/08/09 21:04:39
Describe each of the input parameters, many are un
igorcov1
2016/08/10 18:05:03
Done.
| |
| 182 RequestPinResponse ShowPinDialog( | |
| 183 const std::string& extension_id, | |
| 184 const std::string& extension_name, | |
| 185 const long long sign_request_id, | |
| 186 const std::string& dialog_type, | |
| 187 const base::string16& error_message, | |
| 188 const bool accept_input, | |
| 189 const RequestPinView::RequestPinCallback& callback); | |
| 190 | |
| 191 // This function is called when extension calls the stopPinRequest method. | |
| 192 // The active dialog is closed if the |extension_id| matches the | |
| 193 // |active_dialog_extension_id_|. Returns whether the dialog was closed. | |
| 194 bool CloseDialog(const std::string& extension_id); | |
| 195 | |
| 196 // Stores internally the |signRequestId| along with current timestamp. Also | |
| 197 // cleans up the storage from expired IDs. In unlikely case that the ID | |
| 198 // exists in the storage, returns false. Otherwise returns true. | |
| 199 bool AddSignRequestId(const uint64_t signRequestId); | |
| 200 | |
| 201 RequestPinView* active_view_for_testing() { return active_pin_dialog_; } | |
| 202 views::Widget* active_window_for_testing() { return active_window_; } | |
|
stevenjb
2016/08/09 21:04:39
This is a lot of UI specific code added to a class
igorcov1
2016/08/10 18:05:03
Created the PinDialogManager class to manage the d
| |
| 203 | |
| 153 private: | 204 private: |
| 154 class CertKeyProviderImpl; | 205 class CertKeyProviderImpl; |
| 155 class CertificateProviderImpl; | 206 class CertificateProviderImpl; |
| 156 class SSLPrivateKey; | 207 class SSLPrivateKey; |
| 157 | 208 |
| 158 // Requests the current list of certificates from every registered extension. | 209 // Requests the current list of certificates from every registered extension. |
| 159 // Once all extensions replied or a timeout was reached, the internal | 210 // Once all extensions replied or a timeout was reached, the internal |
| 160 // |extension_to_certificates_| is updated and |callback| is run with the | 211 // |extension_to_certificates_| is updated and |callback| is run with the |
| 161 // retrieved list of certificates. | 212 // retrieved list of certificates. |
| 162 void GetCertificatesFromExtensions( | 213 void GetCertificatesFromExtensions( |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 178 // Requests extension with |extension_id| to sign |digest| with the private | 229 // Requests extension with |extension_id| to sign |digest| with the private |
| 179 // key certified by |certificate|. |hash| was used to create |digest|. | 230 // key certified by |certificate|. |hash| was used to create |digest|. |
| 180 // |callback| will be run with the reply of the extension or an error. | 231 // |callback| will be run with the reply of the extension or an error. |
| 181 void RequestSignatureFromExtension( | 232 void RequestSignatureFromExtension( |
| 182 const std::string& extension_id, | 233 const std::string& extension_id, |
| 183 const scoped_refptr<net::X509Certificate>& certificate, | 234 const scoped_refptr<net::X509Certificate>& certificate, |
| 184 net::SSLPrivateKey::Hash hash, | 235 net::SSLPrivateKey::Hash hash, |
| 185 const std::string& digest, | 236 const std::string& digest, |
| 186 const net::SSLPrivateKey::SignCallback& callback); | 237 const net::SSLPrivateKey::SignCallback& callback); |
| 187 | 238 |
| 239 // Cleans the map of sign request ids, removing the ones that have expired. | |
| 240 void RemoveExpiredSignRequests(timeval* tv); | |
| 241 | |
| 188 std::unique_ptr<Delegate> delegate_; | 242 std::unique_ptr<Delegate> delegate_; |
| 189 | 243 |
| 190 // An instance of net::ClientKeyStore::CertKeyProvider that is registered at | 244 // An instance of net::ClientKeyStore::CertKeyProvider that is registered at |
| 191 // the net::ClientKeyStore singleton. | 245 // the net::ClientKeyStore singleton. |
| 192 std::unique_ptr<CertKeyProviderImpl> cert_key_provider_; | 246 std::unique_ptr<CertKeyProviderImpl> cert_key_provider_; |
| 193 | 247 |
| 194 // State about all pending sign requests. | 248 // State about all pending sign requests. |
| 195 certificate_provider::SignRequests sign_requests_; | 249 certificate_provider::SignRequests sign_requests_; |
| 196 | 250 |
| 197 // Contains all pending certificate requests. | 251 // Contains all pending certificate requests. |
| 198 certificate_provider::CertificateRequests certificate_requests_; | 252 certificate_provider::CertificateRequests certificate_requests_; |
| 199 | 253 |
| 254 // State about the last response from user to the requestPin from extension. | |
| 255 std::map<std::string, bool> last_rejected_; | |
| 256 | |
| 257 // The map with sign request ids issued by Chrome as key and the time when the | |
| 258 // id was generated as value. | |
| 259 std::map<uint64_t, uint64_t> sign_request_ids_; | |
| 260 | |
| 261 // There can be only one active dialog to request PIN from this extension. | |
| 262 // Keeps the ownership. | |
| 263 chromeos::RequestPinView* active_pin_dialog_ = nullptr; | |
| 264 std::string active_dialog_extension_id_; | |
| 265 views::Widget* active_window_ = nullptr; | |
| 266 | |
| 200 // Contains all certificates that the extensions returned during the lifetime | 267 // Contains all certificates that the extensions returned during the lifetime |
| 201 // of this service. Each certificate is associated with the extension that | 268 // of this service. Each certificate is associated with the extension that |
| 202 // reported the certificate in response to the most recent certificate | 269 // reported the certificate in response to the most recent certificate |
| 203 // request. If a certificate was reported previously but in the most recent | 270 // request. If a certificate was reported previously but in the most recent |
| 204 // responses, it is still cached but not loses it's association with any | 271 // responses, it is still cached but not loses it's association with any |
| 205 // extension. This ensures that a certificate can't magically appear as | 272 // extension. This ensures that a certificate can't magically appear as |
| 206 // platform certificate (e.g. in the client certificate selection dialog) | 273 // platform certificate (e.g. in the client certificate selection dialog) |
| 207 // after an extension doesn't report it anymore. | 274 // after an extension doesn't report it anymore. |
| 208 certificate_provider::ThreadSafeCertificateMap certificate_map_; | 275 certificate_provider::ThreadSafeCertificateMap certificate_map_; |
| 209 | 276 |
| 210 base::ThreadChecker thread_checker_; | 277 base::ThreadChecker thread_checker_; |
| 211 base::WeakPtrFactory<CertificateProviderService> weak_factory_; | 278 base::WeakPtrFactory<CertificateProviderService> weak_factory_; |
| 212 | 279 |
| 213 DISALLOW_COPY_AND_ASSIGN(CertificateProviderService); | 280 DISALLOW_COPY_AND_ASSIGN(CertificateProviderService); |
| 214 }; | 281 }; |
| 215 | 282 |
| 216 } // namespace chromeos | 283 } // namespace chromeos |
| 217 | 284 |
| 218 #endif // CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_CERTIFICATE_PROVIDER_SER VICE_H_ | 285 #endif // CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_CERTIFICATE_PROVIDER_SER VICE_H_ |
| OLD | NEW |