Index: chromeos/network/onc/onc_translator_onc_to_shill.cc |
diff --git a/chromeos/network/onc/onc_translator_onc_to_shill.cc b/chromeos/network/onc/onc_translator_onc_to_shill.cc |
index 70831c4d8ae4738d52c44a1dc740dc4f1c323bb2..44f172242f27e837fe12f08c417fece516bd4ec3 100644 |
--- a/chromeos/network/onc/onc_translator_onc_to_shill.cc |
+++ b/chromeos/network/onc/onc_translator_onc_to_shill.cc |
@@ -26,6 +26,12 @@ namespace onc { |
namespace { |
+scoped_ptr<base::ListValue> SingletonStringList(const std::string& str) { |
+ base::ListValue* list = new base::ListValue; |
+ list->AppendString(str); |
+ return make_scoped_ptr(list); |
+} |
+ |
scoped_ptr<base::StringValue> ConvertValueToString(const base::Value& value) { |
std::string str; |
if (!value.GetAsString(&str)) |
@@ -40,12 +46,15 @@ scoped_ptr<base::StringValue> ConvertValueToString(const base::Value& value) { |
// TranslateONCHierarchy. |
class LocalTranslator { |
public: |
- LocalTranslator(const OncValueSignature& onc_signature, |
- const base::DictionaryValue& onc_object, |
- base::DictionaryValue* shill_dictionary) |
+ LocalTranslator( |
+ const OncValueSignature& onc_signature, |
+ const base::DictionaryValue& onc_object, |
+ base::DictionaryValue* shill_dictionary, |
+ const FingerprintToPEM& fingerprint_to_pem) |
: onc_signature_(&onc_signature), |
onc_object_(&onc_object), |
- shill_dictionary_(shill_dictionary) { |
+ shill_dictionary_(shill_dictionary), |
+ fingerprint_to_pem_(fingerprint_to_pem) { |
field_translation_table_ = GetFieldTranslationTable(onc_signature); |
} |
@@ -53,6 +62,7 @@ class LocalTranslator { |
private: |
void TranslateOpenVPN(); |
+ void TranslateIPsec(); |
void TranslateVPN(); |
void TranslateWiFi(); |
void TranslateEAP(); |
@@ -79,6 +89,7 @@ class LocalTranslator { |
const FieldTranslationEntry* field_translation_table_; |
const base::DictionaryValue* onc_object_; |
base::DictionaryValue* shill_dictionary_; |
+ FingerprintToPEM fingerprint_to_pem_; |
DISALLOW_COPY_AND_ASSIGN(LocalTranslator); |
}; |
@@ -90,6 +101,8 @@ void LocalTranslator::TranslateFields() { |
TranslateVPN(); |
else if (onc_signature_ == &kOpenVPNSignature) |
TranslateOpenVPN(); |
+ else if (onc_signature_ == &kIPsecSignature) |
+ TranslateIPsec(); |
else if (onc_signature_ == &kWiFiSignature) |
TranslateWiFi(); |
else if (onc_signature_ == &kEAPSignature) |
@@ -101,12 +114,23 @@ void LocalTranslator::TranslateFields() { |
void LocalTranslator::TranslateOpenVPN() { |
// Shill supports only one RemoteCertKU but ONC a list. |
// Copy only the first entry if existing. |
- const base::ListValue* certKUs = NULL; |
- std::string certKU; |
- if (onc_object_->GetListWithoutPathExpansion(vpn::kRemoteCertKU, &certKUs) && |
- certKUs->GetString(0, &certKU)) { |
+ const base::ListValue* cert_kus = NULL; |
+ std::string cert_ku; |
+ if (onc_object_->GetListWithoutPathExpansion(vpn::kRemoteCertKU, &cert_kus) && |
+ cert_kus->GetString(0, &cert_ku)) { |
shill_dictionary_->SetStringWithoutPathExpansion( |
- flimflam::kOpenVPNRemoteCertKUProperty, certKU); |
+ flimflam::kOpenVPNRemoteCertKUProperty, cert_ku); |
+ } |
+ |
+ std::string ca_cert_fingerprint; |
+ if (onc_object_->GetStringWithoutPathExpansion(vpn::kServerCAFingerprint, |
+ &ca_cert_fingerprint)) { |
+ std::string ca_cert_pem = fingerprint_to_pem_.Run(ca_cert_fingerprint); |
+ if (!ca_cert_pem.empty()) { |
+ shill_dictionary_->SetWithoutPathExpansion( |
+ shill::kOpenVPNCaCertPemProperty, |
+ SingletonStringList(ca_cert_pem).release()); |
+ } |
} |
for (base::DictionaryValue::Iterator it(*onc_object_); !it.IsAtEnd(); |
@@ -122,6 +146,20 @@ void LocalTranslator::TranslateOpenVPN() { |
} |
} |
+void LocalTranslator::TranslateIPsec() { |
+ std::string ca_cert_fingerprint; |
+ if (onc_object_->GetStringWithoutPathExpansion(vpn::kServerCAFingerprint, |
+ &ca_cert_fingerprint)) { |
+ std::string ca_cert_pem = fingerprint_to_pem_.Run(ca_cert_fingerprint); |
+ if (!ca_cert_pem.empty()) { |
+ shill_dictionary_->SetWithoutPathExpansion( |
+ shill::kL2tpIpsecCaCertPemProperty, |
+ SingletonStringList(ca_cert_pem).release()); |
+ } |
+ } |
+ CopyFieldsAccordingToSignature(); |
+} |
+ |
void LocalTranslator::TranslateVPN() { |
std::string type; |
onc_object_->GetStringWithoutPathExpansion(vpn::kType, &type); |
@@ -162,6 +200,17 @@ void LocalTranslator::TranslateEAP() { |
} |
} |
+ std::string ca_cert_fingerprint; |
+ if (onc_object_->GetStringWithoutPathExpansion(eap::kServerCAFingerprint, |
+ &ca_cert_fingerprint)) { |
+ std::string ca_cert_pem = fingerprint_to_pem_.Run(ca_cert_fingerprint); |
+ if (!ca_cert_pem.empty()) { |
+ shill_dictionary_->SetWithoutPathExpansion( |
+ shill::kEapCaCertPemProperty, |
+ SingletonStringList(ca_cert_pem).release()); |
+ } |
+ } |
+ |
CopyFieldsAccordingToSignature(); |
} |
@@ -226,11 +275,14 @@ void LocalTranslator::TranslateWithTableAndSet( |
// Iterates recursively over |onc_object| and its |signature|. At each object |
// applies the local translation using LocalTranslator::TranslateFields. The |
// results are written to |shill_dictionary|. |
-void TranslateONCHierarchy(const OncValueSignature& signature, |
- const base::DictionaryValue& onc_object, |
- base::DictionaryValue* shill_dictionary) { |
+void TranslateONCHierarchy( |
+ const OncValueSignature& signature, |
+ const base::DictionaryValue& onc_object, |
+ const FingerprintToPEM& fingerprint_to_pem, |
+ base::DictionaryValue* shill_dictionary) { |
// Translates fields of |onc_object| and writes them to |shill_dictionary_|. |
- LocalTranslator translator(signature, onc_object, shill_dictionary); |
+ LocalTranslator translator(signature, onc_object, shill_dictionary, |
+ fingerprint_to_pem); |
translator.TranslateFields(); |
// Recurse into nested objects. |
@@ -244,7 +296,7 @@ void TranslateONCHierarchy(const OncValueSignature& signature, |
GetFieldSignature(signature, it.key()); |
TranslateONCHierarchy(*field_signature->value_signature, *inner_object, |
- shill_dictionary); |
+ fingerprint_to_pem, shill_dictionary); |
} |
} |
@@ -252,10 +304,12 @@ void TranslateONCHierarchy(const OncValueSignature& signature, |
scoped_ptr<base::DictionaryValue> TranslateONCObjectToShill( |
const OncValueSignature* onc_signature, |
- const base::DictionaryValue& onc_object) { |
+ const base::DictionaryValue& onc_object, |
+ const FingerprintToPEM& fingerprint_to_pem) { |
CHECK(onc_signature != NULL); |
scoped_ptr<base::DictionaryValue> shill_dictionary(new base::DictionaryValue); |
- TranslateONCHierarchy(*onc_signature, onc_object, shill_dictionary.get()); |
+ TranslateONCHierarchy(*onc_signature, onc_object, fingerprint_to_pem, |
+ shill_dictionary.get()); |
return shill_dictionary.Pass(); |
} |