Mesh: Add functionality to find unique app credentials 32/238932/1
authorAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 20 Jul 2020 08:33:05 +0000 (14:03 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 20 Jul 2020 10:14:26 +0000 (15:44 +0530)
Unique app credentials would be used to differentiate
and authenticate mesh applications

Change-Id: If8b19d802465282e78ebc3d60f845bed95a68660
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
bt-service/CMakeLists.txt
bt-service/services/bt-request-handler.c

index 82a5f39..fa38491 100644 (file)
@@ -94,6 +94,7 @@ SET(PKG_MODULES
         capi-network-connection
         cynara-client
         cynara-creds-gdbus
+        aul
        json-c
        ell
         eventsystem
@@ -112,6 +113,7 @@ SET(PKG_MODULES
         capi-network-connection
         cynara-client
         cynara-creds-gdbus
+        aul
        json-c
        ell
         eventsystem
index 89cc960..10b56f0 100644 (file)
@@ -24,6 +24,7 @@
 #include <cynara-client.h>
 #include <cynara-creds-gdbus.h>
 #include <systemd/sd-daemon.h>
+#include <aul.h>
 
 #include "bluetooth-api.h"
 #include "bluetooth-audio-api.h"
@@ -4666,6 +4667,30 @@ int __bt_core_request(int function_name,
        return result;
 }
 
+static int __bt_service_get_requester_app_id(const char *unique_name, char *app_id, int len)
+{
+       int ret;
+       pid_t pid = 0;
+
+       retv_if(bt_service_conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+       retv_if(unique_name == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
+
+       ret = __bt_service_get_sender_pid(unique_name, &pid);
+       if (ret != BLUETOOTH_ERROR_NONE) {
+               BT_ERR("Fail to get the sender pid");
+               return ret;
+       }
+
+       ret = aul_app_get_appid_bypid(pid, app_id, len);
+       if (ret != AUL_R_OK) {
+               BT_ERR("app_id not found");
+               return BLUETOOTH_ERROR_NOT_SUPPORT;
+       }
+       BT_DBG("Sender app_id: %s", app_id);
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
 gboolean __bt_service_check_privilege(int function_name,
                                        int service_type,
                                        const char *unique_name)
@@ -5109,13 +5134,24 @@ gboolean __bt_service_check_privilege(int function_name,
                break;
        }
 
-       if (client_creds && function_name >= BT_FUNC_MESH_BASE) {
-               BT_INFO("MESH Function called creds [%s]", client_creds);
-               requester_unique_creds = g_strdup(client_creds);
-               free(client_creds);
+       if (function_name >= BT_FUNC_MESH_BASE) {
+               BT_INFO("MESH Function called");
+               char app_id[256] = { 0, };
 
-       } else
+               if (BLUETOOTH_ERROR_NONE == __bt_service_get_requester_app_id(unique_name,
+                                       app_id, sizeof(app_id))) {
+                       requester_unique_creds = g_strdup(app_id);
+               } else {
+                       BT_DBG("Requester app_id not found, use client creds");
+                       requester_unique_creds = g_strdup(client_creds);
+               }
+               BT_DBG("Requester unique_creds: %s", requester_unique_creds);
+       } else {
                BT_INFO("Non MESH Function called client creds [%s]", client_creds);
+       }
+
+       if (client_creds)
+               free(client_creds);
 
        if (user_creds)
                free(user_creds);