From: Sangyoon Jang Date: Mon, 24 Jan 2022 05:59:31 +0000 (+0900) Subject: Generate security setup for cion cpp code X-Git-Tag: accepted/tizen/unified/20220216.010312~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=555f2466d65b2136adab05623299ad535279754e;p=platform%2Fcore%2Fappfw%2Ftidl.git Generate security setup for cion cpp code Change-Id: I2ba76e0219418df0440fb2273e0de27e3ad11eab Signed-off-by: Sangyoon Jang --- diff --git a/idlc/gen_cion/cpp_cion_gen_base.cc b/idlc/gen_cion/cpp_cion_gen_base.cc index a0319cb..1e4346e 100644 --- a/idlc/gen_cion/cpp_cion_gen_base.cc +++ b/idlc/gen_cion/cpp_cion_gen_base.cc @@ -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, "", + attr->GetValue()); + else if (attr->GetKey() == "cert_path") + security_path += ReplaceAll(CB_INTERFACE_SECURITY_CERT, "", + attr->GetValue()); + else if (attr->GetKey() == "private_key") + security_path += ReplaceAll(CB_INTERFACE_SECURITY_PRIVATE_KEY, "", + attr->GetValue()); + } + + return security_path; +} + void CppCionGeneratorBase::GenVersion(std::ofstream& stream) { GenTemplate(CB_VERSION, stream, [&]()->std::string { diff --git a/idlc/gen_cion/cpp_cion_gen_base.h b/idlc/gen_cion/cpp_cion_gen_base.h index 38f3c21..b7570fe 100644 --- a/idlc/gen_cion/cpp_cion_gen_base.h +++ b/idlc/gen_cion/cpp_cion_gen_base.h @@ -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); diff --git a/idlc/gen_cion/cpp_cion_gen_base_cb.h b/idlc/gen_cion/cpp_cion_gen_base_cb.h index d6043c9..fa946be 100644 --- a/idlc/gen_cion/cpp_cion_gen_base_cb.h +++ b/idlc/gen_cion/cpp_cion_gen_base_cb.h @@ -290,6 +290,30 @@ $$ } )__cpp_cb"; +const char CB_INTERFACE_SECURITY_CA[] = +R"__cpp_cb( + if (cion_security_set_ca_path(security, "") != 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, "") != 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, "") != 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 diff --git a/idlc/gen_cion/cpp_cion_group_body_gen.cc b/idlc/gen_cion/cpp_cion_group_body_gen.cc index 51ab1ee..8bd51f2 100644 --- a/idlc/gen_cion/cpp_cion_group_body_gen.cc +++ b/idlc/gen_cion/cpp_cion_group_body_gen.cc @@ -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, "", iface.GetID()) - << NLine(1); + ReplaceAll(CB_GROUP_INTERFACE_CTOR) + .Change("", iface.GetID()) + .Change("", GenSecurity(iface)) + .Out(stream); } void CppCionGroupBodyGen::GenDestructor(std::ofstream& stream, diff --git a/idlc/gen_cion/cpp_cion_group_body_gen_cb.h b/idlc/gen_cion/cpp_cion_group_body_gen_cb.h index 5450595..adf535b 100644 --- a/idlc/gen_cion/cpp_cion_group_body_gen_cb.h +++ b/idlc/gen_cion/cpp_cion_group_body_gen_cb.h @@ -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::type, decltype(cion_security_destroy)*>( security, cion_security_destroy); - + cion_group_h group = nullptr; ret = cion_group_create(&group, topic_name_.c_str(), security); if (ret != CION_ERROR_NONE) { diff --git a/idlc/gen_cion/cpp_cion_proxy_body_gen.cc b/idlc/gen_cion/cpp_cion_proxy_body_gen.cc index 05dd623..1be3e02 100644 --- a/idlc/gen_cion/cpp_cion_proxy_body_gen.cc +++ b/idlc/gen_cion/cpp_cion_proxy_body_gen.cc @@ -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("", GenSecurity(iface)) + .Out(stream); } void CppCionProxyBodyGen::GenDestructor(std::ofstream& stream, diff --git a/idlc/gen_cion/cpp_cion_proxy_body_gen_cb.h b/idlc/gen_cion/cpp_cion_proxy_body_gen_cb.h index 54cd1ca..84df8bc 100644 --- a/idlc/gen_cion/cpp_cion_proxy_body_gen_cb.h +++ b/idlc/gen_cion/cpp_cion_proxy_body_gen_cb.h @@ -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::type, decltype(cion_security_destroy)*>( security, cion_security_destroy); - + cion_client_h client = nullptr; ret = cion_client_create(&client, service_name.c_str(), security); if (ret != CION_ERROR_NONE) { diff --git a/idlc/gen_cion/cpp_cion_stub_body_gen.cc b/idlc/gen_cion/cpp_cion_stub_body_gen.cc index 925926e..2d10b92 100644 --- a/idlc/gen_cion/cpp_cion_stub_body_gen.cc +++ b/idlc/gen_cion/cpp_cion_stub_body_gen.cc @@ -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("", GenSecurity(iface)) + .Out(stream); } void CppCionStubBodyGen::GenDefaultMethods(std::ofstream& stream, diff --git a/idlc/gen_cion/cpp_cion_stub_body_gen_cb.h b/idlc/gen_cion/cpp_cion_stub_body_gen_cb.h index 00b5b94..b6c6712 100644 --- a/idlc/gen_cion/cpp_cion_stub_body_gen_cb.h +++ b/idlc/gen_cion/cpp_cion_stub_body_gen_cb.h @@ -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::type, decltype(cion_security_destroy)*>( security, cion_security_destroy); - + cion_server_h server; ret = cion_server_create(&server, service_name.c_str(), display_name.c_str(), security);