2 * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file pfx_cert_install.c
18 * @author Janusz Kozerski (j.kozerski@samsung.com)
26 #include <cert-svc/cpkcs12.h>
28 #include "certificates/certificate_util.h"
29 #include "certificates/certificates.h"
31 static const char * const dir_path = PATH_SDCARD;
33 static void install_pfx_button_cb(void *data, Evas_Object *obj, void *event_info);
35 static struct ListElement *firstListElement = NULL;
36 static struct ListElement *lastListElement = NULL;
38 void pfx_cert_install_cb(void *data, Evas_Object *obj, void *event_info) {
41 struct ug_data *ad = (struct ug_data *) data;
42 Evas_Object *list = NULL;
47 firstListElement = initList();
48 lastListElement = firstListElement;
50 list = elm_list_add(ad->win_main);
51 elm_list_mode_set(list, ELM_LIST_COMPRESS);
55 dir = opendir(dir_path);
57 LOGE("There's no such directory: %s", dir_path);
58 return; //TODO What if there's no SD card?
61 LOGD("Scanning dir (%s) - looking for certs", dir_path);
62 while ((dp = readdir(dir)) != NULL) {
64 tmp = path_cat(dir_path, dp->d_name);
65 char *dot = strrchr(dp->d_name, '.');
67 if(dot != NULL && strlen(dot)>3 && (strncmp(dot, ".pfx", 4) == 0 || strncmp(dot, ".PFX", 4) == 0 ||
68 strncmp(dot, ".p12", 4) == 0 || strncmp(dot, ".P12", 4) == 0)) {
69 if (!(dp->d_type == DT_DIR)) {
71 struct ListElement *current;
72 current = addListElement(lastListElement, dp->d_name);
73 lastListElement = current;
74 it = elm_list_item_append(list, dp->d_name, NULL, NULL, install_pfx_button_cb, current);
75 LOGD("elm list append = %s", current->name);
85 elm_naviframe_item_push(ad->navi_bar, dgettext(PACKAGE, "CHOOSE_PFX_TO_INSTALL"), NULL, NULL, list, NULL);
88 static void install_pfx_button_cb(void *data, Evas_Object *obj, void *event_info) {
90 struct ListElement *current = (struct ListElement *) data;
91 struct ug_data *ad = get_ug_data();
92 Elm_Object_Item *it = (Elm_Object_Item *) elm_list_selected_item_get(obj);
94 elm_list_item_selected_set(it, EINA_FALSE);
98 CertSvcString certSvcString_path;
100 result = asprintf(&path, "%s/%s", dir_path, current->name);
102 LOGD("aspfintf failed (-1)");
105 certsvc_string_new(ad->instance, path, strlen(path), &certSvcString_path);
108 if(certsvc_pkcs12_has_password(ad->instance, certSvcString_path, &returned_value)
110 LOGD("Wrong PKCS12 or PFX file.");
111 elm_naviframe_item_pop(ad->navi_bar);
115 switch (returned_value){
117 LOGD("%s is passwod protected", current->name);
118 put_pkcs12_name_and_pass_cb(current, NULL, NULL);
122 LOGD("%s is NOT passwod protected", current->name);
123 put_pkcs12_name_cb(current, NULL, NULL);