| 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 #include "chrome/browser/extensions/api/platform_keys/verify_trust_api.h" | 5 #include "chrome/browser/extensions/api/platform_keys/verify_trust_api.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> |
| 8 | 9 |
| 9 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/memory/linked_ptr.h" | |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "chrome/browser/extensions/api/platform_keys/platform_keys_api.h" | 13 #include "chrome/browser/extensions/api/platform_keys/platform_keys_api.h" |
| 14 #include "chrome/common/extensions/api/platform_keys_internal.h" | 14 #include "chrome/common/extensions/api/platform_keys_internal.h" |
| 15 #include "extensions/browser/extension_registry_factory.h" | 15 #include "extensions/browser/extension_registry_factory.h" |
| 16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 17 #include "net/cert/cert_verifier.h" | 17 #include "net/cert/cert_verifier.h" |
| 18 #include "net/cert/cert_verify_result.h" | 18 #include "net/cert/cert_verify_result.h" |
| 19 #include "net/cert/x509_certificate.h" | 19 #include "net/cert/x509_certificate.h" |
| 20 #include "net/log/net_log_with_source.h" | 20 #include "net/log/net_log_with_source.h" |
| 21 #include "net/ssl/ssl_config_service.h" | 21 #include "net/ssl/ssl_config_service.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 64 |
| 65 // Calls back |callback| with the result and no error. | 65 // Calls back |callback| with the result and no error. |
| 66 void CallBackWithResult(const VerifyCallback& callback, | 66 void CallBackWithResult(const VerifyCallback& callback, |
| 67 std::unique_ptr<net::CertVerifyResult> verify_result, | 67 std::unique_ptr<net::CertVerifyResult> verify_result, |
| 68 RequestState* request_state, | 68 RequestState* request_state, |
| 69 int return_value); | 69 int return_value); |
| 70 | 70 |
| 71 // One CertVerifier per extension to verify trust. Each verifier is created on | 71 // One CertVerifier per extension to verify trust. Each verifier is created on |
| 72 // first usage and deleted when this IOPart is destructed or the respective | 72 // first usage and deleted when this IOPart is destructed or the respective |
| 73 // extension is unloaded. | 73 // extension is unloaded. |
| 74 std::map<std::string, linked_ptr<net::CertVerifier>> extension_to_verifier_; | 74 std::map<std::string, std::unique_ptr<net::CertVerifier>> |
| 75 extension_to_verifier_; |
| 75 }; | 76 }; |
| 76 | 77 |
| 77 // static | 78 // static |
| 78 BrowserContextKeyedAPIFactory<VerifyTrustAPI>* | 79 BrowserContextKeyedAPIFactory<VerifyTrustAPI>* |
| 79 VerifyTrustAPI::GetFactoryInstance() { | 80 VerifyTrustAPI::GetFactoryInstance() { |
| 80 return g_factory.Pointer(); | 81 return g_factory.Pointer(); |
| 81 } | 82 } |
| 82 | 83 |
| 83 template <> | 84 template <> |
| 84 void BrowserContextKeyedAPIFactory< | 85 void BrowserContextKeyedAPIFactory< |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 reinterpret_cast<const char*>(cert_der.data()), cert_der.size())); | 171 reinterpret_cast<const char*>(cert_der.data()), cert_der.size())); |
| 171 } | 172 } |
| 172 scoped_refptr<net::X509Certificate> cert_chain( | 173 scoped_refptr<net::X509Certificate> cert_chain( |
| 173 net::X509Certificate::CreateFromDERCertChain(der_cert_chain)); | 174 net::X509Certificate::CreateFromDERCertChain(der_cert_chain)); |
| 174 if (!cert_chain) { | 175 if (!cert_chain) { |
| 175 callback.Run(platform_keys::kErrorInvalidX509Cert, 0, 0); | 176 callback.Run(platform_keys::kErrorInvalidX509Cert, 0, 0); |
| 176 return; | 177 return; |
| 177 } | 178 } |
| 178 | 179 |
| 179 if (!base::ContainsKey(extension_to_verifier_, extension_id)) { | 180 if (!base::ContainsKey(extension_to_verifier_, extension_id)) { |
| 180 extension_to_verifier_[extension_id] = | 181 extension_to_verifier_[extension_id] = net::CertVerifier::CreateDefault(); |
| 181 make_linked_ptr(net::CertVerifier::CreateDefault().release()); | |
| 182 } | 182 } |
| 183 net::CertVerifier* verifier = extension_to_verifier_[extension_id].get(); | 183 net::CertVerifier* verifier = extension_to_verifier_[extension_id].get(); |
| 184 | 184 |
| 185 std::unique_ptr<net::CertVerifyResult> verify_result( | 185 std::unique_ptr<net::CertVerifyResult> verify_result( |
| 186 new net::CertVerifyResult); | 186 new net::CertVerifyResult); |
| 187 std::unique_ptr<net::NetLogWithSource> net_log(new net::NetLogWithSource); | 187 std::unique_ptr<net::NetLogWithSource> net_log(new net::NetLogWithSource); |
| 188 const int flags = 0; | 188 const int flags = 0; |
| 189 | 189 |
| 190 std::string ocsp_response; | 190 std::string ocsp_response; |
| 191 net::CertVerifyResult* const verify_result_ptr = verify_result.get(); | 191 net::CertVerifyResult* const verify_result_ptr = verify_result.get(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 218 std::unique_ptr<net::CertVerifyResult> verify_result, | 218 std::unique_ptr<net::CertVerifyResult> verify_result, |
| 219 RequestState* request_state, | 219 RequestState* request_state, |
| 220 int return_value) { | 220 int return_value) { |
| 221 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 221 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
| 222 | 222 |
| 223 callback.Run(std::string() /* no error message */, return_value, | 223 callback.Run(std::string() /* no error message */, return_value, |
| 224 verify_result->cert_status); | 224 verify_result->cert_status); |
| 225 } | 225 } |
| 226 | 226 |
| 227 } // namespace extensions | 227 } // namespace extensions |
| OLD | NEW |