| 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 "chromeos/network/certificate_pattern.h" | 5 #include "chromeos/network/certificate_pattern.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "components/onc/onc_constants.h" | 9 #include "components/onc/onc_constants.h" |
| 10 | 10 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 common_name_.clear(); | 69 common_name_.clear(); |
| 70 locality_.clear(); | 70 locality_.clear(); |
| 71 organization_.clear(); | 71 organization_.clear(); |
| 72 organizational_unit_.clear(); | 72 organizational_unit_.clear(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 scoped_ptr<base::DictionaryValue> IssuerSubjectPattern::CreateONCDictionary() | 75 scoped_ptr<base::DictionaryValue> IssuerSubjectPattern::CreateONCDictionary() |
| 76 const { | 76 const { |
| 77 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 77 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
| 78 if (!common_name_.empty()) | 78 if (!common_name_.empty()) |
| 79 dict->SetString(onc::certificate::kCommonName, common_name_); | 79 dict->SetString(onc::client_cert::kCommonName, common_name_); |
| 80 if (!locality_.empty()) | 80 if (!locality_.empty()) |
| 81 dict->SetString(onc::certificate::kLocality, locality_); | 81 dict->SetString(onc::client_cert::kLocality, locality_); |
| 82 if (!organization_.empty()) | 82 if (!organization_.empty()) |
| 83 dict->SetString(onc::certificate::kOrganization, organization_); | 83 dict->SetString(onc::client_cert::kOrganization, organization_); |
| 84 if (!organizational_unit_.empty()) | 84 if (!organizational_unit_.empty()) |
| 85 dict->SetString(onc::certificate::kOrganizationalUnit, | 85 dict->SetString(onc::client_cert::kOrganizationalUnit, |
| 86 organizational_unit_); | 86 organizational_unit_); |
| 87 return dict.Pass(); | 87 return dict.Pass(); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void IssuerSubjectPattern::ReadFromONCDictionary( | 90 void IssuerSubjectPattern::ReadFromONCDictionary( |
| 91 const base::DictionaryValue& dict) { | 91 const base::DictionaryValue& dict) { |
| 92 Clear(); | 92 Clear(); |
| 93 | 93 |
| 94 dict.GetStringWithoutPathExpansion(onc::certificate::kCommonName, | 94 dict.GetStringWithoutPathExpansion(onc::client_cert::kCommonName, |
| 95 &common_name_); | 95 &common_name_); |
| 96 dict.GetStringWithoutPathExpansion(onc::certificate::kLocality, &locality_); | 96 dict.GetStringWithoutPathExpansion(onc::client_cert::kLocality, &locality_); |
| 97 dict.GetStringWithoutPathExpansion(onc::certificate::kOrganization, | 97 dict.GetStringWithoutPathExpansion(onc::client_cert::kOrganization, |
| 98 &organization_); | 98 &organization_); |
| 99 dict.GetStringWithoutPathExpansion(onc::certificate::kOrganizationalUnit, | 99 dict.GetStringWithoutPathExpansion(onc::client_cert::kOrganizationalUnit, |
| 100 &organizational_unit_); | 100 &organizational_unit_); |
| 101 } | 101 } |
| 102 | 102 |
| 103 //////////////////////////////////////////////////////////////////////////////// | 103 //////////////////////////////////////////////////////////////////////////////// |
| 104 // CertificatePattern | 104 // CertificatePattern |
| 105 | 105 |
| 106 CertificatePattern::CertificatePattern() { | 106 CertificatePattern::CertificatePattern() { |
| 107 } | 107 } |
| 108 | 108 |
| 109 CertificatePattern::~CertificatePattern() { | 109 CertificatePattern::~CertificatePattern() { |
| 110 } | 110 } |
| 111 | 111 |
| 112 bool CertificatePattern::Empty() const { | 112 bool CertificatePattern::Empty() const { |
| 113 return issuer_ca_pems_.empty() && issuer_.Empty() && subject_.Empty(); | 113 return issuer_ca_pems_.empty() && issuer_.Empty() && subject_.Empty(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void CertificatePattern::Clear() { | 116 void CertificatePattern::Clear() { |
| 117 issuer_ca_pems_.clear(); | 117 issuer_ca_pems_.clear(); |
| 118 issuer_.Clear(); | 118 issuer_.Clear(); |
| 119 subject_.Clear(); | 119 subject_.Clear(); |
| 120 enrollment_uri_list_.clear(); | 120 enrollment_uri_list_.clear(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 scoped_ptr<base::DictionaryValue> CertificatePattern::CreateONCDictionary() | 123 scoped_ptr<base::DictionaryValue> CertificatePattern::CreateONCDictionary() |
| 124 const { | 124 const { |
| 125 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 125 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
| 126 | 126 |
| 127 if (!issuer_ca_pems_.empty()) { | 127 if (!issuer_ca_pems_.empty()) { |
| 128 dict->SetWithoutPathExpansion(onc::certificate::kIssuerCAPEMs, | 128 dict->SetWithoutPathExpansion(onc::client_cert::kIssuerCAPEMs, |
| 129 CreateListFromStrings(issuer_ca_pems_)); | 129 CreateListFromStrings(issuer_ca_pems_)); |
| 130 } | 130 } |
| 131 | 131 |
| 132 if (!issuer_.Empty()) | 132 if (!issuer_.Empty()) |
| 133 dict->SetWithoutPathExpansion(onc::certificate::kIssuer, | 133 dict->SetWithoutPathExpansion(onc::client_cert::kIssuer, |
| 134 issuer_.CreateONCDictionary().release()); | 134 issuer_.CreateONCDictionary().release()); |
| 135 | 135 |
| 136 if (!subject_.Empty()) | 136 if (!subject_.Empty()) |
| 137 dict->SetWithoutPathExpansion(onc::certificate::kSubject, | 137 dict->SetWithoutPathExpansion(onc::client_cert::kSubject, |
| 138 subject_.CreateONCDictionary().release()); | 138 subject_.CreateONCDictionary().release()); |
| 139 | 139 |
| 140 if (!enrollment_uri_list_.empty()) | 140 if (!enrollment_uri_list_.empty()) |
| 141 dict->SetWithoutPathExpansion(onc::certificate::kEnrollmentURI, | 141 dict->SetWithoutPathExpansion(onc::client_cert::kEnrollmentURI, |
| 142 CreateListFromStrings(enrollment_uri_list_)); | 142 CreateListFromStrings(enrollment_uri_list_)); |
| 143 return dict.Pass(); | 143 return dict.Pass(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 bool CertificatePattern::ReadFromONCDictionary( | 146 bool CertificatePattern::ReadFromONCDictionary( |
| 147 const base::DictionaryValue& dict) { | 147 const base::DictionaryValue& dict) { |
| 148 Clear(); | 148 Clear(); |
| 149 | 149 |
| 150 const base::DictionaryValue* child_dict = NULL; | 150 const base::DictionaryValue* child_dict = NULL; |
| 151 const base::ListValue* child_list = NULL; | 151 const base::ListValue* child_list = NULL; |
| 152 | 152 |
| 153 // All of these are optional. | 153 // All of these are optional. |
| 154 if (dict.GetListWithoutPathExpansion(onc::certificate::kIssuerCAPEMs, | 154 if (dict.GetListWithoutPathExpansion(onc::client_cert::kIssuerCAPEMs, |
| 155 &child_list) && | 155 &child_list) && |
| 156 child_list) { | 156 child_list) { |
| 157 if (!GetAsListOfStrings(*child_list, &issuer_ca_pems_)) | 157 if (!GetAsListOfStrings(*child_list, &issuer_ca_pems_)) |
| 158 return false; | 158 return false; |
| 159 } | 159 } |
| 160 if (dict.GetDictionaryWithoutPathExpansion(onc::certificate::kIssuer, | 160 if (dict.GetDictionaryWithoutPathExpansion(onc::client_cert::kIssuer, |
| 161 &child_dict) && | 161 &child_dict) && |
| 162 child_dict) { | 162 child_dict) { |
| 163 issuer_.ReadFromONCDictionary(*child_dict); | 163 issuer_.ReadFromONCDictionary(*child_dict); |
| 164 } | 164 } |
| 165 child_dict = NULL; | 165 child_dict = NULL; |
| 166 if (dict.GetDictionaryWithoutPathExpansion(onc::certificate::kSubject, | 166 if (dict.GetDictionaryWithoutPathExpansion(onc::client_cert::kSubject, |
| 167 &child_dict) && | 167 &child_dict) && |
| 168 child_dict) { | 168 child_dict) { |
| 169 subject_.ReadFromONCDictionary(*child_dict); | 169 subject_.ReadFromONCDictionary(*child_dict); |
| 170 } | 170 } |
| 171 child_list = NULL; | 171 child_list = NULL; |
| 172 if (dict.GetListWithoutPathExpansion(onc::certificate::kEnrollmentURI, | 172 if (dict.GetListWithoutPathExpansion(onc::client_cert::kEnrollmentURI, |
| 173 &child_list) && | 173 &child_list) && |
| 174 child_list) { | 174 child_list) { |
| 175 if (!GetAsListOfStrings(*child_list, &enrollment_uri_list_)) | 175 if (!GetAsListOfStrings(*child_list, &enrollment_uri_list_)) |
| 176 return false; | 176 return false; |
| 177 } | 177 } |
| 178 | 178 |
| 179 return true; | 179 return true; |
| 180 } | 180 } |
| 181 | 181 |
| 182 } // namespace chromeos | 182 } // namespace chromeos |
| OLD | NEW |