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

Side by Side Diff: chrome/browser/chromeos/cros/onc_network_parser.cc

Issue 10916094: Move the NSS functions out of CertDatabase into a new NSSCertDatabase class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 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 | Annotate | Revision Log
OLDNEW
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/onc_network_parser.h" 5 #include "chrome/browser/chromeos/cros/onc_network_parser.h"
6 6
7 #include <keyhi.h> 7 #include <keyhi.h>
8 #include <pk11pub.h> 8 #include <pk11pub.h>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 10 matching lines...) Expand all
21 #include "chrome/browser/chromeos/cros/onc_constants.h" 21 #include "chrome/browser/chromeos/cros/onc_constants.h"
22 #include "chrome/browser/chromeos/proxy_config_service_impl.h" 22 #include "chrome/browser/chromeos/proxy_config_service_impl.h"
23 #include "chrome/browser/prefs/proxy_config_dictionary.h" 23 #include "chrome/browser/prefs/proxy_config_dictionary.h"
24 #include "chrome/common/net/x509_certificate_model.h" 24 #include "chrome/common/net/x509_certificate_model.h"
25 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
26 #include "crypto/encryptor.h" 26 #include "crypto/encryptor.h"
27 #include "crypto/hmac.h" 27 #include "crypto/hmac.h"
28 #include "crypto/scoped_nss_types.h" 28 #include "crypto/scoped_nss_types.h"
29 #include "crypto/symmetric_key.h" 29 #include "crypto/symmetric_key.h"
30 #include "grit/generated_resources.h" 30 #include "grit/generated_resources.h"
31 #include "net/base/cert_database.h"
32 #include "net/base/crypto_module.h" 31 #include "net/base/crypto_module.h"
33 #include "net/base/net_errors.h" 32 #include "net/base/net_errors.h"
33 #include "net/base/nss_cert_database.h"
34 #include "net/base/pem_tokenizer.h" 34 #include "net/base/pem_tokenizer.h"
35 #include "net/base/x509_certificate.h" 35 #include "net/base/x509_certificate.h"
36 #include "net/proxy/proxy_bypass_rules.h" 36 #include "net/proxy/proxy_bypass_rules.h"
37 #include "third_party/cros_system_api/dbus/service_constants.h" 37 #include "third_party/cros_system_api/dbus/service_constants.h"
38 #include "ui/base/l10n/l10n_util.h" 38 #include "ui/base/l10n/l10n_util.h"
39 39
40 namespace chromeos { 40 namespace chromeos {
41 41
42 // Local constants. 42 // Local constants.
43 namespace { 43 namespace {
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 LOG(WARNING) << "ONC File: certificate missing identifier at index" 518 LOG(WARNING) << "ONC File: certificate missing identifier at index"
519 << cert_index; 519 << cert_index;
520 parse_error_ = l10n_util::GetStringUTF8( 520 parse_error_ = l10n_util::GetStringUTF8(
521 IDS_NETWORK_CONFIG_ERROR_CERT_GUID_MISSING); 521 IDS_NETWORK_CONFIG_ERROR_CERT_GUID_MISSING);
522 return NULL; 522 return NULL;
523 } 523 }
524 524
525 if (!certificate->GetBoolean("Remove", &remove)) 525 if (!certificate->GetBoolean("Remove", &remove))
526 remove = false; 526 remove = false;
527 527
528 net::CertDatabase cert_database; 528 net::NSSCertDatabase cert_database;
529 if (remove) { 529 if (remove) {
530 if (!DeleteCertAndKeyByNickname(guid)) { 530 if (!DeleteCertAndKeyByNickname(guid)) {
531 parse_error_ = l10n_util::GetStringUTF8( 531 parse_error_ = l10n_util::GetStringUTF8(
532 IDS_NETWORK_CONFIG_ERROR_CERT_DELETE); 532 IDS_NETWORK_CONFIG_ERROR_CERT_DELETE);
533 } 533 }
534 return NULL; 534 return NULL;
535 } 535 }
536 536
537 // Not removing, so let's get the data we need to add this certificate. 537 // Not removing, so let's get the data we need to add this certificate.
538 std::string cert_type; 538 std::string cert_type;
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 } 815 }
816 return true; 816 return true;
817 } 817 }
818 818
819 scoped_refptr<net::X509Certificate> 819 scoped_refptr<net::X509Certificate>
820 OncNetworkParser::ParseServerOrCaCertificate( 820 OncNetworkParser::ParseServerOrCaCertificate(
821 int cert_index, 821 int cert_index,
822 const std::string& cert_type, 822 const std::string& cert_type,
823 const std::string& guid, 823 const std::string& guid,
824 base::DictionaryValue* certificate) { 824 base::DictionaryValue* certificate) {
825 net::CertDatabase cert_database; 825 net::NSSCertDatabase cert_database;
826 bool web_trust = false; 826 bool web_trust = false;
827 base::ListValue* trust_list = NULL; 827 base::ListValue* trust_list = NULL;
828 if (certificate->GetList("Trust", &trust_list)) { 828 if (certificate->GetList("Trust", &trust_list)) {
829 for (size_t i = 0; i < trust_list->GetSize(); ++i) { 829 for (size_t i = 0; i < trust_list->GetSize(); ++i) {
830 std::string trust_type; 830 std::string trust_type;
831 if (!trust_list->GetString(i, &trust_type)) { 831 if (!trust_list->GetString(i, &trust_type)) {
832 LOG(WARNING) << "ONC File: certificate trust is invalid at index " 832 LOG(WARNING) << "ONC File: certificate trust is invalid at index "
833 << cert_index; 833 << cert_index;
834 parse_error_ = l10n_util::GetStringUTF8( 834 parse_error_ = l10n_util::GetStringUTF8(
835 IDS_NETWORK_CONFIG_ERROR_CERT_TRUST_INVALID); 835 IDS_NETWORK_CONFIG_ERROR_CERT_TRUST_INVALID);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 ListCertsWithNickname(guid, &certs); 944 ListCertsWithNickname(guid, &certs);
945 if (!certs.empty()) { 945 if (!certs.empty()) {
946 LOG(WARNING) << "Cert GUID is already in use: " << guid; 946 LOG(WARNING) << "Cert GUID is already in use: " << guid;
947 parse_error_ = l10n_util::GetStringUTF8( 947 parse_error_ = l10n_util::GetStringUTF8(
948 IDS_NETWORK_CONFIG_ERROR_CERT_GUID_COLLISION); 948 IDS_NETWORK_CONFIG_ERROR_CERT_GUID_COLLISION);
949 return NULL; 949 return NULL;
950 } 950 }
951 951
952 net::CertificateList cert_list; 952 net::CertificateList cert_list;
953 cert_list.push_back(x509_cert); 953 cert_list.push_back(x509_cert);
954 net::CertDatabase::ImportCertFailureList failures; 954 net::NSSCertDatabase::ImportCertFailureList failures;
955 bool success = false; 955 bool success = false;
956 net::CertDatabase::TrustBits trust = web_trust ? 956 net::NSSCertDatabase::TrustBits trust = web_trust ?
957 net::CertDatabase::TRUSTED_SSL : 957 net::NSSCertDatabase::TRUSTED_SSL :
958 net::CertDatabase::TRUST_DEFAULT; 958 net::NSSCertDatabase::TRUST_DEFAULT;
959 if (cert_type == "Server") { 959 if (cert_type == "Server") {
960 success = cert_database.ImportServerCert(cert_list, trust, &failures); 960 success = cert_database.ImportServerCert(cert_list, trust, &failures);
961 } else { // Authority cert 961 } else { // Authority cert
962 success = cert_database.ImportCACerts(cert_list, trust, &failures); 962 success = cert_database.ImportCACerts(cert_list, trust, &failures);
963 } 963 }
964 if (!failures.empty()) { 964 if (!failures.empty()) {
965 LOG(WARNING) << "ONC File: Error (" 965 LOG(WARNING) << "ONC File: Error ("
966 << net::ErrorToString(failures[0].net_error) 966 << net::ErrorToString(failures[0].net_error)
967 << ") importing " << cert_type << " certificate at index " 967 << ") importing " << cert_type << " certificate at index "
968 << cert_index; 968 << cert_index;
(...skipping 11 matching lines...) Expand all
980 VLOG(2) << "Successfully imported server/ca certificate at index " 980 VLOG(2) << "Successfully imported server/ca certificate at index "
981 << cert_index; 981 << cert_index;
982 982
983 return x509_cert; 983 return x509_cert;
984 } 984 }
985 985
986 scoped_refptr<net::X509Certificate> OncNetworkParser::ParseClientCertificate( 986 scoped_refptr<net::X509Certificate> OncNetworkParser::ParseClientCertificate(
987 int cert_index, 987 int cert_index,
988 const std::string& guid, 988 const std::string& guid,
989 base::DictionaryValue* certificate) { 989 base::DictionaryValue* certificate) {
990 net::CertDatabase cert_database; 990 net::NSSCertDatabase cert_database;
991 std::string pkcs12_data; 991 std::string pkcs12_data;
992 if (!certificate->GetString("PKCS12", &pkcs12_data) || 992 if (!certificate->GetString("PKCS12", &pkcs12_data) ||
993 pkcs12_data.empty()) { 993 pkcs12_data.empty()) {
994 LOG(WARNING) << "ONC File: PKCS12 data is missing for Client " 994 LOG(WARNING) << "ONC File: PKCS12 data is missing for Client "
995 << "certificate at index " << cert_index; 995 << "certificate at index " << cert_index;
996 parse_error_ = l10n_util::GetStringUTF8( 996 parse_error_ = l10n_util::GetStringUTF8(
997 IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MISSING); 997 IDS_NETWORK_CONFIG_ERROR_CERT_DATA_MISSING);
998 return NULL; 998 return NULL;
999 } 999 }
1000 1000
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 }; 1065 };
1066 CR_DEFINE_STATIC_LOCAL(EnumMapper<ClientCertType>, parser, 1066 CR_DEFINE_STATIC_LOCAL(EnumMapper<ClientCertType>, parser,
1067 (table, arraysize(table), CLIENT_CERT_TYPE_NONE)); 1067 (table, arraysize(table), CLIENT_CERT_TYPE_NONE));
1068 return parser.Get(type); 1068 return parser.Get(type);
1069 } 1069 }
1070 1070
1071 // static 1071 // static
1072 void OncNetworkParser::ListCertsWithNickname(const std::string& label, 1072 void OncNetworkParser::ListCertsWithNickname(const std::string& label,
1073 net::CertificateList* result) { 1073 net::CertificateList* result) {
1074 net::CertificateList all_certs; 1074 net::CertificateList all_certs;
1075 net::CertDatabase cert_db; 1075 net::NSSCertDatabase cert_db;
1076 cert_db.ListCerts(&all_certs); 1076 cert_db.ListCerts(&all_certs);
1077 result->clear(); 1077 result->clear();
1078 for (net::CertificateList::iterator iter = all_certs.begin(); 1078 for (net::CertificateList::iterator iter = all_certs.begin();
1079 iter != all_certs.end(); ++iter) { 1079 iter != all_certs.end(); ++iter) {
1080 if (iter->get()->os_cert_handle()->nickname) { 1080 if (iter->get()->os_cert_handle()->nickname) {
1081 // Separate the nickname stored in the certificate at the colon, since 1081 // Separate the nickname stored in the certificate at the colon, since
1082 // NSS likes to store it as token:nickname. 1082 // NSS likes to store it as token:nickname.
1083 const char* delimiter = 1083 const char* delimiter =
1084 ::strchr(iter->get()->os_cert_handle()->nickname, ':'); 1084 ::strchr(iter->get()->os_cert_handle()->nickname, ':');
1085 if (delimiter) { 1085 if (delimiter) {
(...skipping 18 matching lines...) Expand all
1104 PORT_Free(private_key_nickname); 1104 PORT_Free(private_key_nickname);
1105 SECKEY_DestroyPrivateKey(private_key); 1105 SECKEY_DestroyPrivateKey(private_key);
1106 } 1106 }
1107 } 1107 }
1108 } 1108 }
1109 1109
1110 // static 1110 // static
1111 bool OncNetworkParser::DeleteCertAndKeyByNickname(const std::string& label) { 1111 bool OncNetworkParser::DeleteCertAndKeyByNickname(const std::string& label) {
1112 net::CertificateList cert_list; 1112 net::CertificateList cert_list;
1113 ListCertsWithNickname(label, &cert_list); 1113 ListCertsWithNickname(label, &cert_list);
1114 net::CertDatabase cert_db; 1114 net::NSSCertDatabase cert_db;
1115 bool result = true; 1115 bool result = true;
1116 for (net::CertificateList::iterator iter = cert_list.begin(); 1116 for (net::CertificateList::iterator iter = cert_list.begin();
1117 iter != cert_list.end(); ++iter) { 1117 iter != cert_list.end(); ++iter) {
1118 // If we fail, we try and delete the rest still. 1118 // If we fail, we try and delete the rest still.
1119 // TODO(gspencer): this isn't very "transactional". If we fail on some, but 1119 // TODO(gspencer): this isn't very "transactional". If we fail on some, but
1120 // not all, then it's possible to leave things in a weird state. 1120 // not all, then it's possible to leave things in a weird state.
1121 // Luckily there should only be one cert with a particular 1121 // Luckily there should only be one cert with a particular
1122 // label, and the cert not being found is one of the few reasons the 1122 // label, and the cert not being found is one of the few reasons the
1123 // delete could fail, but still... The other choice is to return 1123 // delete could fail, but still... The other choice is to return
1124 // failure immediately, but that doesn't seem to do what is intended. 1124 // failure immediately, but that doesn't seem to do what is intended.
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after
2011 // on the value of AuthenticationType. 2011 // on the value of AuthenticationType.
2012 { "L2TP-IPsec", PROVIDER_TYPE_L2TP_IPSEC_PSK }, 2012 { "L2TP-IPsec", PROVIDER_TYPE_L2TP_IPSEC_PSK },
2013 { "OpenVPN", PROVIDER_TYPE_OPEN_VPN }, 2013 { "OpenVPN", PROVIDER_TYPE_OPEN_VPN },
2014 }; 2014 };
2015 CR_DEFINE_STATIC_LOCAL(EnumMapper<ProviderType>, parser, 2015 CR_DEFINE_STATIC_LOCAL(EnumMapper<ProviderType>, parser,
2016 (table, arraysize(table), PROVIDER_TYPE_MAX)); 2016 (table, arraysize(table), PROVIDER_TYPE_MAX));
2017 return parser.Get(type); 2017 return parser.Get(type);
2018 } 2018 }
2019 2019
2020 } // namespace chromeos 2020 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698