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" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 CHECK(g_cert_library) << "CertLibrary::Get() called before Initialize()"; | 114 CHECK(g_cert_library) << "CertLibrary::Get() called before Initialize()"; |
115 return g_cert_library; | 115 return g_cert_library; |
116 } | 116 } |
117 | 117 |
118 // static | 118 // static |
119 bool CertLibrary::IsInitialized() { | 119 bool CertLibrary::IsInitialized() { |
120 return g_cert_library; | 120 return g_cert_library; |
121 } | 121 } |
122 | 122 |
123 CertLibrary::CertLibrary() { | 123 CertLibrary::CertLibrary() { |
124 NetworkHandler::Get()->cert_loader()->AddObserver(this); | 124 CertLoader::Get()->AddObserver(this); |
125 } | 125 } |
126 | 126 |
127 CertLibrary::~CertLibrary() { | 127 CertLibrary::~CertLibrary() { |
128 NetworkHandler::Get()->cert_loader()->RemoveObserver(this); | 128 CertLoader::Get()->RemoveObserver(this); |
129 } | 129 } |
130 | 130 |
131 void CertLibrary::AddObserver(CertLibrary::Observer* observer) { | 131 void CertLibrary::AddObserver(CertLibrary::Observer* observer) { |
132 observer_list_.AddObserver(observer); | 132 observer_list_.AddObserver(observer); |
133 } | 133 } |
134 | 134 |
135 void CertLibrary::RemoveObserver(CertLibrary::Observer* observer) { | 135 void CertLibrary::RemoveObserver(CertLibrary::Observer* observer) { |
136 observer_list_.RemoveObserver(observer); | 136 observer_list_.RemoveObserver(observer); |
137 } | 137 } |
138 | 138 |
139 bool CertLibrary::CertificatesLoading() const { | 139 bool CertLibrary::CertificatesLoading() const { |
140 return NetworkHandler::Get()->cert_loader()->CertificatesLoading(); | 140 return CertLoader::Get()->CertificatesLoading(); |
141 } | 141 } |
142 | 142 |
143 bool CertLibrary::CertificatesLoaded() const { | 143 bool CertLibrary::CertificatesLoaded() const { |
144 return NetworkHandler::Get()->cert_loader()->certificates_loaded(); | 144 return CertLoader::Get()->certificates_loaded(); |
145 } | 145 } |
146 | 146 |
147 bool CertLibrary::IsHardwareBacked() const { | 147 bool CertLibrary::IsHardwareBacked() const { |
148 return NetworkHandler::Get()->cert_loader()->IsHardwareBacked(); | 148 return CertLoader::Get()->IsHardwareBacked(); |
149 } | 149 } |
150 | 150 |
151 int CertLibrary::NumCertificates(CertType type) const { | 151 int CertLibrary::NumCertificates(CertType type) const { |
152 const net::CertificateList& cert_list = GetCertificateListForType(type); | 152 const net::CertificateList& cert_list = GetCertificateListForType(type); |
153 return static_cast<int>(cert_list.size()); | 153 return static_cast<int>(cert_list.size()); |
154 } | 154 } |
155 | 155 |
156 string16 CertLibrary::GetCertDisplayStringAt(CertType type, int index) const { | 156 string16 CertLibrary::GetCertDisplayStringAt(CertType type, int index) const { |
157 net::X509Certificate* cert = GetCertificateAt(type, index); | 157 net::X509Certificate* cert = GetCertificateAt(type, index); |
158 bool hardware_backed = IsCertHardwareBackedAt(type, index); | 158 bool hardware_backed = IsCertHardwareBackedAt(type, index); |
159 return GetDisplayString(cert, hardware_backed); | 159 return GetDisplayString(cert, hardware_backed); |
160 } | 160 } |
161 | 161 |
162 std::string CertLibrary::GetCertPEMAt(CertType type, int index) const { | 162 std::string CertLibrary::GetCertPEMAt(CertType type, int index) const { |
163 return CertToPEM(*GetCertificateAt(type, index)); | 163 return CertToPEM(*GetCertificateAt(type, index)); |
164 } | 164 } |
165 | 165 |
166 std::string CertLibrary::GetCertPkcs11IdAt(CertType type, int index) const { | 166 std::string CertLibrary::GetCertPkcs11IdAt(CertType type, int index) const { |
167 net::X509Certificate* cert = GetCertificateAt(type, index); | 167 net::X509Certificate* cert = GetCertificateAt(type, index); |
168 return x509_certificate_model::GetPkcs11Id(cert->os_cert_handle()); | 168 return x509_certificate_model::GetPkcs11Id(cert->os_cert_handle()); |
169 } | 169 } |
170 | 170 |
171 bool CertLibrary::IsCertHardwareBackedAt(CertType type, int index) const { | 171 bool CertLibrary::IsCertHardwareBackedAt(CertType type, int index) const { |
172 if (!NetworkHandler::Get()->cert_loader()->IsHardwareBacked()) | 172 if (!CertLoader::Get()->IsHardwareBacked()) |
173 return false; | 173 return false; |
174 net::X509Certificate* cert = GetCertificateAt(type, index); | 174 net::X509Certificate* cert = GetCertificateAt(type, index); |
175 std::string cert_token_name = | 175 std::string cert_token_name = |
176 x509_certificate_model::GetTokenName(cert->os_cert_handle()); | 176 x509_certificate_model::GetTokenName(cert->os_cert_handle()); |
177 return cert_token_name == | 177 return cert_token_name == |
178 NetworkHandler::Get()->cert_loader()->tpm_token_name(); | 178 CertLoader::Get()->tpm_token_name(); |
179 } | 179 } |
180 | 180 |
181 int CertLibrary::GetCertIndexByPEM(CertType type, | 181 int CertLibrary::GetCertIndexByPEM(CertType type, |
182 const std::string& pem_encoded) const { | 182 const std::string& pem_encoded) const { |
183 int num_certs = NumCertificates(type); | 183 int num_certs = NumCertificates(type); |
184 for (int index = 0; index < num_certs; ++index) { | 184 for (int index = 0; index < num_certs; ++index) { |
185 net::X509Certificate* cert = GetCertificateAt(type, index); | 185 net::X509Certificate* cert = GetCertificateAt(type, index); |
186 if (CertToPEM(*cert) != pem_encoded) | 186 if (CertToPEM(*cert) != pem_encoded) |
187 continue; | 187 continue; |
188 return index; | 188 return index; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 return user_certs_; | 275 return user_certs_; |
276 if (type == CERT_TYPE_SERVER) | 276 if (type == CERT_TYPE_SERVER) |
277 return server_certs_; | 277 return server_certs_; |
278 if (type == CERT_TYPE_SERVER_CA) | 278 if (type == CERT_TYPE_SERVER_CA) |
279 return server_ca_certs_; | 279 return server_ca_certs_; |
280 DCHECK(type == CERT_TYPE_DEFAULT); | 280 DCHECK(type == CERT_TYPE_DEFAULT); |
281 return certs_; | 281 return certs_; |
282 } | 282 } |
283 | 283 |
284 } // namespace chromeos | 284 } // namespace chromeos |
OLD | NEW |