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. 4 5 #include "chromeos/network/onc/onc_translation_tables.h" 6 7 #include <cstddef> 8 9 #include "base/logging.h" 10 #include "components/onc/onc_constants.h" 11 #include "third_party/cros_system_api/dbus/service_constants.h" 12 13 namespace chromeos { 14 namespace onc { 15 16 // CertificatePattern is converted with function CreateUIData(...) to UIData 17 // stored in Shill. 18 // 19 // Proxy settings are converted to Shill by function 20 // ConvertOncProxySettingsToProxyConfig(...). 21 // 22 // Translation of IPConfig objects is not supported, yet. 23 24 namespace { 25 26 const FieldTranslationEntry eap_fields[] = { 27 { ::onc::eap::kAnonymousIdentity, shill::kEapAnonymousIdentityProperty}, 28 { ::onc::eap::kIdentity, shill::kEapIdentityProperty}, 29 // This field is converted during translation, see onc_translator_*. 30 // { ::onc::eap::kInner, shill::kEapPhase2AuthProperty }, 31 32 // This field is converted during translation, see onc_translator_*. 33 // { ::onc::eap::kOuter, shill::kEapMethodProperty }, 34 { ::onc::eap::kPassword, shill::kEapPasswordProperty}, 35 { ::onc::eap::kSaveCredentials, shill::kSaveCredentialsProperty}, 36 { ::onc::eap::kServerCAPEMs, shill::kEapCaCertPemProperty}, 37 { ::onc::eap::kUseSystemCAs, shill::kEapUseSystemCasProperty}, 38 {NULL}}; 39 40 const FieldTranslationEntry ipsec_fields[] = { 41 // Ignored by Shill, not necessary to synchronize. 42 // { ::onc::ipsec::kAuthenticationType, shill::kL2tpIpsecAuthenticationType 43 // }, 44 { ::onc::ipsec::kGroup, shill::kL2tpIpsecTunnelGroupProperty}, 45 // Ignored by Shill, not necessary to synchronize. 46 // { ::onc::ipsec::kIKEVersion, shill::kL2tpIpsecIkeVersion }, 47 { ::onc::ipsec::kPSK, shill::kL2tpIpsecPskProperty}, 48 { ::onc::vpn::kSaveCredentials, shill::kSaveCredentialsProperty}, 49 { ::onc::ipsec::kServerCAPEMs, shill::kL2tpIpsecCaCertPemProperty}, 50 {NULL}}; 51 52 const FieldTranslationEntry l2tp_fields[] = { 53 { ::onc::vpn::kPassword, shill::kL2tpIpsecPasswordProperty}, 54 // We don't synchronize l2tp's SaveCredentials field for now, as Shill 55 // doesn't 56 // support separate settings for ipsec and l2tp. 57 // { ::onc::vpn::kSaveCredentials, &kBoolSignature }, 58 { ::onc::vpn::kUsername, shill::kL2tpIpsecUserProperty}, {NULL}}; 59 60 const FieldTranslationEntry openvpn_fields[] = { 61 { ::onc::openvpn::kAuth, shill::kOpenVPNAuthProperty}, 62 { ::onc::openvpn::kAuthNoCache, shill::kOpenVPNAuthNoCacheProperty}, 63 { ::onc::openvpn::kAuthRetry, shill::kOpenVPNAuthRetryProperty}, 64 { ::onc::openvpn::kCipher, shill::kOpenVPNCipherProperty}, 65 { ::onc::openvpn::kCompLZO, shill::kOpenVPNCompLZOProperty}, 66 { ::onc::openvpn::kCompNoAdapt, shill::kOpenVPNCompNoAdaptProperty}, 67 { ::onc::openvpn::kKeyDirection, shill::kOpenVPNKeyDirectionProperty}, 68 { ::onc::openvpn::kNsCertType, shill::kOpenVPNNsCertTypeProperty}, 69 { ::onc::vpn::kPassword, shill::kOpenVPNPasswordProperty}, 70 { ::onc::openvpn::kPort, shill::kOpenVPNPortProperty}, 71 { ::onc::openvpn::kProto, shill::kOpenVPNProtoProperty}, 72 { ::onc::openvpn::kPushPeerInfo, shill::kOpenVPNPushPeerInfoProperty}, 73 { ::onc::openvpn::kRemoteCertEKU, shill::kOpenVPNRemoteCertEKUProperty}, 74 // This field is converted during translation, see onc_translator_*. 75 // { ::onc::openvpn::kRemoteCertKU, shill::kOpenVPNRemoteCertKUProperty }, 76 { ::onc::openvpn::kRemoteCertTLS, shill::kOpenVPNRemoteCertTLSProperty}, 77 { ::onc::openvpn::kRenegSec, shill::kOpenVPNRenegSecProperty}, 78 { ::onc::vpn::kSaveCredentials, shill::kSaveCredentialsProperty}, 79 { ::onc::openvpn::kServerCAPEMs, shill::kOpenVPNCaCertPemProperty}, 80 { ::onc::openvpn::kServerPollTimeout, 81 shill::kOpenVPNServerPollTimeoutProperty}, 82 { ::onc::openvpn::kShaper, shill::kOpenVPNShaperProperty}, 83 { ::onc::openvpn::kStaticChallenge, shill::kOpenVPNStaticChallengeProperty}, 84 { ::onc::openvpn::kTLSAuthContents, shill::kOpenVPNTLSAuthContentsProperty}, 85 { ::onc::openvpn::kTLSRemote, shill::kOpenVPNTLSRemoteProperty}, 86 { ::onc::vpn::kUsername, shill::kOpenVPNUserProperty}, 87 { ::onc::openvpn::kVerifyHash, shill::kOpenVPNVerifyHashProperty}, 88 {NULL}}; 89 90 const FieldTranslationEntry verify_x509_fields[] = { 91 { ::onc::verify_x509::kName, shill::kOpenVPNVerifyX509NameProperty}, 92 { ::onc::verify_x509::kType, shill::kOpenVPNVerifyX509TypeProperty}, 93 {NULL}}; 94 95 const FieldTranslationEntry vpn_fields[] = { 96 { ::onc::vpn::kAutoConnect, shill::kAutoConnectProperty}, 97 { ::onc::vpn::kHost, shill::kProviderHostProperty}, 98 // This field is converted during translation, see onc_translator_*. 99 // { ::onc::vpn::kType, shill::kProviderTypeProperty }, 100 {NULL}}; 101 102 const FieldTranslationEntry wifi_fields[] = { 103 { ::onc::wifi::kAutoConnect, shill::kAutoConnectProperty}, 104 { ::onc::wifi::kBSSID, shill::kWifiBSsid}, 105 { ::onc::wifi::kFrequency, shill::kWifiFrequency}, 106 { ::onc::wifi::kFrequencyList, shill::kWifiFrequencyListProperty}, 107 { ::onc::wifi::kHiddenSSID, shill::kWifiHiddenSsid}, 108 { ::onc::wifi::kPassphrase, shill::kPassphraseProperty}, 109 // This field is converted during translation, see onc_translator_*. 110 // { ::onc::wifi::kSSID, shill::kWifiHexSsid}, 111 // This field is converted during translation, see onc_translator_*. 112 // { ::onc::wifi::kSecurity, shill::kSecurityProperty }, 113 { ::onc::wifi::kSignalStrength, shill::kSignalStrengthProperty}, 114 {NULL}}; 115 116 const FieldTranslationEntry cellular_apn_fields[] = { 117 { ::onc::cellular_apn::kName, shill::kApnProperty}, 118 { ::onc::cellular_apn::kUsername, shill::kApnUsernameProperty}, 119 { ::onc::cellular_apn::kPassword, shill::kApnPasswordProperty}, 120 {NULL}}; 121 122 const FieldTranslationEntry cellular_provider_fields[] = { 123 { ::onc::cellular_provider::kCode, shill::kOperatorCodeKey}, 124 { ::onc::cellular_provider::kCountry, shill::kOperatorCountryKey}, 125 { ::onc::cellular_provider::kName, shill::kOperatorNameKey}, 126 {NULL}}; 127 128 const FieldTranslationEntry cellular_fields[] = { 129 { ::onc::cellular::kActivateOverNonCellularNetwork, 130 shill::kActivateOverNonCellularNetworkProperty}, 131 { ::onc::cellular::kActivationState, shill::kActivationStateProperty}, 132 { ::onc::cellular::kAllowRoaming, shill::kCellularAllowRoamingProperty}, 133 { ::onc::cellular::kCarrier, shill::kCarrierProperty}, 134 { ::onc::cellular::kESN, shill::kEsnProperty}, 135 { ::onc::cellular::kFamily, shill::kTechnologyFamilyProperty}, 136 { ::onc::cellular::kFirmwareRevision, shill::kFirmwareRevisionProperty}, 137 { ::onc::cellular::kFoundNetworks, shill::kFoundNetworksProperty}, 138 { ::onc::cellular::kHardwareRevision, shill::kHardwareRevisionProperty}, 139 { ::onc::cellular::kICCID, shill::kIccidProperty}, 140 { ::onc::cellular::kIMEI, shill::kImeiProperty}, 141 { ::onc::cellular::kIMSI, shill::kImsiProperty}, 142 { ::onc::cellular::kManufacturer, shill::kManufacturerProperty}, 143 { ::onc::cellular::kMDN, shill::kMdnProperty}, 144 { ::onc::cellular::kMEID, shill::kMeidProperty}, 145 { ::onc::cellular::kMIN, shill::kMinProperty}, 146 { ::onc::cellular::kModelID, shill::kModelIDProperty}, 147 { ::onc::cellular::kNetworkTechnology, shill::kNetworkTechnologyProperty}, 148 { ::onc::cellular::kPRLVersion, shill::kPRLVersionProperty}, 149 { ::onc::cellular::kProviderRequiresRoaming, 150 shill::kProviderRequiresRoamingProperty}, 151 { ::onc::cellular::kRoamingState, shill::kRoamingStateProperty}, 152 { ::onc::cellular::kSelectedNetwork, shill::kSelectedNetworkProperty}, 153 { ::onc::cellular::kSIMLockStatus, shill::kSIMLockStatusProperty}, 154 { ::onc::cellular::kSIMPresent, shill::kSIMPresentProperty}, 155 { ::onc::cellular::kSupportedCarriers, shill::kSupportedCarriersProperty}, 156 { ::onc::cellular::kSupportNetworkScan, shill::kSupportNetworkScanProperty}, 157 {NULL}}; 158 159 const FieldTranslationEntry network_fields[] = { 160 // Shill doesn't allow setting the name for non-VPN networks. 161 // This field is conditionally translated, see onc_translator_*. 162 // { ::onc::network_config::kName, shill::kNameProperty }, 163 { ::onc::network_config::kGUID, shill::kGuidProperty}, 164 // This field is converted during translation, see onc_translator_*. 165 // { ::onc::network_config::kType, shill::kTypeProperty }, 166 167 // This field is converted during translation, see 168 // onc_translator_shill_to_onc.cc. It is only converted when going from 169 // Shill->ONC, and ignored otherwise. 170 // { ::onc::network_config::kConnectionState, shill::kStateProperty }, 171 {NULL}}; 172 173 struct OncValueTranslationEntry { 174 const OncValueSignature* onc_signature; 175 const FieldTranslationEntry* field_translation_table; 176 }; 177 178 const OncValueTranslationEntry onc_value_translation_table[] = { 179 { &kEAPSignature, eap_fields }, 180 { &kIPsecSignature, ipsec_fields }, 181 { &kL2TPSignature, l2tp_fields }, 182 { &kOpenVPNSignature, openvpn_fields }, 183 { &kVerifyX509Signature, verify_x509_fields }, 184 { &kVPNSignature, vpn_fields }, 185 { &kWiFiSignature, wifi_fields }, 186 { &kWiFiWithStateSignature, wifi_fields }, 187 { &kCellularApnSignature, cellular_apn_fields }, 188 { &kCellularProviderSignature, cellular_provider_fields }, 189 { &kCellularSignature, cellular_fields }, 190 { &kCellularWithStateSignature, cellular_fields }, 191 { &kNetworkWithStateSignature, network_fields }, 192 { &kNetworkConfigurationSignature, network_fields }, 193 { NULL } 194 }; 195 196 struct NestedShillDictionaryEntry { 197 const OncValueSignature* onc_signature; 198 // NULL terminated list of Shill property keys. 199 const char* const* shill_property_path; 200 }; 201 202 const char* cellular_apn_property_path_entries[] = { 203 shill::kCellularApnProperty, 204 NULL 205 }; 206 207 const NestedShillDictionaryEntry nested_shill_dictionaries[] = { 208 { &kCellularApnSignature, cellular_apn_property_path_entries }, 209 { NULL } 210 }; 211 212 } // namespace 213 214 const StringTranslationEntry kNetworkTypeTable[] = { 215 // This mapping is ensured in the translation code. 216 // { network_type::kEthernet, shill::kTypeEthernet }, 217 // { network_type::kEthernet, shill::kTypeEthernetEap }, 218 { ::onc::network_type::kWiFi, shill::kTypeWifi}, 219 { ::onc::network_type::kCellular, shill::kTypeCellular}, 220 { ::onc::network_type::kVPN, shill::kTypeVPN}, 221 {NULL}}; 222 223 const StringTranslationEntry kVPNTypeTable[] = { 224 { ::onc::vpn::kTypeL2TP_IPsec, shill::kProviderL2tpIpsec}, 225 { ::onc::vpn::kOpenVPN, shill::kProviderOpenVpn}, {NULL}}; 226 227 // The first matching line is chosen. 228 const StringTranslationEntry kWiFiSecurityTable[] = { 229 { ::onc::wifi::kNone, shill::kSecurityNone}, 230 { ::onc::wifi::kWEP_PSK, shill::kSecurityWep}, 231 { ::onc::wifi::kWPA_PSK, shill::kSecurityPsk}, 232 { ::onc::wifi::kWPA_EAP, shill::kSecurity8021x}, 233 { ::onc::wifi::kWPA_PSK, shill::kSecurityRsn}, 234 { ::onc::wifi::kWPA_PSK, shill::kSecurityWpa}, 235 {NULL}}; 236 237 const StringTranslationEntry kEAPOuterTable[] = { 238 { ::onc::eap::kPEAP, shill::kEapMethodPEAP}, 239 { ::onc::eap::kEAP_TLS, shill::kEapMethodTLS}, 240 { ::onc::eap::kEAP_TTLS, shill::kEapMethodTTLS}, 241 { ::onc::eap::kLEAP, shill::kEapMethodLEAP}, 242 {NULL}}; 243 244 // Translation of the EAP.Inner field in case of EAP.Outer == PEAP 245 const StringTranslationEntry kEAP_PEAP_InnerTable[] = { 246 { ::onc::eap::kMD5, shill::kEapPhase2AuthPEAPMD5}, 247 { ::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthPEAPMSCHAPV2}, {NULL}}; 248 249 // Translation of the EAP.Inner field in case of EAP.Outer == TTLS 250 const StringTranslationEntry kEAP_TTLS_InnerTable[] = { 251 { ::onc::eap::kMD5, shill::kEapPhase2AuthTTLSMD5}, 252 { ::onc::eap::kMSCHAPv2, shill::kEapPhase2AuthTTLSMSCHAPV2}, 253 { ::onc::eap::kPAP, shill::kEapPhase2AuthTTLSPAP}, 254 {NULL}}; 255 256 const FieldTranslationEntry* GetFieldTranslationTable( 257 const OncValueSignature& onc_signature) { 258 for (const OncValueTranslationEntry* it = onc_value_translation_table; 259 it->onc_signature != NULL; ++it) { 260 if (it->onc_signature == &onc_signature) 261 return it->field_translation_table; 262 } 263 return NULL; 264 } 265 266 std::vector<std::string> GetPathToNestedShillDictionary( 267 const OncValueSignature& onc_signature) { 268 std::vector<std::string> shill_property_path; 269 for (const NestedShillDictionaryEntry* it = nested_shill_dictionaries; 270 it->onc_signature != NULL; ++it) { 271 if (it->onc_signature == &onc_signature) { 272 for (const char* const* key = it->shill_property_path; *key != NULL; 273 ++key) { 274 shill_property_path.push_back(std::string(*key)); 275 } 276 break; 277 } 278 } 279 return shill_property_path; 280 } 281 282 bool GetShillPropertyName(const std::string& onc_field_name, 283 const FieldTranslationEntry table[], 284 std::string* shill_property_name) { 285 for (const FieldTranslationEntry* it = table; 286 it->onc_field_name != NULL; ++it) { 287 if (it->onc_field_name != onc_field_name) 288 continue; 289 *shill_property_name = it->shill_property_name; 290 return true; 291 } 292 return false; 293 } 294 295 bool TranslateStringToShill(const StringTranslationEntry table[], 296 const std::string& onc_value, 297 std::string* shill_value) { 298 for (int i = 0; table[i].onc_value != NULL; ++i) { 299 if (onc_value != table[i].onc_value) 300 continue; 301 *shill_value = table[i].shill_value; 302 return true; 303 } 304 LOG(ERROR) << "Value '" << onc_value << "' cannot be translated to Shill"; 305 return false; 306 } 307 308 bool TranslateStringToONC(const StringTranslationEntry table[], 309 const std::string& shill_value, 310 std::string* onc_value) { 311 for (int i = 0; table[i].shill_value != NULL; ++i) { 312 if (shill_value != table[i].shill_value) 313 continue; 314 *onc_value = table[i].onc_value; 315 return true; 316 } 317 LOG(ERROR) << "Value '" << shill_value << "' cannot be translated to ONC"; 318 return false; 319 } 320 321 } // namespace onc 322 } // namespace chromeos 323