Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chromeos / network / onc / onc_signature.cc
blob562730c9865dba8b5d71db39743f0f857905863d
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
3 // found in the LICENSE file.
5 #include "chromeos/network/onc/onc_signature.h"
7 #include "components/onc/onc_constants.h"
8 #include "third_party/cros_system_api/dbus/service_constants.h"
10 using base::Value;
12 namespace chromeos {
13 namespace onc {
14 namespace {
16 const OncValueSignature kBoolSignature = {base::Value::TYPE_BOOLEAN, NULL};
17 const OncValueSignature kStringSignature = {base::Value::TYPE_STRING, NULL};
18 const OncValueSignature kIntegerSignature = {base::Value::TYPE_INTEGER, NULL};
19 const OncValueSignature kStringListSignature = {base::Value::TYPE_LIST,
20 NULL,
21 &kStringSignature};
22 const OncValueSignature kIntegerListSignature = {base::Value::TYPE_LIST,
23 NULL,
24 &kIntegerSignature};
25 const OncValueSignature kIPConfigListSignature = {base::Value::TYPE_LIST,
26 NULL,
27 &kIPConfigSignature};
28 const OncValueSignature kCellularApnListSignature = {base::Value::TYPE_LIST,
29 NULL,
30 &kCellularApnSignature};
31 const OncValueSignature kCellularFoundNetworkListSignature = {
32 base::Value::TYPE_LIST,
33 NULL,
34 &kCellularFoundNetworkSignature};
36 const OncFieldSignature issuer_subject_pattern_fields[] = {
37 {::onc::client_cert::kCommonName, &kStringSignature},
38 {::onc::client_cert::kLocality, &kStringSignature},
39 {::onc::client_cert::kOrganization, &kStringSignature},
40 {::onc::client_cert::kOrganizationalUnit, &kStringSignature},
41 {NULL}};
43 const OncFieldSignature certificate_pattern_fields[] = {
44 {::onc::kRecommended, &kRecommendedSignature},
45 {::onc::client_cert::kEnrollmentURI, &kStringListSignature},
46 {::onc::client_cert::kIssuer, &kIssuerSubjectPatternSignature},
47 {::onc::client_cert::kIssuerCARef, &kStringListSignature},
48 // Used internally. Not officially supported.
49 {::onc::client_cert::kIssuerCAPEMs, &kStringListSignature},
50 {::onc::client_cert::kSubject, &kIssuerSubjectPatternSignature},
51 {NULL}};
53 const OncFieldSignature eap_fields[] = {
54 {::onc::kRecommended, &kRecommendedSignature},
55 {::onc::eap::kAnonymousIdentity, &kStringSignature},
56 {::onc::client_cert::kClientCertPattern, &kCertificatePatternSignature},
57 {::onc::client_cert::kClientCertRef, &kStringSignature},
58 {::onc::client_cert::kClientCertType, &kStringSignature},
59 {::onc::eap::kIdentity, &kStringSignature},
60 {::onc::eap::kInner, &kStringSignature},
61 {::onc::eap::kOuter, &kStringSignature},
62 {::onc::eap::kPassword, &kStringSignature},
63 {::onc::eap::kSaveCredentials, &kBoolSignature},
64 // Used internally. Not officially supported.
65 {::onc::eap::kServerCAPEMs, &kStringListSignature},
66 {::onc::eap::kServerCARef, &kStringSignature},
67 {::onc::eap::kServerCARefs, &kStringListSignature},
68 {::onc::eap::kUseSystemCAs, &kBoolSignature},
69 {::onc::eap::kUseProactiveKeyCaching, &kBoolSignature},
70 {NULL}};
72 const OncFieldSignature ipsec_fields[] = {
73 {::onc::kRecommended, &kRecommendedSignature},
74 {::onc::ipsec::kAuthenticationType, &kStringSignature},
75 {::onc::client_cert::kClientCertPattern, &kCertificatePatternSignature},
76 {::onc::client_cert::kClientCertRef, &kStringSignature},
77 {::onc::client_cert::kClientCertType, &kStringSignature},
78 {::onc::ipsec::kGroup, &kStringSignature},
79 {::onc::ipsec::kIKEVersion, &kIntegerSignature},
80 {::onc::ipsec::kPSK, &kStringSignature},
81 {::onc::vpn::kSaveCredentials, &kBoolSignature},
82 // Used internally. Not officially supported.
83 {::onc::ipsec::kServerCAPEMs, &kStringListSignature},
84 {::onc::ipsec::kServerCARef, &kStringSignature},
85 {::onc::ipsec::kServerCARefs, &kStringListSignature},
86 {::onc::ipsec::kXAUTH, &kXAUTHSignature},
87 // Not yet supported.
88 // { ipsec::kEAP, &kEAPSignature },
89 {NULL}};
91 const OncFieldSignature xauth_fields[] = {
92 {::onc::vpn::kPassword, &kStringSignature},
93 {::onc::vpn::kUsername, &kStringSignature},
94 {NULL}};
96 const OncFieldSignature l2tp_fields[] = {
97 {::onc::kRecommended, &kRecommendedSignature},
98 {::onc::l2tp::kPassword, &kStringSignature},
99 {::onc::l2tp::kSaveCredentials, &kBoolSignature},
100 {::onc::l2tp::kUsername, &kStringSignature},
101 {::onc::l2tp::kLcpEchoDisabled, &kBoolSignature},
102 {NULL}};
104 const OncFieldSignature openvpn_fields[] = {
105 {::onc::kRecommended, &kRecommendedSignature},
106 {::onc::openvpn::kAuth, &kStringSignature},
107 {::onc::openvpn::kAuthNoCache, &kBoolSignature},
108 {::onc::openvpn::kAuthRetry, &kStringSignature},
109 {::onc::openvpn::kCipher, &kStringSignature},
110 {::onc::client_cert::kClientCertPattern, &kCertificatePatternSignature},
111 {::onc::client_cert::kClientCertRef, &kStringSignature},
112 {::onc::client_cert::kClientCertType, &kStringSignature},
113 {::onc::openvpn::kCompLZO, &kStringSignature},
114 {::onc::openvpn::kCompNoAdapt, &kBoolSignature},
115 {::onc::openvpn::kIgnoreDefaultRoute, &kBoolSignature},
116 {::onc::openvpn::kKeyDirection, &kStringSignature},
117 {::onc::openvpn::kNsCertType, &kStringSignature},
118 {::onc::openvpn::kOTP, &kStringSignature},
119 {::onc::openvpn::kPassword, &kStringSignature},
120 {::onc::openvpn::kPort, &kIntegerSignature},
121 {::onc::openvpn::kProto, &kStringSignature},
122 {::onc::openvpn::kPushPeerInfo, &kBoolSignature},
123 {::onc::openvpn::kRemoteCertEKU, &kStringSignature},
124 {::onc::openvpn::kRemoteCertKU, &kStringListSignature},
125 {::onc::openvpn::kRemoteCertTLS, &kStringSignature},
126 {::onc::openvpn::kRenegSec, &kIntegerSignature},
127 {::onc::vpn::kSaveCredentials, &kBoolSignature},
128 // Used internally. Not officially supported.
129 {::onc::openvpn::kServerCAPEMs, &kStringListSignature},
130 {::onc::openvpn::kServerCARef, &kStringSignature},
131 {::onc::openvpn::kServerCARefs, &kStringListSignature},
132 // Not supported, yet.
133 {::onc::openvpn::kServerCertPEM, &kStringSignature},
134 {::onc::openvpn::kServerCertRef, &kStringSignature},
135 {::onc::openvpn::kServerPollTimeout, &kIntegerSignature},
136 {::onc::openvpn::kShaper, &kIntegerSignature},
137 {::onc::openvpn::kStaticChallenge, &kStringSignature},
138 {::onc::openvpn::kTLSAuthContents, &kStringSignature},
139 {::onc::openvpn::kTLSRemote, &kStringSignature},
140 {::onc::openvpn::kUserAuthenticationType, &kStringSignature},
141 {::onc::vpn::kUsername, &kStringSignature},
142 // Not supported, yet.
143 {::onc::openvpn::kVerb, &kStringSignature},
144 {::onc::openvpn::kVerifyHash, &kStringSignature},
145 {::onc::openvpn::kVerifyX509, &kVerifyX509Signature},
146 {NULL}};
148 const OncFieldSignature third_party_vpn_fields[] = {
149 {::onc::kRecommended, &kRecommendedSignature},
150 {::onc::third_party_vpn::kExtensionID, &kStringSignature},
151 {NULL}};
153 const OncFieldSignature verify_x509_fields[] = {
154 {::onc::verify_x509::kName, &kStringSignature},
155 {::onc::verify_x509::kType, &kStringSignature},
156 {NULL}};
158 const OncFieldSignature vpn_fields[] = {
159 {::onc::kRecommended, &kRecommendedSignature},
160 {::onc::vpn::kAutoConnect, &kBoolSignature},
161 {::onc::vpn::kHost, &kStringSignature},
162 {::onc::vpn::kIPsec, &kIPsecSignature},
163 {::onc::vpn::kL2TP, &kL2TPSignature},
164 {::onc::vpn::kOpenVPN, &kOpenVPNSignature},
165 {::onc::vpn::kThirdPartyVpn, &kThirdPartyVPNSignature},
166 {::onc::vpn::kType, &kStringSignature},
167 {NULL}};
169 const OncFieldSignature ethernet_fields[] = {
170 {::onc::kRecommended, &kRecommendedSignature},
171 {::onc::ethernet::kAuthentication, &kStringSignature},
172 {::onc::ethernet::kEAP, &kEAPSignature},
173 {NULL}};
175 const OncFieldSignature ipconfig_fields[] = {
176 {::onc::ipconfig::kGateway, &kStringSignature},
177 {::onc::ipconfig::kIPAddress, &kStringSignature},
178 {::onc::ipconfig::kNameServers, &kStringListSignature},
179 {::onc::ipconfig::kRoutingPrefix, &kIntegerSignature},
180 {::onc::ipconfig::kSearchDomains, &kStringListSignature},
181 {::onc::ipconfig::kType, &kStringSignature},
182 {::onc::ipconfig::kWebProxyAutoDiscoveryUrl, &kStringSignature},
183 {NULL}};
185 const OncFieldSignature proxy_location_fields[] = {
186 {::onc::proxy::kHost, &kStringSignature},
187 {::onc::proxy::kPort, &kIntegerSignature},
188 {NULL}};
190 const OncFieldSignature proxy_manual_fields[] = {
191 {::onc::proxy::kFtp, &kProxyLocationSignature},
192 {::onc::proxy::kHttp, &kProxyLocationSignature},
193 {::onc::proxy::kHttps, &kProxyLocationSignature},
194 {::onc::proxy::kSocks, &kProxyLocationSignature},
195 {NULL}};
197 const OncFieldSignature proxy_settings_fields[] = {
198 {::onc::kRecommended, &kRecommendedSignature},
199 {::onc::proxy::kExcludeDomains, &kStringListSignature},
200 {::onc::proxy::kManual, &kProxyManualSignature},
201 {::onc::proxy::kPAC, &kStringSignature},
202 {::onc::proxy::kType, &kStringSignature},
203 {NULL}};
205 const OncFieldSignature wifi_fields[] = {
206 {::onc::kRecommended, &kRecommendedSignature},
207 {::onc::wifi::kAllowGatewayARPPolling, &kBoolSignature},
208 {::onc::wifi::kAutoConnect, &kBoolSignature},
209 {::onc::wifi::kEAP, &kEAPSignature},
210 {::onc::wifi::kHexSSID, &kStringSignature},
211 {::onc::wifi::kHiddenSSID, &kBoolSignature},
212 {::onc::wifi::kPassphrase, &kStringSignature},
213 {::onc::wifi::kRoamThreshold, &kIntegerSignature},
214 {::onc::wifi::kSSID, &kStringSignature},
215 {::onc::wifi::kSecurity, &kStringSignature},
216 {NULL}};
218 const OncFieldSignature wifi_with_state_fields[] = {
219 {::onc::wifi::kBSSID, &kStringSignature},
220 {::onc::wifi::kFrequency, &kIntegerSignature},
221 {::onc::wifi::kFrequencyList, &kIntegerListSignature},
222 {::onc::wifi::kSignalStrength, &kIntegerSignature},
223 {NULL}};
225 const OncFieldSignature wimax_fields[] = {
226 {::onc::kRecommended, &kRecommendedSignature},
227 {::onc::wimax::kAutoConnect, &kBoolSignature},
228 {::onc::wimax::kEAP, &kEAPSignature},
229 {NULL}};
231 const OncFieldSignature wimax_with_state_fields[] = {
232 {::onc::wimax::kSignalStrength, &kIntegerSignature},
233 {NULL}};
235 const OncFieldSignature cellular_payment_portal_fields[] = {
236 {::onc::cellular_payment_portal::kMethod, &kStringSignature},
237 {::onc::cellular_payment_portal::kPostData, &kStringSignature},
238 {::onc::cellular_payment_portal::kUrl, &kStringSignature},
239 {NULL}};
241 const OncFieldSignature cellular_provider_fields[] = {
242 {::onc::cellular_provider::kCode, &kStringSignature},
243 {::onc::cellular_provider::kCountry, &kStringSignature},
244 {::onc::cellular_provider::kName, &kStringSignature},
245 {NULL}};
247 const OncFieldSignature cellular_apn_fields[] = {
248 {::onc::cellular_apn::kAccessPointName, &kStringSignature},
249 {::onc::cellular_apn::kName, &kStringSignature},
250 {::onc::cellular_apn::kUsername, &kStringSignature},
251 {::onc::cellular_apn::kPassword, &kStringSignature},
252 {::onc::cellular_apn::kLocalizedName, &kStringSignature},
253 {::onc::cellular_apn::kLanguage, &kStringSignature},
254 {NULL}};
256 const OncFieldSignature cellular_found_network_fields[] = {
257 {::onc::cellular_found_network::kStatus, &kStringSignature},
258 {::onc::cellular_found_network::kNetworkId, &kStringSignature},
259 {::onc::cellular_found_network::kShortName, &kStringSignature},
260 {::onc::cellular_found_network::kLongName, &kStringSignature},
261 {::onc::cellular_found_network::kTechnology, &kStringSignature},
262 {NULL}};
264 const OncFieldSignature sim_lock_status_fields[] = {
265 {::onc::sim_lock_status::kLockEnabled, &kBoolSignature},
266 {::onc::sim_lock_status::kLockType, &kStringSignature},
267 {::onc::sim_lock_status::kRetriesLeft, &kIntegerSignature},
268 {NULL}};
270 const OncFieldSignature cellular_fields[] = {
271 {::onc::kRecommended, &kRecommendedSignature},
272 {::onc::cellular::kAPN, &kCellularApnSignature},
273 {::onc::cellular::kAPNList, &kCellularApnListSignature},
274 {::onc::cellular::kCarrier, &kStringSignature},
275 {::onc::cellular::kAutoConnect, &kBoolSignature},
276 {NULL}};
278 const OncFieldSignature cellular_with_state_fields[] = {
279 {::onc::cellular::kActivationType, &kStringSignature},
280 {::onc::cellular::kActivationState, &kStringSignature},
281 {::onc::cellular::kAllowRoaming, &kBoolSignature},
282 {::onc::cellular::kESN, &kStringSignature},
283 {::onc::cellular::kFamily, &kStringSignature},
284 {::onc::cellular::kFirmwareRevision, &kStringSignature},
285 {::onc::cellular::kFoundNetworks, &kCellularFoundNetworkListSignature},
286 {::onc::cellular::kHardwareRevision, &kStringSignature},
287 {::onc::cellular::kHomeProvider, &kCellularProviderSignature},
288 {::onc::cellular::kICCID, &kStringSignature},
289 {::onc::cellular::kIMEI, &kStringSignature},
290 {::onc::cellular::kIMSI, &kStringSignature},
291 {::onc::cellular::kLastGoodAPN, &kCellularApnSignature},
292 {::onc::cellular::kManufacturer, &kStringSignature},
293 {::onc::cellular::kMDN, &kStringSignature},
294 {::onc::cellular::kMEID, &kStringSignature},
295 {::onc::cellular::kMIN, &kStringSignature},
296 {::onc::cellular::kModelID, &kStringSignature},
297 {::onc::cellular::kNetworkTechnology, &kStringSignature},
298 {::onc::cellular::kPaymentPortal, &kCellularPaymentPortalSignature},
299 {::onc::cellular::kPRLVersion, &kIntegerSignature},
300 {::onc::cellular::kRoamingState, &kStringSignature},
301 {::onc::cellular::kServingOperator, &kCellularProviderSignature},
302 {::onc::cellular::kSignalStrength, &kIntegerSignature},
303 {::onc::cellular::kSIMLockStatus, &kSIMLockStatusSignature},
304 {::onc::cellular::kSIMPresent, &kBoolSignature},
305 {::onc::cellular::kSupportNetworkScan, &kBoolSignature},
306 {::onc::cellular::kSupportedCarriers, &kStringListSignature},
307 {NULL}};
309 const OncFieldSignature network_configuration_fields[] = {
310 {::onc::network_config::kCellular, &kCellularSignature},
311 {::onc::network_config::kEthernet, &kEthernetSignature},
312 {::onc::network_config::kGUID, &kStringSignature},
313 {::onc::network_config::kIPAddressConfigType, &kStringSignature},
314 {::onc::network_config::kName, &kStringSignature},
315 {::onc::network_config::kNameServersConfigType, &kStringSignature},
316 {::onc::network_config::kPriority, &kIntegerSignature},
317 {::onc::network_config::kProxySettings, &kProxySettingsSignature},
318 {::onc::kRecommended, &kRecommendedSignature},
319 {::onc::kRemove, &kBoolSignature},
320 {::onc::network_config::kStaticIPConfig, &kStaticIPConfigSignature},
321 {::onc::network_config::kType, &kStringSignature},
322 {::onc::network_config::kVPN, &kVPNSignature},
323 {::onc::network_config::kWiFi, &kWiFiSignature},
324 {::onc::network_config::kWimax, &kWiMAXSignature},
325 {NULL}};
327 const OncFieldSignature network_with_state_fields[] = {
328 {::onc::network_config::kCellular, &kCellularWithStateSignature},
329 {::onc::network_config::kConnectionState, &kStringSignature},
330 {::onc::network_config::kConnectable, &kBoolSignature},
331 {::onc::network_config::kErrorState, &kStringSignature},
332 {::onc::network_config::kIPConfigs, &kIPConfigListSignature},
333 {::onc::network_config::kMacAddress, &kStringSignature},
334 {::onc::network_config::kRestrictedConnectivity, &kBoolSignature},
335 {::onc::network_config::kSavedIPConfig, &kSavedIPConfigSignature},
336 {::onc::network_config::kSource, &kStringSignature},
337 {::onc::network_config::kWiFi, &kWiFiWithStateSignature},
338 {::onc::network_config::kWimax, &kWiMAXWithStateSignature},
339 {NULL}};
341 const OncFieldSignature global_network_configuration_fields[] = {
342 {::onc::global_network_config::kAllowOnlyPolicyNetworksToAutoconnect,
343 &kBoolSignature},
344 {::onc::global_network_config::kDisableNetworkTypes, &kStringListSignature},
345 {NULL}};
347 const OncFieldSignature certificate_fields[] = {
348 {::onc::certificate::kGUID, &kStringSignature},
349 {::onc::certificate::kPKCS12, &kStringSignature},
350 {::onc::kRemove, &kBoolSignature},
351 {::onc::certificate::kTrustBits, &kStringListSignature},
352 {::onc::certificate::kType, &kStringSignature},
353 {::onc::certificate::kX509, &kStringSignature},
354 {NULL}};
356 const OncFieldSignature toplevel_configuration_fields[] = {
357 {::onc::toplevel_config::kCertificates, &kCertificateListSignature},
358 {::onc::toplevel_config::kNetworkConfigurations,
359 &kNetworkConfigurationListSignature},
360 {::onc::toplevel_config::kGlobalNetworkConfiguration,
361 &kGlobalNetworkConfigurationSignature},
362 {::onc::toplevel_config::kType, &kStringSignature},
363 {::onc::encrypted::kCipher, &kStringSignature},
364 {::onc::encrypted::kCiphertext, &kStringSignature},
365 {::onc::encrypted::kHMAC, &kStringSignature},
366 {::onc::encrypted::kHMACMethod, &kStringSignature},
367 {::onc::encrypted::kIV, &kStringSignature},
368 {::onc::encrypted::kIterations, &kIntegerSignature},
369 {::onc::encrypted::kSalt, &kStringSignature},
370 {::onc::encrypted::kStretch, &kStringSignature},
371 {NULL}};
373 } // namespace
375 const OncValueSignature kRecommendedSignature = {base::Value::TYPE_LIST,
376 NULL,
377 &kStringSignature};
378 const OncValueSignature kEAPSignature = {base::Value::TYPE_DICTIONARY,
379 eap_fields,
380 NULL};
381 const OncValueSignature kIssuerSubjectPatternSignature = {
382 base::Value::TYPE_DICTIONARY,
383 issuer_subject_pattern_fields,
384 NULL};
385 const OncValueSignature kCertificatePatternSignature = {
386 base::Value::TYPE_DICTIONARY,
387 certificate_pattern_fields,
388 NULL};
389 const OncValueSignature kIPsecSignature = {base::Value::TYPE_DICTIONARY,
390 ipsec_fields,
391 NULL};
392 const OncValueSignature kXAUTHSignature = {base::Value::TYPE_DICTIONARY,
393 xauth_fields,
394 NULL};
395 const OncValueSignature kL2TPSignature = {base::Value::TYPE_DICTIONARY,
396 l2tp_fields,
397 NULL};
398 const OncValueSignature kOpenVPNSignature = {base::Value::TYPE_DICTIONARY,
399 openvpn_fields,
400 NULL};
401 const OncValueSignature kThirdPartyVPNSignature = {base::Value::TYPE_DICTIONARY,
402 third_party_vpn_fields,
403 NULL};
404 const OncValueSignature kVerifyX509Signature = {base::Value::TYPE_DICTIONARY,
405 verify_x509_fields,
406 NULL};
407 const OncValueSignature kVPNSignature = {base::Value::TYPE_DICTIONARY,
408 vpn_fields,
409 NULL};
410 const OncValueSignature kEthernetSignature = {base::Value::TYPE_DICTIONARY,
411 ethernet_fields,
412 NULL};
413 const OncValueSignature kIPConfigSignature = {base::Value::TYPE_DICTIONARY,
414 ipconfig_fields,
415 NULL};
416 const OncValueSignature kSavedIPConfigSignature = {base::Value::TYPE_DICTIONARY,
417 ipconfig_fields,
418 NULL};
419 const OncValueSignature kStaticIPConfigSignature = {
420 base::Value::TYPE_DICTIONARY,
421 ipconfig_fields,
422 NULL};
423 const OncValueSignature kProxyLocationSignature = {base::Value::TYPE_DICTIONARY,
424 proxy_location_fields,
425 NULL};
426 const OncValueSignature kProxyManualSignature = {base::Value::TYPE_DICTIONARY,
427 proxy_manual_fields,
428 NULL};
429 const OncValueSignature kProxySettingsSignature = {base::Value::TYPE_DICTIONARY,
430 proxy_settings_fields,
431 NULL};
432 const OncValueSignature kWiFiSignature = {base::Value::TYPE_DICTIONARY,
433 wifi_fields,
434 NULL};
435 const OncValueSignature kWiMAXSignature = {base::Value::TYPE_DICTIONARY,
436 wimax_fields,
437 NULL};
438 const OncValueSignature kCertificateSignature = {base::Value::TYPE_DICTIONARY,
439 certificate_fields,
440 NULL};
441 const OncValueSignature kNetworkConfigurationSignature = {
442 base::Value::TYPE_DICTIONARY,
443 network_configuration_fields,
444 NULL};
445 const OncValueSignature kGlobalNetworkConfigurationSignature = {
446 base::Value::TYPE_DICTIONARY,
447 global_network_configuration_fields,
448 NULL};
449 const OncValueSignature kCertificateListSignature = {base::Value::TYPE_LIST,
450 NULL,
451 &kCertificateSignature};
452 const OncValueSignature kNetworkConfigurationListSignature = {
453 base::Value::TYPE_LIST,
454 NULL,
455 &kNetworkConfigurationSignature};
456 const OncValueSignature kToplevelConfigurationSignature = {
457 base::Value::TYPE_DICTIONARY,
458 toplevel_configuration_fields,
459 NULL};
461 // Derived "ONC with State" signatures.
462 const OncValueSignature kNetworkWithStateSignature = {
463 base::Value::TYPE_DICTIONARY,
464 network_with_state_fields,
465 NULL,
466 &kNetworkConfigurationSignature};
467 const OncValueSignature kWiFiWithStateSignature = {base::Value::TYPE_DICTIONARY,
468 wifi_with_state_fields,
469 NULL,
470 &kWiFiSignature};
471 const OncValueSignature kWiMAXWithStateSignature = {
472 base::Value::TYPE_DICTIONARY,
473 wimax_with_state_fields,
474 NULL,
475 &kWiMAXSignature};
476 const OncValueSignature kCellularSignature = {base::Value::TYPE_DICTIONARY,
477 cellular_fields,
478 NULL};
479 const OncValueSignature kCellularWithStateSignature = {
480 base::Value::TYPE_DICTIONARY,
481 cellular_with_state_fields,
482 NULL,
483 &kCellularSignature};
484 const OncValueSignature kCellularPaymentPortalSignature = {
485 base::Value::TYPE_DICTIONARY,
486 cellular_payment_portal_fields,
487 NULL};
488 const OncValueSignature kCellularProviderSignature = {
489 base::Value::TYPE_DICTIONARY,
490 cellular_provider_fields,
491 NULL};
492 const OncValueSignature kCellularApnSignature = {base::Value::TYPE_DICTIONARY,
493 cellular_apn_fields,
494 NULL};
495 const OncValueSignature kCellularFoundNetworkSignature = {
496 base::Value::TYPE_DICTIONARY,
497 cellular_found_network_fields,
498 NULL};
499 const OncValueSignature kSIMLockStatusSignature = {base::Value::TYPE_DICTIONARY,
500 sim_lock_status_fields,
501 NULL};
503 const OncFieldSignature* GetFieldSignature(const OncValueSignature& signature,
504 const std::string& onc_field_name) {
505 if (!signature.fields)
506 return NULL;
507 for (const OncFieldSignature* field_signature = signature.fields;
508 field_signature->onc_field_name != NULL; ++field_signature) {
509 if (onc_field_name == field_signature->onc_field_name)
510 return field_signature;
512 if (signature.base_signature)
513 return GetFieldSignature(*signature.base_signature, onc_field_name);
514 return NULL;
517 namespace {
519 struct CredentialEntry {
520 const OncValueSignature* value_signature;
521 const char* field_name;
524 const CredentialEntry credentials[] = {
525 {&kEAPSignature, ::onc::eap::kPassword},
526 {&kIPsecSignature, ::onc::ipsec::kPSK},
527 {&kXAUTHSignature, ::onc::vpn::kPassword},
528 {&kL2TPSignature, ::onc::vpn::kPassword},
529 {&kOpenVPNSignature, ::onc::vpn::kPassword},
530 {&kOpenVPNSignature, ::onc::openvpn::kTLSAuthContents},
531 {&kWiFiSignature, ::onc::wifi::kPassphrase},
532 {&kCellularApnSignature, ::onc::cellular_apn::kPassword},
533 {NULL}};
535 } // namespace
537 bool FieldIsCredential(const OncValueSignature& signature,
538 const std::string& onc_field_name) {
539 for (const CredentialEntry* entry = credentials;
540 entry->value_signature != NULL; ++entry) {
541 if (&signature == entry->value_signature &&
542 onc_field_name == entry->field_name) {
543 return true;
546 return false;
549 } // namespace onc
550 } // namespace chromeos