Commit e93217a6 authored by pneubeck@chromium.org's avatar pneubeck@chromium.org

Add ethernet to ONC validation and Shill translation.

BUG=126870
(for networking_private_api_nonchromeos.cc)
TBR=gspencer@chromium.org

Review URL: https://chromiumcodereview.appspot.com/23506040

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223630 0039d316-1c4b-4281-b951-d872f2087c98
parent 503aa8b1
......@@ -232,7 +232,10 @@ bool NetworkingPrivateGetVisibleNetworksFunction::RunImpl() {
" \"ConnectionState\": \"Connected\","
" \"GUID\": \"stub_ethernet\","
" \"Name\": \"eth0\","
" \"Type\": \"Ethernet\""
" \"Type\": \"Ethernet\","
" \"Ethernet\": {"
" \"Authentication\": \"None\""
" }"
" },"
" {"
" \"ConnectionState\": \"Connected\","
......
......@@ -115,7 +115,10 @@ var availableTests = [
"ConnectionState": "Connected",
"GUID": "stub_ethernet",
"Name": "eth0",
"Type": "Ethernet"
"Type": "Ethernet",
"Ethernet": {
"Authentication": "None"
}
},
{
"ConnectionState": "Connected",
......
......@@ -144,7 +144,6 @@ const OncFieldSignature vpn_fields[] = {
const OncFieldSignature ethernet_fields[] = {
{ kRecommended, &kRecommendedSignature },
// Not supported, yet.
{ ethernet::kAuthentication, &kStringSignature },
{ ethernet::kEAP, &kEAPSignature },
{ NULL }
......
......@@ -212,7 +212,9 @@ const NestedShillDictionaryEntry nested_shill_dictionaries[] = {
} // namespace
const StringTranslationEntry kNetworkTypeTable[] = {
{ network_type::kEthernet, flimflam::kTypeEthernet },
// This mapping is ensured in the translation code.
// { network_type::kEthernet, flimflam::kTypeEthernet },
// { network_type::kEthernet, shill::kTypeEthernetEap },
{ network_type::kWiFi, flimflam::kTypeWifi },
{ network_type::kCellular, flimflam::kTypeCellular },
{ network_type::kVPN, flimflam::kTypeVPN },
......
......@@ -52,6 +52,7 @@ class LocalTranslator {
void TranslateFields();
private:
void TranslateEthernet();
void TranslateOpenVPN();
void TranslateVPN();
void TranslateWiFi();
......@@ -86,6 +87,8 @@ class LocalTranslator {
void LocalTranslator::TranslateFields() {
if (onc_signature_ == &kNetworkConfigurationSignature)
TranslateNetworkConfiguration();
else if (onc_signature_ == &kEthernetSignature)
TranslateEthernet();
else if (onc_signature_ == &kVPNSignature)
TranslateVPN();
else if (onc_signature_ == &kOpenVPNSignature)
......@@ -98,6 +101,20 @@ void LocalTranslator::TranslateFields() {
CopyFieldsAccordingToSignature();
}
void LocalTranslator::TranslateEthernet() {
std::string authentication;
onc_object_->GetStringWithoutPathExpansion(ethernet::kAuthentication,
&authentication);
const char* shill_type = flimflam::kTypeEthernet;
if (authentication == ethernet::k8021X)
shill_type = shill::kTypeEthernetEap;
shill_dictionary_->SetStringWithoutPathExpansion(flimflam::kTypeProperty,
shill_type);
CopyFieldsAccordingToSignature();
}
void LocalTranslator::TranslateOpenVPN() {
// Shill supports only one RemoteCertKU but ONC a list.
// Copy only the first entry if existing.
......@@ -171,14 +188,17 @@ void LocalTranslator::TranslateEAP() {
void LocalTranslator::TranslateNetworkConfiguration() {
std::string type;
onc_object_->GetStringWithoutPathExpansion(network_config::kType, &type);
TranslateWithTableAndSet(type, kNetworkTypeTable, flimflam::kTypeProperty);
// Set the type except for Ethernet which is set in TranslateEthernet.
if (type != network_type::kEthernet)
TranslateWithTableAndSet(type, kNetworkTypeTable, flimflam::kTypeProperty);
// Shill doesn't allow setting the name for non-VPN networks.
if (type == network_type::kVPN) {
std::string name;
onc_object_->GetStringWithoutPathExpansion(network_config::kName, &name);
shill_dictionary_->SetStringWithoutPathExpansion(
flimflam::kNameProperty, name);
shill_dictionary_->SetStringWithoutPathExpansion(flimflam::kNameProperty,
name);
}
CopyFieldsAccordingToSignature();
......
......@@ -58,6 +58,7 @@ class ShillToONCTranslator {
scoped_ptr<base::DictionaryValue> CreateTranslatedONCObject();
private:
void TranslateEthernet();
void TranslateOpenVPN();
void TranslateVPN();
void TranslateWiFiWithState();
......@@ -109,6 +110,8 @@ ShillToONCTranslator::CreateTranslatedONCObject() {
onc_object_.reset(new base::DictionaryValue);
if (onc_signature_ == &kNetworkWithStateSignature) {
TranslateNetworkWithState();
} else if (onc_signature_ == &kEthernetSignature) {
TranslateEthernet();
} else if (onc_signature_ == &kVPNSignature) {
TranslateVPN();
} else if (onc_signature_ == &kOpenVPNSignature) {
......@@ -123,6 +126,17 @@ ShillToONCTranslator::CreateTranslatedONCObject() {
return onc_object_.Pass();
}
void ShillToONCTranslator::TranslateEthernet() {
std::string shill_network_type;
shill_dictionary_->GetStringWithoutPathExpansion(flimflam::kTypeProperty,
&shill_network_type);
const char* onc_auth = ethernet::kNone;
if (shill_network_type == shill::kTypeEthernetEap)
onc_auth = ethernet::k8021X;
onc_object_->SetStringWithoutPathExpansion(ethernet::kAuthentication,
onc_auth);
}
void ShillToONCTranslator::TranslateOpenVPN() {
// Shill supports only one RemoteCertKU but ONC requires a list. If existing,
// wraps the value into a list.
......@@ -219,14 +233,21 @@ void ShillToONCTranslator::TranslateCellularWithState() {
}
void ShillToONCTranslator::TranslateNetworkWithState() {
TranslateWithTableAndSet(flimflam::kTypeProperty, kNetworkTypeTable,
network_config::kType);
CopyPropertiesAccordingToSignature();
std::string network_type;
if (onc_object_->GetStringWithoutPathExpansion(network_config::kType,
&network_type)) {
TranslateAndAddNestedObject(network_type);
std::string shill_network_type;
shill_dictionary_->GetStringWithoutPathExpansion(flimflam::kTypeProperty,
&shill_network_type);
std::string onc_network_type = network_type::kEthernet;
if (shill_network_type != flimflam::kTypeEthernet &&
shill_network_type != shill::kTypeEthernetEap) {
TranslateStringToONC(
kNetworkTypeTable, shill_network_type, &onc_network_type);
}
if (!onc_network_type.empty()) {
onc_object_->SetStringWithoutPathExpansion(network_config::kType,
onc_network_type);
TranslateAndAddNestedObject(onc_network_type);
}
// Since Name is a read only field in Shill unless it's a VPN, it is copied
......
......@@ -42,7 +42,9 @@ INSTANTIATE_TEST_CASE_P(
ONCTranslatorOncToShillTest,
ONCTranslatorOncToShillTest,
::testing::Values(
std::make_pair("managed_ethernet.onc", "shill_ethernet.json"),
std::make_pair("ethernet.onc", "shill_ethernet.json"),
std::make_pair("ethernet_with_eap_and_cert_pems.onc",
"shill_ethernet_with_eap.json"),
std::make_pair("valid_wifi_psk.onc", "shill_wifi_psk.json"),
std::make_pair("wifi_clientcert_with_cert_pems.onc",
"shill_wifi_clientcert.json"),
......@@ -86,6 +88,10 @@ INSTANTIATE_TEST_CASE_P(
ONCTranslatorShillToOncTest,
ONCTranslatorShillToOncTest,
::testing::Values(
std::make_pair("shill_ethernet.json",
"translation_of_shill_ethernet.onc"),
std::make_pair("shill_ethernet_with_eap.json",
"translation_of_shill_ethernet_with_eap.onc"),
std::make_pair("shill_wifi_clientcert.json",
"translation_of_shill_wifi_clientcert.onc"),
std::make_pair("shill_wifi_wpa1.json",
......
......@@ -154,7 +154,10 @@ INSTANTIATE_TEST_CASE_P(
OncParams("managed_vpn.onc",
&kNetworkConfigurationSignature,
true),
OncParams("managed_ethernet.onc",
OncParams("ethernet.onc",
&kNetworkConfigurationSignature,
true),
OncParams("ethernet_with_eap.onc",
&kNetworkConfigurationSignature,
true),
OncParams("translation_of_shill_wifi_with_state.onc",
......
{
"Ethernet":{
"Authentication":"None",
"EAP":{
"ClientCertPattern":{
"EnrollmentURI":[
"chrome-extension://delkjfjibodjclmdijflfnimdmgdagfk/generate-cert.html"
],
"IssuerCARef":[
"{58ac1967-a0e7-49e9-be68-123abc}",
"{42cb13cd-140c-4941-9fb6-456def}"
]
},
"ClientCertType":"Pattern",
"Identity":"abc ${LOGIN_ID}@my.domain.com",
"Outer":"EAP-TLS",
"SaveCredentials":true,
"UseSystemCAs":true
}
},
"GUID":"guid",
"Name":"name",
"Type":"Ethernet"
}
{
"Ethernet":{
"Authentication":"8021X",
"EAP":{
"ClientCertPattern":{
"EnrollmentURI":[
"chrome-extension://delkjfjibodjclmdijflfnimdmgdagfk/generate-cert.html"
],
"IssuerCAPEMs":[
"pem1",
"pem2"
]
},
"ClientCertType":"Pattern",
"Identity":"abc ${LOGIN_ID}@my.domain.com",
"Outer":"EAP-TLS",
"SaveCredentials":true,
"UseSystemCAs":true
}
},
"GUID":"guid",
"Name":"name",
"Type":"Ethernet"
}
{
"EAP.EAP":"TLS",
"EAP.Identity":"abc ${LOGIN_ID}@my.domain.com",
"EAP.UseSystemCAs":true,
"GUID":"guid",
"SaveCredentials":true,
"Type":"etherneteap"
}
{
"Ethernet":{
"Authentication":"None"
},
"GUID":"guid",
"Name":"",
"Type":"Ethernet"
}
{
"Ethernet":{
"Authentication":"8021X"
},
"GUID":"guid",
"Name":"",
"Type":"Ethernet"
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment