Migration from 3.0 to 4.0 81/141781/4 accepted/tizen/4.0/unified/20170816.010856 accepted/tizen/4.0/unified/20170816.014508 accepted/tizen/4.0/unified/20170828.224448 accepted/tizen/unified/20170803.010511 submit/tizen/20170801.110349 submit/tizen_4.0/20170811.094300 submit/tizen_4.0/20170814.115522 submit/tizen_4.0/20170828.110001 submit/tizen_4.0_unified/20170814.115522 tizen_4.0.IoT.p1_release
authorjkjo92 <jkjo92@samsung.com>
Tue, 1 Aug 2017 10:45:03 +0000 (19:45 +0900)
committerJinkeun Jo <jkjo92@samsung.com>
Tue, 1 Aug 2017 10:59:15 +0000 (10:59 +0000)
1. On-demand tine out
2. Changed to be used in system-fw
3. fix memory leak
4. fix svace issue
Change-Id: I540151a57555642d8f22d82985fe0a2287ec1b1c
Signed-off-by: jkjo92 <jkjo92@samsung.com>
common/fido_json_handler.c
common/fido_tlv_util.c [changed mode: 0644->0755]
packaging/fido-client.spec [changed mode: 0644->0755]
packaging/fido.service [changed mode: 0644->0755]
packaging/org.tizen.fido.service [changed mode: 0644->0755]
server/fido_app_id_handler.c [changed mode: 0644->0755]
server/fido_asm_plugin_manager.c
server/fido_privilege_checker.c [changed mode: 0644->0755]
server/fido_server.c

index 4dcb4f7..98ade9f 100755 (executable)
@@ -2406,7 +2406,7 @@ _uaf_composer_compose_dereg_request(_response_t *uaf_res)
        json_builder_add_string_value(header_root, uaf_res->header->app_id);
 
        json_builder_set_member_name(header_root, _JSON_KEY_OP);
-       json_builder_add_string_value(header_root, strdup(_UAF_OPERATION_NAME_KEY_DE_REG));
+       json_builder_add_string_value(header_root, _UAF_OPERATION_NAME_KEY_DE_REG);
 
        json_builder_set_member_name(header_root, _JSON_KEY_SERVER_DATA);
        json_builder_add_string_value(header_root, uaf_res->header->server_data);
@@ -2488,7 +2488,6 @@ _uaf_composer_compose_dereg_request(_response_t *uaf_res)
                                _INFO("keyid=[%s]", key_id_enc);
                        }
                        SAFE_DELETE(key_id_enc);
-
                }
 
                _INFO("after assertions");
@@ -2619,6 +2618,7 @@ _uaf_composer_compose_dereg_request(_response_t *uaf_res)
                                json_object_set_string_member(authObject, _JSON_KEY_KEY_ID, (char *)key_id_enc);
                                _INFO("keyid=[%s]", key_id_enc);
                        }
+                       SAFE_DELETE(key_id_enc);
                }
                json_node_take_object(authNode, authObject);
                json_array_add_element(authArray, authNode);
old mode 100644 (file)
new mode 100755 (executable)
index 5b2c28d..02d162f
@@ -139,11 +139,12 @@ _tlv_util_decode_reg_assertion(char *tlv_enc)
                        }
 
                        _INFO("Found TAG_KEYID");
+                       SAFE_DELETE(tlv_dec);
                        return assrt_tlv;
                }
        }
 
-
+       SAFE_DELETE(tlv_dec);
        return NULL;
 }
 
old mode 100644 (file)
new mode 100755 (executable)
index a667d9f..7843263
@@ -123,6 +123,9 @@ install -m 0644 %SOURCE1 %{buildroot}/usr/share/dbus-1/system-services/org.tizen
 mkdir -p %{buildroot}%{_sysconfdir}/dbus-1/system.d
 install -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/dbus-1/system.d/
 
+mkdir -p %{buildroot}%{_unitdir}
+install -m 644 %SOURCE3 %{buildroot}%{_unitdir}/fido.service
+
 mkdir -p %{buildroot}/usr/share/dbus-1/system-services
 install -m 0644 %SOURCE4 %{buildroot}/usr/share/dbus-1/system-services/org.tizen.dummyasm.service
 
@@ -175,6 +178,7 @@ chsmack -a '_' %{_libdir}/fido/asm/
 
 %if 0%{?tizen_version_major} >= 3
 %attr(0644,root,root) /usr/share/dbus-1/system-services/org.tizen.fido.service
+%attr(0644,root,root) %{_unitdir}/fido.service
 
 %else
 %{_libdir}/systemd/system/org.tizen.fido.service
old mode 100644 (file)
new mode 100755 (executable)
index 6d09e27..dadfb05
@@ -1,9 +1,10 @@
 [Unit]
 Description=FIDO Client service
-After=tizen-runtime.target
-Requires=tizen-runtime.target
 
 [Service]
+User=service_fw
+Group=service_fw
+SmackProcessLabel=System
 Type=dbus
 BusName=org.tizen.fido
 ExecStart=/usr/bin/fido-service
old mode 100644 (file)
new mode 100755 (executable)
index 2bd3ab3..c8ab4ba
@@ -3,6 +3,5 @@ Description=FIDO Service D-Bus
 
 [D-BUS Service]
 Name=org.tizen.fido
-Exec=/usr/bin/fido-service
-User=service_fw
-Group=service_fw
+Exec=/bin/false
+SystemdService=fido.service
old mode 100644 (file)
new mode 100755 (executable)
index 90637ea..dc38c69
@@ -584,7 +584,7 @@ _verify_and_get_facet_id(const char *uaf_app_id, GDBusMethodInvocation *invocati
        cb_data->user_data = user_data;
 
        /*Case 1: UAF JSON does not have appID, so no check is required, put facetid*/
-       if (uaf_app_id == NULL) {
+       if ((uaf_app_id == NULL) || (!strcmp(uaf_app_id, ""))) {
                _DBG("UAF msg does not have appID");
                cb_data->real_app_id = __get_tz_facet_id_of_caller(app_id, invocation);
                g_timeout_add(2, __timer_expired, cb_data);
index d812e34..d8c4e9f 100755 (executable)
@@ -173,8 +173,10 @@ __load_plugins(char **plugin_path)
 
        closedir(dir);
 
-       if (is_asm_found == false)
+       if (is_asm_found == false) {
+               _ERR("Failed to find asm");
                return FIDO_ERROR_NOT_SUPPORTED;
+       }
 
        return FIDO_ERROR_NONE;
 }
@@ -293,6 +295,7 @@ _asm_plugin_mgr_discover_all(_asm_plugin_discover_response_cb cb, void *user_dat
        cb_data->user_data = user_data;
 
        if (cb_data->asm_proxy_list_iter == NULL) {
+               _ERR("asm proxy table is empty");
                free(cb_data);
                return FIDO_ERROR_NOT_SUPPORTED;
        }
@@ -351,6 +354,7 @@ _on_asm_dbus_reply(GObject *proxy, GAsyncResult *res, gpointer user_data)
        if (dbus_resp != NULL)
                g_variant_unref(dbus_resp);
 
+       SAFE_DELETE(asm_response_json);
        SAFE_DELETE(cb_data);
 }
 
@@ -372,7 +376,7 @@ _asm_ipc_send(const char *asm_id, const char *asm_request, _asm_ipc_response_cb
        _INFO("asm_request=[%s]", asm_request);
 
        if (asm_id == NULL) {
-               _ERR("dbus proxy failed");
+               _ERR("asm id is NULL");
                return FIDO_ERROR_NOT_SUPPORTED;
        }
 
@@ -423,7 +427,7 @@ _asm_ipc_send_sync(const char *asm_id, const char *asm_req)
        _INFO("_asm_ipc_send_sync");
 
        if (asm_id == NULL) {
-               _ERR("dbus proxy failed");
+               _ERR("asm id is NULL");
                return NULL;
        }
 
@@ -459,6 +463,7 @@ _asm_ipc_send_sync(const char *asm_id, const char *asm_req)
                        NULL,
                        &error);
 
+       SAFE_DELETE(method_name);
        if (error != NULL)
                _ERR("g_dbus_proxy_call_sync failed [%s]", error->message);
        else
old mode 100644 (file)
new mode 100755 (executable)
index 59a9633..cbbe15f
@@ -95,9 +95,9 @@ __check_privilege_by_cynara(const char *client, const char *session, const char
        }
 
        return FIDO_ERROR_NONE;
-#endif
-
+#else
        return FIDO_ERROR_NONE;
+#endif
 }
 
 static int
index d6c6201..b7b4bc5 100755 (executable)
 #include "fido-stub.h"
 
 #define _FIDO_SERVICE_DBUS_PATH       "/org/tizen/fido"
+
+/* timeout for terminating on-demand service */
+#define _FIDO_SERVICE_MIN_TIMEOUT      1       /* seconds */
+#define _FIDO_SERVICE_BOOTUP_TIMEOUT   30      /* seconds */
+#define _FIDO_SERVICE_PROCESS_TIMEOUT  90      /* seconds */
+
 static guint owner_id = 0;
 //GDBusObjectManagerServer *fido_dbus_mgr = NULL;
 static Fido* fido_dbus_obj = NULL;
+static GMainLoop *mainloop = NULL;
+static guint timeout_handle;
 
 //TODO : current assumption is, ASM will handle multiple request queueing
 
@@ -75,6 +83,7 @@ typedef struct _process_cb_data {
 } _process_cb_data_t;
 
 static void __process_dereg_queue(_dereg_q_t *dereg_q);
+static void __set_timeout(int seconds);
 
 static char**
 __create_empty_json_2d_array(void)
@@ -179,6 +188,11 @@ _send_process_response(_process_cb_data_t *cb_data, int tz_err_code, char *uaf_r
 {
        _INFO("_send_process_response");
 
+       if (cb_data == NULL) {
+               SAFE_DELETE(uaf_response_json);
+               return;
+       }
+
        /*TODO*/
        _dbus_info_t *dbus_info = (_dbus_info_t *)(cb_data->dbus_info);
        if (dbus_info != NULL) {
@@ -234,6 +248,8 @@ _discover_response_intermediate_cb(GList *asm_response_list, void *user_data)
 
        if (asm_response_list != NULL)
                g_list_free_full(asm_response_list, __free_asm_discover_response_list_item);
+
+       SAFE_DELETE(cb_data);
 }
 
 static int
@@ -671,6 +687,7 @@ __handle_auth(_process_cb_data_t *cb_data, _matched_auth_data_t *matched_auth)
                _ERR("ASM in data missing");
                _send_process_response(cb_data, FIDO_ERROR_NO_SUITABLE_AUTHENTICATOR, NULL);
 
+               _free_fido_asm_auth_in(auth_asm_in);
                SAFE_DELETE(version);
 
                return;
@@ -710,10 +727,13 @@ _ui_response_callback(int error_code, _ui_auth_data_t *selected_auth_data, void
 
        if (cb_data->type == _PROCESS_TYPE_REG)
                __handle_reg(cb_data, match_data);
-
        else if (cb_data->type == _PROCESS_TYPE_AUTH)
                __handle_auth(cb_data, match_data);
-
+       else {
+               _send_process_response(cb_data, FIDO_ERROR_UNKNOWN, NULL);
+               _free_matched_auth_data(match_data);
+               return;
+       }
        _free_matched_auth_data(match_data);
 
 }
@@ -724,8 +744,10 @@ _asm_response_dereg_process(int error_code, const char *asm_response_json, void
        _dereg_q_t *dereg_q = (_dereg_q_t*)(user_data);
        _process_cb_data_t *cb_data = (_process_cb_data_t*)(dereg_q->cb_data);
 
-       if (cb_data == NULL)
+       if (cb_data == NULL) {
+               SAFE_DELETE(dereg_q);
                return;
+       }
 
        /*Process next dereg*/
        GQueue *q = (GQueue*) (dereg_q->dereg_asm_in_q);
@@ -741,6 +763,8 @@ _asm_response_dereg_process(int error_code, const char *asm_response_json, void
                g_queue_free(dereg_q->dereg_asm_in_q);
                dereg_q->dereg_asm_in_q = NULL;
                _INFO("After Deleting dereg_asm_in_q");
+
+               SAFE_DELETE(dereg_q);
        }
 
 }
@@ -751,14 +775,17 @@ __process_dereg_queue(_dereg_q_t *dereg_q)
        _INFO("__process_dereg_queue");
 
        GQueue *q = dereg_q->dereg_asm_in_q;
-       if (q == NULL)
+       if (q == NULL) {
+               SAFE_DELETE(dereg_q);
                return;
+       }
 
        if (g_queue_is_empty(q) == true) {
                _INFO("Deleting dereg_asm_in_q");
                g_queue_free(dereg_q->dereg_asm_in_q);
                dereg_q->dereg_asm_in_q = NULL;
                _INFO("After Deleting dereg_asm_in_q");
+               SAFE_DELETE(dereg_q);
                return;
        }
 
@@ -811,6 +838,7 @@ __process_dereg_queue(_dereg_q_t *dereg_q)
                                          asm_req_json, _asm_response_dereg_process, dereg_q);
        } else {
                _send_process_response(cb_data, FIDO_ERROR_INVALID_PARAMETER, NULL);
+               SAFE_DELETE(dereg_q);
        }
 
        _free_matched_auth_dereg(dereg_data);
@@ -1170,14 +1198,20 @@ _discover_response_cb_for_process(int tz_error_code, int error_code, GList *avai
                }
        } else {
                GList *allowed_auth_list_iter = allowed_auth_list;
-               _matched_auth_data_t *match_data = (_matched_auth_data_t *)(allowed_auth_list_iter->data);
-
-               if (cb_data->type == _PROCESS_TYPE_REG)
-                       __handle_reg(cb_data, match_data);
-
-               else if (cb_data->type == _PROCESS_TYPE_AUTH)
-                       __handle_auth(cb_data, match_data);
+               if (allowed_auth_list_iter != NULL) {
+                       _matched_auth_data_t *match_data = (_matched_auth_data_t *)(allowed_auth_list_iter->data);
 
+                       if (cb_data->type == _PROCESS_TYPE_REG)
+                               __handle_reg(cb_data, match_data);
+                       else if (cb_data->type == _PROCESS_TYPE_AUTH)
+                               __handle_auth(cb_data, match_data);
+                       else {
+                               _send_process_response(cb_data, FIDO_ERROR_UNKNOWN, NULL);
+                               if (allowed_auth_list != NULL)
+                                       g_list_free_full(allowed_auth_list, _free_matched_auth_data);
+                               return;
+                       }
+               }
        }
        if (allowed_auth_list != NULL)
                g_list_free_full(allowed_auth_list, _free_matched_auth_data);
@@ -1242,6 +1276,9 @@ __facet_id_cb(int err, const char *facet_id, void *user_data)
 gboolean
 _dbus_on_fido_init(Fido *object, GDBusMethodInvocation *invocation)
 {
+       _INFO("_dbus_on_fido_init");
+       __set_timeout(_FIDO_SERVICE_PROCESS_TIMEOUT);
+
        fido_complete_fido_uaf_init(object, invocation, FIDO_ERROR_NONE);
 
        return true;
@@ -1250,6 +1287,9 @@ _dbus_on_fido_init(Fido *object, GDBusMethodInvocation *invocation)
 gboolean
 _dbus_on_fido_deinit(Fido *object, GDBusMethodInvocation *invocation)
 {
+       _INFO("_dbus_on_fido_deinit");
+       __set_timeout(_FIDO_SERVICE_PROCESS_TIMEOUT);
+
        if (is_allowed_to_call(invocation, _FIDO_CLIENT_PRIVILEGE) == false) {
                fido_complete_fido_uaf_deinit(object, invocation, FIDO_ERROR_PERMISSION_DENIED);
        } else {
@@ -1264,6 +1304,8 @@ gboolean
 _dbus_on_fido_discover(Fido *object, GDBusMethodInvocation *invocation)
 {
        _INFO("_dbus_on_fido_discover");
+
+       __set_timeout(_FIDO_SERVICE_PROCESS_TIMEOUT);
        if (is_allowed_to_call(invocation, _FIDO_CLIENT_PRIVILEGE) == false) {
 
                __send_discover_response(object, invocation, FIDO_ERROR_PERMISSION_DENIED,
@@ -1341,6 +1383,7 @@ _dbus_on_fido_uaf_is_supported(Fido *object, GDBusMethodInvocation *invocation,
 {
        _INFO("_dbus_on_fido_uaf_is_supported");
 
+       __set_timeout(_FIDO_SERVICE_PROCESS_TIMEOUT);
        return _dbus_handle_process_or_check_policy(object, invocation, uaf_request_json, NULL,
                                                                                                _PROCESS_TYPE_CHECK_POLICY);
 }
@@ -1351,6 +1394,7 @@ _dbus_on_fido_process_operation(Fido *object, GDBusMethodInvocation *invocation,
 {
        _INFO("_dbus_on_fido_process_operation");
 
+       __set_timeout(_FIDO_SERVICE_PROCESS_TIMEOUT);
        return _dbus_handle_process_or_check_policy(object, invocation, uaf_request_json,
                                                                                                channel_binding_json, _PROCESS_TYPE_MIN);
 }
@@ -1359,6 +1403,7 @@ _dbus_on_fido_process_operation(Fido *object, GDBusMethodInvocation *invocation,
 _dbus_on_fido_uaf_notify_result(Fido *object, GDBusMethodInvocation *invocation, const gchar *arg_cookie, gint arg_respose_code,
                                                                const gchar *uaf_response_json)
 {
+       __set_timeout(_FIDO_SERVICE_PROCESS_TIMEOUT);
        fido_complete_fido_uaf_notify_result(object, invocation, 0, 0);
        return true;
 }*/
@@ -1438,6 +1483,31 @@ on_name_lost(GDBusConnection *connection,
                exit(1);
 }
 
+
+static gboolean
+__timeout_cb(gpointer user_data)
+{
+       _INFO("__timeout_cb Enter");
+       g_main_loop_quit(mainloop);
+       mainloop = NULL;
+       return false;
+}
+
+static void
+__set_timeout(int seconds)
+{
+       if (seconds < _FIDO_SERVICE_MIN_TIMEOUT) {
+               _ERR("timeout value is wrong");
+               return;
+       }
+
+       if (timeout_handle)
+               g_source_remove(timeout_handle);
+
+       timeout_handle = g_timeout_add_seconds(seconds, __timeout_cb, NULL);
+       _INFO("__set_timeout handle=%d", timeout_handle);
+}
+
 static bool
 __initialize_dbus(void)
 {
@@ -1479,8 +1549,6 @@ __initialize(void)
 int
 main(void)
 {
-       GMainLoop *mainloop = NULL;
-
        dlog_print(DLOG_INFO, "FIDO", "start");
 
        _INFO("Starting FIDO SVC");
@@ -1488,8 +1556,10 @@ main(void)
        mainloop = g_main_loop_new(NULL, FALSE);
 
        __initialize();
+       __set_timeout(_FIDO_SERVICE_BOOTUP_TIMEOUT);
 
        g_main_loop_run(mainloop);
+       g_main_loop_unref(mainloop);
 
        _INFO("Ending FIDO SVC");
        return 0;