shill: Support raw PEM data for CA Certificates

For all connection types that support CA Certificates (L2TP-IPSec,
OpenVPN, 802.1x WiFi) support a Service property that contains the
raw contents of the PEM certificate to be used in authenticating
the remote entity.

BUG=chromium-os:39685
TEST=Unit tests; Manual: Set the EAP.CACertPEM property on a
service and ensure that the data is stored and retrieved from
the profile correctly with newlines intact.

Change-Id: I4adc850dbb38a8b9afb55fc40260d67bcaa33485
Reviewed-on: https://gerrit.chromium.org/gerrit/45642
Commit-Queue: Paul Stewart <pstew@chromium.org>
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/wifi_service_unittest.cc b/wifi_service_unittest.cc
index 16499e9..457a39a 100644
--- a/wifi_service_unittest.cc
+++ b/wifi_service_unittest.cc
@@ -19,6 +19,7 @@
 #include "shill/event_dispatcher.h"
 #include "shill/manager.h"
 #include "shill/mock_adaptors.h"
+#include "shill/mock_certificate_file.h"
 #include "shill/mock_control.h"
 #include "shill/mock_log.h"
 #include "shill/mock_nss.h"
@@ -1210,6 +1211,28 @@
   }
 }
 
+TEST_F(WiFiServiceTest, Populate8021xPEM) {
+  WiFiServiceRefPtr service = MakeSimpleService(flimflam::kSecurityNone);
+  Service::EapCredentials eap;
+  eap.ca_cert_pem = "-pem-certificate-here-";
+  service->set_eap(eap);
+  MockCertificateFile *certificate_file = new MockCertificateFile();
+  service->certificate_file_.reset(certificate_file);  // Passes ownership.
+
+  const string kPEMCertfile("/tmp/pem-cert");
+  FilePath pem_cert(kPEMCertfile);
+  EXPECT_CALL(*certificate_file, CreateDERFromString(eap.ca_cert_pem))
+      .WillOnce(Return(pem_cert));
+
+  map<string, ::DBus::Variant> params;
+  service->Populate8021xProperties(&params);
+  EXPECT_TRUE(ContainsKey(params, wpa_supplicant::kNetworkPropertyEapCaCert));
+  if (ContainsKey(params, wpa_supplicant::kNetworkPropertyEapCaCert)) {
+    EXPECT_EQ(kPEMCertfile, params[wpa_supplicant::kNetworkPropertyEapCaCert]
+              .reader().get_string());
+  }
+}
+
 TEST_F(WiFiServiceTest, ClearWriteOnlyDerivedProperty) {
   WiFiServiceRefPtr wifi_service = MakeSimpleService(flimflam::kSecurityWep);