mesh: Add authorization checks for Manager iface methods
authorInga Stotland <inga.stotland@intel.com>
Wed, 30 Oct 2019 06:27:49 +0000 (23:27 -0700)
committerAnupam Roy <anupam.r@samsung.com>
Tue, 17 Dec 2019 19:12:28 +0000 (00:42 +0530)
This adds a check for org.bluez.mesh.Manager1 interface calls to
validate that a message sender, i.e. thatt the sender is the original
owner of the node object generated on Attach() method call.
If the check fails, org.bluez.mesh.Error.NotAuthorized is returned.

Change-Id: Ibf46b6e27df02ce2a62a84f2f68c4e7639a0889f
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
mesh/manager.c

index f6ffd8f..dd4f355 100644 (file)
@@ -289,6 +289,10 @@ static struct l_dbus_message *import_node_call(struct l_dbus *dbus,
        uint8_t num_ele;
        uint8_t *key;
        uint32_t n;
+       const char *sender = l_dbus_message_get_sender(msg);
+
+       if (strcmp(sender, node_get_owner(node)))
+               return dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED, NULL);
 
        if (!l_dbus_message_get_arguments(msg, "qyay", &primary, &num_ele,
                                                                &iter_key))
@@ -313,6 +317,10 @@ static struct l_dbus_message *delete_node_call(struct l_dbus *dbus,
        struct mesh_net *net = node_get_net(node);
        uint16_t primary;
        uint8_t num_ele;
+       const char *sender = l_dbus_message_get_sender(msg);
+
+       if (strcmp(sender, node_get_owner(node)))
+               return dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED, NULL);
 
        if (!l_dbus_message_get_arguments(msg, "qy", &primary, &num_ele))
                return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL);
@@ -370,6 +378,10 @@ static struct l_dbus_message *start_scan_call(struct l_dbus *dbus,
        uint16_t duration;
        struct mesh_io *io;
        struct mesh_net *net;
+       const char *sender = l_dbus_message_get_sender(msg);
+
+       if (strcmp(sender, node_get_owner(node)))
+               return dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED, NULL);
 
        if (!l_dbus_message_get_arguments(msg, "q", &duration))
                return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL);
@@ -404,11 +416,17 @@ static struct l_dbus_message *cancel_scan_call(struct l_dbus *dbus,
                                                void *user_data)
 {
        struct mesh_node *node = user_data;
+       const char *sender = l_dbus_message_get_sender(msg);
 
-       if (scan_node != node)
-               return dbus_error(msg, MESH_ERROR_BUSY, NULL);
+       if (strcmp(sender, node_get_owner(node)) || !node_is_provisioner(node))
+               return dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED, NULL);
 
-       scan_cancel(NULL, node);
+       if (scan_node) {
+               if (scan_node != node)
+                       return dbus_error(msg, MESH_ERROR_BUSY, NULL);
+
+               scan_cancel(NULL, node);
+       }
 
        return l_dbus_message_new_method_return(msg);
 }
@@ -448,6 +466,10 @@ static struct l_dbus_message *create_subnet_call(struct l_dbus *dbus,
        struct mesh_node *node = user_data;
        uint8_t key[16];
        uint16_t net_idx;
+       const char *sender = l_dbus_message_get_sender(msg);
+
+       if (strcmp(sender, node_get_owner(node)))
+               return dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED, NULL);
 
        if (!l_dbus_message_get_arguments(msg, "q", &net_idx) ||
                                                net_idx == PRIMARY_NET_IDX)
@@ -466,6 +488,10 @@ static struct l_dbus_message *update_subnet_call(struct l_dbus *dbus,
        struct mesh_node *node = user_data;
        struct keyring_net_key key;
        uint16_t net_idx;
+       const char *sender = l_dbus_message_get_sender(msg);
+
+       if (strcmp(sender, node_get_owner(node)))
+               return dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED, NULL);
 
        if (!l_dbus_message_get_arguments(msg, "q", &net_idx) ||
                                                net_idx > MAX_KEY_IDX)
@@ -503,6 +529,10 @@ static struct l_dbus_message *delete_subnet_call(struct l_dbus *dbus,
 {
        struct mesh_node *node = user_data;
        uint16_t net_idx;
+       const char *sender = l_dbus_message_get_sender(msg);
+
+       if (strcmp(sender, node_get_owner(node)))
+               return dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED, NULL);
 
        if (!l_dbus_message_get_arguments(msg, "q", &net_idx) ||
                                                net_idx > MAX_KEY_IDX)
@@ -522,6 +552,10 @@ static struct l_dbus_message *import_subnet_call(struct l_dbus *dbus,
        uint16_t net_idx;
        uint8_t *key;
        uint32_t n;
+       const char *sender = l_dbus_message_get_sender(msg);
+
+       if (strcmp(sender, node_get_owner(node)))
+               return dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED, NULL);
 
        if (!l_dbus_message_get_arguments(msg, "qay", &net_idx, &iter_key))
                return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL);
@@ -576,6 +610,10 @@ static struct l_dbus_message *create_appkey_call(struct l_dbus *dbus,
        struct mesh_node *node = user_data;
        uint16_t net_idx, app_idx;
        uint8_t key[16];
+       const char *sender = l_dbus_message_get_sender(msg);
+
+       if (strcmp(sender, node_get_owner(node)))
+               return dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED, NULL);
 
        if (!l_dbus_message_get_arguments(msg, "qq", &net_idx, &app_idx))
                return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL);
@@ -593,6 +631,10 @@ static struct l_dbus_message *update_appkey_call(struct l_dbus *dbus,
        struct keyring_net_key net_key;
        struct keyring_app_key app_key;
        uint16_t app_idx;
+       const char *sender = l_dbus_message_get_sender(msg);
+
+       if (strcmp(sender, node_get_owner(node)))
+               return dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED, NULL);
 
        if (!l_dbus_message_get_arguments(msg, "q", &app_idx) ||
                                                        app_idx > MAX_KEY_IDX)
@@ -620,6 +662,10 @@ static struct l_dbus_message *delete_appkey_call(struct l_dbus *dbus,
 {
        struct mesh_node *node = user_data;
        uint16_t app_idx;
+       const char *sender = l_dbus_message_get_sender(msg);
+
+       if (strcmp(sender, node_get_owner(node)))
+               return dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED, NULL);
 
        if (!l_dbus_message_get_arguments(msg, "q", &app_idx))
                return dbus_error(msg, MESH_ERROR_INVALID_ARGS, NULL);
@@ -638,6 +684,10 @@ static struct l_dbus_message *import_appkey_call(struct l_dbus *dbus,
        uint16_t net_idx, app_idx;
        uint8_t *key;
        uint32_t n;
+       const char *sender = l_dbus_message_get_sender(msg);
+
+       if (strcmp(sender, node_get_owner(node)))
+               return dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED, NULL);
 
        if (!l_dbus_message_get_arguments(msg, "qqay", &net_idx, &app_idx,
                                                                &iter_key))
@@ -659,6 +709,10 @@ static struct l_dbus_message *set_key_phase_call(struct l_dbus *dbus,
        struct keyring_net_key key;
        uint16_t net_idx;
        uint8_t phase;
+       const char *sender = l_dbus_message_get_sender(msg);
+
+       if (strcmp(sender, node_get_owner(node)))
+               return dbus_error(msg, MESH_ERROR_NOT_AUTHORIZED, NULL);
 
        if (!l_dbus_message_get_arguments(msg, "qy", &net_idx, &phase) ||
                                        phase == KEY_REFRESH_PHASE_ONE ||