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

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

Issue 18121007: *WIP* Store NSS slots per profile. Move keygen to chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cert manager basics working Created 7 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
« no previous file with comments | « net/ssl/client_cert_store_impl_mac.cc ('k') | net/ssl/client_cert_store_impl_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_impl.h" 5 #include "net/ssl/client_cert_store_impl.h"
6 6
7 #include <nss.h> 7 #include <nss.h>
8 #include <ssl.h> 8 #include <ssl.h>
9 9
10 #include "base/callback.h"
10 #include "base/logging.h" 11 #include "base/logging.h"
11 #include "net/cert/x509_util.h" 12 #include "net/cert/x509_util.h"
12 13
13 namespace net { 14 namespace net {
14 15
15 namespace { 16 namespace {
16 17
17 // Examines the certificates in |cert_list| to find all certificates that match 18 // Examines the certificates in |cert_list| to find all certificates that match
18 // the client certificate request in |request|, storing the matching 19 // the client certificate request in |request|, storing the matching
19 // certificates in |selected_certs|. 20 // certificates in |selected_certs|.
(...skipping 21 matching lines...) Expand all
41 const std::string& authority = request.cert_authorities[i]; 42 const std::string& authority = request.cert_authorities[i];
42 ca_names_items[i].type = siBuffer; 43 ca_names_items[i].type = siBuffer;
43 ca_names_items[i].data = 44 ca_names_items[i].data =
44 reinterpret_cast<unsigned char*>(const_cast<char*>(authority.data())); 45 reinterpret_cast<unsigned char*>(const_cast<char*>(authority.data()));
45 ca_names_items[i].len = static_cast<unsigned int>(authority.size()); 46 ca_names_items[i].len = static_cast<unsigned int>(authority.size());
46 } 47 }
47 ca_names.nnames = static_cast<int>(ca_names_items.size()); 48 ca_names.nnames = static_cast<int>(ca_names_items.size());
48 if (!ca_names_items.empty()) 49 if (!ca_names_items.empty())
49 ca_names.names = &ca_names_items[0]; 50 ca_names.names = &ca_names_items[0];
50 51
52 size_t num_raw = 0;
51 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list); 53 for (CERTCertListNode* node = CERT_LIST_HEAD(cert_list);
52 !CERT_LIST_END(node, cert_list); 54 !CERT_LIST_END(node, cert_list);
53 node = CERT_LIST_NEXT(node)) { 55 node = CERT_LIST_NEXT(node)) {
56 ++num_raw;
54 // Only offer unexpired certificates. 57 // Only offer unexpired certificates.
55 if (CERT_CheckCertValidTimes(node->cert, PR_Now(), PR_TRUE) != 58 if (CERT_CheckCertValidTimes(node->cert, PR_Now(), PR_TRUE) !=
56 secCertTimeValid) { 59 secCertTimeValid) {
60 LOG(WARNING) << " skipped an expired cert";
57 continue; 61 continue;
58 } 62 }
59 63
60 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle( 64 scoped_refptr<X509Certificate> cert = X509Certificate::CreateFromHandle(
61 node->cert, X509Certificate::OSCertHandles()); 65 node->cert, X509Certificate::OSCertHandles());
62 66
63 // Check if the certificate issuer is allowed by the server. 67 // Check if the certificate issuer is allowed by the server.
64 if (request.cert_authorities.empty() || 68 if (request.cert_authorities.empty() ||
65 (!query_nssdb && 69 (!query_nssdb &&
66 cert->IsIssuedByEncoded(request.cert_authorities)) || 70 cert->IsIssuedByEncoded(request.cert_authorities)) ||
67 (query_nssdb && 71 (query_nssdb &&
68 NSS_CmpCertChainWCANames(node->cert, &ca_names) == SECSuccess)) { 72 NSS_CmpCertChainWCANames(node->cert, &ca_names) == SECSuccess)) {
73 LOG(WARNING) << " selected a cert";
69 selected_certs->push_back(cert); 74 selected_certs->push_back(cert);
70 } 75 }
76 else
77 LOG(WARNING) << " skipped a cert";
71 } 78 }
79 LOG(WARNING) << "num_raw:" << num_raw << " res:"<<selected_certs->size();
72 80
73 std::sort(selected_certs->begin(), selected_certs->end(), 81 std::sort(selected_certs->begin(), selected_certs->end(),
74 x509_util::ClientCertSorter()); 82 x509_util::ClientCertSorter());
75 return true; 83 return true;
76 } 84 }
77 85
78 } // namespace 86 } // namespace
79 87
80 bool ClientCertStoreImpl::GetClientCerts(const SSLCertRequestInfo& request, 88 void ClientCertStoreImpl::GetClientCerts(const SSLCertRequestInfo& request,
81 CertificateList* selected_certs) { 89 CertificateList* selected_certs,
90 const base::Closure& callback) {
82 CERTCertList* client_certs = CERT_FindUserCertsByUsage( 91 CERTCertList* client_certs = CERT_FindUserCertsByUsage(
83 CERT_GetDefaultCertDB(), certUsageSSLClient, 92 CERT_GetDefaultCertDB(), certUsageSSLClient,
84 PR_FALSE, PR_FALSE, NULL); 93 PR_FALSE, PR_FALSE, NULL);
85 // It is ok for a user not to have any client certs. 94 // It is ok for a user not to have any client certs.
86 if (!client_certs) 95 if (!client_certs) {
87 return true; 96 callback.Run();
97 return;
98 }
88 99
89 bool rv = GetClientCertsImpl(client_certs, request, true, selected_certs); 100 GetClientCertsImpl(client_certs, request, true, selected_certs);
90 CERT_DestroyCertList(client_certs); 101 CERT_DestroyCertList(client_certs);
91 return rv; 102 callback.Run();
92 } 103 }
93 104
94 bool ClientCertStoreImpl::SelectClientCertsForTesting( 105 bool ClientCertStoreImpl::SelectClientCertsForTesting(
95 const CertificateList& input_certs, 106 const CertificateList& input_certs,
96 const SSLCertRequestInfo& request, 107 const SSLCertRequestInfo& request,
97 CertificateList* selected_certs) { 108 CertificateList* selected_certs) {
98 CERTCertList* cert_list = CERT_NewCertList(); 109 CERTCertList* cert_list = CERT_NewCertList();
99 if (!cert_list) 110 if (!cert_list)
100 return false; 111 return false;
101 for (size_t i = 0; i < input_certs.size(); ++i) { 112 for (size_t i = 0; i < input_certs.size(); ++i) {
102 CERT_AddCertToListTail( 113 CERT_AddCertToListTail(
103 cert_list, CERT_DupCertificate(input_certs[i]->os_cert_handle())); 114 cert_list, CERT_DupCertificate(input_certs[i]->os_cert_handle()));
104 } 115 }
105 116
106 bool rv = GetClientCertsImpl(cert_list, request, false, selected_certs); 117 bool rv = GetClientCertsImpl(cert_list, request, false, selected_certs);
107 CERT_DestroyCertList(cert_list); 118 CERT_DestroyCertList(cert_list);
108 return rv; 119 return rv;
109 } 120 }
110 121
111 } // namespace net 122 } // namespace net
OLDNEW
« no previous file with comments | « net/ssl/client_cert_store_impl_mac.cc ('k') | net/ssl/client_cert_store_impl_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698