| 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 | 10 |
| 11 #include "base/base64.h" | 11 #include "base/base64.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chromeos/network/network_event_log.h" | 14 #include "chromeos/network/network_event_log.h" |
| 15 #include "chromeos/network/onc/onc_utils.h" | 15 #include "chromeos/network/onc/onc_utils.h" |
| 16 #include "components/onc/onc_constants.h" | 16 #include "components/onc/onc_constants.h" |
| 17 #include "crypto/scoped_nss_types.h" |
| 17 #include "net/base/crypto_module.h" | 18 #include "net/base/crypto_module.h" |
| 18 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 19 #include "net/cert/nss_cert_database.h" | 20 #include "net/cert/nss_cert_database.h" |
| 20 #include "net/cert/x509_certificate.h" | 21 #include "net/cert/x509_certificate.h" |
| 21 | 22 |
| 22 #define ONC_LOG_WARNING(message) \ | 23 #define ONC_LOG_WARNING(message) \ |
| 23 NET_LOG_DEBUG("ONC Certificate Import Warning", message) | 24 NET_LOG_DEBUG("ONC Certificate Import Warning", message) |
| 24 #define ONC_LOG_ERROR(message) \ | 25 #define ONC_LOG_ERROR(message) \ |
| 25 NET_LOG_ERROR("ONC Certificate Import Error", message) | 26 NET_LOG_ERROR("ONC Certificate Import Error", message) |
| 26 | 27 |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 } | 312 } |
| 312 | 313 |
| 313 std::string decoded_pkcs12; | 314 std::string decoded_pkcs12; |
| 314 if (!base::Base64Decode(pkcs12_data, &decoded_pkcs12)) { | 315 if (!base::Base64Decode(pkcs12_data, &decoded_pkcs12)) { |
| 315 ONC_LOG_ERROR( | 316 ONC_LOG_ERROR( |
| 316 "Unable to base64 decode PKCS#12 data: \"" + pkcs12_data + "\"."); | 317 "Unable to base64 decode PKCS#12 data: \"" + pkcs12_data + "\"."); |
| 317 return false; | 318 return false; |
| 318 } | 319 } |
| 319 | 320 |
| 320 // Since this has a private key, always use the private module. | 321 // Since this has a private key, always use the private module. |
| 321 scoped_refptr<net::CryptoModule> module(net::CryptoModule::CreateFromHandle( | 322 crypto::ScopedPK11Slot private_slot(target_nssdb_->GetPrivateSlot()); |
| 322 target_nssdb_->GetPrivateSlot().get())); | 323 if (!private_slot) |
| 324 return false; |
| 325 scoped_refptr<net::CryptoModule> module( |
| 326 net::CryptoModule::CreateFromHandle(private_slot.get())); |
| 323 net::CertificateList imported_certs; | 327 net::CertificateList imported_certs; |
| 324 | 328 |
| 325 int import_result = target_nssdb_->ImportFromPKCS12( | 329 int import_result = target_nssdb_->ImportFromPKCS12( |
| 326 module.get(), decoded_pkcs12, base::string16(), false, &imported_certs); | 330 module.get(), decoded_pkcs12, base::string16(), false, &imported_certs); |
| 327 if (import_result != net::OK) { | 331 if (import_result != net::OK) { |
| 328 ONC_LOG_ERROR( | 332 ONC_LOG_ERROR( |
| 329 base::StringPrintf("Unable to import client certificate (error %s)", | 333 base::StringPrintf("Unable to import client certificate (error %s)", |
| 330 net::ErrorToString(import_result))); | 334 net::ErrorToString(import_result))); |
| 331 return false; | 335 return false; |
| 332 } | 336 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 353 PK11_SetPrivateKeyNickname(private_key, const_cast<char*>(guid.c_str())); | 357 PK11_SetPrivateKeyNickname(private_key, const_cast<char*>(guid.c_str())); |
| 354 SECKEY_DestroyPrivateKey(private_key); | 358 SECKEY_DestroyPrivateKey(private_key); |
| 355 } else { | 359 } else { |
| 356 ONC_LOG_WARNING("Unable to find private key for certificate."); | 360 ONC_LOG_WARNING("Unable to find private key for certificate."); |
| 357 } | 361 } |
| 358 return true; | 362 return true; |
| 359 } | 363 } |
| 360 | 364 |
| 361 } // namespace onc | 365 } // namespace onc |
| 362 } // namespace chromeos | 366 } // namespace chromeos |
| OLD | NEW |