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

Side by Side Diff: chrome/browser/chromeos/options/cert_library.cc

Issue 421113002: Use correct slot id for client certs in network config. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments. Created 6 years, 4 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 "chrome/browser/chromeos/options/cert_library.h" 5 #include "chrome/browser/chromeos/options/cert_library.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/i18n/string_compare.h" 10 #include "base/i18n/string_compare.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 142 }
143 143
144 bool CertLibrary::CertificatesLoaded() const { 144 bool CertLibrary::CertificatesLoaded() const {
145 return CertLoader::Get()->certificates_loaded(); 145 return CertLoader::Get()->certificates_loaded();
146 } 146 }
147 147
148 bool CertLibrary::IsHardwareBacked() const { 148 bool CertLibrary::IsHardwareBacked() const {
149 return CertLoader::Get()->IsHardwareBacked(); 149 return CertLoader::Get()->IsHardwareBacked();
150 } 150 }
151 151
152 std::string CertLibrary::GetTPMSlotID() const {
153 return base::IntToString(CertLoader::Get()->TPMTokenSlotID());
154 }
155
156 int CertLibrary::NumCertificates(CertType type) const { 152 int CertLibrary::NumCertificates(CertType type) const {
157 const net::CertificateList& cert_list = GetCertificateListForType(type); 153 const net::CertificateList& cert_list = GetCertificateListForType(type);
158 return static_cast<int>(cert_list.size()); 154 return static_cast<int>(cert_list.size());
159 } 155 }
160 156
161 base::string16 CertLibrary::GetCertDisplayStringAt(CertType type, 157 base::string16 CertLibrary::GetCertDisplayStringAt(CertType type,
162 int index) const { 158 int index) const {
163 net::X509Certificate* cert = GetCertificateAt(type, index); 159 net::X509Certificate* cert = GetCertificateAt(type, index);
164 bool hardware_backed = IsCertHardwareBackedAt(type, index); 160 bool hardware_backed = IsCertHardwareBackedAt(type, index);
165 return GetDisplayString(cert, hardware_backed); 161 return GetDisplayString(cert, hardware_backed);
166 } 162 }
167 163
168 std::string CertLibrary::GetServerCACertPEMAt(int index) const { 164 std::string CertLibrary::GetServerCACertPEMAt(int index) const {
169 return CertToPEM(*GetCertificateAt(CERT_TYPE_SERVER_CA, index)); 165 return CertToPEM(*GetCertificateAt(CERT_TYPE_SERVER_CA, index));
170 } 166 }
171 167
172 std::string CertLibrary::GetUserCertPkcs11IdAt(int index) const { 168 std::string CertLibrary::GetUserCertPkcs11IdAt(int index, int* slot_id) const {
173 net::X509Certificate* cert = GetCertificateAt(CERT_TYPE_USER, index); 169 net::X509Certificate* cert = GetCertificateAt(CERT_TYPE_USER, index);
174 return CertLoader::GetPkcs11IdForCert(*cert); 170 return CertLoader::GetPkcs11IdAndSlotForCert(*cert, slot_id);
175 } 171 }
176 172
177 bool CertLibrary::IsCertHardwareBackedAt(CertType type, int index) const { 173 bool CertLibrary::IsCertHardwareBackedAt(CertType type, int index) const {
178 net::X509Certificate* cert = GetCertificateAt(type, index); 174 net::X509Certificate* cert = GetCertificateAt(type, index);
179 return CertLoader::Get()->IsCertificateHardwareBacked(cert); 175 return CertLoader::Get()->IsCertificateHardwareBacked(cert);
180 } 176 }
181 177
182 int CertLibrary::GetServerCACertIndexByPEM( 178 int CertLibrary::GetServerCACertIndexByPEM(
183 const std::string& pem_encoded) const { 179 const std::string& pem_encoded) const {
184 int num_certs = NumCertificates(CERT_TYPE_SERVER_CA); 180 int num_certs = NumCertificates(CERT_TYPE_SERVER_CA);
185 for (int index = 0; index < num_certs; ++index) { 181 for (int index = 0; index < num_certs; ++index) {
186 net::X509Certificate* cert = GetCertificateAt(CERT_TYPE_SERVER_CA, index); 182 net::X509Certificate* cert = GetCertificateAt(CERT_TYPE_SERVER_CA, index);
187 if (CertToPEM(*cert) != pem_encoded) 183 if (CertToPEM(*cert) != pem_encoded)
188 continue; 184 continue;
189 return index; 185 return index;
190 } 186 }
191 return -1; 187 return -1;
192 } 188 }
193 189
194 int CertLibrary::GetUserCertIndexByPkcs11Id( 190 int CertLibrary::GetUserCertIndexByPkcs11Id(
195 const std::string& pkcs11_id) const { 191 const std::string& pkcs11_id) const {
196 int num_certs = NumCertificates(CERT_TYPE_USER); 192 int num_certs = NumCertificates(CERT_TYPE_USER);
197 for (int index = 0; index < num_certs; ++index) { 193 for (int index = 0; index < num_certs; ++index) {
198 net::X509Certificate* cert = GetCertificateAt(CERT_TYPE_USER, index); 194 net::X509Certificate* cert = GetCertificateAt(CERT_TYPE_USER, index);
199 std::string id = CertLoader::GetPkcs11IdForCert(*cert); 195 int slot_id = -1;
196 std::string id = CertLoader::GetPkcs11IdAndSlotForCert(*cert, &slot_id);
200 if (id == pkcs11_id) 197 if (id == pkcs11_id)
201 return index; 198 return index;
202 } 199 }
203 return -1; // Not found. 200 return -1; // Not found.
204 } 201 }
205 202
206 void CertLibrary::OnCertificatesLoaded(const net::CertificateList& cert_list, 203 void CertLibrary::OnCertificatesLoaded(const net::CertificateList& cert_list,
207 bool initial_load) { 204 bool initial_load) {
208 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 205 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
209 VLOG(1) << "CertLibrary::OnCertificatesLoaded: " << cert_list.size(); 206 VLOG(1) << "CertLibrary::OnCertificatesLoaded: " << cert_list.size();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 return user_certs_; 272 return user_certs_;
276 if (type == CERT_TYPE_SERVER) 273 if (type == CERT_TYPE_SERVER)
277 return server_certs_; 274 return server_certs_;
278 if (type == CERT_TYPE_SERVER_CA) 275 if (type == CERT_TYPE_SERVER_CA)
279 return server_ca_certs_; 276 return server_ca_certs_;
280 DCHECK(type == CERT_TYPE_DEFAULT); 277 DCHECK(type == CERT_TYPE_DEFAULT);
281 return certs_; 278 return certs_;
282 } 279 }
283 280
284 } // namespace chromeos 281 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/options/cert_library.h ('k') | chrome/browser/chromeos/options/vpn_config_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698