summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xemail-api/email-api-smime.c196
-rwxr-xr-xemail-api/include/email-api-smime.h56
-rwxr-xr-xemail-common-use/include/email-internal-types.h5
-rwxr-xr-xemail-core/email-core-cert.c411
-rw-r--r--email-core/email-core-key-manager.c54
-rwxr-xr-xemail-core/email-core-smime.c53
-rwxr-xr-xemail-core/email-storage/email-storage.c654
-rwxr-xr-xemail-core/email-storage/include/email-storage.h13
-rw-r--r--email-core/include/email-core-key-manager.h3
-rwxr-xr-xemail-daemon/main.c170
-rwxr-xr-xres/email-service.sql15
-rwxr-xr-xutilities/test-application/testapp-account.c94
12 files changed, 67 insertions, 1657 deletions
diff --git a/email-api/email-api-smime.c b/email-api/email-api-smime.c
index 66c9c02..57bdaa1 100755
--- a/email-api/email-api-smime.c
+++ b/email-api/email-api-smime.c
@@ -45,142 +45,6 @@
#include "email-core-signal.h"
#include "email-ipc.h"
-EXPORT_API int email_add_certificate(char *certificate_path, char *email_address)
-{
- EM_DEBUG_API_BEGIN ();
- EM_DEBUG_FUNC_BEGIN_SEC("certificate_path[%s]", certificate_path);
- int result_from_ipc = 0;
- int err = EMAIL_ERROR_NONE;
-
- if (!certificate_path) {
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
- return EMAIL_ERROR_INVALID_PARAM;
- }
-
- HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_ADD_CERTIFICATE);
- if (hAPI == NULL) {
- EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
- err = EMAIL_ERROR_NULL_VALUE;
- goto FINISH_OFF;
- }
-
- if (!emipc_add_parameter(hAPI, ePARAMETER_IN, certificate_path, EM_SAFE_STRLEN(certificate_path)+1)) {
- EM_DEBUG_EXCEPTION_SEC("emipc_add_parameter certificate_path[%s] failed", certificate_path);
- err = EMAIL_ERROR_NULL_VALUE;
- goto FINISH_OFF;
- }
-
- if (!emipc_add_parameter(hAPI, ePARAMETER_IN, email_address, EM_SAFE_STRLEN(email_address)+1)) {
- EM_DEBUG_EXCEPTION_SEC("emipc_add_parameter certificate_path[%s] failed", email_address);
- err = EMAIL_ERROR_NULL_VALUE;
- goto FINISH_OFF;
- }
-
- if (emipc_execute_proxy_api(hAPI) < 0) {
- EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
- err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
- goto FINISH_OFF;
- }
-
- result_from_ipc = emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
- if (result_from_ipc != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emipc_get_parameter failed");
- err = EMAIL_ERROR_IPC_CRASH;
- goto FINISH_OFF;
- }
-
-FINISH_OFF:
-
- if (hAPI)
- emipc_destroy_email_api(hAPI);
-
- EM_DEBUG_API_END ("err[%d]", err);
- return err;
-}
-
-EXPORT_API int email_delete_certificate(char *email_address)
-{
- EM_DEBUG_API_BEGIN ();
- EM_DEBUG_FUNC_BEGIN_SEC("email_address[%s]", email_address);
- int result_from_ipc = 0;
- int err = EMAIL_ERROR_NONE;
-
- if (!email_address) {
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
- return EMAIL_ERROR_INVALID_PARAM;
- }
-
- HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_DELETE_CERTIFICATE);
- if (hAPI == NULL) {
- EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
- err = EMAIL_ERROR_NULL_VALUE;
- goto FINISH_OFF;
- }
-
- if (!emipc_add_parameter(hAPI, ePARAMETER_IN, email_address, EM_SAFE_STRLEN(email_address)+1)) {
- EM_DEBUG_EXCEPTION_SEC("emipc_add_parameter email_address[%s] failed", email_address);
- err = EMAIL_ERROR_NULL_VALUE;
- goto FINISH_OFF;
- }
-
- if (emipc_execute_proxy_api(hAPI) < 0) {
- EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
- err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
- goto FINISH_OFF;
- }
-
- result_from_ipc = emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
- if (result_from_ipc != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emipc_get_parameter failed");
- err = EMAIL_ERROR_IPC_CRASH;
- goto FINISH_OFF;
- }
-
-FINISH_OFF:
-
- if (hAPI)
- emipc_destroy_email_api(hAPI);
-
- EM_DEBUG_API_END ("err[%d]", err);
- return err;
-}
-
-EXPORT_API int email_get_certificate(char *email_address, email_certificate_t **certificate)
-{
- EM_DEBUG_API_BEGIN ();
- int err = EMAIL_ERROR_NONE;
- char temp_email_address[130] = {0, };
- char *multi_user_name = NULL;
- emstorage_certificate_tbl_t *cert = NULL;
-
- EM_IF_NULL_RETURN_VALUE(email_address, EMAIL_ERROR_INVALID_PARAM);
- EM_IF_NULL_RETURN_VALUE(certificate, EMAIL_ERROR_INVALID_PARAM);
-
- if ((err = emipc_get_user_name(&multi_user_name)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emipc_get_user_name failed : [%d]", err);
- goto FINISH_OFF;
- }
-
- SNPRINTF(temp_email_address, sizeof(temp_email_address), "<%s>", email_address);
-
- if (!emstorage_get_certificate_by_email_address(multi_user_name, temp_email_address, &cert, false, 0, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_get_certificate_by_index failed - %d", err);
- goto FINISH_OFF;
- }
-
- if (!em_convert_certificate_tbl_to_certificate(cert, certificate, &err)) {
- EM_DEBUG_EXCEPTION("em_convert_certificate_tbl_to_certificate failed");
- goto FINISH_OFF;
- }
-
-FINISH_OFF:
-
- EM_SAFE_FREE(multi_user_name);
-
- EM_DEBUG_API_END ("err[%d]", err);
- return err;
-}
-
EXPORT_API int email_get_decrypt_message(int mail_id, email_mail_data_t **output_mail_data,
email_attachment_data_t **output_attachment_data,
int *output_attachment_count, int *verify)
@@ -494,57 +358,6 @@ EXPORT_API int email_verify_signature_ex(email_mail_data_t *input_mail_data, ema
return err;
}
-EXPORT_API int email_verify_certificate(char *certificate_path, int *verify)
-{
- EM_DEBUG_API_BEGIN ();
- EM_DEBUG_FUNC_BEGIN_SEC("certificate_path[%s]", certificate_path);
- int err = EMAIL_ERROR_NONE;
- int result_from_ipc = 0;
- int p_verify = 0;
-
- if (!certificate_path) {
- EM_DEBUG_EXCEPTION("Invalid parameter");
- return EMAIL_ERROR_INVALID_PARAM;
- }
-
- HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_VERIFY_CERTIFICATE);
- if (hAPI == NULL) {
- EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
- err = EMAIL_ERROR_NULL_VALUE;
- goto FINISH_OFF;
- }
-
- if (!emipc_add_parameter(hAPI, ePARAMETER_IN, certificate_path, EM_SAFE_STRLEN(certificate_path)+1)) {
- EM_DEBUG_EXCEPTION_SEC("emipc_add_paramter failed : [%s]", certificate_path);
- err = EMAIL_ERROR_NULL_VALUE;
- goto FINISH_OFF;
- }
-
- if (emipc_execute_proxy_api(hAPI) < 0) {
- EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
- err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
- goto FINISH_OFF;
- }
-
- result_from_ipc = emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &p_verify);
- if (result_from_ipc != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emipc_get_parameter failed");
- err = EMAIL_ERROR_IPC_CRASH;
- goto FINISH_OFF;
- }
-
-FINISH_OFF:
-
- if (hAPI)
- emipc_destroy_email_api(hAPI);
-
- if (verify != NULL)
- *verify = p_verify;
-
- EM_DEBUG_API_END ("err[%d]", err);
- return err;
-}
-
/*
EXPORT_API int email_check_ocsp_status(char *email_address, char *response_url, unsigned *handle)
{
@@ -700,12 +513,3 @@ FINISH_OFF:
EM_DEBUG_API_END ("err[%d]", err);
return err;
}
-
-EXPORT_API int email_free_certificate(email_certificate_t **certificate, int count)
-{
- EM_DEBUG_API_BEGIN ("certificate[%p] count[%d]", certificate, count);
- int err = EMAIL_ERROR_NONE;
- emcore_free_certificate(certificate, count, &err);
- EM_DEBUG_API_END ("err[%d]", err);
- return err;
-}
diff --git a/email-api/include/email-api-smime.h b/email-api/include/email-api-smime.h
index 6517e2a..75dbd7d 100755
--- a/email-api/include/email-api-smime.h
+++ b/email-api/include/email-api-smime.h
@@ -51,46 +51,6 @@ extern "C" {
/**
- * @brief Stores a public certificate information in the database.
- *
- * @since_tizen 2.3
- * @privlevel public
- * @privilege %http://tizen.org/privilege/email
- *
- * @param[in] certificate_path The file path of public certificate
- * @param[in] email_address The keyword for searching the certificate information
- *
- * @return #EMAIL_ERROR_NONE on success,
- * otherwise an error code (see #EMAIL_ERROR_XXX) on failure
- */
-EXPORT_API int email_add_certificate(char *certificate_path, char *email_address) DEPRECATED;
-
-/**
- * @brief Deletes a public certificate information from the database.
- *
- * @param[in] email_address The keyword for deleting the certificate information
- *
- * @return #EMAIL_ERROR_NONE on success,
- * otherwise an error code (see #EMAIL_ERROR_XXX) on failure
- */
-EXPORT_API int email_delete_certificate(char *email_address) DEPRECATED;
-
-/**
- * @brief Gets the the public certificate information from the database.
- *
- * @since_tizen 2.3
- * @privlevel public
- * @privilege %http://tizen.org/privilege/email
- *
- * @param[in] email_address The keyword for getting the certificate information
- * @param[out] certificate The certificate
- *
- * @return #EMAIL_ERROR_NONE on success,
- * otherwise an error code (see #EMAIL_ERROR_XXX) on failure
- */
-EXPORT_API int email_get_certificate(char *email_address, email_certificate_t **certificate) DEPRECATED;
-
-/**
* @brief Gets a decrypted message.
*
* @since_tizen 2.3
@@ -166,22 +126,6 @@ EXPORT_API int email_verify_signature(int mail_id, int *verify);
EXPORT_API int email_verify_signature_ex(email_mail_data_t *input_mail_data, email_attachment_data_t *input_attachment_data, int input_attachment_count, int *verify);
/**
- * @brief Verifies a certificate.
- *
- * @since_tizen 2.3
- * @privlevel public
- * @privilege %http://tizen.org/privilege/email
- *
- * @param[in] certificate_path The path of the certificate
- * @param[out] verify The verification status \n
- * false : failed verification, true : verification successful
- *
- * @return #EMAIL_ERROR_NONE on success,
- * otherwise an error code (see #EMAIL_ERROR_XXX) on failure
- */
-EXPORT_API int email_verify_certificate(char *certificate_path, int *verify) DEPRECATED;
-
-/**
* @brief Gets the certificate from the server (using exchange server).
*
* @since_tizen 2.3
diff --git a/email-common-use/include/email-internal-types.h b/email-common-use/include/email-internal-types.h
index 44d0fba..65edda1 100755
--- a/email-common-use/include/email-internal-types.h
+++ b/email-common-use/include/email-internal-types.h
@@ -544,10 +544,7 @@ enum {
_EMAIL_API_GET_USER_NAME = 0x01500006,
/* Smime */
- _EMAIL_API_ADD_CERTIFICATE = 0x01600000, /**< IPC API ID for email_add_certificate */
- _EMAIL_API_DELETE_CERTIFICATE = 0x01600001, /**< IPC API ID for email_delete_certificate */
- _EMAIL_API_VERIFY_SIGNATURE = 0x01600002, /**< IPC API ID for email_verify_signature */
- _EMAIL_API_VERIFY_CERTIFICATE = 0x01600003, /**< IPC API ID for email_verify_certificate */
+ _EMAIL_API_VERIFY_SIGNATURE = 0x01600001, /**< IPC API ID for email_verify_signature */
};
#ifdef __cplusplus
diff --git a/email-core/email-core-cert.c b/email-core/email-core-cert.c
index 40f8ce6..c567588 100755
--- a/email-core/email-core-cert.c
+++ b/email-core/email-core-cert.c
@@ -60,165 +60,8 @@ typedef enum {
CERT_TYPE_P7S
} cert_type;
-static int emcore_get_certificate_type(char *extension, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("extensiong is [%s]", extension);
- int index = 0;
- int type = 0;
- int err = EMAIL_ERROR_NONE;
- char *supported_file_type[] = {"pfx", "p12", "p7s", "pem", "der", "crt", "cer", NULL};
-
- if (!extension) {
- EM_DEBUG_EXCEPTION("Invalid parameter");
- err = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- while(supported_file_type[index]) {
- EM_DEBUG_LOG_SEC("certificate extension[%d]:[%s]", index, supported_file_type[index]);
- if (strcasecmp(extension, supported_file_type[index]) == 0) {
- switch (index) {
- case 0:
- case 1:
- type = CERT_TYPE_PKCS12;
- err = EMAIL_ERROR_INVALID_CERTIFICATE;
- break;
- case 2:
- type = CERT_TYPE_P7S;
- break;
- case 3:
- case 4:
- case 5:
- case 6:
- type = CERT_TYPE_PKCS7;
- break;
- default:
- type = CERT_TYPE_ETC;
- err = EMAIL_ERROR_INVALID_CERTIFICATE;
- break;
- }
- }
- index++;
- }
-
-FINISH_OFF:
-
- if (err_code) {
- *err_code = err;
- }
-
- EM_DEBUG_FUNC_END("File type is [%d]", type);
- return type;
-}
-/*
-static GList *emcore_make_glist_from_string(char *email_address_list)
-{
- EM_DEBUG_FUNC_BEGIN_SEC("email_address list : [%s]", email_address_list);
- int index = 0;
- const gchar seperator = 0x01;
- GList *email_list = NULL;
- gchar *p_email_address_list = NULL;
- gchar **token_list = NULL;
-
- p_email_address_list = g_strdup(email_address_list);
-
- token_list = g_strsplit(p_email_address_list, &seperator, -1);
- while (token_list[index] != NULL) {
- email_list = g_list_append(email_list, token_list[index]);
- index++;
- }
-
- if (p_email_address_list)
- g_free(p_email_address_list);
-
- return email_list;
-}
-
-static char *emcore_store_public_certificate(STACK_OF(X509) *certificates, char *email_address, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN();
- int index = 0;
- int err = EMAIL_ERROR_NONE;
- char *file_path = NULL;
- BIO *outfile = NULL;
-
- file_path = (char *)em_malloc(256);
- if (file_path == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- SNPRINTF(file_path, 256, "%s%s%s", CERT_SVC_STORE_PATH, TRUSTED_USER, email_address);
- outfile = BIO_new_file(file_path, WRITE_MODE);
- if (outfile == NULL) {
- EM_DEBUG_EXCEPTION("File open failed[write mode]");
- err = EMAIL_ERROR_SYSTEM_FAILURE;
- goto FINISH_OFF;
- }
-
- for (index = 0; index < sk_X509_num(certificates); index++) {
- EM_DEBUG_LOG("Write the certificate in pem file : [%d]", index);
- PEM_write_bio_X509(outfile, sk_X509_value(certificates, index));
- }
-
-FINISH_OFF:
-
- if (outfile)
- BIO_free(outfile);
-
- EM_DEBUG_FUNC_END();
-
- return file_path;
-}
-*/
-#if 0
-INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, char *password, EVP_PKEY **pri_key, X509 **cert, STACK_OF(X509) **ca, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN_SEC("Certificate path : [%s], password : [%s]", certificate, password);
-
- int err = EMAIL_ERROR_NONE;
- int ret = false;
- FILE *fp = NULL;
- PKCS12 *p12 = NULL;
-
- err = em_fopen(certificate, "rb", &fp);
- if (err != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION_SEC("em_fopen failed : [%s] [%d]", certificate, err);
- goto FINISH_OFF;
- }
-
- p12 = d2i_PKCS12_fp(fp, NULL);
- if (!p12) {
- EM_DEBUG_EXCEPTION("d2i_PKCS12_fp failed");
- err = EMAIL_ERROR_SYSTEM_FAILURE;
- goto FINISH_OFF;
- }
-
- if (!PKCS12_parse(p12, password, pri_key, cert, ca)) {
- EM_DEBUG_EXCEPTION("PKCS12_parse failed");
- err = EMAIL_ERROR_SYSTEM_FAILURE;
- goto FINISH_OFF;
- }
-
- ret = true;
-
-FINISH_OFF:
-
- if (fp)
- fclose(fp);
-
- if (p12)
- PKCS12_free(p12);
-
- if (err_code)
- *err_code = err;
-
- return ret;
-}
-#endif
-
-INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, EVP_PKEY **pri_key, X509 **cert, STACK_OF(X509) **ca, int *err_code)
+INTERNAL_FUNC int emcore_load_PFX_file(char *certificate, EVP_PKEY **pri_key, X509 **cert,
+ STACK_OF(X509) **ca, int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("certificate : [%s]", certificate);
int err = EMAIL_ERROR_NONE;
@@ -402,185 +245,6 @@ FINISH_OFF:
return ret;
}
-INTERNAL_FUNC int emcore_add_public_certificate(char *multi_user_name, char *public_cert_path, char *save_name, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN_SEC("Path [%s], filename [%s]", public_cert_path, save_name);
- int err = EMAIL_ERROR_NONE;
- int ret = false;
- int validity = 0;
- int cert_type = 0;
- char temp_file[512] = {0, };
- char temp_save_name[512] = {0, };
- char filepath[512] = {0, };
- char *extension = NULL;
- emstorage_certificate_tbl_t *cert = NULL;
- CERT_CONTEXT *context = NULL;
-
- if (public_cert_path == NULL || save_name == NULL) {
- EM_DEBUG_EXCEPTION("Invalid parameter");
- err = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- /* Initilize the structure of certificate */
- context = cert_svc_cert_context_init();
-
- /* Parse the file type */
- extension = em_get_extension_from_file_path(public_cert_path, NULL);
- if (extension == NULL) {
- EM_DEBUG_EXCEPTION("Invalid parameter");
- err = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- /* Get the file type information */
- cert_type = emcore_get_certificate_type(extension, &err);
- if (!cert_type || err == EMAIL_ERROR_INVALID_CERTIFICATE) {
- EM_DEBUG_EXCEPTION("Invalid certificate");
- goto FINISH_OFF;
- }
-
- /* Create temp file and rename */
- if (cert_type == CERT_TYPE_P7S) {
- extension = "der";
- }
-
- SNPRINTF(temp_file, sizeof(temp_file), "%s%s%s.%s", MAILTEMP, DIR_SEPERATOR, save_name, extension);
- EM_DEBUG_LOG_SEC("temp cert path : [%s]", temp_file);
-
- if (!emstorage_copy_file(public_cert_path, temp_file, false, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_copy_file failed [%d]", err);
- goto FINISH_OFF;
- }
-
- /* Load the public certificate */
- err = cert_svc_load_file_to_context(context, temp_file);
- if (err != CERT_SVC_ERR_NO_ERROR) {
- EM_DEBUG_EXCEPTION("Load cert failed : [%d]", err);
- err = EMAIL_ERROR_INVALID_CERTIFICATE;
- goto FINISH_OFF;
- }
-
- /* Verify the certificate */
- if (cert_svc_verify_certificate(context, &validity) != CERT_SVC_ERR_NO_ERROR) {
- EM_DEBUG_EXCEPTION("cert_svc_verify_certificate failed");
-// err = EMAIL_ERROR_INVALID_CERTIFICATE;
-// goto FINISH_OFF;
- }
-
- if (validity <= 0) {
- EM_DEBUG_LOG("Invalid certificate");
- }
-
- /* Load the certificate information */
- if (cert_svc_extract_certificate_data(context) != CERT_SVC_ERR_NO_ERROR) {
- EM_DEBUG_EXCEPTION("Extract the certificate failed");
- err = EMAIL_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
-
- /* Store the certificate file to trusted folder */
- if (cert_svc_add_certificate_to_store(temp_file, TRUSTED_USER) != CERT_SVC_ERR_NO_ERROR) {
- EM_DEBUG_EXCEPTION("Add certificate to trusted folder");
- err = EMAIL_ERROR_UNKNOWN;
- goto FINISH_OFF;
- }
-
- /* Store the certificate to DB */
- SNPRINTF(filepath, sizeof(filepath), "%s%s%s.%s", CERT_SVC_STORE_PATH, TRUSTED_USER, save_name, extension);
- SNPRINTF(temp_save_name, sizeof(temp_save_name), "<%s>", save_name);
-
- cert = (emstorage_certificate_tbl_t *)em_malloc(sizeof(emstorage_certificate_tbl_t));
- if (cert == NULL) {
- EM_DEBUG_EXCEPTION("em_malloc failed");
- err = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- cert->issue_year = context->certDesc->info.validPeriod.firstYear;
- cert->issue_year = context->certDesc->info.validPeriod.firstYear;
- cert->issue_month = context->certDesc->info.validPeriod.firstMonth;
- cert->issue_day = context->certDesc->info.validPeriod.firstDay;
- cert->expiration_year= context->certDesc->info.validPeriod.secondYear;
- cert->expiration_month = context->certDesc->info.validPeriod.secondMonth;
- cert->expiration_day = context->certDesc->info.validPeriod.secondDay;
- cert->issue_organization_name = EM_SAFE_STRDUP(context->certDesc->info.issuer.organizationName);
- cert->email_address = EM_SAFE_STRDUP(temp_save_name);
- cert->subject_str = EM_SAFE_STRDUP(context->certDesc->info.issuerStr);
- cert->filepath = EM_SAFE_STRDUP(filepath);
-
- if (emstorage_add_certificate(multi_user_name, cert, true, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_add_certificate failed");
- goto FINISH_OFF;
- }
-
- if (!emstorage_delete_file(public_cert_path, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_delete_file failed [%d]", err);
- goto FINISH_OFF;
- }
-
- ret = true;
-
-FINISH_OFF:
-
- emstorage_delete_file(temp_file, NULL);
-
- emstorage_free_certificate(&cert, 1, NULL);
-
- cert_svc_cert_context_final(context);
-
- if (err_code != NULL) {
- *err_code = err;
- }
-
- EM_DEBUG_FUNC_END();
-
- return ret;
-
-}
-
-INTERNAL_FUNC int emcore_delete_public_certificate(char *multi_user_name, char *email_address, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN();
- int ret = false;
- int err = EMAIL_ERROR_NONE;
- emstorage_certificate_tbl_t *certificate = NULL;
-
- if (email_address == NULL) {
- EM_DEBUG_EXCEPTION("Invalid parameter");
- err = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- if (!emstorage_get_certificate_by_email_address(multi_user_name, email_address, &certificate, false, 0, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_get_certificate failed");
- goto FINISH_OFF;
- }
-
- if (remove(certificate->filepath) < 0) {
- EM_DEBUG_EXCEPTION_SEC("remove failed : [%s]", certificate->filepath);
- goto FINISH_OFF;
- }
-
- if (!emstorage_delete_certificate(multi_user_name, certificate->certificate_id, true, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_delete_certificate failed");
- goto FINISH_OFF;
- }
-
- ret = true;
-FINISH_OFF:
-
- if (certificate != NULL)
- emstorage_free_certificate(&certificate, 1, NULL);
-
- if (err_code != NULL)
- *err_code = err;
-
- EM_DEBUG_FUNC_END();
-
- return ret;
-}
-
INTERNAL_FUNC int emcore_verify_signature(char *p7s_file_path, char *mime_entity, int *validity, int *err_code)
{
EM_DEBUG_FUNC_BEGIN_SEC("path : [%s], mime_entity : [%s]", p7s_file_path, mime_entity);
@@ -648,74 +312,3 @@ FINISH_OFF:
EM_DEBUG_FUNC_END();
return ret;
}
-
-INTERNAL_FUNC int emcore_verify_certificate(char *certificate, int *validity, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN();
- int ret = false;
- int err = EMAIL_ERROR_NONE;
- int p_validity = 0;
-
- CERT_CONTEXT *context = NULL;
-
- context = cert_svc_cert_context_init();
-
- err = cert_svc_load_file_to_context(context, certificate);
- if (err != CERT_SVC_ERR_NO_ERROR) {
- EM_DEBUG_EXCEPTION("Certificate load failed");
- goto FINISH_OFF;
- }
-
- err = cert_svc_verify_certificate(context, &p_validity);
- if (err != CERT_SVC_ERR_NO_ERROR) {
- EM_DEBUG_EXCEPTION("Certificate verify failed");
- goto FINISH_OFF;
- }
-
- ret = true;
-
-FINISH_OFF:
-
- if (validity != NULL)
- *validity = p_validity;
-
- if (err_code != NULL) {
- *err_code = err;
- }
-
- cert_svc_cert_context_final(context);
-
- EM_DEBUG_FUNC_END();
- return ret;
-}
-
-INTERNAL_FUNC int emcore_free_certificate(email_certificate_t **certificate, int count, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("certificate [%p], count [%d]", certificate, count);
-
- if (count <= 0 || !certificate || !*certificate) {
- EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
- if (err_code)
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- return false;
- }
-
- email_certificate_t *p_certificate = *certificate;
- int i;
-
- for (i=0;i<count;i++) {
- EM_SAFE_FREE(p_certificate[i].issue_organization_name);
- EM_SAFE_FREE(p_certificate[i].email_address);
- EM_SAFE_FREE(p_certificate[i].subject_str);
- EM_SAFE_FREE(p_certificate[i].filepath);
- }
-
- EM_SAFE_FREE(p_certificate);
- *certificate = NULL;
-
- if (err_code)
- *err_code = EMAIL_ERROR_NONE;
-
- EM_DEBUG_FUNC_END();
- return true;
-}
diff --git a/email-core/email-core-key-manager.c b/email-core/email-core-key-manager.c
index ddd9ed5..5d45393 100644
--- a/email-core/email-core-key-manager.c
+++ b/email-core/email-core-key-manager.c
@@ -30,6 +30,7 @@
#include "email-core-utils.h"
#include "email-debug-log.h"
+#include "email-utilities.h"
/* Adding '/' method for system daemon */
static char *add_shared_owner_prefix(const char *name)
@@ -167,3 +168,56 @@ FINISH_OFF:
EM_DEBUG_FUNC_END();
return err;
}
+
+INTERNAL_FUNC int emcore_get_certificate_in_key_manager(char *alias, char *password,
+ const unsigned char **cert_data,
+ int *cert_size)
+{
+ EM_DEBUG_FUNC_BEGIN();
+ int err = EMAIL_ERROR_NONE;
+
+ if (alias == NULL) {
+ EM_DEBUG_EXCEPTION("Invalid parameter");
+ err = EMAIL_ERROR_INVALID_PARAM;
+ return err;
+ }
+
+ int ckmc_ret = CKMC_ERROR_NONE;
+ unsigned char *p_cert_data = NULL;
+ ckmc_cert_s *output_cert = NULL;
+
+ ckmc_ret = ckmc_get_cert(alias, password, &output_cert);
+ if (ckmc_ret != CKMC_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("ckmc_get_cert failed : [%d]", ckmc_ret);
+ err = EMAIL_ERROR_SECURED_STORAGE_FAILURE;
+ goto FINISH_OFF;
+ }
+
+ EM_DEBUG_LOG("Cert size : [%d]", output_cert->cert_size);
+ EM_DEBUG_LOG("Cert format : [%d]", output_cert->data_format);
+ EM_DEBUG_LOG_DEV("Cert string : [%s]", output_cert->raw_cert);
+
+ p_cert_data = em_malloc(output_cert->cert_size + 1);
+ if (p_cert_data == NULL) {
+ EM_DEBUG_EXCEPTION("em_malloc failed");
+ err = EMAIL_ERROR_OUT_OF_MEMORY;
+ goto FINISH_OFF;
+ }
+
+ memcpy(p_cert_data, output_cert->raw_cert, output_cert->cert_size);
+
+ *cert_data = p_cert_data;
+ *cert_size = output_cert->cert_size;
+
+FINISH_OFF:
+
+ if (output_cert)
+ ckmc_cert_free(output_cert);
+
+ if (err != EMAIL_ERROR_NONE) {
+ EM_SAFE_FREE(p_cert_data);
+ }
+
+ EM_DEBUG_FUNC_END();
+ return err;
+}
diff --git a/email-core/email-core-smime.c b/email-core/email-core-smime.c
index b7e651d..d96291e 100755
--- a/email-core/email-core-smime.c
+++ b/email-core/email-core-smime.c
@@ -48,6 +48,7 @@
#include "email-core-smime.h"
#include "email-core-pgp.h"
#include "email-core-cert.h"
+#include "email-core-key-manager.h"
#include "email-debug-log.h"
/* /opt/share/cert-svc/certs is a base path */
@@ -138,8 +139,6 @@ static int get_x509_stack_of_recipient_certs(char *multi_user_name,
int i = 0, j = 0;
int cert_size = 0;
char *temp_recipients = NULL;
- char *email_address = NULL;
- char file_name[512] = {0, };
const unsigned char *in_cert = NULL;
ADDRESS *token_address = NULL;
@@ -147,9 +146,6 @@ static int get_x509_stack_of_recipient_certs(char *multi_user_name,
X509 *x509_cert = NULL;
STACK_OF(X509) *temp_recipient_certs = NULL;
- CERT_CONTEXT *context = NULL;
- emstorage_certificate_tbl_t *cert = NULL;
-
if (!recipients || !output_recipient_certs) {
EM_DEBUG_EXCEPTION("Invalid parameter");
err = EMAIL_ERROR_INVALID_PARAM;
@@ -167,39 +163,15 @@ static int get_x509_stack_of_recipient_certs(char *multi_user_name,
rfc822_parse_adrlist(&token_address, temp_recipients, NULL);
while (token_address) {
- context = cert_svc_cert_context_init();
- if (!context) { /*prevent 20162*/
- EM_DEBUG_EXCEPTION("cert_svc_cert_context_init failed");
- goto FINISH_OFF;
- }
-
EM_DEBUG_LOG_SEC("email_address_mailbox : [%s], email_address_host : [%s]", token_address->mailbox,
token_address->host);
-
- email_address = g_strdup_printf("<%s@%s>", token_address->mailbox, token_address->host);
- if (!emstorage_get_certificate_by_email_address(multi_user_name, email_address, &cert, false, 0, &err)) {
- EM_DEBUG_EXCEPTION("emstorage_get_certificate_by_email_address failed : [%d]", err);
+ /* Plan : Certificate load to using key-manager */
+ err = emcore_get_certificate_in_key_manager(token_address->host, NULL, &in_cert, &cert_size);
+ if (err != EMAIL_ERROR_NONE) {
+ EM_DEBUG_EXCEPTION("emcore_get_certificate_in_key_manager failed : [%d]", err);
goto FINISH_OFF;
}
- if (!cert) { /*prevent 20161*/
- EM_DEBUG_EXCEPTION("cert is NULL");
- goto FINISH_OFF;
- }
-
-
- SNPRINTF(file_name, sizeof(file_name), "%s", cert->filepath);
- EM_DEBUG_LOG_SEC("file_name : [%s]", file_name);
- int cert_err = cert_svc_load_file_to_context(context, file_name);
- if (cert_err != CERT_SVC_ERR_NO_ERROR) {
- EM_DEBUG_EXCEPTION("cert_svc_load_file_to_context failed : [%d]", err);
- err = EMAIL_ERROR_SYSTEM_FAILURE;
- goto FINISH_OFF;
- }
-
- in_cert = context->certBuf->data;
- cert_size = context->certBuf->size;
-
if (d2i_X509(&x509_cert, &in_cert, cert_size) == NULL) {
EM_DEBUG_EXCEPTION("d2i_X509 failed");
err = EMAIL_ERROR_SYSTEM_FAILURE;
@@ -211,15 +183,8 @@ static int get_x509_stack_of_recipient_certs(char *multi_user_name,
err = EMAIL_ERROR_SYSTEM_FAILURE;
goto FINISH_OFF;
}
-
- cert_svc_cert_context_final(context);
- context = NULL;
- emstorage_free_certificate(&cert, 1, NULL);
- cert = NULL;
-
x509_cert = NULL;
-
token_address = token_address->next;
}
@@ -237,14 +202,8 @@ FINISH_OFF:
X509_free(x509_cert);
}
- if (cert)
- emstorage_free_certificate(&cert, 1, NULL);
-
- if (context)
- cert_svc_cert_context_final(context);
-
+ EM_SAFE_FREE(in_cert);
EM_SAFE_FREE(temp_recipients);
- EM_SAFE_FREE(email_address);
if (token_address)
mail_free_address(&token_address);
diff --git a/email-core/email-storage/email-storage.c b/email-core/email-storage/email-storage.c
index b2060c6..e99646a 100755
--- a/email-core/email-storage/email-storage.c
+++ b/email-core/email-storage/email-storage.c
@@ -16431,660 +16431,6 @@ INTERNAL_FUNC int emstorage_free_list_filter(email_list_filter_t **input_filter_
return err;
}
-INTERNAL_FUNC int emstorage_add_certificate(char *multi_user_name, emstorage_certificate_tbl_t *certificate, int transaction, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("certificate:[%p], transaction:[%d], err_code:[%p]", certificate, transaction, err_code);
-
- if (!certificate) {
- EM_DEBUG_EXCEPTION("certificate:[%p], transaction:[%d], err_code:[%p]", certificate, transaction, err_code);
- if (err_code)
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- return false;
- }
-
- int rc = -1, ret = false;
- int error = EMAIL_ERROR_NONE;
- DB_STMT hStmt = NULL;
- char sql_query_string[QUERY_SIZE] = {0, };
-#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
- char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
-#endif
-
- sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
-
- EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
-
- char *sql = "SELECT max(rowid) FROM mail_certificate_tbl;";
- char **result = NULL;
-
- /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
- ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
-
- if (NULL==result[1]) rc = 1;
- else rc = atoi(result[1])+1;
- sqlite3_free_table(result);
-
- certificate->certificate_id = rc;
-#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
- if ((error = _get_cert_password_file_name(certificate->certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
- goto FINISH_OFF;
- }
-#endif
- SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "INSERT INTO mail_certificate_tbl VALUES "
- "( "
- " ? " /* Index of certificate */
- " , ? " /* Select the account */
- " , ? " /* Year of issue */
- " , ? " /* Month of issue */
- " , ? " /* Day of issue */
- " , ? " /* Year of expiration */
- " , ? " /* Month of expiration */
- " , ? " /* Day of expiration */
- " , ? " /* Organization of issue */
- " , ? " /* Email address */
- " , ? " /* Subject of certificate */
- " , ? " /* Name of saved certificate */
- ") ");
-
-
- /* rc = sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL); */
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
- EM_DEBUG_LOG_SEC(">>>> SQL STMT [ %s ] ", sql_query_string);
- _bind_stmt_field_data_int(hStmt, CERTFICATE_BIND_TYPE_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->certificate_id);
- _bind_stmt_field_data_int(hStmt, ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_year);
- _bind_stmt_field_data_int(hStmt, ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_month);
- _bind_stmt_field_data_int(hStmt, ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_day);
- _bind_stmt_field_data_int(hStmt, EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_year);
- _bind_stmt_field_data_int(hStmt, EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_month);
- _bind_stmt_field_data_int(hStmt, EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_day);
- _bind_stmt_field_data_string(hStmt, ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_organization_name, 0, ISSUE_ORGANIZATION_LEN_IN_MAIL_CERTIFICATE_TBL);
- _bind_stmt_field_data_string(hStmt, EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->email_address, 0, EMAIL_ADDRESS_LEN_IN_MAIL_CERTIFICATE_TBL);
- _bind_stmt_field_data_string(hStmt, SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->subject_str, 0, SUBJECT_STRING_LEN_IN_MAIL_CERTIFICATE_TBL);
- _bind_stmt_field_data_string(hStmt, FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->filepath, 0, FILE_NAME_LEN_IN_MAIL_CERTIFICATE_TBL);
- /* rc = sqlite3_step(hStmt); */
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
-
- EM_DEBUG_DB_EXEC((rc == SQLITE_FULL), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
- ("sqlite3_step fail:%d", rc));
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("sqlite3_step fail:%d, errmsg = %s.", rc, sqlite3_errmsg(local_db_handle)));
-
- ret = true;
-
-FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
- if (hStmt != NULL) {
- rc = sqlite3_finalize(hStmt);
- if (rc != SQLITE_OK) {
- EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc);
- error = EMAIL_ERROR_DB_FAILURE;
- }
- }
-
- if (error == EMAIL_ERROR_NONE) {
- if (!emcore_notify_storage_event (NOTI_CERTIFICATE_ADD, certificate->certificate_id, 0, NULL, 0))
- EM_DEBUG_EXCEPTION ("emcore_notify_storage_event(NOTI_CERTIFICATE_ADD] : Notification failed");
- }
-
- if (err_code != NULL)
- *err_code = error;
-
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
-}
-
-INTERNAL_FUNC int emstorage_free_certificate(emstorage_certificate_tbl_t **certificate_list, int count, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("certificate_list[%p], count[%d], err_code[%p]", certificate_list, count, err_code);
-
- int ret = false;
- int error = EMAIL_ERROR_NONE;
-
- if (count > 0) {
- if (!certificate_list || !*certificate_list) {
- EM_DEBUG_EXCEPTION("certificate_list[%p], count[%d]", certificate_list, count);
- error = EMAIL_ERROR_INVALID_PARAM;
- goto FINISH_OFF;
- }
-
- emstorage_certificate_tbl_t *p = *certificate_list;
- int i = 0;
-
- for (; i < count; i++) {
- EM_SAFE_FREE(p[i].issue_organization_name);
- EM_SAFE_FREE(p[i].email_address);
- EM_SAFE_FREE(p[i].subject_str);
- EM_SAFE_FREE(p[i].filepath);
- EM_SAFE_FREE(p[i].password);
- }
-
- EM_SAFE_FREE(p);
- *certificate_list = NULL;
- }
-
- ret = true;
-
-FINISH_OFF:
- if (err_code != NULL)
- *err_code = error;
-
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
-}
-
-INTERNAL_FUNC int emstorage_get_certificate_list(char *multi_user_name, int *select_num, emstorage_certificate_tbl_t **certificate_list, int transaction, int with_password, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN();
-
- int i = 0, count = 0, rc = -1, ret = false;
- int error = EMAIL_ERROR_NONE;
- emstorage_certificate_tbl_t *p_data_tbl = NULL;
-
- DB_STMT hStmt = NULL;
-
- if (!select_num || !certificate_list) {
- EM_DEBUG_EXCEPTION("select_num[%p], account_list[%p]", select_num, certificate_list);
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- return false;
- }
-
- sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_READ_TRANSACTION(transaction);
-
- char sql_query_string[QUERY_SIZE] = {0, };
- char *sql = "SELECT count(*) FROM mail_certificate_tbl;";
- char **result;
-
- /* rc = sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL); */
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_get_table(local_db_handle, sql, &result, NULL, NULL, NULL), rc);
- EM_DEBUG_DB_EXEC(SQLITE_OK != rc, {error = EMAIL_ERROR_DB_FAILURE;sqlite3_free_table(result);goto FINISH_OFF; },
- ("SQL(%s) sqlite3_get_table fail:%d -%s", sql, rc, sqlite3_errmsg(local_db_handle)));
-
- count = atoi(result[1]);
- sqlite3_free_table(result);
-
- if (!count) {
- EM_DEBUG_EXCEPTION("no account found...");
- error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
- ret = true;
- goto FINISH_OFF;
- }
- EM_DEBUG_LOG("count = %d", rc);
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT * FROM mail_certificate_tbl ORDER BY account_id");
-
- /* rc = sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL); */
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc);
-
- EM_DEBUG_LOG("After sqlite3_prepare_v2 hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
- /* rc = sqlite3_step(hStmt); */
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("sqlite3_step fail:%d", rc));
- if (rc == SQLITE_DONE) {
- EM_DEBUG_EXCEPTION("no account found...");
-
- error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
- count = 0;
- ret = true;
- goto FINISH_OFF;
- }
-
- if (!(p_data_tbl = (emstorage_certificate_tbl_t *)malloc(sizeof(emstorage_certificate_tbl_t) * count))) {
- EM_DEBUG_EXCEPTION("malloc failed...");
- error = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
- memset(p_data_tbl, 0x00, sizeof(emstorage_certificate_tbl_t) * count);
- for (i = 0; i < count; i++) {
- /* get recordset */
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].certificate_id), CERTFICATE_BIND_TYPE_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].issue_year), ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].issue_month), ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].issue_day), ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].expiration_year), EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].expiration_month), EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl[i].expiration_day), EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].issue_organization_name), 0, ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].email_address), 0, EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].subject_str), 0, SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl[i].filepath), 0, FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL);
- if (with_password == true) {
-#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
- /* get password from the secure storage */
- char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
-
- EM_SAFE_FREE(p_data_tbl[i].password);
-
- /* get password file name */
- if ((error = _get_cert_password_file_name(p_data_tbl[i].certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
- goto FINISH_OFF;
- }
-
- /* read password from secure storage */
- if ((error = _read_password_from_secure_storage(cert_password_file_name, &(p_data_tbl[i].password))) < 0) {
- EM_DEBUG_EXCEPTION("_read_password_from_secure_storage() failed...");
- goto FINISH_OFF;
- }
- EM_DEBUG_LOG_SEC("recv_password_file_name[%s], password[%s]", cert_password_file_name, p_data_tbl[i].password);
-#endif
- }
-
- /* rc = sqlite3_step(hStmt); */
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_LOG("after sqlite3_step(), i = %d, rc = %d.", i, rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("sqlite3_step fail:%d", rc));
- }
-
- ret = true;
-
-FINISH_OFF:
- if (ret == true) {
- *certificate_list = p_data_tbl;
- *select_num = count;
- EM_DEBUG_LOG("COUNT : %d", count);
- }
- else if (p_data_tbl != NULL)
- emstorage_free_certificate(&p_data_tbl, count, NULL);
- if (hStmt != NULL) {
- rc = sqlite3_finalize(hStmt);
- hStmt = NULL;
- if (rc != SQLITE_OK) {
- EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc);
- error = EMAIL_ERROR_DB_FAILURE;
- }
- }
-
- EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
-
- if (err_code != NULL)
- *err_code = error;
-
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
-}
-
-INTERNAL_FUNC int emstorage_get_certificate_by_email_address(char *multi_user_name, char *email_address, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN_SEC("email_address[%s], certificate[%p], transaction[%d], err_code[%p]", email_address, certificate, transaction, err_code);
-
- if (!certificate) {
- EM_DEBUG_EXCEPTION_SEC("email_address[%s], certificate[%p]", email_address, certificate);
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- return false;
- }
-
- int ret = false;
- int error = EMAIL_ERROR_NONE;
- emstorage_certificate_tbl_t *p_data_tbl = NULL;
- DB_STMT hStmt = NULL;
- char sql_query_string[QUERY_SIZE] = {0, };
- int rc = -1;
- int sql_len = 0;
-#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
- char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
-#endif
-
- sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_READ_TRANSACTION(transaction);
-
- /* Make query string */
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT ");
- sql_len = EM_SAFE_STRLEN(sql_query_string);
-
- /* dummy value, FROM WHERE clause */
- SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "* FROM mail_certificate_tbl WHERE email_address = '%s'", email_address);
-
- /* FROM clause */
- EM_DEBUG_LOG_SEC("query = [%s]", sql_query_string);
-
- /* execute a sql and count rows */
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("sqlite3_step fail:%d", rc));
-
- if (rc == SQLITE_DONE) {
- EM_DEBUG_EXCEPTION("no matched certificate found...");
- error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
- goto FINISH_OFF;
- }
-
- /* Assign query result to structure */
- if (!(p_data_tbl = (emstorage_certificate_tbl_t *)malloc(sizeof(emstorage_certificate_tbl_t)))) {
- EM_DEBUG_EXCEPTION("malloc failed...");
- error = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- memset(p_data_tbl, 0x00, sizeof(emstorage_certificate_tbl_t));
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->certificate_id), CERTFICATE_BIND_TYPE_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_year), ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_month), ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_day), ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_year), EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_month), EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_day), EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->issue_organization_name), 0, ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_address), 0, EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->subject_str), 0, SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->filepath), 0, FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL);
-
- if (with_password) {
-#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
- /* get password file name */
- if ((error = _get_cert_password_file_name(p_data_tbl->certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
- goto FINISH_OFF;
- }
-
- /* read password from secure storage */
- if ((error = _read_password_from_secure_storage(cert_password_file_name, &(p_data_tbl->password))) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION(" _read_password_from_secure_storage() failed...");
- goto FINISH_OFF;
- }
- EM_DEBUG_LOG_SEC("cert_password_file_name[%s], password[%s]", cert_password_file_name, p_data_tbl->password);
-#endif
- }
- ret = true;
-
-FINISH_OFF:
- if (ret == true)
- *certificate = p_data_tbl;
-
- if (hStmt != NULL) {
- rc = sqlite3_finalize(hStmt);
- if (rc != SQLITE_OK) {
- EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc);
- error = EMAIL_ERROR_DB_FAILURE;
- }
- }
-
- EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
-
- if (err_code != NULL)
- *err_code = error;
-
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
-}
-
-INTERNAL_FUNC int emstorage_get_certificate_by_index(char *multi_user_name, int index, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("index[%d], certificate[%p], transaction[%d], err_code[%p]", index, certificate, transaction, err_code);
-
- if (!certificate) {
- EM_DEBUG_EXCEPTION("index[%d], account[%p]", index, certificate);
- if (err_code != NULL)
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- return false;
- }
-
- int ret = false;
- int error = EMAIL_ERROR_NONE;
- emstorage_certificate_tbl_t *p_data_tbl = NULL;
- DB_STMT hStmt = NULL;
- char sql_query_string[QUERY_SIZE] = {0, };
- int rc = -1;
- int sql_len = 0;
-#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
- char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
-#endif
-
- sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_READ_TRANSACTION(transaction);
-
- /* Make query string */
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "SELECT ");
- sql_len = EM_SAFE_STRLEN(sql_query_string);
-
- /* dummy value, FROM WHERE clause */
- SNPRINTF(sql_query_string + sql_len, sizeof(sql_query_string) - sql_len, "* FROM mail_certificate_tbl WHERE certificate_id = %d", index);
-
- /* FROM clause */
- EM_DEBUG_LOG_SEC("query = [%s]", sql_query_string);
-
- /* execute a sql and count rows */
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("sqlite3_step fail:%d", rc));
-
- if (rc == SQLITE_DONE) {
- EM_DEBUG_EXCEPTION("no matched certificate found...");
- error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
- goto FINISH_OFF;
- }
-
- /* Assign query result to structure */
- if (!(p_data_tbl = (emstorage_certificate_tbl_t *)malloc(sizeof(emstorage_certificate_tbl_t)))) {
- EM_DEBUG_EXCEPTION("malloc failed...");
- error = EMAIL_ERROR_OUT_OF_MEMORY;
- goto FINISH_OFF;
- }
-
- memset(p_data_tbl, 0x00, sizeof(emstorage_certificate_tbl_t));
-
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->certificate_id), CERTFICATE_BIND_TYPE_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_year), ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_month), ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->issue_day), ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_year), EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_month), EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_int(hStmt, &(p_data_tbl->expiration_day), EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->issue_organization_name), 0, ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->email_address), 0, EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->subject_str), 0, SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL);
- _get_stmt_field_data_string(hStmt, &(p_data_tbl->filepath), 0, FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL);
-
- if (with_password) {
-#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
- /* get password file name */
- if ((error = _get_cert_password_file_name(p_data_tbl->certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
- goto FINISH_OFF;
- }
-
- /* read password from secure storage */
- if ((error = _read_password_from_secure_storage(cert_password_file_name, &(p_data_tbl->password))) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION(" _read_password_from_secure_storage() failed...");
- goto FINISH_OFF;
- }
- EM_DEBUG_LOG_SEC("cert_password_file_name[%s], password[%s]", cert_password_file_name, p_data_tbl->password);
-#endif
- }
- ret = true;
-
-FINISH_OFF:
- if (ret == true)
- *certificate = p_data_tbl;
-
- if (hStmt != NULL) {
- rc = sqlite3_finalize(hStmt);
- if (rc != SQLITE_OK) {
- EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc);
- error = EMAIL_ERROR_DB_FAILURE;
- }
- }
-
- EMSTORAGE_FINISH_READ_TRANSACTION(transaction);
-
- if (err_code != NULL)
- *err_code = error;
-
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
-}
-
-INTERNAL_FUNC int emstorage_delete_certificate(char *multi_user_name, int certificate_id, int transaction, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("certificate_id[%d], transaction[%d], err_code[%p]", certificate_id, transaction, err_code);
-
- if (certificate_id < 1) {
- EM_DEBUG_EXCEPTION(" certificate_id[%d]", certificate_id);
- if (err_code)
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- return false;
- }
-
- int rc = -1, ret = false;
- int error = EMAIL_ERROR_NONE;
- sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
-
- /* TODO : delete password files - file names can be obtained from db or a rule that makes a name */
- char sql_query_string[QUERY_SIZE] = {0, };
-#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
- char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
- /* get password file name */
- if ((error = _get_cert_password_file_name(certificate_id, cert_password_file_name)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("em_storage_get_password_file_name failed.");
- goto FINISH_OFF;
- }
-#endif
- /* delete from db */
- memset(sql_query_string, 0x00, sizeof(sql_query_string));
- SNPRINTF(sql_query_string, sizeof(sql_query_string), "DELETE FROM mail_certificate_tbl WHERE certificate_id = %d", certificate_id);
- error = emstorage_exec_query_by_prepare_v2(local_db_handle, sql_query_string);
- if (error != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emstorage_exec_query_by_prepare_v2 failed:[%d]", error);
- goto FINISH_OFF;
- }
-
- /* validate account existence */
- rc = sqlite3_changes(local_db_handle);
- if (rc == 0) {
- EM_DEBUG_EXCEPTION(" no matched certificate found...");
- error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
- goto FINISH_OFF;
- }
-
- ret = true;
-
-FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
-
- if (err_code != NULL)
- *err_code = error;
-
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
-}
-
-INTERNAL_FUNC int emstorage_update_certificate(char *multi_user_name, int certificate_id, emstorage_certificate_tbl_t *certificate, int transaction, int *err_code)
-{
- EM_DEBUG_FUNC_BEGIN("certificate_id[%d], certificate[%p], transaction[%d], err_code[%p]", certificate_id, certificate, transaction, err_code);
-
- if (certificate_id < 1) {
- EM_DEBUG_EXCEPTION(" certificate_id[%d]", certificate_id);
- if (err_code)
- *err_code = EMAIL_ERROR_INVALID_PARAM;
- return false;
- }
-
- int error = EMAIL_ERROR_NONE;
- int rc, ret = false;
-
- DB_STMT hStmt = NULL;
- char sql_query_string[QUERY_SIZE] = {0, };
-#ifdef __FEATURE_SUPPORT_PRIVATE_CERTIFICATE__
- char cert_password_file_name[MAX_PW_FILE_NAME_LENGTH];
-#endif
-
- sqlite3 *local_db_handle = emstorage_get_db_connection(multi_user_name);
- EMSTORAGE_START_WRITE_TRANSACTION(multi_user_name, transaction, error);
-
- SNPRINTF(sql_query_string, sizeof(sql_query_string),
- "UPDATE mail_certificate_tbl SET"
- " issue_year = ?"
- ", issue_month = ?" /* Index of certificate */
- ", issue_day = ?" /* Select the account */
- ", expiration_year = ?" /* Year of issue */
- ", expiration_month = ?" /* Month of issue */
- ", expiration_day = ?" /* Day of issue */
- ", issue_organization_name = ?" /* Year of expiration */
- ", email_address = ?" /* Month of expiration */
- ", subject_str = ?" /* Day of expiration */
- ", filepath = ?" /* Organization of issue */
- ", password = ?"
- " WHERE certificate_id = ?");
-
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_prepare_v2(local_db_handle, sql_query_string, EM_SAFE_STRLEN(sql_query_string), &hStmt, NULL), rc);
- EM_DEBUG_LOG("After sqlite3_prepare hStmt = %p", hStmt);
- EM_DEBUG_DB_EXEC((SQLITE_OK != rc), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("SQL(%s) sqlite3_prepare fail:(%d) %s", sql_query_string, rc, sqlite3_errmsg(local_db_handle)));
-
- _bind_stmt_field_data_int(hStmt, ISSUE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_year);
- _bind_stmt_field_data_int(hStmt, ISSUE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_month);
- _bind_stmt_field_data_int(hStmt, ISSUE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_day);
- _bind_stmt_field_data_int(hStmt, EXPIRE_YEAR_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_year);
- _bind_stmt_field_data_int(hStmt, EXPIRE_MONTH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_month);
- _bind_stmt_field_data_int(hStmt, EXPIRE_DAY_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->expiration_day);
- _bind_stmt_field_data_string(hStmt, ISSUE_ORGANIZATION_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->issue_organization_name, 0, ISSUE_ORGANIZATION_LEN_IN_MAIL_CERTIFICATE_TBL);
- _bind_stmt_field_data_string(hStmt, EMAIL_ADDRESS_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->email_address, 0, EMAIL_ADDRESS_LEN_IN_MAIL_CERTIFICATE_TBL);
- _bind_stmt_field_data_string(hStmt, SUBJECT_STRING_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->subject_str, 0, SUBJECT_STRING_LEN_IN_MAIL_CERTIFICATE_TBL);
- _bind_stmt_field_data_string(hStmt, FILE_PATH_IDX_IN_MAIL_CERTIFICATE_TBL, certificate->filepath, 0, FILE_NAME_LEN_IN_MAIL_CERTIFICATE_TBL);
-
- /* rc = sqlite3_step(hStmt); */
- EMSTORAGE_PROTECTED_FUNC_CALL(sqlite3_step(hStmt), rc);
- EM_DEBUG_DB_EXEC((SQLITE_FULL == rc), {error = EMAIL_ERROR_MAIL_MEMORY_FULL;goto FINISH_OFF; },
- ("sqlite3_step fail:%d", rc));
- EM_DEBUG_DB_EXEC((rc != SQLITE_ROW && rc != SQLITE_DONE), {error = EMAIL_ERROR_DB_FAILURE;goto FINISH_OFF; },
- ("sqlite3_step fail:%d", rc));
-
- /* validate account existence */
- rc = sqlite3_changes(local_db_handle);
- if (rc == 0) {
- EM_DEBUG_EXCEPTION(" no matched account found...");
-
- error = EMAIL_ERROR_ACCOUNT_NOT_FOUND;
- goto FINISH_OFF;
- }
-
- ret = true;
-
-FINISH_OFF:
- EMSTORAGE_FINISH_WRITE_TRANSACTION(multi_user_name, transaction, ret, error);
-
- if (hStmt != NULL) {
- rc = sqlite3_finalize(hStmt);
- if (rc != SQLITE_OK) {
- EM_DEBUG_EXCEPTION("sqlite3_finalize error [%d]", rc);
- error = EMAIL_ERROR_DB_FAILURE;
- }
- }
-
- if (error == EMAIL_ERROR_NONE) {
- if (!emcore_notify_storage_event (NOTI_CERTIFICATE_UPDATE, certificate->certificate_id, 0, NULL, 0))
- EM_DEBUG_EXCEPTION ("emcore_notify_storage_event[ NOTI_CERTIFICATE_UPDATE] : Notification Failed >>> ");
- }
-
- if (err_code != NULL)
- *err_code = error;
-
- EM_DEBUG_FUNC_END("ret [%d]", ret);
- return ret;
-}
-
/* Tasks --------------------------------------------------------------------------*/
INTERNAL_FUNC int emstorage_add_task(char *multi_user_name, email_task_type_t input_task_type, email_task_priority_t input_task_priority, char *input_task_parameter, int input_task_parameter_length, int input_transaction, int *output_task_id)
{
diff --git a/email-core/email-storage/include/email-storage.h b/email-core/email-storage/include/email-storage.h
index 63c36bc..da88623 100755
--- a/email-core/email-storage/include/email-storage.h
+++ b/email-core/email-storage/include/email-storage.h
@@ -1657,19 +1657,6 @@ INTERNAL_FUNC int emstorage_free_local_activity(emstorage_activity_tbl_t **local
INTERNAL_FUNC int emstorage_free_activity_id_list(int *activity_id_list, int *error_code);
#endif
-
-INTERNAL_FUNC int emstorage_add_certificate(char *multi_user_name, emstorage_certificate_tbl_t *certificate, int transaction, int *err_code);
-
-INTERNAL_FUNC int emstorage_free_certificate(emstorage_certificate_tbl_t **certificate_list, int count, int *err_code);
-
-INTERNAL_FUNC int emstorage_get_certificate_list(char *multi_user_name, int *select_num, emstorage_certificate_tbl_t **certificate_list, int transaction, int with_password, int *err_code);
-
-INTERNAL_FUNC int emstorage_get_certificate_by_email_address(char *multi_user_name, char *email_address, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code);
-
-INTERNAL_FUNC int emstorage_get_certificate_by_index(char *multi_user_name, int index, emstorage_certificate_tbl_t **certificate, int transaction, int with_password, int *err_code);
-
-INTERNAL_FUNC int emstorage_delete_certificate(char *multi_user_name, int index, int transaction, int *err_code);
-
/* task begin */
INTERNAL_FUNC int emstorage_add_task(char *multi_user_name, email_task_type_t input_task_type, email_task_priority_t input_task_priority, char *input_task_parameter, int input_task_parameter_length, int input_transaction, int *output_task_id);
diff --git a/email-core/include/email-core-key-manager.h b/email-core/include/email-core-key-manager.h
index 5fc84c5..02e3267 100644
--- a/email-core/include/email-core-key-manager.h
+++ b/email-core/include/email-core-key-manager.h
@@ -29,6 +29,9 @@ extern "C" {
INTERNAL_FUNC int emcore_add_password_in_key_manager(char *data_name, char *stored_data);
INTERNAL_FUNC int emcore_get_password_in_key_manager(char *data_name, char **stored_data);
INTERNAL_FUNC int emcore_remove_password_in_key_manager(char *data_name);
+INTERNAL_FUNC int emcore_get_certificate_in_key_manager(char *alias, char *password,
+ const unsigned char **cert_data,
+ int *cert_size);
#ifdef __cplusplus
}
diff --git a/email-daemon/main.c b/email-daemon/main.c
index 035f495..b4ddc9e 100755
--- a/email-daemon/main.c
+++ b/email-daemon/main.c
@@ -2879,125 +2879,6 @@ void stb_get_task_information(HIPC_API a_hAPI)
EM_DEBUG_FUNC_END();
}
-void stb_add_certificate(HIPC_API a_hAPI)
-{
- int err = EMAIL_ERROR_NONE;
- int cert_file_len = 0;
- int email_address_len = 0;
- char *cert_file_path = NULL;
- char *email_address = NULL;
- emipc_email_api_info *api_info = (emipc_email_api_info *)a_hAPI;
- int nAPPID = emipc_get_app_id(a_hAPI);
- char *multi_user_name = NULL;
- char *prefix_path = NULL;
- char real_file_path[255] = {0};
-
- if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
- multi_user_name = NULL;
- }
-
- /* Get the absolute path */
- if (EM_SAFE_STRLEN(multi_user_name) > 0) {
- err = emcore_get_container_path(multi_user_name, &prefix_path);
- if (err != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_get_container_path failed : [%d]", err);
- goto FINISH_OFF;
- }
- } else {
- prefix_path = strdup("");
- }
-
- cert_file_len = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
- if (cert_file_len > 0) {
- cert_file_path = em_malloc(cert_file_len + 1);
- emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, cert_file_len, cert_file_path);
- }
-
- /* check smack rule for accessing file path */
- if (cert_file_path) {
- memset(real_file_path, 0x00, sizeof(real_file_path));
- SNPRINTF(real_file_path, sizeof(real_file_path), "%s%s", prefix_path, cert_file_path);
-
- if (!emdaemon_check_smack_rule(api_info->response_id, real_file_path)) {
- EM_DEBUG_EXCEPTION("emdaemon_check_smack_rule fail");
- err = EMAIL_ERROR_NO_SMACK_RULE;
- goto FINISH_OFF;
- }
- }
-
- email_address_len = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 1);
- if (email_address_len > 0) {
- email_address = em_malloc(email_address_len + 1);
- emipc_get_parameter(a_hAPI, ePARAMETER_IN, 1, email_address_len, email_address);
- }
-
- if (!emcore_add_public_certificate(multi_user_name, cert_file_path, email_address, &err)) {
- EM_DEBUG_EXCEPTION("em_core_smime_add_certificate failed");
- }
-
-FINISH_OFF:
-
- if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
- EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
-
- if (EMAIL_ERROR_NONE == err) {
- EM_DEBUG_LOG("email_mail_add_attachment -Success");
- }
-
- if (!emipc_execute_stub_api(a_hAPI))
- EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
-
- EM_SAFE_FREE(prefix_path);
- EM_SAFE_FREE(cert_file_path);
- EM_SAFE_FREE(email_address);
- EM_SAFE_FREE(multi_user_name);
- EM_DEBUG_FUNC_END();
-}
-
-void stb_delete_certificate(HIPC_API a_hAPI)
-{
- int err = EMAIL_ERROR_NONE;
- int email_address_len = 0;
- char *email_address = NULL;
- char temp_email_address[130] = {0, };
- int nAPPID = emipc_get_app_id(a_hAPI);
- char *multi_user_name = NULL;
-
- if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
- multi_user_name = NULL;
- }
-
- email_address_len = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
- if (email_address_len > 0) {
- EM_DEBUG_LOG("email address string length [%d]", email_address_len);
- email_address = em_malloc(email_address_len + 1);
- emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, email_address_len, email_address);
- EM_DEBUG_LOG_SEC("email address [%s]", email_address);
- }
-
- SNPRINTF(temp_email_address, sizeof(temp_email_address), "<%s>", email_address);
- if (!emcore_delete_public_certificate(multi_user_name, temp_email_address, &err)) {
- EM_DEBUG_EXCEPTION("em_core_smime_add_certificate failed");
- }
-
- if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &err, sizeof(int)))
- EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
-
- if (EMAIL_ERROR_NONE == err) {
- EM_DEBUG_LOG("email_mail_add_attachment -Success");
- }
-
- if (!emipc_execute_stub_api(a_hAPI))
- EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed");
-
-
- EM_SAFE_FREE(email_address);
- EM_SAFE_FREE(multi_user_name);
- EM_DEBUG_FUNC_END();
-}
-
void stb_verify_signature(HIPC_API a_hAPI)
{
int err = EMAIL_ERROR_NONE;
@@ -3082,45 +2963,6 @@ FINISH_OFF:
EM_DEBUG_FUNC_END();
}
-void stb_verify_certificate(HIPC_API a_hAPI)
-{
- int err = EMAIL_ERROR_NONE;
- int verify = 0;
- int cert_file_len = 0;
- char *cert_file_path = 0;
- int nAPPID = emipc_get_app_id(a_hAPI);
- char *multi_user_name = NULL;
-
- if ((err = emcore_get_user_name(nAPPID, &multi_user_name)) != EMAIL_ERROR_NONE) {
- EM_DEBUG_EXCEPTION("emcore_get_user_info failed : [%d]", err);
- multi_user_name = NULL;
- }
-
- cert_file_len = emipc_get_parameter_length(a_hAPI, ePARAMETER_IN, 0);
- if (cert_file_len > 0) {
- cert_file_path = em_malloc(cert_file_len + 1);
- emipc_get_parameter(a_hAPI, ePARAMETER_IN, 0, cert_file_len, cert_file_path);
- }
-
- if (!emcore_verify_certificate(cert_file_path, &verify, &err)) {
- EM_DEBUG_EXCEPTION("em_core_smime_add_certificate failed");
- }
-
- if (!emipc_add_parameter(a_hAPI, ePARAMETER_OUT, &verify, sizeof(int)))
- EM_DEBUG_EXCEPTION("emipc_add_parameter local_result failed ");
-
- if (verify) {
- EM_DEBUG_LOG("Verify S/MIME signed mail-Success");
- }
-
- if (!emipc_execute_stub_api(a_hAPI))
- EM_DEBUG_EXCEPTION("emipc_execute_stub_api failed ");
-
- EM_SAFE_FREE(cert_file_path);
- EM_SAFE_FREE(multi_user_name);
- EM_DEBUG_FUNC_END();
-}
-
void stb_ping_service(HIPC_API a_hAPI)
{
EM_DEBUG_FUNC_BEGIN();
@@ -4068,22 +3910,10 @@ void stb_API_mapper(HIPC_API a_hAPI)
stb_get_task_information(a_hAPI);
break;
- case _EMAIL_API_ADD_CERTIFICATE:
- stb_add_certificate(a_hAPI);
- break;
-
- case _EMAIL_API_DELETE_CERTIFICATE:
- stb_delete_certificate(a_hAPI);
- break;
-
case _EMAIL_API_VERIFY_SIGNATURE:
stb_verify_signature(a_hAPI);
break;
- case _EMAIL_API_VERIFY_CERTIFICATE:
- stb_verify_certificate(a_hAPI);
- break;
-
case _EMAIL_API_PING_SERVICE :
stb_ping_service(a_hAPI);
break;
diff --git a/res/email-service.sql b/res/email-service.sql
index bac3073..dcf7f5b 100755
--- a/res/email-service.sql
+++ b/res/email-service.sql
@@ -227,21 +227,6 @@ CREATE TABLE mail_local_activity_tbl
src_mbox VARCHAR(129),
dest_mbox VARCHAR(129)
);
-CREATE TABLE mail_certificate_tbl
-(
- certificate_id INTEGER,
- issue_year INTEGER,
- issue_month INTEGER,
- issue_day INTEGER,
- expiration_year INTEGER,
- expiration_month INTEGER,
- expiration_day INTEGER,
- issue_organization_name VARCHAR(256),
- email_address VARCHAR(129),
- subject_str VARCHAR(256),
- filepath VARCHAR(256),
- password VARCHAR(51)
-);
CREATE TABLE mail_task_tbl
(
task_id INTEGER PRIMARY KEY,
diff --git a/utilities/test-application/testapp-account.c b/utilities/test-application/testapp-account.c
index 5eae241..f18e1a2 100755
--- a/utilities/test-application/testapp-account.c
+++ b/utilities/test-application/testapp-account.c
@@ -880,86 +880,6 @@ static gboolean testapp_test_load_default_account_id()
return FALSE;
}
-static gboolean testapp_test_add_certificate()
-{
- int ret = 0;
- char save_name[50] = {0, };
- char certificate_path[255] = {0, };
-
- testapp_print("Input cert path : ");
- if (0 >= scanf("%s", certificate_path))
- testapp_print("Invalid input. ");
-
- testapp_print("Input cert email-address : ");
- if (0 >= scanf("%s", save_name))
- testapp_print("Invalid input. ");
-
- testapp_print("cert path : [%s]", certificate_path);
- testapp_print("email-address : [%s]", save_name);
-
- ret = email_add_certificate(certificate_path, save_name);
- if (ret != EMAIL_ERROR_NONE) {
- testapp_print("Add certificate failed\n");
- return false;
- }
-
- testapp_print("Add certificate success\n");
- return true;
-}
-
-static gboolean testapp_test_get_certificate()
-{
- int ret = 0;
- char save_name[20] = {0, };
- email_certificate_t *certificate = NULL;
-
- testapp_print("Input cert email-address : ");
- if (0 >= scanf("%s", save_name))
- testapp_print("Invalid input. ");
-
- ret = email_get_certificate(save_name, &certificate);
- if (ret != EMAIL_ERROR_NONE) {
- testapp_print("Get certificate failed\n");
- return false;
- }
-
- testapp_print("certificate_id : %d\n", certificate->certificate_id);
- testapp_print("issue_year : %d\n", certificate->issue_year);
- testapp_print("issue_month : %d\n", certificate->issue_month);
- testapp_print("issue_day : %d\n", certificate->issue_day);
- testapp_print("expiration_year : %d\n", certificate->expiration_year);
- testapp_print("expiration_month : %d\n", certificate->expiration_month);
- testapp_print("expiration_day : %d\n", certificate->expiration_day);
- testapp_print("issue_organization_name : %s\n", certificate->issue_organization_name);
- testapp_print("subject_string : %s\n", certificate->subject_str);
- testapp_print("file path : %s\n", certificate->filepath);
-
- if (certificate)
- email_free_certificate(&certificate, 1);
-
- testapp_print("Get certificate success\n");
- return true;
-}
-
-static gboolean testapp_test_delete_certificate()
-{
- int ret = 0;
- char save_name[20] = {0, };
-
- testapp_print("Input cert email-address : ");
- if (0 >= scanf("%s", save_name))
- testapp_print("Invalid input. ");
-
- ret = email_delete_certificate(save_name);
- if (ret != EMAIL_ERROR_NONE) {
- testapp_print("Delete certificate failed\n");
- return false;
- }
-
- testapp_print("Delete certificate success\n");
- return true;
-}
-
static gboolean testapp_test_add_account()
{
int err = EMAIL_ERROR_NONE;
@@ -1109,22 +1029,10 @@ static gboolean testapp_test_interpret_command (int selected_number)
break;
case 18:
- testapp_test_add_certificate();
- break;
-
- case 19:
- testapp_test_get_certificate();
- break;
-
- case 20:
- testapp_test_delete_certificate();
- break;
-
- case 21:
testapp_test_add_account();
break;
- case 22:
+ case 19:
testapp_test_update_peak_schedule();
break;