OLD | NEW |
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 "chrome/browser/chromeos/cros/cert_library.h" | 5 #include "chrome/browser/chromeos/cros/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" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/observer_list_threadsafe.h" | 12 #include "base/observer_list_threadsafe.h" |
13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "chrome/browser/browser_process.h" // g_browser_process | 16 #include "chrome/browser/browser_process.h" // g_browser_process |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/net/x509_certificate_model.h" | 18 #include "chrome/common/net/x509_certificate_model.h" |
19 #include "chromeos/dbus/cryptohome_client.h" | 19 #include "chromeos/dbus/cryptohome_client.h" |
20 #include "chromeos/dbus/dbus_thread_manager.h" | 20 #include "chromeos/dbus/dbus_thread_manager.h" |
21 #include "chromeos/login/login_state.h" | 21 #include "chromeos/login/login_state.h" |
| 22 #include "chromeos/network/onc/onc_utils.h" |
22 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
23 #include "crypto/nss_util.h" | 24 #include "crypto/nss_util.h" |
24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
25 #include "net/cert/cert_database.h" | 26 #include "net/cert/cert_database.h" |
26 #include "net/cert/nss_cert_database.h" | 27 #include "net/cert/nss_cert_database.h" |
27 #include "third_party/icu/public/i18n/unicode/coll.h" // icu::Collator | 28 #include "third_party/icu/public/i18n/unicode/coll.h" // icu::Collator |
28 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
29 #include "ui/base/l10n/l10n_util_collator.h" | 30 #include "ui/base/l10n/l10n_util_collator.h" |
30 | 31 |
31 namespace chromeos { | 32 namespace chromeos { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 const net::CertificateList& cert_list = GetCertificateListForType(type); | 142 const net::CertificateList& cert_list = GetCertificateListForType(type); |
142 return static_cast<int>(cert_list.size()); | 143 return static_cast<int>(cert_list.size()); |
143 } | 144 } |
144 | 145 |
145 string16 CertLibrary::GetCertDisplayStringAt(CertType type, int index) const { | 146 string16 CertLibrary::GetCertDisplayStringAt(CertType type, int index) const { |
146 net::X509Certificate* cert = GetCertificateAt(type, index); | 147 net::X509Certificate* cert = GetCertificateAt(type, index); |
147 bool hardware_backed = IsCertHardwareBackedAt(type, index); | 148 bool hardware_backed = IsCertHardwareBackedAt(type, index); |
148 return GetDisplayString(cert, hardware_backed); | 149 return GetDisplayString(cert, hardware_backed); |
149 } | 150 } |
150 | 151 |
151 std::string CertLibrary::GetCertNicknameAt(CertType type, int index) const { | 152 std::string CertLibrary::GetCertFingerprintAt(CertType type, int index) const { |
152 net::X509Certificate* cert = GetCertificateAt(type, index); | 153 net::X509Certificate* cert = GetCertificateAt(type, index); |
153 return x509_certificate_model::GetNickname(cert->os_cert_handle()); | 154 return onc::GetHexFingerprintOfCert(*cert); |
154 } | 155 } |
155 | 156 |
156 std::string CertLibrary::GetCertPkcs11IdAt(CertType type, int index) const { | 157 std::string CertLibrary::GetCertPkcs11IdAt(CertType type, int index) const { |
157 net::X509Certificate* cert = GetCertificateAt(type, index); | 158 net::X509Certificate* cert = GetCertificateAt(type, index); |
158 return x509_certificate_model::GetPkcs11Id(cert->os_cert_handle()); | 159 return x509_certificate_model::GetPkcs11Id(cert->os_cert_handle()); |
159 } | 160 } |
160 | 161 |
161 bool CertLibrary::IsCertHardwareBackedAt(CertType type, int index) const { | 162 bool CertLibrary::IsCertHardwareBackedAt(CertType type, int index) const { |
162 if (!NetworkHandler::Get()->cert_loader()->IsHardwareBacked()) | 163 if (!NetworkHandler::Get()->cert_loader()->IsHardwareBacked()) |
163 return false; | 164 return false; |
164 net::X509Certificate* cert = GetCertificateAt(type, index); | 165 net::X509Certificate* cert = GetCertificateAt(type, index); |
165 std::string cert_token_name = | 166 std::string cert_token_name = |
166 x509_certificate_model::GetTokenName(cert->os_cert_handle()); | 167 x509_certificate_model::GetTokenName(cert->os_cert_handle()); |
167 return cert_token_name == | 168 return cert_token_name == |
168 NetworkHandler::Get()->cert_loader()->tpm_token_name(); | 169 NetworkHandler::Get()->cert_loader()->tpm_token_name(); |
169 } | 170 } |
170 | 171 |
171 int CertLibrary::GetCertIndexByNickname(CertType type, | 172 int CertLibrary::GetCertIndexByFingerprint( |
172 const std::string& nickname) const { | 173 CertType type, |
| 174 const std::string& fingerprint) const { |
173 int num_certs = NumCertificates(type); | 175 int num_certs = NumCertificates(type); |
| 176 int found_index = -1; |
174 for (int index = 0; index < num_certs; ++index) { | 177 for (int index = 0; index < num_certs; ++index) { |
175 net::X509Certificate* cert = GetCertificateAt(type, index); | 178 net::X509Certificate* cert = GetCertificateAt(type, index); |
176 net::X509Certificate::OSCertHandle cert_handle = cert->os_cert_handle(); | 179 if (onc::GetHexFingerprintOfCert(*cert) != fingerprint) |
177 std::string nick = x509_certificate_model::GetNickname(cert_handle); | 180 continue; |
178 if (nick == nickname) | 181 if (found_index != -1 && !GetCertificateAt(type, index)->Equals(cert)) { |
179 return index; | 182 LOG(ERROR) << "Fingerprint not unique in list."; |
| 183 return -1; |
| 184 } |
| 185 found_index = index; |
180 } | 186 } |
181 return -1; // Not found. | 187 return found_index; |
182 } | 188 } |
183 | 189 |
184 int CertLibrary::GetCertIndexByPkcs11Id(CertType type, | 190 int CertLibrary::GetCertIndexByPkcs11Id(CertType type, |
185 const std::string& pkcs11_id) const { | 191 const std::string& pkcs11_id) const { |
186 int num_certs = NumCertificates(type); | 192 int num_certs = NumCertificates(type); |
187 for (int index = 0; index < num_certs; ++index) { | 193 for (int index = 0; index < num_certs; ++index) { |
188 net::X509Certificate* cert = GetCertificateAt(type, index); | 194 net::X509Certificate* cert = GetCertificateAt(type, index); |
189 net::X509Certificate::OSCertHandle cert_handle = cert->os_cert_handle(); | 195 net::X509Certificate::OSCertHandle cert_handle = cert->os_cert_handle(); |
190 std::string id = x509_certificate_model::GetPkcs11Id(cert_handle); | 196 std::string id = x509_certificate_model::GetPkcs11Id(cert_handle); |
191 if (id == pkcs11_id) | 197 if (id == pkcs11_id) |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 if (type == CERT_TYPE_USER) | 271 if (type == CERT_TYPE_USER) |
266 return user_certs_; | 272 return user_certs_; |
267 if (type == CERT_TYPE_SERVER) | 273 if (type == CERT_TYPE_SERVER) |
268 return server_certs_; | 274 return server_certs_; |
269 if (type == CERT_TYPE_SERVER_CA) | 275 if (type == CERT_TYPE_SERVER_CA) |
270 return server_ca_certs_; | 276 return server_ca_certs_; |
271 DCHECK(type == CERT_TYPE_DEFAULT); | 277 DCHECK(type == CERT_TYPE_DEFAULT); |
272 return certs_; | 278 return certs_; |
273 } | 279 } |
274 | 280 |
275 } // chromeos | 281 } // namespace chromeos |
OLD | NEW |