Check if appcontrol is valid on the sender side
authorInkyun Kil <inkyun.kil@samsung.com>
Thu, 30 Aug 2018 07:26:30 +0000 (16:26 +0900)
committer길인균/Tizen Platform Lab(SR)/Engineer/삼성전자 <inkyun.kil@samsung.com>
Fri, 14 Sep 2018 07:42:52 +0000 (16:42 +0900)
Change-Id: Ie13ef3c4bdb2b3929d4b0abafc2b6e5bb5ae047c
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
src/common/appcontrol_manager.cc
src/common/appcontrol_manager.h
src/common/db_manager.cc
src/common/db_manager.h
src/common/mdg_manager.cc

index 25cfd0a788d9d74d6f770e1ddc153ca2c7fb9b36..8eadf8911198bfcaa780df1882f9c71136f4459c 100644 (file)
@@ -9,7 +9,10 @@
 #include <bundle.h>
 
 #include <map>
+#include <vector>
 
+#include "common/capability.h"
+#include "common/db_manager.h"
 #include "common/utils/logging.h"
 
 namespace {
@@ -59,6 +62,36 @@ bool AppControlManager::LaunchApplication(const unsigned char* bundle_data,
   return true;
 }
 
+bool AppControlManager::CheckRemoteAppControl(const std::string& device_id,
+    const unsigned char* appcontrol, size_t len) {
+  bundle* b = bundle_decode(appcontrol, len);
+  if (!b) {
+    LOG(ERROR) << "Invalid bundle data!";
+    return false;
+  }
+
+  const char* appid_cstr = aul_svc_get_appid(b);
+  if (!appid_cstr) {
+    LOG(ERROR) << "Failed to get appid!";
+    bundle_free(b);
+    return false;
+  }
+
+  std::string appid(appid_cstr);
+  std::vector<Capability> cap_list = DBManager::SelectCapabilites(device_id);
+  for (auto& cap : cap_list) {
+    if (appid == cap.appid()) {
+      LOG(INFO) << "Found the appcontrol!";
+      bundle_free(b);
+      return true;
+    }
+  }
+
+  LOG(ERROR) << "Invalid appcontrol!";
+  bundle_free(b);
+  return false;
+}
+
 int AppControlManager::AulHandler(aul_type type, bundle* kb, void* data) {
   return 0;
 }
index 8ab9027b9b07192f1388e426fa7119d5dc839240..b069d351ea773f186dfb1b2509a7b6c68d52767d 100644 (file)
 #include <boost/signals2.hpp>
 
 #include <functional>
+#include <string>
 
 #include "common/capability.h"
+#include "common/capability_manager.h"
 
 namespace capmgr {
 
@@ -33,6 +35,8 @@ class AppControlManager {
   }
   bool LaunchApplication(const unsigned char* bundle_data, size_t len,
       void* data);
+  bool CheckRemoteAppControl(const std::string& device_id,
+      const unsigned char* appcontrol, size_t len);
 
  private:
   class AppControlReplyHandler {
index 65996af4f514129cdf4e34d8e35b2358a009c4f2..bddf225793b0af84f8a23e17a8b1c976fcb4d493 100644 (file)
@@ -64,6 +64,9 @@ const char kQueryInsertCap[] =
 const char kQueryDeleteCap[] =
     "DELETE FROM capabilities WHERE device_id=? AND operation=? AND uri=? AND "
     "  mime=? AND appid=?";
+const char kQuerySelectCap[] =
+    "SELECT operation, uri, mime, appid, pkgid FROM capabilities "
+    "WHERE device_id=?";
 const char kQueryInsertRemoteApp[] =
     "INSERT INTO remote_app_info (device_id, appid, pkgid, label, version) "
     "VALUES (?, ?, ?, ?, ?)";
@@ -252,6 +255,35 @@ bool DBManager::DeleteCapability(const std::string& device_id,
   return true;
 }
 
+std::vector<Capability> DBManager::SelectCapabilites(
+      const std::string& device_id) {
+  auto guard = Instance().sql_conn_->GetTransactionGuard();
+  std::shared_ptr<SQLStatement> stmt = Instance().sql_conn_->PrepareStatement(
+      kQuerySelectCap);
+  if (!stmt) {
+    LOG(ERROR) << "Failed to prepare statement";
+    return {};
+  }
+
+  if (!stmt->BindString(1, device_id))
+    return {};
+
+  std::vector<Capability> cap_list;
+  while (stmt->Step() == SQLStatement::StepResult::ROW) {
+    int idx = 0;
+    std::string operation = stmt->GetColumnString(idx++);
+    std::string uri = stmt->GetColumnString(idx++);
+    std::string mime = stmt->GetColumnString(idx++);
+    std::string appid = stmt->GetColumnString(idx++);
+    std::string pkgid = stmt->GetColumnString(idx++);
+
+    Capability cap(operation, uri, mime, appid, pkgid);
+    cap_list.push_back(cap);
+  }
+
+  return cap_list;
+}
+
 bool DBManager::InsertRemotePackage(const std::string& device_id,
     const RemotePackageInfo& remote_pkg_info) {
   auto guard = Instance().sql_conn_->GetTransactionGuard();
index b9b2ba5412a179575f91faba975384b963e558bb..b1f7f60d7c1f4621392a318426006ec5b8f69d34 100644 (file)
@@ -29,6 +29,8 @@ class DBManager {
       const std::vector<Capability>& caps);
   static bool DeleteCapability(const std::string& device_id,
       const Capability& cap);
+  static std::vector<Capability> SelectCapabilites(
+      const std::string& device_id);
   static bool InsertRemotePackage(const std::string& device_id,
     const RemotePackageInfo& remote_pkg_info);
   static bool DeleteRemotePackage(const std::string& device_id,
index b27d85f33ff75f56b5d1ef22adf69440078953fb..075f06b63a9a0d0987913eec80d9028bfbaf4e45 100755 (executable)
@@ -677,6 +677,10 @@ void MDGManager::ExchangeCapabilities() {
 
 int MDGManager::SendAppControl(const std::string& device_id,
     const unsigned char* appcontrol, size_t len) {
+  if (!AppControlManager::GetAppControlManager().CheckRemoteAppControl(
+      device_id, appcontrol, len))
+    return -1;
+
   return SendData(device_id, Command::SEND_APPCONTROL, appcontrol, len);
 }