| 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 #include "net/ssl/client_cert_store_nss.h" | 5 #include "net/ssl/client_cert_store_nss.h" |
| 6 | 6 |
| 7 #include <nss.h> | 7 #include <nss.h> |
| 8 #include <ssl.h> | 8 #include <ssl.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <memory> |
| 11 #include <utility> | 12 #include <utility> |
| 12 | 13 |
| 13 #include "base/bind.h" | 14 #include "base/bind.h" |
| 14 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
| 15 #include "base/location.h" | 16 #include "base/location.h" |
| 16 #include "base/logging.h" | 17 #include "base/logging.h" |
| 17 #include "base/memory/scoped_ptr.h" | |
| 18 #include "base/strings/string_piece.h" | 18 #include "base/strings/string_piece.h" |
| 19 #include "base/threading/worker_pool.h" | 19 #include "base/threading/worker_pool.h" |
| 20 #include "crypto/nss_crypto_module_delegate.h" | 20 #include "crypto/nss_crypto_module_delegate.h" |
| 21 #include "net/cert/x509_util.h" | 21 #include "net/cert/x509_util.h" |
| 22 #include "net/ssl/ssl_cert_request_info.h" | 22 #include "net/ssl/ssl_cert_request_info.h" |
| 23 | 23 |
| 24 namespace net { | 24 namespace net { |
| 25 | 25 |
| 26 ClientCertStoreNSS::ClientCertStoreNSS( | 26 ClientCertStoreNSS::ClientCertStoreNSS( |
| 27 const PasswordDelegateFactory& password_delegate_factory) | 27 const PasswordDelegateFactory& password_delegate_factory) |
| 28 : password_delegate_factory_(password_delegate_factory) {} | 28 : password_delegate_factory_(password_delegate_factory) {} |
| 29 | 29 |
| 30 ClientCertStoreNSS::~ClientCertStoreNSS() {} | 30 ClientCertStoreNSS::~ClientCertStoreNSS() {} |
| 31 | 31 |
| 32 void ClientCertStoreNSS::GetClientCerts(const SSLCertRequestInfo& request, | 32 void ClientCertStoreNSS::GetClientCerts(const SSLCertRequestInfo& request, |
| 33 CertificateList* selected_certs, | 33 CertificateList* selected_certs, |
| 34 const base::Closure& callback) { | 34 const base::Closure& callback) { |
| 35 scoped_ptr<crypto::CryptoModuleBlockingPasswordDelegate> password_delegate; | 35 std::unique_ptr<crypto::CryptoModuleBlockingPasswordDelegate> |
| 36 password_delegate; |
| 36 if (!password_delegate_factory_.is_null()) { | 37 if (!password_delegate_factory_.is_null()) { |
| 37 password_delegate.reset( | 38 password_delegate.reset( |
| 38 password_delegate_factory_.Run(request.host_and_port)); | 39 password_delegate_factory_.Run(request.host_and_port)); |
| 39 } | 40 } |
| 40 if (base::WorkerPool::PostTaskAndReply( | 41 if (base::WorkerPool::PostTaskAndReply( |
| 41 FROM_HERE, | 42 FROM_HERE, |
| 42 base::Bind(&ClientCertStoreNSS::GetAndFilterCertsOnWorkerThread, | 43 base::Bind(&ClientCertStoreNSS::GetAndFilterCertsOnWorkerThread, |
| 43 // Caller is responsible for keeping the ClientCertStore | 44 // Caller is responsible for keeping the ClientCertStore |
| 44 // alive until the callback is run. | 45 // alive until the callback is run. |
| 45 base::Unretained(this), base::Passed(&password_delegate), | 46 base::Unretained(this), base::Passed(&password_delegate), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 filtered_certs->push_back(cert); | 108 filtered_certs->push_back(cert); |
| 108 } | 109 } |
| 109 DVLOG(2) << "num_raw:" << num_raw | 110 DVLOG(2) << "num_raw:" << num_raw |
| 110 << " num_filtered:" << filtered_certs->size(); | 111 << " num_filtered:" << filtered_certs->size(); |
| 111 | 112 |
| 112 std::sort(filtered_certs->begin(), filtered_certs->end(), | 113 std::sort(filtered_certs->begin(), filtered_certs->end(), |
| 113 x509_util::ClientCertSorter()); | 114 x509_util::ClientCertSorter()); |
| 114 } | 115 } |
| 115 | 116 |
| 116 void ClientCertStoreNSS::GetAndFilterCertsOnWorkerThread( | 117 void ClientCertStoreNSS::GetAndFilterCertsOnWorkerThread( |
| 117 scoped_ptr<crypto::CryptoModuleBlockingPasswordDelegate> password_delegate, | 118 std::unique_ptr<crypto::CryptoModuleBlockingPasswordDelegate> |
| 119 password_delegate, |
| 118 const SSLCertRequestInfo* request, | 120 const SSLCertRequestInfo* request, |
| 119 CertificateList* selected_certs) { | 121 CertificateList* selected_certs) { |
| 120 CertificateList platform_certs; | 122 CertificateList platform_certs; |
| 121 GetPlatformCertsOnWorkerThread(std::move(password_delegate), &platform_certs); | 123 GetPlatformCertsOnWorkerThread(std::move(password_delegate), &platform_certs); |
| 122 FilterCertsOnWorkerThread(platform_certs, *request, selected_certs); | 124 FilterCertsOnWorkerThread(platform_certs, *request, selected_certs); |
| 123 } | 125 } |
| 124 | 126 |
| 125 // static | 127 // static |
| 126 void ClientCertStoreNSS::GetPlatformCertsOnWorkerThread( | 128 void ClientCertStoreNSS::GetPlatformCertsOnWorkerThread( |
| 127 scoped_ptr<crypto::CryptoModuleBlockingPasswordDelegate> password_delegate, | 129 std::unique_ptr<crypto::CryptoModuleBlockingPasswordDelegate> |
| 130 password_delegate, |
| 128 net::CertificateList* certs) { | 131 net::CertificateList* certs) { |
| 129 CERTCertList* found_certs = | 132 CERTCertList* found_certs = |
| 130 CERT_FindUserCertsByUsage(CERT_GetDefaultCertDB(), certUsageSSLClient, | 133 CERT_FindUserCertsByUsage(CERT_GetDefaultCertDB(), certUsageSSLClient, |
| 131 PR_FALSE, PR_FALSE, password_delegate.get()); | 134 PR_FALSE, PR_FALSE, password_delegate.get()); |
| 132 if (!found_certs) { | 135 if (!found_certs) { |
| 133 DVLOG(2) << "No client certs found."; | 136 DVLOG(2) << "No client certs found."; |
| 134 return; | 137 return; |
| 135 } | 138 } |
| 136 for (CERTCertListNode* node = CERT_LIST_HEAD(found_certs); | 139 for (CERTCertListNode* node = CERT_LIST_HEAD(found_certs); |
| 137 !CERT_LIST_END(node, found_certs); node = CERT_LIST_NEXT(node)) { | 140 !CERT_LIST_END(node, found_certs); node = CERT_LIST_NEXT(node)) { |
| 138 certs->push_back(X509Certificate::CreateFromHandle( | 141 certs->push_back(X509Certificate::CreateFromHandle( |
| 139 node->cert, X509Certificate::OSCertHandles())); | 142 node->cert, X509Certificate::OSCertHandles())); |
| 140 } | 143 } |
| 141 CERT_DestroyCertList(found_certs); | 144 CERT_DestroyCertList(found_certs); |
| 142 } | 145 } |
| 143 | 146 |
| 144 } // namespace net | 147 } // namespace net |
| OLD | NEW |