| 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 "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 #include <stddef.h> | 10 #include <stddef.h> |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 if (!base::Base64Decode(pkcs12_data, &decoded_pkcs12)) { | 279 if (!base::Base64Decode(pkcs12_data, &decoded_pkcs12)) { |
| 280 LOG(ERROR) << "Unable to base64 decode PKCS#12 data: \"" << pkcs12_data | 280 LOG(ERROR) << "Unable to base64 decode PKCS#12 data: \"" << pkcs12_data |
| 281 << "\"."; | 281 << "\"."; |
| 282 return false; | 282 return false; |
| 283 } | 283 } |
| 284 | 284 |
| 285 // Since this has a private key, always use the private module. | 285 // Since this has a private key, always use the private module. |
| 286 crypto::ScopedPK11Slot private_slot(nssdb->GetPrivateSlot()); | 286 crypto::ScopedPK11Slot private_slot(nssdb->GetPrivateSlot()); |
| 287 if (!private_slot) | 287 if (!private_slot) |
| 288 return false; | 288 return false; |
| 289 scoped_refptr<net::CryptoModule> module( | 289 |
| 290 net::CryptoModule::CreateFromHandle(private_slot.get())); | |
| 291 net::CertificateList imported_certs; | 290 net::CertificateList imported_certs; |
| 292 | 291 |
| 293 int import_result = nssdb->ImportFromPKCS12( | 292 int import_result = |
| 294 module.get(), decoded_pkcs12, base::string16(), false, &imported_certs); | 293 nssdb->ImportFromPKCS12(private_slot.get(), decoded_pkcs12, |
| 294 base::string16(), false, &imported_certs); |
| 295 if (import_result != net::OK) { | 295 if (import_result != net::OK) { |
| 296 std::string error_string = net::ErrorToString(import_result); | 296 std::string error_string = net::ErrorToString(import_result); |
| 297 LOG(ERROR) << "Unable to import client certificate, error: " | 297 LOG(ERROR) << "Unable to import client certificate, error: " |
| 298 << error_string; | 298 << error_string; |
| 299 return false; | 299 return false; |
| 300 } | 300 } |
| 301 | 301 |
| 302 if (imported_certs.size() == 0) { | 302 if (imported_certs.size() == 0) { |
| 303 LOG(WARNING) << "PKCS12 data contains no importable certificates."; | 303 LOG(WARNING) << "PKCS12 data contains no importable certificates."; |
| 304 return true; | 304 return true; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 321 PK11_SetPrivateKeyNickname(private_key, const_cast<char*>(guid.c_str())); | 321 PK11_SetPrivateKeyNickname(private_key, const_cast<char*>(guid.c_str())); |
| 322 SECKEY_DestroyPrivateKey(private_key); | 322 SECKEY_DestroyPrivateKey(private_key); |
| 323 } else { | 323 } else { |
| 324 LOG(WARNING) << "Unable to find private key for certificate."; | 324 LOG(WARNING) << "Unable to find private key for certificate."; |
| 325 } | 325 } |
| 326 return true; | 326 return true; |
| 327 } | 327 } |
| 328 | 328 |
| 329 } // namespace onc | 329 } // namespace onc |
| 330 } // namespace chromeos | 330 } // namespace chromeos |
| OLD | NEW |