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

Side by Side Diff: chromeos/network/certificate_pattern.cc

Issue 16946002: Resolve certificate references in ONC by PEM. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added a unit test for the resolve function. Created 7 years, 5 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
« no previous file with comments | « chromeos/network/certificate_pattern.h ('k') | chromeos/network/certificate_pattern_matcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 "chromeos/network/onc/onc_constants.h"
9 10
10 namespace chromeos { 11 namespace chromeos {
11 12
12 namespace { 13 namespace {
13 14
14 // Keys for converting classes below to/from dictionaries. 15 // Keys for converting classes below to/from dictionaries.
15 const char kCommonNameKey[] = "CommonName"; 16 const char kCommonNameKey[] = "CommonName";
16 const char kLocalityKey[] = "Locality"; 17 const char kLocalityKey[] = "Locality";
17 const char kOrganizationKey[] = "Organization"; 18 const char kOrganizationKey[] = "Organization";
18 const char kOrganizationalUnitKey[] = "OrganizationalUnit"; 19 const char kOrganizationalUnitKey[] = "OrganizationalUnit";
19 const char kIssuerCaRefKey[] = "IssuerCARef";
20 const char kIssuerKey[] = "Issuer"; 20 const char kIssuerKey[] = "Issuer";
21 const char kSubjectKey[] = "Subject"; 21 const char kSubjectKey[] = "Subject";
22 const char kEnrollmentUriKey[] = "EnrollmentURI"; 22 const char kEnrollmentUriKey[] = "EnrollmentURI";
23 23
24 bool GetAsListOfStrings(const base::Value& value, 24 bool GetAsListOfStrings(const base::Value& value,
25 std::vector<std::string>* result) { 25 std::vector<std::string>* result) {
26 const base::ListValue* list = NULL; 26 const base::ListValue* list = NULL;
27 if (!value.GetAsList(&list)) 27 if (!value.GetAsList(&list))
28 return false; 28 return false;
29 result->clear(); 29 result->clear();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 } 107 }
108 108
109 //////////////////////////////////////////////////////////////////////////////// 109 ////////////////////////////////////////////////////////////////////////////////
110 // CertificatePattern 110 // CertificatePattern
111 111
112 CertificatePattern::CertificatePattern() {} 112 CertificatePattern::CertificatePattern() {}
113 113
114 CertificatePattern::~CertificatePattern() {} 114 CertificatePattern::~CertificatePattern() {}
115 115
116 bool CertificatePattern::Empty() const { 116 bool CertificatePattern::Empty() const {
117 return issuer_ca_ref_list_.empty() && 117 return issuer_ca_pems_.empty() &&
118 issuer_.Empty() && 118 issuer_.Empty() &&
119 subject_.Empty(); 119 subject_.Empty();
120 } 120 }
121 121
122 void CertificatePattern::Clear() { 122 void CertificatePattern::Clear() {
123 issuer_ca_ref_list_.clear(); 123 issuer_ca_pems_.clear();
124 issuer_.Clear(); 124 issuer_.Clear();
125 subject_.Clear(); 125 subject_.Clear();
126 enrollment_uri_list_.clear(); 126 enrollment_uri_list_.clear();
127 } 127 }
128 128
129 base::DictionaryValue* CertificatePattern::CreateAsDictionary() const { 129 base::DictionaryValue* CertificatePattern::CreateAsDictionary() const {
130 base::DictionaryValue* dict = new base::DictionaryValue; 130 base::DictionaryValue* dict = new base::DictionaryValue;
131 131
132 if (!issuer_ca_ref_list_.empty()) 132 if (!issuer_ca_pems_.empty()) {
133 dict->Set(kIssuerCaRefKey, CreateListFromStrings(issuer_ca_ref_list_)); 133 dict->Set(onc::certificate::kIssuerCAPEMs,
134 CreateListFromStrings(issuer_ca_pems_));
135 }
134 136
135 if (!issuer_.Empty()) 137 if (!issuer_.Empty())
136 dict->Set(kIssuerKey, issuer_.CreateAsDictionary()); 138 dict->Set(kIssuerKey, issuer_.CreateAsDictionary());
137 139
138 if (!subject_.Empty()) 140 if (!subject_.Empty())
139 dict->Set(kSubjectKey, subject_.CreateAsDictionary()); 141 dict->Set(kSubjectKey, subject_.CreateAsDictionary());
140 142
141 if (!enrollment_uri_list_.empty()) 143 if (!enrollment_uri_list_.empty())
142 dict->Set(kEnrollmentUriKey, CreateListFromStrings(enrollment_uri_list_)); 144 dict->Set(kEnrollmentUriKey, CreateListFromStrings(enrollment_uri_list_));
143 return dict; 145 return dict;
144 } 146 }
145 147
146 bool CertificatePattern::CopyFromDictionary(const base::DictionaryValue &dict) { 148 bool CertificatePattern::CopyFromDictionary(const base::DictionaryValue &dict) {
147 const base::DictionaryValue* child_dict = NULL; 149 const base::DictionaryValue* child_dict = NULL;
148 const base::ListValue* child_list = NULL; 150 const base::ListValue* child_list = NULL;
149 Clear(); 151 Clear();
150 152
151 // All of these are optional. 153 // All of these are optional.
152 if (dict.GetList(kIssuerCaRefKey, &child_list) && child_list) { 154 if (dict.GetList(onc::certificate::kIssuerCAPEMs, &child_list) &&
153 if (!GetAsListOfStrings(*child_list, &issuer_ca_ref_list_)) 155 child_list) {
156 if (!GetAsListOfStrings(*child_list, &issuer_ca_pems_))
154 return false; 157 return false;
155 } 158 }
156 if (dict.GetDictionary(kIssuerKey, &child_dict) && child_dict) { 159 if (dict.GetDictionary(kIssuerKey, &child_dict) && child_dict) {
157 if (!issuer_.CopyFromDictionary(*child_dict)) 160 if (!issuer_.CopyFromDictionary(*child_dict))
158 return false; 161 return false;
159 } 162 }
160 child_dict = NULL; 163 child_dict = NULL;
161 if (dict.GetDictionary(kSubjectKey, &child_dict) && child_dict) { 164 if (dict.GetDictionary(kSubjectKey, &child_dict) && child_dict) {
162 if (!subject_.CopyFromDictionary(*child_dict)) 165 if (!subject_.CopyFromDictionary(*child_dict))
163 return false; 166 return false;
164 } 167 }
165 child_list = NULL; 168 child_list = NULL;
166 if (dict.GetList(kEnrollmentUriKey, &child_list) && child_list) { 169 if (dict.GetList(kEnrollmentUriKey, &child_list) && child_list) {
167 if (!GetAsListOfStrings(*child_list, &enrollment_uri_list_)) 170 if (!GetAsListOfStrings(*child_list, &enrollment_uri_list_))
168 return false; 171 return false;
169 } 172 }
170 173
171 // If we didn't copy anything from the dictionary, then it had better be 174 // If we didn't copy anything from the dictionary, then it had better be
172 // empty. 175 // empty.
173 DCHECK(dict.empty() == Empty()); 176 DCHECK(dict.empty() == Empty());
174 if (dict.empty() != Empty()) 177 if (dict.empty() != Empty())
175 return false; 178 return false;
176 179
177 return true; 180 return true;
178 } 181 }
179 182
180 } // namespace chromeos 183 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/network/certificate_pattern.h ('k') | chromeos/network/certificate_pattern_matcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698