Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: net/ssl/client_cert_store_chromeos.cc

Issue 419013003: Replace c/b/nss_context by a KeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added cert_database namespace. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_chromeos.h" 5 #include "net/ssl/client_cert_store_chromeos.h"
6 6
7 #include <cert.h> 7 #include <cert.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h"
10 #include "crypto/nss_crypto_module_delegate.h" 11 #include "crypto/nss_crypto_module_delegate.h"
11 #include "crypto/nss_util_internal.h"
12 12
13 namespace net { 13 namespace net {
14 14
15 namespace {
16
17 typedef base::Callback<void(crypto::ScopedPK11Slot system_slot,
18 crypto::ScopedPK11Slot private_slot)>
19 GetSystemAndPrivateSlotCallback;
20
21 // Gets the private slot for the user with the username hash |username_hash| and
22 // calls |callback| with both |system_slot| and the obtained private slot.
23 void GetPrivateSlotAndCallBack(const std::string& username_hash,
24 const GetSystemAndPrivateSlotCallback& callback,
25 crypto::ScopedPK11Slot system_slot) {
26 base::Callback<void(crypto::ScopedPK11Slot)> wrapped_callback =
27 base::Bind(callback, base::Passed(&system_slot));
28
29 crypto::ScopedPK11Slot slot(
30 crypto::GetPrivateSlotForChromeOSUser(username_hash, wrapped_callback));
31 if (slot)
32 wrapped_callback.Run(slot.Pass());
33 }
34
35 // Gets the system slot, then the private slot for the user with the username
36 // hash |username_hash|, and finally calls |callback| with both slots.
37 void GetSystemAndPrivateSlot(const std::string& username_hash,
38 const GetSystemAndPrivateSlotCallback& callback) {
39 crypto::ScopedPK11Slot system_slot(crypto::GetSystemNSSKeySlot(
40 base::Bind(&GetPrivateSlotAndCallBack, username_hash, callback)));
41 if (system_slot)
42 GetPrivateSlotAndCallBack(username_hash, callback, system_slot.Pass());
43 }
44
45 } // namespace
46
47 ClientCertStoreChromeOS::ClientCertStoreChromeOS( 15 ClientCertStoreChromeOS::ClientCertStoreChromeOS(
48 bool use_system_slot, 16 scoped_ptr<NSSProfileFilterChromeOSFactory> profile_filter_factory,
49 const std::string& username_hash,
50 const PasswordDelegateFactory& password_delegate_factory) 17 const PasswordDelegateFactory& password_delegate_factory)
51 : ClientCertStoreNSS(password_delegate_factory), 18 : ClientCertStoreNSS(password_delegate_factory),
52 use_system_slot_(use_system_slot), 19 profile_filter_factory_(profile_filter_factory.Pass()) {
53 username_hash_(username_hash) {
54 } 20 }
55 21
56 ClientCertStoreChromeOS::~ClientCertStoreChromeOS() {} 22 ClientCertStoreChromeOS::~ClientCertStoreChromeOS() {}
57 23
58 void ClientCertStoreChromeOS::GetClientCerts( 24 void ClientCertStoreChromeOS::GetClientCerts(
59 const SSLCertRequestInfo& cert_request_info, 25 const SSLCertRequestInfo& cert_request_info,
60 CertificateList* selected_certs, 26 CertificateList* selected_certs,
61 const base::Closure& callback) { 27 const base::Closure& callback) {
62 GetSystemAndPrivateSlotCallback bound_callback = 28 base::Callback<void(const NSSProfileFilterChromeOS&)> bound_callback =
63 base::Bind(&ClientCertStoreChromeOS::DidGetSystemAndPrivateSlot, 29 base::Bind(&ClientCertStoreChromeOS::DidGetProfileFilter,
64 // Caller is responsible for keeping the ClientCertStore alive 30 // Caller is responsible for keeping the ClientCertStore alive
65 // until the callback is run. 31 // until the callback is run.
66 base::Unretained(this), 32 base::Unretained(this),
67 &cert_request_info, 33 &cert_request_info,
68 selected_certs, 34 selected_certs,
69 callback); 35 callback);
70 36
71 if (use_system_slot_) { 37 scoped_ptr<NSSProfileFilterChromeOS> filter(
72 GetSystemAndPrivateSlot(username_hash_, bound_callback); 38 profile_filter_factory_->CreateFilter(bound_callback));
73 } else { 39 if (filter)
74 // Skip getting the system slot. 40 bound_callback.Run(*filter);
75 GetPrivateSlotAndCallBack(
76 username_hash_, bound_callback, crypto::ScopedPK11Slot());
77 }
78 } 41 }
79 42
80 void ClientCertStoreChromeOS::GetClientCertsImpl( 43 void ClientCertStoreChromeOS::GetClientCertsImpl(
81 CERTCertList* cert_list, 44 CERTCertList* cert_list,
82 const SSLCertRequestInfo& request, 45 const SSLCertRequestInfo& request,
83 bool query_nssdb, 46 bool query_nssdb,
84 CertificateList* selected_certs) { 47 CertificateList* selected_certs) {
85 ClientCertStoreNSS::GetClientCertsImpl( 48 ClientCertStoreNSS::GetClientCertsImpl(
86 cert_list, request, query_nssdb, selected_certs); 49 cert_list, request, query_nssdb, selected_certs);
87 50
88 size_t pre_size = selected_certs->size(); 51 size_t pre_size = selected_certs->size();
89 selected_certs->erase( 52 selected_certs->erase(
90 std::remove_if( 53 std::remove_if(
91 selected_certs->begin(), 54 selected_certs->begin(),
92 selected_certs->end(), 55 selected_certs->end(),
93 NSSProfileFilterChromeOS::CertNotAllowedForProfilePredicate( 56 NSSProfileFilterChromeOS::CertNotAllowedForProfilePredicate(
94 profile_filter_)), 57 profile_filter_)),
95 selected_certs->end()); 58 selected_certs->end());
96 DVLOG(1) << "filtered " << pre_size - selected_certs->size() << " of " 59 DVLOG(1) << "filtered " << pre_size - selected_certs->size() << " of "
97 << pre_size << " certs"; 60 << pre_size << " certs";
98 } 61 }
99 62
100 void ClientCertStoreChromeOS::DidGetSystemAndPrivateSlot( 63 void ClientCertStoreChromeOS::DidGetProfileFilter(
101 const SSLCertRequestInfo* request, 64 const SSLCertRequestInfo* request,
102 CertificateList* selected_certs, 65 CertificateList* selected_certs,
103 const base::Closure& callback, 66 const base::Closure& callback,
104 crypto::ScopedPK11Slot system_slot, 67 const NSSProfileFilterChromeOS& profile_filter) {
105 crypto::ScopedPK11Slot private_slot) { 68 profile_filter_ = profile_filter;
106 profile_filter_.Init(crypto::GetPublicSlotForChromeOSUser(username_hash_),
107 private_slot.Pass(),
108 system_slot.Pass());
109 ClientCertStoreNSS::GetClientCerts(*request, selected_certs, callback); 69 ClientCertStoreNSS::GetClientCerts(*request, selected_certs, callback);
110 } 70 }
111 71
112 } // namespace net 72 } // namespace net
OLDNEW
« net/ssl/client_cert_store_chromeos.h ('K') | « net/ssl/client_cert_store_chromeos.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698