| 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 <string> | 12 #include <string> |
| 12 #include <vector> | 13 #include <vector> |
| 13 | 14 |
| 14 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 17 #include "base/memory/scoped_ptr.h" | |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
| 20 #include "chrome/browser/chromeos/certificate_provider/certificate_info.h" | 20 #include "chrome/browser/chromeos/certificate_provider/certificate_info.h" |
| 21 #include "chrome/browser/chromeos/certificate_provider/certificate_requests.h" | 21 #include "chrome/browser/chromeos/certificate_provider/certificate_requests.h" |
| 22 #include "chrome/browser/chromeos/certificate_provider/sign_requests.h" | 22 #include "chrome/browser/chromeos/certificate_provider/sign_requests.h" |
| 23 #include "chrome/browser/chromeos/certificate_provider/thread_safe_certificate_m
ap.h" | 23 #include "chrome/browser/chromeos/certificate_provider/thread_safe_certificate_m
ap.h" |
| 24 #include "components/keyed_service/core/keyed_service.h" | 24 #include "components/keyed_service/core/keyed_service.h" |
| 25 #include "net/cert/x509_certificate.h" | 25 #include "net/cert/x509_certificate.h" |
| 26 #include "net/ssl/ssl_private_key.h" | 26 #include "net/ssl/ssl_private_key.h" |
| 27 | 27 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 // |SetDelegate| must be called exactly once directly after construction. | 94 // |SetDelegate| must be called exactly once directly after construction. |
| 95 CertificateProviderService(); | 95 CertificateProviderService(); |
| 96 ~CertificateProviderService() override; | 96 ~CertificateProviderService() override; |
| 97 | 97 |
| 98 // Must be called exactly once after construction and before other methods are | 98 // Must be called exactly once after construction and before other methods are |
| 99 // called. The delegate will be destroyed in the destructor of the service and | 99 // called. The delegate will be destroyed in the destructor of the service and |
| 100 // not before, which allows to unregister observers (e.g. for | 100 // not before, which allows to unregister observers (e.g. for |
| 101 // OnExtensionUnloaded) in the delegate's destructor on behalf of the service. | 101 // OnExtensionUnloaded) in the delegate's destructor on behalf of the service. |
| 102 void SetDelegate(scoped_ptr<Delegate> delegate); | 102 void SetDelegate(std::unique_ptr<Delegate> delegate); |
| 103 | 103 |
| 104 // Must be called with the reply of an extension to a previous certificate | 104 // Must be called with the reply of an extension to a previous certificate |
| 105 // request. For each request, it is expected that every registered extension | 105 // request. For each request, it is expected that every registered extension |
| 106 // replies exactly once with the latest list of certificates. | 106 // replies exactly once with the latest list of certificates. |
| 107 // |cert_request_id| must refer to a previously broadcast certificate request. | 107 // |cert_request_id| must refer to a previously broadcast certificate request. |
| 108 // Returns false and ignores the call if the request id is unknown or it was | 108 // Returns false and ignores the call if the request id is unknown or it was |
| 109 // called before with the same combination of request id and extension id. | 109 // called before with the same combination of request id and extension id. |
| 110 // E.g. the request could have timed out before an extension replies. | 110 // E.g. the request could have timed out before an extension replies. |
| 111 bool SetCertificatesProvidedByExtension( | 111 bool SetCertificatesProvidedByExtension( |
| 112 const std::string& extension_id, | 112 const std::string& extension_id, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 136 bool LookUpCertificate(const net::X509Certificate& cert, | 136 bool LookUpCertificate(const net::X509Certificate& cert, |
| 137 bool* is_currently_provided, | 137 bool* is_currently_provided, |
| 138 std::string* extension_id); | 138 std::string* extension_id); |
| 139 | 139 |
| 140 // Returns a CertificateProvider that always returns the latest list of | 140 // Returns a CertificateProvider that always returns the latest list of |
| 141 // certificates that are provided by all registered extensions. Therefore, it | 141 // certificates that are provided by all registered extensions. Therefore, it |
| 142 // is sufficient to create the CertificateProvider once and then repeatedly | 142 // is sufficient to create the CertificateProvider once and then repeatedly |
| 143 // call its |GetCertificates()|. The returned provider is valid even after the | 143 // call its |GetCertificates()|. The returned provider is valid even after the |
| 144 // destruction of this service. | 144 // destruction of this service. |
| 145 // The returned provider can be used on any thread. | 145 // The returned provider can be used on any thread. |
| 146 scoped_ptr<CertificateProvider> CreateCertificateProvider(); | 146 std::unique_ptr<CertificateProvider> CreateCertificateProvider(); |
| 147 | 147 |
| 148 // Must be called if extension with id |extension_id| is unloaded and cannot | 148 // Must be called if extension with id |extension_id| is unloaded and cannot |
| 149 // serve certificates anymore. This should be called everytime the | 149 // serve certificates anymore. This should be called everytime the |
| 150 // corresponding notification of the ExtensionRegistry is triggered. | 150 // corresponding notification of the ExtensionRegistry is triggered. |
| 151 void OnExtensionUnloaded(const std::string& extension_id); | 151 void OnExtensionUnloaded(const std::string& extension_id); |
| 152 | 152 |
| 153 private: | 153 private: |
| 154 class CertKeyProviderImpl; | 154 class CertKeyProviderImpl; |
| 155 class CertificateProviderImpl; | 155 class CertificateProviderImpl; |
| 156 class SSLPrivateKey; | 156 class SSLPrivateKey; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 178 // Requests extension with |extension_id| to sign |digest| with the private | 178 // Requests extension with |extension_id| to sign |digest| with the private |
| 179 // key certified by |certificate|. |hash| was used to create |digest|. | 179 // key certified by |certificate|. |hash| was used to create |digest|. |
| 180 // |callback| will be run with the reply of the extension or an error. | 180 // |callback| will be run with the reply of the extension or an error. |
| 181 void RequestSignatureFromExtension( | 181 void RequestSignatureFromExtension( |
| 182 const std::string& extension_id, | 182 const std::string& extension_id, |
| 183 const scoped_refptr<net::X509Certificate>& certificate, | 183 const scoped_refptr<net::X509Certificate>& certificate, |
| 184 net::SSLPrivateKey::Hash hash, | 184 net::SSLPrivateKey::Hash hash, |
| 185 const std::string& digest, | 185 const std::string& digest, |
| 186 const net::SSLPrivateKey::SignCallback& callback); | 186 const net::SSLPrivateKey::SignCallback& callback); |
| 187 | 187 |
| 188 scoped_ptr<Delegate> delegate_; | 188 std::unique_ptr<Delegate> delegate_; |
| 189 | 189 |
| 190 // An instance of net::ClientKeyStore::CertKeyProvider that is registered at | 190 // An instance of net::ClientKeyStore::CertKeyProvider that is registered at |
| 191 // the net::ClientKeyStore singleton. | 191 // the net::ClientKeyStore singleton. |
| 192 scoped_ptr<CertKeyProviderImpl> cert_key_provider_; | 192 std::unique_ptr<CertKeyProviderImpl> cert_key_provider_; |
| 193 | 193 |
| 194 // State about all pending sign requests. | 194 // State about all pending sign requests. |
| 195 certificate_provider::SignRequests sign_requests_; | 195 certificate_provider::SignRequests sign_requests_; |
| 196 | 196 |
| 197 // Contains all pending certificate requests. | 197 // Contains all pending certificate requests. |
| 198 certificate_provider::CertificateRequests certificate_requests_; | 198 certificate_provider::CertificateRequests certificate_requests_; |
| 199 | 199 |
| 200 // Contains all certificates that the extensions returned during the lifetime | 200 // Contains all certificates that the extensions returned during the lifetime |
| 201 // of this service. Each certificate is associated with the extension that | 201 // of this service. Each certificate is associated with the extension that |
| 202 // reported the certificate in response to the most recent certificate | 202 // reported the certificate in response to the most recent certificate |
| 203 // request. If a certificate was reported previously but in the most recent | 203 // 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 | 204 // 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 | 205 // extension. This ensures that a certificate can't magically appear as |
| 206 // platform certificate (e.g. in the client certificate selection dialog) | 206 // platform certificate (e.g. in the client certificate selection dialog) |
| 207 // after an extension doesn't report it anymore. | 207 // after an extension doesn't report it anymore. |
| 208 certificate_provider::ThreadSafeCertificateMap certificate_map_; | 208 certificate_provider::ThreadSafeCertificateMap certificate_map_; |
| 209 | 209 |
| 210 base::ThreadChecker thread_checker_; | 210 base::ThreadChecker thread_checker_; |
| 211 base::WeakPtrFactory<CertificateProviderService> weak_factory_; | 211 base::WeakPtrFactory<CertificateProviderService> weak_factory_; |
| 212 | 212 |
| 213 DISALLOW_COPY_AND_ASSIGN(CertificateProviderService); | 213 DISALLOW_COPY_AND_ASSIGN(CertificateProviderService); |
| 214 }; | 214 }; |
| 215 | 215 |
| 216 } // namespace chromeos | 216 } // namespace chromeos |
| 217 | 217 |
| 218 #endif // CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_CERTIFICATE_PROVIDER_SER
VICE_H_ | 218 #endif // CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_CERTIFICATE_PROVIDER_SER
VICE_H_ |
| OLD | NEW |