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
3 // found in the LICENSE file.
5 #include "net/ssl/client_cert_store_chromeos.h"
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/callback.h"
18 class CertNotAllowedPredicate
{
20 explicit CertNotAllowedPredicate(
21 const ClientCertStoreChromeOS::CertFilter
& filter
)
23 bool operator()(const scoped_refptr
<X509Certificate
>& cert
) const {
24 return !filter_
.IsCertAllowed(cert
);
28 const ClientCertStoreChromeOS::CertFilter
& filter_
;
33 ClientCertStoreChromeOS::ClientCertStoreChromeOS(
34 scoped_ptr
<CertFilter
> cert_filter
,
35 const PasswordDelegateFactory
& password_delegate_factory
)
36 : ClientCertStoreNSS(password_delegate_factory
),
37 cert_filter_(cert_filter
.Pass()) {
40 ClientCertStoreChromeOS::~ClientCertStoreChromeOS() {}
42 void ClientCertStoreChromeOS::GetClientCerts(
43 const SSLCertRequestInfo
& cert_request_info
,
44 CertificateList
* selected_certs
,
45 const base::Closure
& callback
) {
46 base::Closure bound_callback
=
47 base::Bind(&ClientCertStoreChromeOS::CertFilterInitialized
,
48 // Caller is responsible for keeping the ClientCertStore alive
49 // until the callback is run.
50 base::Unretained(this),
55 if (cert_filter_
->Init(bound_callback
))
59 void ClientCertStoreChromeOS::GetClientCertsImpl(
60 CERTCertList
* cert_list
,
61 const SSLCertRequestInfo
& request
,
63 CertificateList
* selected_certs
) {
64 ClientCertStoreNSS::GetClientCertsImpl(
65 cert_list
, request
, query_nssdb
, selected_certs
);
67 size_t pre_size
= selected_certs
->size();
68 selected_certs
->erase(std::remove_if(selected_certs
->begin(),
69 selected_certs
->end(),
70 CertNotAllowedPredicate(*cert_filter_
)),
71 selected_certs
->end());
72 DVLOG(1) << "filtered " << pre_size
- selected_certs
->size() << " of "
73 << pre_size
<< " certs";
76 void ClientCertStoreChromeOS::CertFilterInitialized(
77 const SSLCertRequestInfo
* request
,
78 CertificateList
* selected_certs
,
79 const base::Closure
& callback
) {
80 ClientCertStoreNSS::GetClientCerts(*request
, selected_certs
, callback
);