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

Side by Side Diff: chromeos/network/onc/onc_certificate_importer_impl.cc

Issue 582413002: Make ONCCertificateImporter async. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
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 "chromeos/network/onc/onc_certificate_importer_impl.h" 5 #include "chromeos/network/onc/onc_certificate_importer_impl.h"
6 6
7 #include <cert.h> 7 #include <cert.h>
8 #include <keyhi.h> 8 #include <keyhi.h>
9 #include <pk11pub.h> 9 #include <pk11pub.h>
10 10
11 #include "base/base64.h" 11 #include "base/base64.h"
12 #include "base/bind.h"
13 #include "base/bind_helpers.h"
14 #include "base/callback.h"
15 #include "base/location.h"
12 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/sequenced_task_runner.h"
18 #include "base/single_thread_task_runner.h"
19 #include "base/thread_task_runner_handle.h"
13 #include "base/values.h" 20 #include "base/values.h"
14 #include "chromeos/network/network_event_log.h" 21 #include "chromeos/network/network_event_log.h"
15 #include "chromeos/network/onc/onc_utils.h" 22 #include "chromeos/network/onc/onc_utils.h"
16 #include "components/onc/onc_constants.h" 23 #include "components/onc/onc_constants.h"
17 #include "crypto/scoped_nss_types.h" 24 #include "crypto/scoped_nss_types.h"
18 #include "net/base/crypto_module.h" 25 #include "net/base/crypto_module.h"
19 #include "net/base/net_errors.h" 26 #include "net/base/net_errors.h"
20 #include "net/cert/nss_cert_database.h" 27 #include "net/cert/nss_cert_database.h"
21 #include "net/cert/x509_certificate.h" 28 #include "net/cert/x509_certificate.h"
22 29
23 #define ONC_LOG_WARNING(message) \
24 NET_LOG_DEBUG("ONC Certificate Import Warning", message)
25 #define ONC_LOG_ERROR(message) \
26 NET_LOG_ERROR("ONC Certificate Import Error", message)
27
28 namespace chromeos { 30 namespace chromeos {
29 namespace onc { 31 namespace onc {
30 32
33 namespace {
34
35 void CallBackOnOriginLoop(
36 const scoped_refptr<base::SingleThreadTaskRunner>& origin_loop,
37 const CertificateImporter::DoneCallback& callback,
38 bool success,
39 const net::CertificateList& onc_trusted_certificates) {
40 origin_loop->PostTask(
41 FROM_HERE, base::Bind(callback, success, onc_trusted_certificates));
42 }
43
44 } // namespace
45
31 CertificateImporterImpl::CertificateImporterImpl( 46 CertificateImporterImpl::CertificateImporterImpl(
47 const scoped_refptr<base::SequencedTaskRunner>& io_task_runner,
32 net::NSSCertDatabase* target_nssdb) 48 net::NSSCertDatabase* target_nssdb)
33 : target_nssdb_(target_nssdb) { 49 : io_task_runner_(io_task_runner),
50 target_nssdb_(target_nssdb),
51 weak_factory_(this) {
34 CHECK(target_nssdb); 52 CHECK(target_nssdb);
35 } 53 }
36 54
37 bool CertificateImporterImpl::ImportCertificates( 55 CertificateImporterImpl::~CertificateImporterImpl() {
56 }
57
58 void CertificateImporterImpl::ImportCertificates(
38 const base::ListValue& certificates, 59 const base::ListValue& certificates,
39 ::onc::ONCSource source, 60 ::onc::ONCSource source,
40 net::CertificateList* onc_trusted_certificates) { 61 const DoneCallback& done_callback) {
41 VLOG(2) << "ONC file has " << certificates.GetSize() << " certificates"; 62 VLOG(2) << "ONC file has " << certificates.GetSize() << " certificates";
63 // |done_callback| must only be called as long as |this| still exists.
64 // Thereforce, call back to |this|. This check of |this| must happen last and
65 // on the origin thread.
66 DoneCallback callback_to_this =
67 base::Bind(&CertificateImporterImpl::RunDoneCallback,
68 weak_factory_.GetWeakPtr(),
69 done_callback);
42 70
71 // |done_callback| must be called on the origin thread.
72 DoneCallback callback_on_origin_loop =
73 base::Bind(&CallBackOnOriginLoop,
74 base::ThreadTaskRunnerHandle::Get(),
75 callback_to_this);
76
77 // This is the actual function that imports the certificates.
78 base::Closure import_certs_callback =
79 base::Bind(&ParseAndStoreCertificates,
80 source,
81 callback_on_origin_loop,
82 base::Owned(certificates.DeepCopy()),
83 target_nssdb_);
84
85 // The NSSCertDatabase must be accessed on |io_task_runner_|
86 io_task_runner_->PostTask(FROM_HERE, import_certs_callback);
87 }
88
89 // static
90 void CertificateImporterImpl::ParseAndStoreCertificates(
91 ::onc::ONCSource source,
92 const DoneCallback& done_callback,
93 base::ListValue* certificates,
94 net::NSSCertDatabase* nssdb) {
43 // Web trust is only granted to certificates imported by the user. 95 // Web trust is only granted to certificates imported by the user.
44 bool allow_trust_imports = source == ::onc::ONC_SOURCE_USER_IMPORT; 96 bool allow_trust_imports = source == ::onc::ONC_SOURCE_USER_IMPORT;
45 if (!ParseAndStoreCertificates(allow_trust_imports, 97 net::CertificateList onc_trusted_certificates;
46 certificates,
47 onc_trusted_certificates,
48 NULL)) {
49 LOG(ERROR) << "Cannot parse some of the certificates in the ONC from "
50 << onc::GetSourceAsString(source);
51 return false;
52 }
53 return true;
54 }
55
56 bool CertificateImporterImpl::ParseAndStoreCertificates(
57 bool allow_trust_imports,
58 const base::ListValue& certificates,
59 net::CertificateList* onc_trusted_certificates,
60 CertsByGUID* imported_server_and_ca_certs) {
61 bool success = true; 98 bool success = true;
62 for (size_t i = 0; i < certificates.GetSize(); ++i) { 99 for (size_t i = 0; i < certificates->GetSize(); ++i) {
63 const base::DictionaryValue* certificate = NULL; 100 const base::DictionaryValue* certificate = NULL;
64 certificates.GetDictionary(i, &certificate); 101 certificates->GetDictionary(i, &certificate);
65 DCHECK(certificate != NULL); 102 DCHECK(certificate != NULL);
66 103
67 VLOG(2) << "Parsing certificate at index " << i << ": " << *certificate; 104 VLOG(2) << "Parsing certificate at index " << i << ": " << *certificate;
68 105
69 if (!ParseAndStoreCertificate(allow_trust_imports, 106 if (!ParseAndStoreCertificate(allow_trust_imports,
70 *certificate, 107 *certificate,
71 onc_trusted_certificates, 108 nssdb,
72 imported_server_and_ca_certs)) { 109 &onc_trusted_certificates)) {
73 success = false; 110 success = false;
74 ONC_LOG_ERROR( 111 LOG(ERROR) << "Cannot parse certificate at index " << i;
75 base::StringPrintf("Cannot parse certificate at index %zu", i));
76 } else { 112 } else {
77 VLOG(2) << "Successfully imported certificate at index " << i; 113 VLOG(2) << "Successfully imported certificate at index " << i;
78 } 114 }
79 } 115 }
80 return success; 116
117 done_callback.Run(success, onc_trusted_certificates);
81 } 118 }
82 119
83 // static 120 // static
84 void CertificateImporterImpl::ListCertsWithNickname( 121 void CertificateImporterImpl::ListCertsWithNickname(
85 const std::string& label, 122 const std::string& label,
86 net::CertificateList* result, 123 net::CertificateList* result,
87 net::NSSCertDatabase* target_nssdb) { 124 net::NSSCertDatabase* target_nssdb) {
88 net::CertificateList all_certs; 125 net::CertificateList all_certs;
89 // TODO(tbarzic): Use async |ListCerts|. 126 // TODO(tbarzic): Use async |ListCerts|.
90 target_nssdb->ListCertsSync(&all_certs); 127 target_nssdb->ListCertsSync(&all_certs);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // Luckily there should only be one cert with a particular 173 // Luckily there should only be one cert with a particular
137 // label, and the cert not being found is one of the few reasons the 174 // label, and the cert not being found is one of the few reasons the
138 // delete could fail, but still... The other choice is to return 175 // delete could fail, but still... The other choice is to return
139 // failure immediately, but that doesn't seem to do what is intended. 176 // failure immediately, but that doesn't seem to do what is intended.
140 if (!target_nssdb->DeleteCertAndKey(iter->get())) 177 if (!target_nssdb->DeleteCertAndKey(iter->get()))
141 result = false; 178 result = false;
142 } 179 }
143 return result; 180 return result;
144 } 181 }
145 182
183 void CertificateImporterImpl::RunDoneCallback(
184 const CertificateImporter::DoneCallback& callback,
185 bool success,
186 const net::CertificateList& onc_trusted_certificates) {
187 if (!success)
188 NET_LOG_ERROR("ONC Certificate Import Error", "");
189 callback.Run(success, onc_trusted_certificates);
190 }
191
146 bool CertificateImporterImpl::ParseAndStoreCertificate( 192 bool CertificateImporterImpl::ParseAndStoreCertificate(
147 bool allow_trust_imports, 193 bool allow_trust_imports,
148 const base::DictionaryValue& certificate, 194 const base::DictionaryValue& certificate,
149 net::CertificateList* onc_trusted_certificates, 195 net::NSSCertDatabase* nssdb,
150 CertsByGUID* imported_server_and_ca_certs) { 196 net::CertificateList* onc_trusted_certificates) {
151 // Get out the attributes of the given certificate. 197 // Get out the attributes of the given certificate.
152 std::string guid; 198 std::string guid;
153 certificate.GetStringWithoutPathExpansion(::onc::certificate::kGUID, &guid); 199 certificate.GetStringWithoutPathExpansion(::onc::certificate::kGUID, &guid);
154 DCHECK(!guid.empty()); 200 DCHECK(!guid.empty());
155 201
156 bool remove = false; 202 bool remove = false;
157 if (certificate.GetBooleanWithoutPathExpansion(::onc::kRemove, &remove) && 203 if (certificate.GetBooleanWithoutPathExpansion(::onc::kRemove, &remove) &&
158 remove) { 204 remove) {
159 if (!DeleteCertAndKeyByNickname(guid, target_nssdb_)) { 205 if (!DeleteCertAndKeyByNickname(guid, nssdb)) {
160 ONC_LOG_ERROR("Unable to delete certificate"); 206 LOG(ERROR) << "Unable to delete certificate";
161 return false; 207 return false;
162 } else { 208 } else {
163 return true; 209 return true;
164 } 210 }
165 } 211 }
166 212
167 // Not removing, so let's get the data we need to add this certificate. 213 // Not removing, so let's get the data we need to add this certificate.
168 std::string cert_type; 214 std::string cert_type;
169 certificate.GetStringWithoutPathExpansion(::onc::certificate::kType, 215 certificate.GetStringWithoutPathExpansion(::onc::certificate::kType,
170 &cert_type); 216 &cert_type);
171 if (cert_type == ::onc::certificate::kServer || 217 if (cert_type == ::onc::certificate::kServer ||
172 cert_type == ::onc::certificate::kAuthority) { 218 cert_type == ::onc::certificate::kAuthority) {
173 return ParseServerOrCaCertificate(allow_trust_imports, 219 return ParseServerOrCaCertificate(allow_trust_imports,
174 cert_type, 220 cert_type,
175 guid, 221 guid,
176 certificate, 222 certificate,
177 onc_trusted_certificates, 223 nssdb,
178 imported_server_and_ca_certs); 224 onc_trusted_certificates);
179 } else if (cert_type == ::onc::certificate::kClient) { 225 } else if (cert_type == ::onc::certificate::kClient) {
180 return ParseClientCertificate(guid, certificate); 226 return ParseClientCertificate(guid, certificate, nssdb);
181 } 227 }
182 228
183 NOTREACHED(); 229 NOTREACHED();
184 return false; 230 return false;
185 } 231 }
186 232
187 bool CertificateImporterImpl::ParseServerOrCaCertificate( 233 bool CertificateImporterImpl::ParseServerOrCaCertificate(
188 bool allow_trust_imports, 234 bool allow_trust_imports,
189 const std::string& cert_type, 235 const std::string& cert_type,
190 const std::string& guid, 236 const std::string& guid,
191 const base::DictionaryValue& certificate, 237 const base::DictionaryValue& certificate,
192 net::CertificateList* onc_trusted_certificates, 238 net::NSSCertDatabase* nssdb,
193 CertsByGUID* imported_server_and_ca_certs) { 239 net::CertificateList* onc_trusted_certificates) {
194 bool web_trust_flag = false; 240 bool web_trust_flag = false;
195 const base::ListValue* trust_list = NULL; 241 const base::ListValue* trust_list = NULL;
196 if (certificate.GetListWithoutPathExpansion(::onc::certificate::kTrustBits, 242 if (certificate.GetListWithoutPathExpansion(::onc::certificate::kTrustBits,
197 &trust_list)) { 243 &trust_list)) {
198 for (base::ListValue::const_iterator it = trust_list->begin(); 244 for (base::ListValue::const_iterator it = trust_list->begin();
199 it != trust_list->end(); ++it) { 245 it != trust_list->end(); ++it) {
200 std::string trust_type; 246 std::string trust_type;
201 if (!(*it)->GetAsString(&trust_type)) 247 if (!(*it)->GetAsString(&trust_type))
202 NOTREACHED(); 248 NOTREACHED();
203 249
204 if (trust_type == ::onc::certificate::kWeb) { 250 if (trust_type == ::onc::certificate::kWeb) {
205 // "Web" implies that the certificate is to be trusted for SSL 251 // "Web" implies that the certificate is to be trusted for SSL
206 // identification. 252 // identification.
207 web_trust_flag = true; 253 web_trust_flag = true;
208 } else { 254 } else {
209 // Trust bits should only increase trust and never restrict. Thus, 255 // Trust bits should only increase trust and never restrict. Thus,
210 // ignoring unknown bits should be safe. 256 // ignoring unknown bits should be safe.
211 ONC_LOG_WARNING("Certificate contains unknown trust type " + 257 LOG(WARNING) << "Certificate contains unknown trust type "
212 trust_type); 258 << trust_type;
213 } 259 }
214 } 260 }
215 } 261 }
216 262
217 bool import_with_ssl_trust = false; 263 bool import_with_ssl_trust = false;
218 if (web_trust_flag) { 264 if (web_trust_flag) {
219 if (!allow_trust_imports) 265 if (!allow_trust_imports)
220 ONC_LOG_WARNING("Web trust not granted for certificate: " + guid); 266 LOG(WARNING) << "Web trust not granted for certificate: " << guid;
221 else 267 else
222 import_with_ssl_trust = true; 268 import_with_ssl_trust = true;
223 } 269 }
224 270
225 std::string x509_data; 271 std::string x509_data;
226 if (!certificate.GetStringWithoutPathExpansion(::onc::certificate::kX509, 272 if (!certificate.GetStringWithoutPathExpansion(::onc::certificate::kX509,
227 &x509_data) || 273 &x509_data) ||
228 x509_data.empty()) { 274 x509_data.empty()) {
229 ONC_LOG_ERROR( 275 LOG(ERROR) << "Certificate missing appropriate certificate data for type: "
230 "Certificate missing appropriate certificate data for type: " + 276 << cert_type;
231 cert_type);
232 return false; 277 return false;
233 } 278 }
234 279
235 scoped_refptr<net::X509Certificate> x509_cert = 280 scoped_refptr<net::X509Certificate> x509_cert =
236 DecodePEMCertificate(x509_data); 281 DecodePEMCertificate(x509_data);
237 if (!x509_cert.get()) { 282 if (!x509_cert.get()) {
238 ONC_LOG_ERROR("Unable to create certificate from PEM encoding, type: " + 283 LOG(ERROR) << "Unable to create certificate from PEM encoding, type: "
239 cert_type); 284 << cert_type;
240 return false; 285 return false;
241 } 286 }
242 287
243 net::NSSCertDatabase::TrustBits trust = (import_with_ssl_trust ? 288 net::NSSCertDatabase::TrustBits trust = (import_with_ssl_trust ?
244 net::NSSCertDatabase::TRUSTED_SSL : 289 net::NSSCertDatabase::TRUSTED_SSL :
245 net::NSSCertDatabase::TRUST_DEFAULT); 290 net::NSSCertDatabase::TRUST_DEFAULT);
246 291
247 if (x509_cert->os_cert_handle()->isperm) { 292 if (x509_cert->os_cert_handle()->isperm) {
248 net::CertType net_cert_type = 293 net::CertType net_cert_type =
249 cert_type == ::onc::certificate::kServer ? net::SERVER_CERT 294 cert_type == ::onc::certificate::kServer ? net::SERVER_CERT
250 : net::CA_CERT; 295 : net::CA_CERT;
251 VLOG(1) << "Certificate is already installed."; 296 VLOG(1) << "Certificate is already installed.";
252 net::NSSCertDatabase::TrustBits missing_trust_bits = 297 net::NSSCertDatabase::TrustBits missing_trust_bits =
253 trust & ~target_nssdb_->GetCertTrust(x509_cert.get(), net_cert_type); 298 trust & ~nssdb->GetCertTrust(x509_cert.get(), net_cert_type);
254 if (missing_trust_bits) { 299 if (missing_trust_bits) {
255 std::string error_reason; 300 std::string error_reason;
256 bool success = false; 301 bool success = false;
257 if (target_nssdb_->IsReadOnly(x509_cert.get())) { 302 if (nssdb->IsReadOnly(x509_cert.get())) {
258 error_reason = " Certificate is stored read-only."; 303 error_reason = " Certificate is stored read-only.";
259 } else { 304 } else {
260 success = target_nssdb_->SetCertTrust(x509_cert.get(), 305 success = nssdb->SetCertTrust(x509_cert.get(), net_cert_type, trust);
261 net_cert_type,
262 trust);
263 } 306 }
264 if (!success) { 307 if (!success) {
265 ONC_LOG_ERROR("Certificate of type " + cert_type + 308 LOG(ERROR) << "Certificate of type " << cert_type
266 " was already present, but trust couldn't be set." + 309 << " was already present, but trust couldn't be set."
267 error_reason); 310 << error_reason;
268 } 311 }
269 } 312 }
270 } else { 313 } else {
271 net::CertificateList cert_list; 314 net::CertificateList cert_list;
272 cert_list.push_back(x509_cert); 315 cert_list.push_back(x509_cert);
273 net::NSSCertDatabase::ImportCertFailureList failures; 316 net::NSSCertDatabase::ImportCertFailureList failures;
274 bool success = false; 317 bool success = false;
275 if (cert_type == ::onc::certificate::kServer) 318 if (cert_type == ::onc::certificate::kServer)
276 success = target_nssdb_->ImportServerCert(cert_list, trust, &failures); 319 success = nssdb->ImportServerCert(cert_list, trust, &failures);
277 else // Authority cert 320 else // Authority cert
278 success = target_nssdb_->ImportCACerts(cert_list, trust, &failures); 321 success = nssdb->ImportCACerts(cert_list, trust, &failures);
279 322
280 if (!failures.empty()) { 323 if (!failures.empty()) {
281 std::string error_string = net::ErrorToString(failures[0].net_error); 324 std::string error_string = net::ErrorToString(failures[0].net_error);
282 ONC_LOG_ERROR( 325 LOG(ERROR) << "Error ( " << error_string
283 base::StringPrintf("Error ( %s ) importing %s certificate", 326 << " ) importing certificate of type " << cert_type;
284 error_string.c_str(),
285 cert_type.c_str()));
286 return false; 327 return false;
287 } 328 }
288 329
289 if (!success) { 330 if (!success) {
290 ONC_LOG_ERROR("Unknown error importing " + cert_type + " certificate."); 331 LOG(ERROR) << "Unknown error importing " << cert_type << " certificate.";
291 return false; 332 return false;
292 } 333 }
293 } 334 }
294 335
295 if (web_trust_flag && onc_trusted_certificates) 336 if (web_trust_flag && onc_trusted_certificates)
296 onc_trusted_certificates->push_back(x509_cert); 337 onc_trusted_certificates->push_back(x509_cert);
297 338
298 if (imported_server_and_ca_certs)
299 (*imported_server_and_ca_certs)[guid] = x509_cert;
300
301 return true; 339 return true;
302 } 340 }
303 341
304 bool CertificateImporterImpl::ParseClientCertificate( 342 bool CertificateImporterImpl::ParseClientCertificate(
305 const std::string& guid, 343 const std::string& guid,
306 const base::DictionaryValue& certificate) { 344 const base::DictionaryValue& certificate,
345 net::NSSCertDatabase* nssdb) {
307 std::string pkcs12_data; 346 std::string pkcs12_data;
308 if (!certificate.GetStringWithoutPathExpansion(::onc::certificate::kPKCS12, 347 if (!certificate.GetStringWithoutPathExpansion(::onc::certificate::kPKCS12,
309 &pkcs12_data) || 348 &pkcs12_data) ||
310 pkcs12_data.empty()) { 349 pkcs12_data.empty()) {
311 ONC_LOG_ERROR("PKCS12 data is missing for client certificate."); 350 LOG(ERROR) << "PKCS12 data is missing for client certificate.";
312 return false; 351 return false;
313 } 352 }
314 353
315 std::string decoded_pkcs12; 354 std::string decoded_pkcs12;
316 if (!base::Base64Decode(pkcs12_data, &decoded_pkcs12)) { 355 if (!base::Base64Decode(pkcs12_data, &decoded_pkcs12)) {
317 ONC_LOG_ERROR( 356 LOG(ERROR) << "Unable to base64 decode PKCS#12 data: \"" << pkcs12_data
318 "Unable to base64 decode PKCS#12 data: \"" + pkcs12_data + "\"."); 357 << "\".";
319 return false; 358 return false;
320 } 359 }
321 360
322 // Since this has a private key, always use the private module. 361 // Since this has a private key, always use the private module.
323 crypto::ScopedPK11Slot private_slot(target_nssdb_->GetPrivateSlot()); 362 crypto::ScopedPK11Slot private_slot(nssdb->GetPrivateSlot());
324 if (!private_slot) 363 if (!private_slot)
325 return false; 364 return false;
326 scoped_refptr<net::CryptoModule> module( 365 scoped_refptr<net::CryptoModule> module(
327 net::CryptoModule::CreateFromHandle(private_slot.get())); 366 net::CryptoModule::CreateFromHandle(private_slot.get()));
328 net::CertificateList imported_certs; 367 net::CertificateList imported_certs;
329 368
330 int import_result = target_nssdb_->ImportFromPKCS12( 369 int import_result = nssdb->ImportFromPKCS12(
331 module.get(), decoded_pkcs12, base::string16(), false, &imported_certs); 370 module.get(), decoded_pkcs12, base::string16(), false, &imported_certs);
332 if (import_result != net::OK) { 371 if (import_result != net::OK) {
333 std::string error_string = net::ErrorToString(import_result); 372 std::string error_string = net::ErrorToString(import_result);
334 ONC_LOG_ERROR( 373 LOG(ERROR) << "Unable to import client certificate, error: "
335 base::StringPrintf("Unable to import client certificate (error %s)", 374 << error_string;
336 error_string.c_str()));
337 return false; 375 return false;
338 } 376 }
339 377
340 if (imported_certs.size() == 0) { 378 if (imported_certs.size() == 0) {
341 ONC_LOG_WARNING("PKCS12 data contains no importable certificates."); 379 LOG(WARNING) << "PKCS12 data contains no importable certificates.";
342 return true; 380 return true;
343 } 381 }
344 382
345 if (imported_certs.size() != 1) { 383 if (imported_certs.size() != 1) {
346 ONC_LOG_WARNING("ONC File: PKCS12 data contains more than one certificate. " 384 LOG(WARNING) << "ONC File: PKCS12 data contains more than one certificate. "
347 "Only the first one will be imported."); 385 "Only the first one will be imported.";
348 } 386 }
349 387
350 scoped_refptr<net::X509Certificate> cert_result = imported_certs[0]; 388 scoped_refptr<net::X509Certificate> cert_result = imported_certs[0];
351 389
352 // Find the private key associated with this certificate, and set the 390 // Find the private key associated with this certificate, and set the
353 // nickname on it. 391 // nickname on it.
354 SECKEYPrivateKey* private_key = PK11_FindPrivateKeyFromCert( 392 SECKEYPrivateKey* private_key = PK11_FindPrivateKeyFromCert(
355 cert_result->os_cert_handle()->slot, 393 cert_result->os_cert_handle()->slot,
356 cert_result->os_cert_handle(), 394 cert_result->os_cert_handle(),
357 NULL); // wincx 395 NULL); // wincx
358 if (private_key) { 396 if (private_key) {
359 PK11_SetPrivateKeyNickname(private_key, const_cast<char*>(guid.c_str())); 397 PK11_SetPrivateKeyNickname(private_key, const_cast<char*>(guid.c_str()));
360 SECKEY_DestroyPrivateKey(private_key); 398 SECKEY_DestroyPrivateKey(private_key);
361 } else { 399 } else {
362 ONC_LOG_WARNING("Unable to find private key for certificate."); 400 LOG(WARNING) << "Unable to find private key for certificate.";
363 } 401 }
364 return true; 402 return true;
365 } 403 }
366 404
367 } // namespace onc 405 } // namespace onc
368 } // namespace chromeos 406 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/onc/onc_certificate_importer_impl.h ('k') | chromeos/network/onc/onc_certificate_importer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698