4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Kyuho Jo <kyuho.jo@samsung.com>, 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.
26 * This file contains the data structures and interfaces needed for application,
27 * to interact with Email Engine.
28 * @file email-api-smime.c
29 * @brief This file contains the data structures and interfaces of SMIME related Functionality provided by
34 #include "email-api-mail.h"
35 #include "email-convert.h"
36 #include "email-api-account.h"
37 #include "email-storage.h"
38 #include "email-utilities.h"
39 #include "email-core-mail.h"
40 #include "email-core-mime.h"
41 #include "email-core-account.h"
42 #include "email-core-cert.h"
43 #include "email-core-smime.h"
44 #include "email-core-pgp.h"
45 #include "email-core-signal.h"
46 #include "email-ipc.h"
48 EXPORT_API int email_add_certificate(char *certificate_path, char *email_address)
50 EM_DEBUG_API_BEGIN ();
51 EM_DEBUG_FUNC_BEGIN_SEC("certificate_path[%s]", certificate_path);
52 int result_from_ipc = 0;
53 int err = EMAIL_ERROR_NONE;
55 if (!certificate_path) {
56 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
57 return EMAIL_ERROR_INVALID_PARAM;
60 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_ADD_CERTIFICATE);
62 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
63 err = EMAIL_ERROR_NULL_VALUE;
67 if (!emipc_add_parameter(hAPI, ePARAMETER_IN, certificate_path, EM_SAFE_STRLEN(certificate_path)+1)) {
68 EM_DEBUG_EXCEPTION_SEC("emipc_add_parameter certificate_path[%s] failed", certificate_path);
69 err = EMAIL_ERROR_NULL_VALUE;
73 if (!emipc_add_parameter(hAPI, ePARAMETER_IN, email_address, EM_SAFE_STRLEN(email_address)+1)) {
74 EM_DEBUG_EXCEPTION_SEC("emipc_add_parameter certificate_path[%s] failed", email_address);
75 err = EMAIL_ERROR_NULL_VALUE;
79 if (emipc_execute_proxy_api(hAPI) < 0) {
80 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
81 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
85 result_from_ipc = emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
86 if (result_from_ipc != EMAIL_ERROR_NONE) {
87 EM_DEBUG_EXCEPTION("emipc_get_parameter failed");
88 err = EMAIL_ERROR_IPC_CRASH;
95 emipc_destroy_email_api(hAPI);
97 EM_DEBUG_API_END ("err[%d]", err);
101 EXPORT_API int email_delete_certificate(char *email_address)
103 EM_DEBUG_API_BEGIN ();
104 EM_DEBUG_FUNC_BEGIN_SEC("email_address[%s]", email_address);
105 int result_from_ipc = 0;
106 int err = EMAIL_ERROR_NONE;
108 if (!email_address) {
109 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
110 return EMAIL_ERROR_INVALID_PARAM;
113 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_DELETE_CERTIFICATE);
115 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
116 err = EMAIL_ERROR_NULL_VALUE;
120 if (!emipc_add_parameter(hAPI, ePARAMETER_IN, email_address, EM_SAFE_STRLEN(email_address)+1)) {
121 EM_DEBUG_EXCEPTION_SEC("emipc_add_parameter email_address[%s] failed", email_address);
122 err = EMAIL_ERROR_NULL_VALUE;
126 if (emipc_execute_proxy_api(hAPI) < 0) {
127 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
128 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
132 result_from_ipc = emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
133 if (result_from_ipc != EMAIL_ERROR_NONE) {
134 EM_DEBUG_EXCEPTION("emipc_get_parameter failed");
135 err = EMAIL_ERROR_IPC_CRASH;
142 emipc_destroy_email_api(hAPI);
144 EM_DEBUG_API_END ("err[%d]", err);
148 EXPORT_API int email_get_certificate(char *email_address, email_certificate_t **certificate)
150 EM_DEBUG_API_BEGIN ();
151 int err = EMAIL_ERROR_NONE;
152 char temp_email_address[130] = {0, };
153 char *multi_user_name = NULL;
154 emstorage_certificate_tbl_t *cert = NULL;
156 EM_IF_NULL_RETURN_VALUE(email_address, EMAIL_ERROR_INVALID_PARAM);
157 EM_IF_NULL_RETURN_VALUE(certificate, EMAIL_ERROR_INVALID_PARAM);
159 if ((err = emipc_get_user_name(&multi_user_name)) != EMAIL_ERROR_NONE) {
160 EM_DEBUG_EXCEPTION("emipc_get_user_name failed : [%d]", err);
164 SNPRINTF(temp_email_address, sizeof(temp_email_address), "<%s>", email_address);
166 if (!emstorage_get_certificate_by_email_address(multi_user_name, temp_email_address, &cert, false, 0, &err)) {
167 EM_DEBUG_EXCEPTION("emstorage_get_certificate_by_index failed - %d", err);
171 if (!em_convert_certificate_tbl_to_certificate(cert, certificate, &err)) {
172 EM_DEBUG_EXCEPTION("em_convert_certificate_tbl_to_certificate failed");
178 EM_SAFE_FREE(multi_user_name);
180 EM_DEBUG_API_END ("err[%d]", err);
184 EXPORT_API int email_get_decrypt_message(int mail_id, email_mail_data_t **output_mail_data,
185 email_attachment_data_t **output_attachment_data,
186 int *output_attachment_count, int *verify)
188 EM_DEBUG_API_BEGIN ("mail_id[%d]", mail_id);
189 int err = EMAIL_ERROR_NONE;
190 int p_output_attachment_count = 0;
192 char *decrypt_filepath = NULL;
194 char *multi_user_name = NULL;
195 email_mail_data_t *p_output_mail_data = NULL;
196 email_attachment_data_t *p_output_attachment_data = NULL;
197 emstorage_account_tbl_t *p_account_tbl = NULL;
199 EM_IF_NULL_RETURN_VALUE(mail_id, EMAIL_ERROR_INVALID_PARAM);
201 if (!output_mail_data || !output_attachment_data || !output_attachment_count) {
202 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
203 err = EMAIL_ERROR_INVALID_PARAM;
207 if ((err = emipc_get_user_name(&multi_user_name)) != EMAIL_ERROR_NONE) {
208 EM_DEBUG_EXCEPTION("emipc_get_user_name failed : [%d]");
212 if ((err = emcore_get_mail_data(multi_user_name, mail_id, &p_output_mail_data)) != EMAIL_ERROR_NONE) {
213 EM_DEBUG_EXCEPTION("emcore_get_mail_data failed");
217 if (!emstorage_get_account_by_id(multi_user_name, p_output_mail_data->account_id, EMAIL_ACC_GET_OPT_OPTIONS, &p_account_tbl, false, &err)) {
218 EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed : [%d]", err);
222 if ((err = emcore_get_attachment_data_list(multi_user_name, mail_id, &p_output_attachment_data, &p_output_attachment_count)) != EMAIL_ERROR_NONE) {
223 EM_DEBUG_EXCEPTION("emcore_get_attachment_data_list failed");
227 for (i = 0; i < p_output_attachment_count; i++) {
228 EM_DEBUG_LOG("mime_type : [%s]", p_output_attachment_data[i].attachment_mime_type);
229 if (p_output_attachment_data[i].attachment_mime_type && (search = strcasestr(p_output_attachment_data[i].attachment_mime_type, "PKCS7-MIME"))) {
230 EM_DEBUG_LOG("Found the encrypt file");
232 } else if (p_output_attachment_data[i].attachment_mime_type && (search = strcasestr(p_output_attachment_data[i].attachment_mime_type, "octet-stream"))) {
233 EM_DEBUG_LOG("Found the encrypt file");
239 EM_DEBUG_EXCEPTION("No have a decrypt file");
240 err = EMAIL_ERROR_INVALID_PARAM;
244 if (p_output_mail_data->smime_type == EMAIL_SMIME_ENCRYPTED || p_output_mail_data->smime_type == EMAIL_SMIME_SIGNED_AND_ENCRYPTED) {
245 emcore_init_openssl_library();
246 if (!emcore_smime_get_decrypt_message(p_output_attachment_data[i].attachment_path, p_account_tbl->certificate_path, &decrypt_filepath, &err)) {
247 EM_DEBUG_EXCEPTION("emcore_smime_get_decrypt_message failed");
248 emcore_clean_openssl_library();
251 emcore_clean_openssl_library();
252 } else if (p_output_mail_data->smime_type == EMAIL_PGP_ENCRYPTED) {
253 if ((err = emcore_pgp_get_decrypted_message(p_output_attachment_data[i].attachment_path, p_output_mail_data->pgp_password, false, &decrypt_filepath, verify)) != EMAIL_ERROR_NONE) {
254 EM_DEBUG_EXCEPTION("emcore_pgp_get_decrypted_message failed : [%d]", err);
257 } else if (p_output_mail_data->smime_type == EMAIL_PGP_SIGNED_AND_ENCRYPTED) {
258 if ((err = emcore_pgp_get_decrypted_message(p_output_attachment_data[i].attachment_path, p_output_mail_data->pgp_password, true, &decrypt_filepath, verify)) != EMAIL_ERROR_NONE) {
259 EM_DEBUG_EXCEPTION("emcore_pgp_get_decrypted_message failed : [%d]", err);
263 EM_DEBUG_LOG("Invalid encrypted mail");
264 err = EMAIL_ERROR_INVALID_PARAM;
268 /* Change decrpyt_message to mail_data_t */
269 if (!emcore_parse_mime_file_to_mail(decrypt_filepath, output_mail_data, output_attachment_data, output_attachment_count, &err)) {
270 EM_DEBUG_EXCEPTION("emcore_parse_mime_file_to_mail failed : [%d]", err);
274 (*output_mail_data)->subject = EM_SAFE_STRDUP(p_output_mail_data->subject);
275 (*output_mail_data)->date_time = p_output_mail_data->date_time;
276 (*output_mail_data)->full_address_return = EM_SAFE_STRDUP(p_output_mail_data->full_address_return);
277 (*output_mail_data)->email_address_recipient = EM_SAFE_STRDUP(p_output_mail_data->email_address_recipient);
278 (*output_mail_data)->email_address_sender = EM_SAFE_STRDUP(p_output_mail_data->email_address_sender);
279 (*output_mail_data)->full_address_reply = EM_SAFE_STRDUP(p_output_mail_data->full_address_reply);
280 (*output_mail_data)->full_address_from = EM_SAFE_STRDUP(p_output_mail_data->full_address_from);
281 (*output_mail_data)->full_address_to = EM_SAFE_STRDUP(p_output_mail_data->full_address_to);
282 (*output_mail_data)->full_address_cc = EM_SAFE_STRDUP(p_output_mail_data->full_address_cc);
283 (*output_mail_data)->full_address_bcc = EM_SAFE_STRDUP(p_output_mail_data->full_address_bcc);
284 (*output_mail_data)->flags_flagged_field = p_output_mail_data->flags_flagged_field;
288 EM_SAFE_FREE(decrypt_filepath);
291 emstorage_free_account(&p_account_tbl, 1, NULL);
293 if (p_output_mail_data)
294 email_free_mail_data(&p_output_mail_data, 1);
296 if (p_output_attachment_data)
297 email_free_attachment_data(&p_output_attachment_data, p_output_attachment_count);
299 EM_SAFE_FREE(multi_user_name);
301 EM_DEBUG_API_END ("err[%d]", err);
305 EXPORT_API int email_get_decrypt_message_ex(email_mail_data_t *input_mail_data,
306 email_attachment_data_t *input_attachment_data,
307 int input_attachment_count,
308 email_mail_data_t **output_mail_data,
309 email_attachment_data_t **output_attachment_data,
310 int *output_attachment_count,
313 EM_DEBUG_API_BEGIN ();
314 int err = EMAIL_ERROR_NONE;
316 char *decrypt_filepath = NULL;
318 char *multi_user_name = NULL;
319 emstorage_account_tbl_t *p_account_tbl = NULL;
321 EM_IF_NULL_RETURN_VALUE(input_mail_data, EMAIL_ERROR_INVALID_PARAM);
323 if (!output_mail_data || !output_attachment_data || !output_attachment_count) {
324 EM_DEBUG_EXCEPTION("EMAIL_ERROR_INVALID_PARAM");
325 err = EMAIL_ERROR_INVALID_PARAM;
329 if ((err = emipc_get_user_name(&multi_user_name)) != EMAIL_ERROR_NONE) {
330 EM_DEBUG_EXCEPTION("emipc_get_user_name failed : [%d]", err);
334 if (!emstorage_get_account_by_id(multi_user_name, input_mail_data->account_id, EMAIL_ACC_GET_OPT_OPTIONS, &p_account_tbl, false, &err)) {
335 EM_DEBUG_EXCEPTION("emstorage_get_account_by_id failed : [%d]", err);
339 for (i = 0; i < input_attachment_count; i++) {
340 EM_DEBUG_LOG("mime_type : [%s]", input_attachment_data[i].attachment_mime_type);
341 if (input_attachment_data[i].attachment_mime_type && (search = strcasestr(input_attachment_data[i].attachment_mime_type, "PKCS7-MIME"))) {
342 EM_DEBUG_LOG("Found the encrypt file");
344 } else if (input_attachment_data[i].attachment_mime_type && (search = strcasestr(input_attachment_data[i].attachment_mime_type, "octet-stream"))) {
345 EM_DEBUG_LOG("Found the encrypt file");
351 EM_DEBUG_EXCEPTION("No have a decrypt file");
352 err = EMAIL_ERROR_INVALID_PARAM;
356 if (input_mail_data->smime_type == EMAIL_SMIME_ENCRYPTED || input_mail_data->smime_type == EMAIL_SMIME_SIGNED_AND_ENCRYPTED) {
357 emcore_init_openssl_library();
358 if (!emcore_smime_get_decrypt_message(input_attachment_data[i].attachment_path, p_account_tbl->certificate_path, &decrypt_filepath, &err)) {
359 EM_DEBUG_EXCEPTION("emcore_smime_get_decrypt_message failed");
360 emcore_clean_openssl_library();
363 emcore_clean_openssl_library();
364 } else if (input_mail_data->smime_type == EMAIL_PGP_ENCRYPTED) {
365 if ((err = emcore_pgp_get_decrypted_message(input_attachment_data[i].attachment_path, input_mail_data->pgp_password, false, &decrypt_filepath, verify)) != EMAIL_ERROR_NONE) {
366 EM_DEBUG_EXCEPTION("emcore_pgp_get_decrypted_message failed : [%d]", err);
369 } else if (input_mail_data->smime_type == EMAIL_PGP_SIGNED_AND_ENCRYPTED) {
370 if ((err = emcore_pgp_get_decrypted_message(input_attachment_data[i].attachment_path, input_mail_data->pgp_password, true, &decrypt_filepath, verify)) != EMAIL_ERROR_NONE) {
371 EM_DEBUG_EXCEPTION("emcore_pgp_get_decrypted_message failed : [%d]", err);
375 EM_DEBUG_LOG("Invalid encrypted mail");
376 err = EMAIL_ERROR_INVALID_PARAM;
380 /* Change decrpyt_message to mail_data_t */
381 if (!emcore_parse_mime_file_to_mail(decrypt_filepath, output_mail_data, output_attachment_data, output_attachment_count, &err)) {
382 EM_DEBUG_EXCEPTION("emcore_parse_mime_file_to_mail failed : [%d]", err);
386 (*output_mail_data)->subject = EM_SAFE_STRDUP(input_mail_data->subject);
387 (*output_mail_data)->date_time = input_mail_data->date_time;
388 (*output_mail_data)->full_address_return = EM_SAFE_STRDUP(input_mail_data->full_address_return);
389 (*output_mail_data)->email_address_recipient = EM_SAFE_STRDUP(input_mail_data->email_address_recipient);
390 (*output_mail_data)->email_address_sender = EM_SAFE_STRDUP(input_mail_data->email_address_sender);
391 (*output_mail_data)->full_address_reply = EM_SAFE_STRDUP(input_mail_data->full_address_reply);
392 (*output_mail_data)->full_address_from = EM_SAFE_STRDUP(input_mail_data->full_address_from);
393 (*output_mail_data)->full_address_to = EM_SAFE_STRDUP(input_mail_data->full_address_to);
394 (*output_mail_data)->full_address_cc = EM_SAFE_STRDUP(input_mail_data->full_address_cc);
395 (*output_mail_data)->full_address_bcc = EM_SAFE_STRDUP(input_mail_data->full_address_bcc);
396 (*output_mail_data)->flags_flagged_field = input_mail_data->flags_flagged_field;
400 EM_SAFE_FREE(decrypt_filepath);
401 EM_SAFE_FREE(multi_user_name);
404 emstorage_free_account(&p_account_tbl, 1, NULL);
406 EM_DEBUG_API_END ("err[%d]", err);
410 EXPORT_API int email_verify_signature(int mail_id, int *verify)
412 EM_DEBUG_API_BEGIN ("mail_id[%d]", mail_id);
415 EM_DEBUG_EXCEPTION("Invalid parameter");
416 return EMAIL_ERROR_INVALID_PARAM;
419 int result_from_ipc = 0;
421 int err = EMAIL_ERROR_NONE;
423 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_VERIFY_SIGNATURE);
425 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
426 err = EMAIL_ERROR_NULL_VALUE;
430 if (!emipc_add_parameter(hAPI, ePARAMETER_IN, &mail_id, sizeof(int))) {
431 EM_DEBUG_EXCEPTION("emipc_add_parameter pass_phrase[%d] failed", mail_id);
432 err = EMAIL_ERROR_NULL_VALUE;
436 if (emipc_execute_proxy_api(hAPI) < 0) {
437 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
438 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
442 result_from_ipc = emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &p_verify);
443 if (result_from_ipc != EMAIL_ERROR_NONE) {
444 EM_DEBUG_EXCEPTION("emipc_get_parameter failed");
445 err = EMAIL_ERROR_IPC_CRASH;
452 emipc_destroy_email_api(hAPI);
457 EM_DEBUG_API_END ("err[%d]", err);
461 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)
463 EM_DEBUG_API_BEGIN ();
465 if (!input_mail_data || !input_attachment_data || input_attachment_count <= 0) {
466 EM_DEBUG_EXCEPTION("Invalid parameter");
467 return EMAIL_ERROR_INVALID_PARAM;
471 int err = EMAIL_ERROR_NONE;
473 for (count = 0; count < input_attachment_count ; count++) {
474 if (input_attachment_data[count].attachment_mime_type && strcasestr(input_attachment_data[count].attachment_mime_type, "SIGNATURE"))
478 if (input_mail_data->smime_type == EMAIL_SMIME_SIGNED) {
479 emcore_init_openssl_library();
480 if (!emcore_verify_signature(input_attachment_data[count].attachment_path, input_mail_data->file_path_mime_entity, verify, &err))
481 EM_DEBUG_EXCEPTION("emcore_verify_signature failed : [%d]", err);
483 emcore_clean_openssl_library();
484 } else if(input_mail_data->smime_type == EMAIL_PGP_SIGNED) {
485 if ((err = emcore_pgp_get_verify_signature(input_attachment_data[count].attachment_path, input_mail_data->file_path_mime_entity, input_mail_data->digest_type, verify)) != EMAIL_ERROR_NONE)
486 EM_DEBUG_EXCEPTION("emcore_pgp_get_verify_siganture failed : [%d]", err);
488 EM_DEBUG_LOG("Invalid signed mail : mime_type[%d]", input_mail_data->smime_type);
489 err = EMAIL_ERROR_INVALID_PARAM;
493 EM_DEBUG_API_END ("err[%d]", err);
497 EXPORT_API int email_verify_certificate(char *certificate_path, int *verify)
499 EM_DEBUG_API_BEGIN ();
500 EM_DEBUG_FUNC_BEGIN_SEC("certificate_path[%s]", certificate_path);
501 int err = EMAIL_ERROR_NONE;
502 int result_from_ipc = 0;
505 if (!certificate_path) {
506 EM_DEBUG_EXCEPTION("Invalid parameter");
507 return EMAIL_ERROR_INVALID_PARAM;
510 HIPC_API hAPI = emipc_create_email_api(_EMAIL_API_VERIFY_CERTIFICATE);
512 EM_DEBUG_EXCEPTION("emipc_create_email_api failed");
513 err = EMAIL_ERROR_NULL_VALUE;
517 if (!emipc_add_parameter(hAPI, ePARAMETER_IN, certificate_path, EM_SAFE_STRLEN(certificate_path)+1)) {
518 EM_DEBUG_EXCEPTION_SEC("emipc_add_paramter failed : [%s]", certificate_path);
519 err = EMAIL_ERROR_NULL_VALUE;
523 if (emipc_execute_proxy_api(hAPI) < 0) {
524 EM_DEBUG_EXCEPTION("emipc_execute_proxy_api failed");
525 err = EMAIL_ERROR_IPC_SOCKET_FAILURE;
529 result_from_ipc = emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &p_verify);
530 if (result_from_ipc != EMAIL_ERROR_NONE) {
531 EM_DEBUG_EXCEPTION("emipc_get_parameter failed");
532 err = EMAIL_ERROR_IPC_CRASH;
539 emipc_destroy_email_api(hAPI);
544 EM_DEBUG_API_END ("err[%d]", err);
549 EXPORT_API int email_check_ocsp_status(char *email_address, char *response_url, unsigned *handle)
551 EM_DEBUG_FUNC_BEGIN_SEC("email_address : [%s], response_url : [%s], handle : [%p]", email_address, response_url, handle);
553 EM_IF_NULL_RETURN_VALUE(email_address, EMAIL_ERROR_INVALID_PARAM);
555 int err = EMAIL_ERROR_NONE;
556 HIPC_API hAPI = NULL;
558 hAPI = emipc_create_email_api(_EMAIL_API_CHECK_OCSP_STATUS);
560 EM_IF_NULL_RETURN_VALUE(hAPI, EMAIL_ERROR_NULL_VALUE);
562 if (!emipc_add_parameter(hAPI, ePARAMETER_IN, email_address, EM_SAFE_STRLEN(email_address)+1)) {
563 EM_DEBUG_EXCEPTION("email_check_ocsp_status--ADD Param email_address failed");
564 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
567 if (!emipc_add_parameter(hAPI, ePARAMETER_IN, response_url, EM_SAFE_STRLEN(response_url)+1)) {
568 EM_DEBUG_EXCEPTION("email_check_ocsp_status--ADD Param response_url failed");
569 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
572 if (emipc_execute_proxy_api(hAPI) != EMAIL_ERROR_NONE) {
573 EM_DEBUG_EXCEPTION("email_check_oscp_status--emipc_execute_proxy_api failed");
574 EM_PROXY_IF_NULL_RETURN_VALUE(0, hAPI, EMAIL_ERROR_NULL_VALUE);
577 emipc_get_parameter(hAPI, ePARAMETER_OUT, 0, sizeof(int), &err);
578 if (err == EMAIL_ERROR_NONE) {
580 emipc_get_parameter(hAPI, ePARAMETER_OUT, 1, sizeof(int), handle);
584 EXPORT_API int email_validate_certificate(int account_id, char *email_address, unsigned *handle)
586 EM_DEBUG_API_BEGIN ("account_id[%d]", account_id);
587 EM_DEBUG_FUNC_BEGIN_SEC("account_id[%d] email_address[%s] handle[%p]", account_id, email_address, handle);
589 EM_IF_NULL_RETURN_VALUE(account_id, EMAIL_ERROR_INVALID_PARAM);
590 EM_IF_NULL_RETURN_VALUE(email_address, EMAIL_ERROR_INVALID_PARAM);
592 int err = EMAIL_ERROR_NONE;
594 char *multi_user_name = NULL;
595 email_account_server_t account_server_type;
596 ASNotiData as_noti_data;
598 if ((err = emipc_get_user_name(&multi_user_name)) != EMAIL_ERROR_NONE) {
599 EM_DEBUG_EXCEPTION("emipc_get_user_name failed : [%d]", err);
603 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
605 if (em_get_account_server_type_by_account_id(multi_user_name, account_id, &account_server_type, false, &err) == false) {
606 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
607 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
611 if (account_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
612 EM_DEBUG_EXCEPTION("This api is not supported except of active sync");
613 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
617 if (em_get_handle_for_activesync(&as_handle, &err) == false) {
618 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync_failed[%d]", err);
619 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
623 as_noti_data.validate_certificate.handle = as_handle;
624 as_noti_data.validate_certificate.account_id = account_id;
625 as_noti_data.validate_certificate.email_address = email_address;
626 as_noti_data.validate_certificate.multi_user_name = multi_user_name;
628 if (em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_VALIDATE_CERTIFICATE, &as_noti_data) == false) {
629 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed");
630 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
639 EM_SAFE_FREE(multi_user_name);
640 EM_DEBUG_API_END ("err[%d]", err);
644 EXPORT_API int email_get_resolve_recipients(int account_id, char *email_address, unsigned *handle)
646 EM_DEBUG_API_BEGIN ("account_id[%d]", account_id);
647 EM_DEBUG_FUNC_BEGIN_SEC("account_id[%d] email_address[%s] handle[%p]", account_id, email_address, handle);
649 EM_IF_NULL_RETURN_VALUE(account_id, EMAIL_ERROR_INVALID_PARAM);
650 EM_IF_NULL_RETURN_VALUE(email_address, EMAIL_ERROR_INVALID_PARAM);
652 int err = EMAIL_ERROR_NONE;
654 char *multi_user_name = NULL;
655 email_account_server_t account_server_type;
656 ASNotiData as_noti_data;
658 if ((err = emipc_get_user_name(&multi_user_name)) != EMAIL_ERROR_NONE) {
659 EM_DEBUG_EXCEPTION("emipc_get_user_name failed : [%d]", err);
663 memset(&as_noti_data, 0x00, sizeof(ASNotiData));
665 if (em_get_account_server_type_by_account_id(multi_user_name, account_id, &account_server_type, false, &err) == false) {
666 EM_DEBUG_EXCEPTION("em_get_account_server_type_by_account_id failed[%d]", err);
667 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
671 if (account_server_type != EMAIL_SERVER_TYPE_ACTIVE_SYNC) {
672 EM_DEBUG_EXCEPTION("This api is not supported except of active sync");
673 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
677 if (em_get_handle_for_activesync(&as_handle, &err) == false) {
678 EM_DEBUG_EXCEPTION("em_get_handle_for_activesync_failed[%d]", err);
679 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
683 as_noti_data.get_resolve_recipients.handle = as_handle;
684 as_noti_data.get_resolve_recipients.account_id = account_id;
685 as_noti_data.get_resolve_recipients.email_address = email_address;
686 as_noti_data.get_resolve_recipients.multi_user_name = multi_user_name;
688 if (em_send_notification_to_active_sync_engine(ACTIVE_SYNC_NOTI_RESOLVE_RECIPIENT, &as_noti_data) == false) {
689 EM_DEBUG_EXCEPTION("em_send_notification_to_active_sync_engine failed");
690 err = EMAIL_ERROR_ACTIVE_SYNC_NOTI_FAILURE;
699 EM_SAFE_FREE(multi_user_name);
700 EM_DEBUG_API_END ("err[%d]", err);
704 EXPORT_API int email_free_certificate(email_certificate_t **certificate, int count)
706 EM_DEBUG_API_BEGIN ("certificate[%p] count[%d]", certificate, count);
707 int err = EMAIL_ERROR_NONE;
708 emcore_free_certificate(certificate, count, &err);
709 EM_DEBUG_API_END ("err[%d]", err);