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 "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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 return static_cast<int>(cert_list.size()); | 154 return static_cast<int>(cert_list.size()); |
155 } | 155 } |
156 | 156 |
157 base::string16 CertLibrary::GetCertDisplayStringAt(CertType type, | 157 base::string16 CertLibrary::GetCertDisplayStringAt(CertType type, |
158 int index) const { | 158 int index) const { |
159 net::X509Certificate* cert = GetCertificateAt(type, index); | 159 net::X509Certificate* cert = GetCertificateAt(type, index); |
160 bool hardware_backed = IsCertHardwareBackedAt(type, index); | 160 bool hardware_backed = IsCertHardwareBackedAt(type, index); |
161 return GetDisplayString(cert, hardware_backed); | 161 return GetDisplayString(cert, hardware_backed); |
162 } | 162 } |
163 | 163 |
164 std::string CertLibrary::GetCertPEMAt(CertType type, int index) const { | 164 std::string CertLibrary::GetServerCACertPEMAt(int index) const { |
165 return CertToPEM(*GetCertificateAt(type, index)); | 165 return CertToPEM(*GetCertificateAt(CERT_TYPE_SERVER_CA, index)); |
166 } | 166 } |
167 | 167 |
168 std::string CertLibrary::GetCertPkcs11IdAt(CertType type, int index) const { | 168 std::string CertLibrary::GetUserCertPkcs11IdAt(int index) const { |
169 net::X509Certificate* cert = GetCertificateAt(type, index); | 169 net::X509Certificate* cert = GetCertificateAt(CERT_TYPE_USER, index); |
170 return x509_certificate_model::GetPkcs11Id(cert->os_cert_handle()); | 170 return CertLoader::GetPkcs11IdForCert(*cert); |
171 } | 171 } |
172 | 172 |
173 bool CertLibrary::IsCertHardwareBackedAt(CertType type, int index) const { | 173 bool CertLibrary::IsCertHardwareBackedAt(CertType type, int index) const { |
174 net::X509Certificate* cert = GetCertificateAt(type, index); | 174 net::X509Certificate* cert = GetCertificateAt(type, index); |
175 return CertLoader::Get()->IsCertificateHardwareBacked(cert); | 175 return CertLoader::Get()->IsCertificateHardwareBacked(cert); |
176 } | 176 } |
177 | 177 |
178 int CertLibrary::GetCertIndexByPEM(CertType type, | 178 int CertLibrary::GetServerCACertIndexByPEM( |
179 const std::string& pem_encoded) const { | 179 const std::string& pem_encoded) const { |
180 int num_certs = NumCertificates(type); | 180 int num_certs = NumCertificates(CERT_TYPE_SERVER_CA); |
181 for (int index = 0; index < num_certs; ++index) { | 181 for (int index = 0; index < num_certs; ++index) { |
182 net::X509Certificate* cert = GetCertificateAt(type, index); | 182 net::X509Certificate* cert = GetCertificateAt(CERT_TYPE_SERVER_CA, index); |
183 if (CertToPEM(*cert) != pem_encoded) | 183 if (CertToPEM(*cert) != pem_encoded) |
184 continue; | 184 continue; |
185 return index; | 185 return index; |
186 } | 186 } |
187 return -1; | 187 return -1; |
188 } | 188 } |
189 | 189 |
190 int CertLibrary::GetCertIndexByPkcs11Id(CertType type, | 190 int CertLibrary::GetUserCertIndexByPkcs11Id( |
191 const std::string& pkcs11_id) const { | 191 const std::string& pkcs11_id) const { |
192 int num_certs = NumCertificates(type); | 192 int num_certs = NumCertificates(CERT_TYPE_USER); |
193 for (int index = 0; index < num_certs; ++index) { | 193 for (int index = 0; index < num_certs; ++index) { |
194 net::X509Certificate* cert = GetCertificateAt(type, index); | 194 net::X509Certificate* cert = GetCertificateAt(CERT_TYPE_USER, index); |
195 net::X509Certificate::OSCertHandle cert_handle = cert->os_cert_handle(); | 195 std::string id = CertLoader::GetPkcs11IdForCert(*cert); |
196 std::string id = x509_certificate_model::GetPkcs11Id(cert_handle); | |
197 if (id == pkcs11_id) | 196 if (id == pkcs11_id) |
198 return index; | 197 return index; |
199 } | 198 } |
200 return -1; // Not found. | 199 return -1; // Not found. |
201 } | 200 } |
202 | 201 |
203 void CertLibrary::OnCertificatesLoaded(const net::CertificateList& cert_list, | 202 void CertLibrary::OnCertificatesLoaded(const net::CertificateList& cert_list, |
204 bool initial_load) { | 203 bool initial_load) { |
205 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 204 CHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
206 VLOG(1) << "CertLibrary::OnCertificatesLoaded: " << cert_list.size(); | 205 VLOG(1) << "CertLibrary::OnCertificatesLoaded: " << cert_list.size(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 return user_certs_; | 271 return user_certs_; |
273 if (type == CERT_TYPE_SERVER) | 272 if (type == CERT_TYPE_SERVER) |
274 return server_certs_; | 273 return server_certs_; |
275 if (type == CERT_TYPE_SERVER_CA) | 274 if (type == CERT_TYPE_SERVER_CA) |
276 return server_ca_certs_; | 275 return server_ca_certs_; |
277 DCHECK(type == CERT_TYPE_DEFAULT); | 276 DCHECK(type == CERT_TYPE_DEFAULT); |
278 return certs_; | 277 return certs_; |
279 } | 278 } |
280 | 279 |
281 } // namespace chromeos | 280 } // namespace chromeos |
OLD | NEW |