From 0a50a1c035f6c3a72fbccceae82ce596961b6ec8 Mon Sep 17 00:00:00 2001 From: SangSoo Lee Date: Tue, 11 Dec 2012 16:55:24 +0900 Subject: [PATCH] code sync Change-Id: Ic551a76f2ec79d60e3bb43d42aa836298ecc825d --- common/IPCHelper.cpp | 27 +++++----- common/SignatureHelper.cpp | 111 ++++++++++++++++++--------------------- common/include/IPCHelper.h | 2 +- common/include/SignatureHelper.h | 13 +++-- packaging/smartcard-service.spec | 4 +- 5 files changed, 75 insertions(+), 82 deletions(-) diff --git a/common/IPCHelper.cpp b/common/IPCHelper.cpp index b8a8993..f06dd43 100644 --- a/common/IPCHelper.cpp +++ b/common/IPCHelper.cpp @@ -201,21 +201,18 @@ ERROR : for (i = 0; i < events; i++) { - if (pollEvents[i].data.fd == fdPoll) - { - SCARD_DEBUG("pollEvents[%d].events [%X]", i, pollEvents[i].events); + SCARD_DEBUG("pollEvents[%d].events [%X]", i, pollEvents[i].events); - if ((pollEvents[i].events & EPOLLHUP) || (pollEvents[i].events & EPOLLERR)) - { - SCARD_DEBUG_ERR("connection is closed"); - result = 0; - break; - } - else if (pollEvents[i].events & EPOLLIN) - { - result = 1; - break; - } + if ((pollEvents[i].events & EPOLLHUP) || (pollEvents[i].events & EPOLLERR)) + { + SCARD_DEBUG_ERR("connection is closed"); + result = 0; + break; + } + else if (pollEvents[i].events & EPOLLIN) + { + result = 1; + break; } } } @@ -369,7 +366,7 @@ ERROR : struct epoll_event ev; ev.events = EPOLLIN | EPOLLHUP | EPOLLERR; - ev.data.fd = fdPoll; + ev.data.fd = ipcSocket; epoll_ctl(fdPoll, EPOLL_CTL_ADD, ipcSocket, &ev); #else diff --git a/common/SignatureHelper.cpp b/common/SignatureHelper.cpp index a5dd4d6..cf59387 100644 --- a/common/SignatureHelper.cpp +++ b/common/SignatureHelper.cpp @@ -18,6 +18,7 @@ /* standard library header */ #include #include +#include #include #include #include @@ -183,14 +184,17 @@ namespace smartcard_service_api { if (value != NULL && strlen(value) > 0) { - ByteArray hash; + ByteArray decodeValue, hash; - OpensslHelper::decodeBase64String(value, hash, false); - if (hash.getLength() > 0) + OpensslHelper::decodeBase64String(value, decodeValue, false); + if (decodeValue.getLength() > 0) { - SCARD_DEBUG("type [%d] hash [%d] : %s", type, hash.getLength(), hash.toString()); - - certHashes.push_back(hash); + OpensslHelper::digestBuffer("sha1", decodeValue.getBuffer(), decodeValue.getLength(), hash); + if(hash.getLength() > 0) + { + SCARD_DEBUG("type [%d] hash [%d] : %s", type, hash.getLength(), hash.toString()); + certHashes.push_back(hash); + } } } } @@ -217,54 +221,52 @@ namespace smartcard_service_api /* export C API */ using namespace smartcard_service_api; -EXTERN_API int signature_helper_get_certificate_hash(const char *packageName, uint8_t *hash, uint32_t *length) +certiHash* __signature_helper_vector_to_linked_list(vector &certHashes) { - int ret = -1; - ByteArray result; + vector::iterator item; + certiHash *head, *tail, *tmp; - if (packageName == NULL || strlen(packageName) == 0 || hash == NULL || length == NULL || *length < 20) - return ret; + head = tail = NULL; - result = SignatureHelper::getCertificationHash(packageName); - - if (result.isEmpty() == false) + for (item = certHashes.begin(); item != certHashes.end(); item++) { - memcpy(hash, result.getBuffer(), (result.getLength() < *length) ? result.getLength() : *length); - *length = result.getLength(); + if((tmp = (certiHash*)calloc(1, sizeof(certiHash)))== NULL) + goto ERROR; - ret = 0; - } - else - { - ret = -1; - } + tmp->length = (*item).getLength(); - return ret; -} + if((tmp->value = (uint8_t*)calloc(tmp->length, sizeof(uint8_t))) == NULL) + goto ERROR; -EXTERN_API int signature_helper_get_certificate_hash_by_pid(int pid, uint8_t *hash, uint32_t *length) -{ - int ret = -1; - ByteArray result; + memcpy(tmp->value, (*item).getBuffer(), tmp->length); + tmp->next = NULL; - if (pid < 0 || hash == NULL || length == NULL || *length < 20) - return ret; + if(head == NULL) + { + head = tail = tmp; + } + else + { + tail->next = tmp; + tail = tmp; + } + } + return head; - result = SignatureHelper::getCertificationHash(pid); +ERROR : + SCARD_DEBUG_ERR("mem alloc fail"); - if (result.isEmpty() == false && result.getLength() < *length) - { - memcpy(hash, result.getBuffer(), result.getLength()); - *length = result.getLength(); + while(head) + { + tmp = head; + head = head->next; + if(tmp->value != NULL) + free(tmp->value); + free(tmp); + } - ret = 0; - } - else - { - ret = -1; - } + return NULL; - return ret; } EXTERN_API int signature_helper_get_process_name(int pid, char *processName, uint32_t length) @@ -279,48 +281,37 @@ EXTERN_API int signature_helper_get_process_name(int pid, char *processName, uin return ret; } -EXTERN_API int signature_helper_get_certificate_hashes(const char *packageName, signature_helper_get_certificate_hashes_cb cb, void *user_param) +EXTERN_API int signature_helper_get_certificate_hashes(const char *packageName, certiHash **hash) { int ret = -1; vector hashes; - if (packageName == NULL || cb == NULL) + if (packageName == NULL) return ret; if (SignatureHelper::getCertificationHashes(packageName, hashes) == true) { - vector::iterator item; - - for (item = hashes.begin(); item != hashes.end(); item++) - { - cb(user_param, (*item).getBuffer(), (*item).getLength()); - } - + *hash = __signature_helper_vector_to_linked_list(hashes); ret = 0; } return ret; } -EXTERN_API int signature_helper_get_certificate_hashes_by_pid(int pid, signature_helper_get_certificate_hashes_cb cb, void *user_param) +EXTERN_API int signature_helper_get_certificate_hashes_by_pid(int pid, certiHash **hash) { int ret = -1; vector hashes; - if (pid <= 0 || cb == NULL) + if (pid <= 0) return ret; if (SignatureHelper::getCertificationHashes(pid, hashes) == true) { - vector::iterator item; - - for (item = hashes.begin(); item != hashes.end(); item++) - { - cb(user_param, (*item).getBuffer(), (*item).getLength()); - } - + *hash = __signature_helper_vector_to_linked_list(hashes); ret = 0; } return ret; } + diff --git a/common/include/IPCHelper.h b/common/include/IPCHelper.h index c7e18bc..2826563 100644 --- a/common/include/IPCHelper.h +++ b/common/include/IPCHelper.h @@ -46,7 +46,7 @@ namespace smartcard_service_api DispatcherHelper *dispatcher; #ifdef CLIENT_IPC_THREAD #ifdef USE_IPC_EPOLL - static const int EPOLL_SIZE = 128; + static const int EPOLL_SIZE = 5; int fdPoll; struct epoll_event *pollEvents; #else diff --git a/common/include/SignatureHelper.h b/common/include/SignatureHelper.h index 01353b8..2d3613e 100644 --- a/common/include/SignatureHelper.h +++ b/common/include/SignatureHelper.h @@ -55,13 +55,18 @@ extern "C" { #endif /* __cplusplus */ +typedef struct _certiHash +{ + uint8_t *value; + uint32_t length; + struct _certiHash *next; +}certiHash; + typedef void (*signature_helper_get_certificate_hashes_cb)(void *user_param, uint8_t *hash, uint32_t length); int signature_helper_get_process_name(int pid, char *processName, uint32_t length); -int signature_helper_get_certificate_hash(const char *packageName, uint8_t *hash, uint32_t *length); -int signature_helper_get_certificate_hash_by_pid(int pid, uint8_t *hash, uint32_t *length); -int signature_helper_get_certificate_hashes(const char *packageName, signature_helper_get_certificate_hashes_cb cb, void *user_param); -int signature_helper_get_certificate_hashes_by_pid(int pid, signature_helper_get_certificate_hashes_cb cb, void *user_param); +int signature_helper_get_certificate_hashes(const char *packageName, certiHash **hash); +int signature_helper_get_certificate_hashes_by_pid(int pid, certiHash **hash); #ifdef __cplusplus } diff --git a/packaging/smartcard-service.spec b/packaging/smartcard-service.spec index 1ff1891..6347749 100644 --- a/packaging/smartcard-service.spec +++ b/packaging/smartcard-service.spec @@ -1,7 +1,7 @@ Name: smartcard-service Summary: Smartcard Service FW -Version: 0.1.0 -Release: 28 +Version: 0.1.4 +Release: 2 Group: libs License: Samsung Proprietary License Source0: %{name}-%{version}.tar.gz -- 2.7.4