4 * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Sunghyun Kwon <sh0701.kwon@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 * email-core-task-manager.c
25 * Created on: 2015. 7. 24.
26 * Author: sh0701.kwon@samsung.com
29 #include <ckmc/ckmc-manager.h>
31 #include "email-core-utils.h"
32 #include "email-debug-log.h"
34 /* Adding '/' method for system daemon */
35 static char *add_shared_owner_prefix(const char *name)
37 EM_DEBUG_FUNC_BEGIN();
38 char *ckm_alias = NULL;
41 EM_DEBUG_EXCEPTION("Invalid parameter");
45 ckm_alias = g_strconcat(ckmc_label_shared_owner, ckmc_label_name_separator, name, NULL);
52 INTERNAL_FUNC int emcore_add_password_in_key_manager(char *data_name, char *stored_data)
54 EM_DEBUG_FUNC_BEGIN();
55 int err = EMAIL_ERROR_NONE;
56 int ckmc_ret = CKMC_ERROR_NONE;
58 ckmc_policy_s email_policy;
59 ckmc_raw_buffer_s email_data;
60 char errno_buf[ERRNO_BUF_SIZE] = {0};
62 if (data_name == NULL) {
63 EM_DEBUG_EXCEPTION("Invalid parameter");
64 err = EMAIL_ERROR_INVALID_PARAM;
68 // alias = add_shared_owner_prefix(data_name);
69 alias = g_strdup(data_name);
70 EM_DEBUG_LOG("alias : [%s]", alias);
72 email_policy.password = NULL;
73 email_policy.extractable = true;
75 EM_DEBUG_LOG("stored_data : [%s]", stored_data);
77 email_data.data = (unsigned char *)stored_data;
78 email_data.size = strlen(stored_data);
80 ckmc_ret = ckmc_save_data(alias, email_data, email_policy);
81 if (ckmc_ret != CKMC_ERROR_NONE) {
82 EM_DEBUG_EXCEPTION("ckmc_save_data failed [%d][%s]", errno, EM_STRERROR(errno_buf));
83 err = EMAIL_ERROR_SECURED_STORAGE_FAILURE;
95 /* Get the stored data */
96 INTERNAL_FUNC int emcore_get_password_in_key_manager(char *data_name, char **stored_data)
98 EM_DEBUG_FUNC_BEGIN();
99 int err = EMAIL_ERROR_NONE;
100 int ckmc_ret = CKMC_ERROR_NONE;
102 ckmc_raw_buffer_s *email_data = NULL;
104 if (data_name == NULL) {
105 EM_DEBUG_EXCEPTION("Invalid parameter");
106 err = EMAIL_ERROR_INVALID_PARAM;
110 // alias = add_shared_owner_prefix(data_name);
111 alias = g_strdup(data_name);
112 EM_DEBUG_LOG("alias : [%s]", alias);
114 ckmc_ret = ckmc_get_data(alias, NULL, &email_data);
115 if (ckmc_ret != CKMC_ERROR_NONE) {
116 EM_DEBUG_EXCEPTION("ckmc_get_data failed : [%d]", ckmc_ret);
117 err = EMAIL_ERROR_SECURED_STORAGE_FAILURE;
121 EM_DEBUG_LOG("stored_data : [%s]", email_data->data);
126 *stored_data = EM_SAFE_STRDUP(email_data->data);
129 ckmc_buffer_free(email_data);
137 /* Remove the stored data */
138 INTERNAL_FUNC int emcore_remove_password_in_key_manager(char *data_name)
140 EM_DEBUG_FUNC_BEGIN();
141 int err = EMAIL_ERROR_NONE;
142 int ckmc_ret = CKMC_ERROR_NONE;
145 if (data_name == NULL) {
146 EM_DEBUG_EXCEPTION("Invalid parameter");
147 err = EMAIL_ERROR_INVALID_PARAM;
151 // alias = add_shared_owner_prefix(data_name);
152 alias = g_strdup(data_name);
153 EM_DEBUG_LOG("alias : [%s]", alias);
155 ckmc_ret = ckmc_remove_alias(alias);
156 if (ckmc_ret != CKMC_ERROR_NONE) {
157 EM_DEBUG_EXCEPTION("ckmc_remove_alias failed : [%d]", ckmc_ret);
158 err = EMAIL_ERROR_SECURED_STORAGE_FAILURE;