Generate security setup for cion cpp code 03/270003/3
authorSangyoon Jang <jeremy.jang@samsung.com>
Mon, 24 Jan 2022 05:59:31 +0000 (14:59 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Tue, 25 Jan 2022 04:10:58 +0000 (13:10 +0900)
Change-Id: I2ba76e0219418df0440fb2273e0de27e3ad11eab
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
idlc/gen_cion/cpp_cion_gen_base.cc
idlc/gen_cion/cpp_cion_gen_base.h
idlc/gen_cion/cpp_cion_gen_base_cb.h
idlc/gen_cion/cpp_cion_group_body_gen.cc
idlc/gen_cion/cpp_cion_group_body_gen_cb.h
idlc/gen_cion/cpp_cion_proxy_body_gen.cc
idlc/gen_cion/cpp_cion_proxy_body_gen_cb.h
idlc/gen_cion/cpp_cion_stub_body_gen.cc
idlc/gen_cion/cpp_cion_stub_body_gen_cb.h

index a0319cb83e08a2507fb1f958b060d5fec31eb8a6..1e4346e38c2852188fa761af2cb1daa745e3a0c4 100644 (file)
@@ -742,6 +742,24 @@ void CppCionGeneratorBase::GenHeaderCallback(std::ofstream& stream,
       .Out(stream);
 }
 
+std::string CppCionGeneratorBase::GenSecurity(const Interface& iface) {
+  std::string security_path;
+
+  for (const auto& attr : iface.GetAttributes()) {
+    if (attr->GetKey() == "ca_path")
+      security_path += ReplaceAll(CB_INTERFACE_SECURITY_CA, "<ARG>",
+          attr->GetValue());
+    else if (attr->GetKey() == "cert_path")
+      security_path += ReplaceAll(CB_INTERFACE_SECURITY_CERT, "<ARG>",
+          attr->GetValue());
+    else if (attr->GetKey() == "private_key")
+      security_path += ReplaceAll(CB_INTERFACE_SECURITY_PRIVATE_KEY, "<ARG>",
+          attr->GetValue());
+  }
+
+  return security_path;
+}
+
 void CppCionGeneratorBase::GenVersion(std::ofstream& stream) {
   GenTemplate(CB_VERSION, stream,
     [&]()->std::string {
index 38f3c2182209d702c916e2e466253860bdd3b675..b7570fe64c7c78f40c98e830b16f994bd8131bbe 100644 (file)
@@ -49,6 +49,7 @@ class CppCionGeneratorBase : public Generator {
                         bool is_proxy);
   void GenHeaderCallbacks(std::ofstream& stream, const Interface& iface,
                           bool is_proxy);
+  std::string GenSecurity(const Interface& iface);
   std::string ConvertTypeToString(const BaseType& type);
   std::string Tab(int cnt);
   std::string NLine(int cnt);
index d6043c93e64f1cf2f6bfaf3092c9266e3f98757f..fa946be38fa11580799018973735cc36bea7ecb0 100644 (file)
@@ -290,6 +290,30 @@ $$
 }
 )__cpp_cb";
 
+const char CB_INTERFACE_SECURITY_CA[] =
+R"__cpp_cb(
+  if (cion_security_set_ca_path(security, "<ARG>") != CION_ERROR_NONE) {
+    _E("Failed to set ca path.");
+    throw InvalidIOException();
+  }
+)__cpp_cb";
+
+const char CB_INTERFACE_SECURITY_CERT[] =
+R"__cpp_cb(
+  if (cion_security_set_cert_path(security, "<ARG>") != CION_ERROR_NONE) {
+    _E("Failed to set cert path.");
+    throw InvalidIOException();
+  }
+)__cpp_cb";
+
+const char CB_INTERFACE_SECURITY_PRIVATE_KEY[] =
+R"__cpp_cb(
+  if (cion_security_set_private_key_path(security, "<ARG>") != CION_ERROR_NONE) {
+    _E("Failed to set private key path.");
+    throw InvalidIOException();
+  }
+)__cpp_cb";
+
 const char CB_LOG_TAG[] =
 R"__cpp_cb(
 #ifdef LOG_TAG
index 51ab1ee916451d66baee18f603864b9bb4a06594..8bd51f2d5eef66aeb50c3e7d2e743bd819c8ce35 100644 (file)
@@ -90,8 +90,10 @@ void CppCionGroupBodyGen::GenInterface(std::ofstream& stream,
 
 void CppCionGroupBodyGen::GenConstructor(std::ofstream& stream,
     const Interface& iface) {
-  stream << ReplaceAll(CB_GROUP_INTERFACE_CTOR, "<CLS_NAME>", iface.GetID())
-         << NLine(1);
+  ReplaceAll(CB_GROUP_INTERFACE_CTOR)
+      .Change("<CLS_NAME>", iface.GetID())
+      .Change("<SET_SECURITY>", GenSecurity(iface))
+      .Out(stream);
 }
 
 void CppCionGroupBodyGen::GenDestructor(std::ofstream& stream,
index 5450595b1586a2ad058ae25e79fd9ecb48803180..adf535bd1f866ce04a2d243fb7b2b2ad95fca97e 100644 (file)
@@ -137,10 +137,11 @@ R"__cpp_cb(
     _E("Failed to create security handle. error(%d)", ret);
     throw InvalidIOException();
   }
+
   auto security_auto = std::unique_ptr<
       std::remove_pointer<cion_security_h>::type, decltype(cion_security_destroy)*>(
           security, cion_security_destroy);
-
+<SET_SECURITY>
   cion_group_h group = nullptr;
   ret = cion_group_create(&group, topic_name_.c_str(), security);
   if (ret != CION_ERROR_NONE) {
index 05dd62359a92df9d7ad288529415e5f0e4afe1c1..1be3e024c4a9725f40b48c0379fecc3e078f9a4a 100644 (file)
@@ -92,13 +92,10 @@ void CppCionProxyBodyGen::GenInterface(std::ofstream& stream,
 
 void CppCionProxyBodyGen::GenConstructor(std::ofstream& stream,
                                      const Interface& iface) {
-  GenTemplate(CB_PROXY_INTERFACE_CTOR, stream,
-    [&]()->std::string {
-      return iface.GetID();
-    },
-    [&]()->std::string {
-      return iface.GetID();
-    });
+  ReplaceAll(CB_PROXY_INTERFACE_CTOR)
+      .Change("$$", iface.GetID())
+      .Change("<SET_SECURITY>", GenSecurity(iface))
+      .Out(stream);
 }
 
 void CppCionProxyBodyGen::GenDestructor(std::ofstream& stream,
index 54cd1ca5f8647596b4fb6350a99c912b8b5a633a..84df8bc9e9732024ecbbb90fc0960cb84add805a 100644 (file)
@@ -355,10 +355,11 @@ $$::$$(IEventListener* listener, const std::string& service_name,
     _E("Failed to create security handle. error(%d)", ret);
     throw InvalidIOException();
   }
+
   auto security_auto = std::unique_ptr<
       std::remove_pointer<cion_security_h>::type, decltype(cion_security_destroy)*>(
           security, cion_security_destroy);
-
+<SET_SECURITY>
   cion_client_h client = nullptr;
   ret = cion_client_create(&client, service_name.c_str(), security);
   if (ret != CION_ERROR_NONE) {
index 925926e45a34ccd97a04fc667080aa7829a564d3..2d10b92c6d5c18a01fe776145fa6da3bf1d68e3c 100644 (file)
@@ -102,7 +102,10 @@ void CppCionStubBodyGen::GenServiceBase(std::ofstream& stream,
 
 void CppCionStubBodyGen::GenConstructor(std::ofstream& stream,
                                     const Interface& iface) {
-  stream << ReplaceAll(CB_CTOR_FRONT, "##", iface.GetID());
+  ReplaceAll(CB_CTOR_FRONT)
+      .Change("##", iface.GetID())
+      .Change("<SET_SECURITY>", GenSecurity(iface))
+      .Out(stream);
 }
 
 void CppCionStubBodyGen::GenDefaultMethods(std::ofstream& stream,
index 00b5b946a6ff8120d584f0a7cce0a97521f1b280..b6c671231fa65b5a552cfddb10204ab5c40ad4bd 100644 (file)
@@ -26,10 +26,11 @@ R"__cpp_cb(
     _E("Failed to create security handle. error(%d)", ret);
     throw InvalidIOException();
   }
+
   auto security_auto = std::unique_ptr<
       std::remove_pointer<cion_security_h>::type, decltype(cion_security_destroy)*>(
           security, cion_security_destroy);
-
+<SET_SECURITY>
   cion_server_h server;
   ret = cion_server_create(&server, service_name.c_str(),
       display_name.c_str(), security);