Implement SetSecurity
authorInkyun Kil <inkyun.kil@samsung.com>
Tue, 9 Mar 2021 01:05:47 +0000 (10:05 +0900)
committer길인균/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <inkyun.kil@samsung.com>
Wed, 10 Mar 2021 07:09:36 +0000 (16:09 +0900)
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
cion/channel/client_channel.cc
cion/channel/server_channel.cc
cion/vine_manager/vine_manager.cc
cion/vine_manager/vine_manager.hh
cion/vine_manager/vine_sender.cc

index 1c672b4fbaca1187bac687bdac18fdfd50cf9ddf..e7de4f1b9af2bef8b0dc0dd5e926bcfd61a16ab9 100644 (file)
@@ -102,7 +102,7 @@ std::shared_ptr<PeerInfo> ClientChannel::GetPeerInfo() {
 }
 
 void ClientChannel::SetSecurity(SecurityInfo sec) {
-  // do something
+  impl_->sender_->SetSecurity(sec);
 }
 
 void ClientChannel::OnDataEvent(std::shared_ptr<IDataInfo> info,
index 8a924ee4c1ff8449d513b3b5ad9e755696725780..ff7101c964964aa931f2e2e4cd158212100e5ac9 100644 (file)
@@ -103,7 +103,7 @@ std::list<std::shared_ptr<PeerInfo>> ServerChannel::GetConnectedPeerList() {
 }
 
 void ServerChannel::SetSecurity(SecurityInfo sec) {
-  // do something
+  impl_->sender_->SetSecurity(sec);
 }
 
 void ServerChannel::OnDataEvent(std::shared_ptr<IDataInfo> info,
index b2891140b9cf800b8279befaa1074230f6d527a3..da82a4ea3e9b52fa5696aaf12d08d9ff1a839c50 100644 (file)
@@ -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, };
index 32c19cf6e0d397726aa970747ebb0090db4b8b1d..3271a3e9034ca603bf646ccc323b1a4c5c5d0ec1 100644 (file)
@@ -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<SessionInfo> 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<PeerInfo> peer_info);
   void Accept(int channel_id, std::shared_ptr<PeerInfo> peer_info);
index 99475fd93f8db0b8ba995b0c5b117a41e43feaa4..d0fc01ff10357fe1c850de90bf5d6534e5b4e7e6 100644 (file)
@@ -72,6 +72,7 @@ std::vector<char> VineSender::SendData(
 }
 
 void VineSender::SetSecurity(SecurityInfo sec) {
+  VineManager::GetInst().SetSecurity(sec, impl_->channel_id_);
 }
 
 }   // namespace cion