From: Inkyun Kil Date: Tue, 9 Mar 2021 01:05:47 +0000 (+0900) Subject: Implement SetSecurity X-Git-Tag: submit/tizen/20210806.015209~81^2~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=25fcb03e0955ab476c8351a695b8bfce976fafff;p=platform%2Fcore%2Fappfw%2Fcion.git Implement SetSecurity Signed-off-by: Inkyun Kil --- diff --git a/cion/channel/client_channel.cc b/cion/channel/client_channel.cc index 1c672b4..e7de4f1 100644 --- a/cion/channel/client_channel.cc +++ b/cion/channel/client_channel.cc @@ -102,7 +102,7 @@ std::shared_ptr ClientChannel::GetPeerInfo() { } void ClientChannel::SetSecurity(SecurityInfo sec) { - // do something + impl_->sender_->SetSecurity(sec); } void ClientChannel::OnDataEvent(std::shared_ptr info, diff --git a/cion/channel/server_channel.cc b/cion/channel/server_channel.cc index 8a924ee..ff7101c 100644 --- a/cion/channel/server_channel.cc +++ b/cion/channel/server_channel.cc @@ -103,7 +103,7 @@ std::list> ServerChannel::GetConnectedPeerList() { } void ServerChannel::SetSecurity(SecurityInfo sec) { - // do something + impl_->sender_->SetSecurity(sec); } void ServerChannel::OnDataEvent(std::shared_ptr info, diff --git a/cion/vine_manager/vine_manager.cc b/cion/vine_manager/vine_manager.cc index b289114..da82a4e 100644 --- a/cion/vine_manager/vine_manager.cc +++ b/cion/vine_manager/vine_manager.cc @@ -108,6 +108,63 @@ channel::IEventObserver* VineManager::GetObserver(int channel_id) { return nullptr; } +void VineManager::SetSecurity(SecurityInfo sec, int channel_id) { + vine_dp_h dp = nullptr; + vine_security_h vs = nullptr; + + for (auto& i : impl_->data_path_list_) { + if (channel_id != i->GetLocalChannelId()) { + dp = i->GetDataPath(); + break; + } + } + + if (dp == nullptr) { + LOGE("No vine data path for %d", channel_id); + return; + } + + int ret = vine_security_create(&vs); + if (ret != VINE_ERROR_NONE) { + LOGE("vine_security_create error %d" , ret); + return; + } + + ret = vine_security_set_ca_path(vs, sec.GetCaPath().c_str()); + if (ret != VINE_ERROR_NONE) { + LOGE("vine_security_set_ca_path error %d" , ret); + vine_security_destroy(vs); + return; + } + + ret = vine_security_set_cert_path(vs, sec.GetCertPath().c_str()); + if (ret != VINE_ERROR_NONE) { + LOGE("vine_security_set_cert_path error %d" , ret); + vine_security_destroy(vs); + return; + } + + ret = vine_security_set_private_key(vs, sec.GetPrivatePath().c_str()); + if (ret != VINE_ERROR_NONE) { + LOGE("vine_security_set_private_key error %d" , ret); + vine_security_destroy(vs); + return; + } + + //TODO + //vine_security_set_type + //vine_security_set_tls_version + //vine_security_set_verification_flags + //vine_security_set_psk + + ret = vine_dp_set_security(dp, vs); + if (ret != VINE_ERROR_NONE) + LOGE("vine_dp_set_security error %d" , ret); + + LOGD("Success for set security"); + vine_security_destroy(vs); +} + void VineManager::HandlingDiscoveredPeer(vine_dp_h dp, size_t received_len, int channel_id, channel::IEventObserver* observer) { unsigned char buf[256] = {0, }; diff --git a/cion/vine_manager/vine_manager.hh b/cion/vine_manager/vine_manager.hh index 32c19cf..3271a3e 100644 --- a/cion/vine_manager/vine_manager.hh +++ b/cion/vine_manager/vine_manager.hh @@ -29,6 +29,7 @@ #include "cion/common/peer_info.hh" #include "cion/channel/idata_info.hh" #include "cion/channel/icontrol_info.hh" +#include "cion/security/security_info.hh" #include "data_path_info.hh" #include "session_info.hh" @@ -84,6 +85,7 @@ class EXPORT_API VineManager { void OpenServer(int channel_id); channel::IEventObserver* GetObserver(int channel_id); std::shared_ptr GetSessionInfo(int channel_id); + void SetSecurity(SecurityInfo sec, int channel_id); void SendPeerInfo(vine_dp_h dp); void Connect(int channel_id, std::shared_ptr peer_info); void Accept(int channel_id, std::shared_ptr peer_info); diff --git a/cion/vine_manager/vine_sender.cc b/cion/vine_manager/vine_sender.cc index 99475fd..d0fc01f 100644 --- a/cion/vine_manager/vine_sender.cc +++ b/cion/vine_manager/vine_sender.cc @@ -72,6 +72,7 @@ std::vector VineSender::SendData( } void VineSender::SetSecurity(SecurityInfo sec) { + VineManager::GetInst().SetSecurity(sec, impl_->channel_id_); } } // namespace cion