#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
} _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)
{
_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) {
if (asm_response_list != NULL)
g_list_free_full(asm_response_list, __free_asm_discover_response_list_item);
+
+ SAFE_DELETE(cb_data);
}
static int
_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;
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);
}
_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);
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);
}
}
_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;
}
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);
}
} 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);
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;
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 {
_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,
{
_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);
}
{
_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);
}
_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;
}*/
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)
{
int
main(void)
{
- GMainLoop *mainloop = NULL;
-
dlog_print(DLOG_INFO, "FIDO", "start");
_INFO("Starting FIDO SVC");
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;