From 4c9c8db40d63694013f2b6aab6fbbc94b089fff2 Mon Sep 17 00:00:00 2001 From: Jihoon Jung Date: Fri, 19 Jun 2015 14:46:00 +0900 Subject: [PATCH] Apply tizen 2.4 smartcard-service Signed-off-by: Ji-hoon Jung Change-Id: I5a74d30399eb77fb1b6426c373c437b6ca1d7d94 --- CMakeLists.txt | 49 +- client/CMakeLists.txt | 72 ++- client/ClientChannel.cpp | 271 ++++++++-- client/ClientGDBus.cpp | 14 + client/Reader.cpp | 108 +++- client/SEService.cpp | 213 ++++++-- client/Session.cpp | 290 ++++++++--- client/include/ClientChannel.h | 42 +- client/include/ClientGDBus.h | 4 + client/include/Reader.h | 25 +- client/include/SEService.h | 36 +- client/include/SEServiceListener.h | 8 +- client/include/Session.h | 59 ++- client/include/smartcard-service.h | 2 + client/smartcard-service.pc | 13 + client/smartcard-service.pc.in | 11 - common/APDUHelper.cpp | 85 ++- common/AccessCondition.cpp | 60 ++- common/AccessControlList.cpp | 35 ++ common/ByteArray.cpp | 19 +- common/CMakeLists.txt | 70 ++- common/EFDIR.cpp | 4 + common/FCI.cpp | 16 +- common/FileObject.cpp | 63 ++- common/GPACE.cpp | 5 + common/GPARAACL.cpp | 7 + common/GPARAM.cpp | 97 +++- common/GPARFACL.cpp | 41 +- common/ISO7816BERTLV.cpp | 30 +- common/OpensslHelper.cpp | 26 +- common/PKCS15.cpp | 9 +- common/PKCS15CDF.cpp | 264 ++++++++++ common/PKCS15DODF.cpp | 11 +- common/PKCS15ODF.cpp | 61 ++- common/PKCS15OID.cpp | 6 + common/PKCS15Object.cpp | 5 + common/PKCS15Path.cpp | 5 + common/PKCS15TokenInfo.cpp | 5 + common/Serializable.cpp | 5 + common/SignatureHelper.cpp | 81 ++- common/include/APDUHelper.h | 13 +- common/include/AccessCondition.h | 9 + common/include/AccessControlList.h | 9 + common/include/ByteArray.h | 9 +- common/include/Channel.h | 10 +- common/include/Debug.h | 10 +- common/include/EFDIR.h | 4 + common/include/Exception.h | 13 +- common/include/FCI.h | 4 + common/include/FileObject.h | 11 +- common/include/GDBusHelper.h | 3 +- common/include/GPACE.h | 8 +- common/include/GPARAACL.h | 5 + common/include/GPARAM.h | 4 + common/include/GPARFACL.h | 5 + common/include/ISO7816BERTLV.h | 5 + common/include/Lock.h | 15 +- common/include/NumberStream.h | 5 + common/include/OpensslHelper.h | 4 + common/include/PKCS15.h | 9 +- common/include/PKCS15CDF.h | 65 +++ common/include/PKCS15DODF.h | 5 + common/include/PKCS15ODF.h | 18 +- common/include/PKCS15OID.h | 5 + common/include/PKCS15Object.h | 4 + common/include/PKCS15Path.h | 5 + common/include/PKCS15TokenInfo.h | 5 + common/include/ProviderHelper.h | 5 + common/include/ReaderHelper.h | 7 +- common/include/SEServiceHelper.h | 7 +- common/include/Serializable.h | 3 +- common/include/SessionHelper.h | 23 +- common/include/SignatureHelper.h | 15 +- common/include/Synchronous.h | 7 +- common/include/Terminal.h | 8 +- common/include/TerminalInterface.h | 6 + common/smartcard-service-common.pc | 13 + common/smartcard-service-common.pc.in | 11 - common/smartcard-service-gdbus.xml | 2 + common/smartcard-service.xml | 11 - debian/changelog | 55 ++ debian/compat | 1 + debian/control | 65 +++ debian/rules | 33 ++ debian/smartcard-service-common-dev.dirs | 2 + debian/smartcard-service-common-dev.install | 5 + debian/smartcard-service-common.dirs | 1 + debian/smartcard-service-common.install | 1 + debian/smartcard-service-dev.dirs | 2 + debian/smartcard-service-dev.install | 5 + debian/smartcard-service-server.dirs | 2 + debian/smartcard-service-server.init | 28 + debian/smartcard-service-server.install | 2 + debian/smartcard-service.dirs | 1 + debian/smartcard-service.install | 1 + packaging/smartcard-service | 206 ++++++++ packaging/smartcard-service-common | 206 ++++++++ packaging/smartcard-service-common-devel.manifest | 5 - packaging/smartcard-service-common.manifest | 5 - packaging/smartcard-service-devel.manifest | 5 - packaging/smartcard-service-server | 206 ++++++++ packaging/smartcard-service-server.manifest | 5 - packaging/smartcard-service.changes | 9 - packaging/smartcard-service.manifest | 5 - packaging/smartcard-service.spec | 236 +++++---- server/CMakeLists.txt | 72 ++- server/ClientInstance.cpp | 4 + server/ServerChannel.cpp | 8 + server/ServerGDBus.cpp | 177 ++++--- server/ServerResource.cpp | 152 ++++-- server/ServerSEService.cpp | 47 +- server/ServerSession.cpp | 173 ++++++- server/include/ClientInstance.h | 4 + server/include/ServerChannel.h | 5 + server/include/ServerGDBus.h | 4 + server/include/ServerResource.h | 7 + server/include/ServerSEService.h | 4 + server/include/ServerSession.h | 8 + server/include/SmartcardDbus.h | 4 +- server/org.tizen.SmartcardService.service | 5 + server/org.tizen.smartcard_service.service | 4 - server/private/AccessControl.cpp | 601 ++++++++++++++++++++++ server/private/PKCS15CDFACL.cpp | 130 +++++ server/private/PKCS15CDFACL.h | 48 ++ server/private/access-control-gdbus.xml | 26 + server/smartcard-daemon.cpp | 6 + server/smartcard-service-server.xml | 8 +- smartcard-service-common-devel.manifest | 6 + smartcard-service-common.manifest | 6 + smartcard-service-devel.manifest | 6 + smartcard-service-server.manifest | 23 + smartcard-service.manifest | 6 + test-client/CMakeLists.txt | 41 +- 133 files changed, 4513 insertions(+), 771 deletions(-) create mode 100644 client/smartcard-service.pc delete mode 100644 client/smartcard-service.pc.in create mode 100644 common/PKCS15CDF.cpp create mode 100644 common/include/PKCS15CDF.h create mode 100644 common/smartcard-service-common.pc delete mode 100644 common/smartcard-service-common.pc.in delete mode 100644 common/smartcard-service.xml create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100755 debian/rules create mode 100644 debian/smartcard-service-common-dev.dirs create mode 100644 debian/smartcard-service-common-dev.install create mode 100644 debian/smartcard-service-common.dirs create mode 100644 debian/smartcard-service-common.install create mode 100644 debian/smartcard-service-dev.dirs create mode 100644 debian/smartcard-service-dev.install create mode 100644 debian/smartcard-service-server.dirs create mode 100755 debian/smartcard-service-server.init create mode 100644 debian/smartcard-service-server.install create mode 100644 debian/smartcard-service.dirs create mode 100644 debian/smartcard-service.install create mode 100644 packaging/smartcard-service create mode 100644 packaging/smartcard-service-common delete mode 100644 packaging/smartcard-service-common-devel.manifest delete mode 100644 packaging/smartcard-service-common.manifest delete mode 100644 packaging/smartcard-service-devel.manifest create mode 100644 packaging/smartcard-service-server delete mode 100644 packaging/smartcard-service-server.manifest delete mode 100644 packaging/smartcard-service.changes delete mode 100644 packaging/smartcard-service.manifest create mode 100644 server/org.tizen.SmartcardService.service delete mode 100644 server/org.tizen.smartcard_service.service create mode 100644 server/private/AccessControl.cpp create mode 100644 server/private/PKCS15CDFACL.cpp create mode 100644 server/private/PKCS15CDFACL.h create mode 100755 server/private/access-control-gdbus.xml create mode 100644 smartcard-service-common-devel.manifest create mode 100644 smartcard-service-common.manifest create mode 100644 smartcard-service-devel.manifest create mode 100644 smartcard-service-server.manifest create mode 100644 smartcard-service.manifest diff --git a/CMakeLists.txt b/CMakeLists.txt index 6e59a80..ee5ffee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,44 +1,31 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(smartcard-service CXX C) MESSAGE("build smartcard-service") -IF("${CMAKE_BUILD_TYPE}" STREQUAL "") - SET(CMAKE_BUILD_TYPE "Release") -ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") +SET(CMAKE_VERBOSE_MAKEFILE OFF) -MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") - -INCLUDE(FindPkgConfig) - -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") - -SET(CMAKE_SHARED_LINKER_FLAGS " -Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}") -SET(CMAKE_EXE_LINKER_FLAGS " -Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}") - -FIND_PROGRAM(UNAME NAMES uname) -EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") -IF("${ARCH}" MATCHES "^arm.*") - ADD_DEFINITIONS("-DTARGET") - MESSAGE("add -DTARGET") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mabi=aapcs-linux -fno-common") -ENDIF("${ARCH}" MATCHES "^arm.*") - -# names -SET(CLIENT_LIB ${PROJECT_NAME}) -SET(COMMON_LIB "smartcard-service-common") -SET(DAEMON "smartcard-daemon") - -# For *.pc files -SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +# apply smack +ADD_DEFINITIONS("-DUSER_SPACE_SMACK") -# Defines IF(DEFINED USE_AUTOSTART) ADD_DEFINITIONS("-DUSE_AUTOSTART") ENDIF() -# apply smack -##ADD_DEFINITIONS("-DUSER_SPACE_SMACK") +# make string from entire content of byte array +ADD_DEFINITIONS("-DTO_STRING_ALL") + +SET(GC_SECTIONS_FLAGS "-fdata-sections -ffunction-sections -Wl,--gc-sections") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GC_SECTIONS_FLAGS}") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GC_SECTIONS_FLAGS}") + +FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen) +EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS + " \\ + --generate-c-code ${CMAKE_CURRENT_SOURCE_DIR}/common/smartcard-service-gdbus \\ + --c-namespace SmartcardService\\ + --interface-prefix org.tizen.SmartcardService. \\ + ${CMAKE_CURRENT_SOURCE_DIR}/common/smartcard-service-gdbus.xml \\ + ") ADD_SUBDIRECTORY(common) ADD_SUBDIRECTORY(client) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index d00cf10..e0fb961 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -1,24 +1,67 @@ -INCLUDE_DIRECTORIES(include) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common/include) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/server/include) +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(smartcard-service CXX) + +SET(LIB_NAME "smartcard-service") +SET(VERSION_MAJOR 1) +SET(VERSION ${VERSION_MAJOR}.0.0) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common/include) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../server/include) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SRCS) -pkg_check_modules(pkgs_client REQUIRED glib-2.0 dlog) +IF("${CMAKE_BUILD_TYPE}" STREQUAL "") + SET(CMAKE_BUILD_TYPE "Release") +ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") +MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") + +# pkg config +INCLUDE(FindPkgConfig) + +SET(PKG_MODULE glib-2.0 dlog) + +pkg_check_modules(pkgs_client REQUIRED ${PKG_MODULE}) + +MESSAGE("${LIB_NAME} ld flag : ${pkgs_client_LDFLAGS}") + FOREACH(flag ${pkgs_client_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}") ENDFOREACH(flag) -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS}") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -finstrument-functions -fPIC") +#SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +#SET(CMAKE_C_FLAGS_RELEASE "-O2") + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS} -finstrument-functions -std=c++0x") +#SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") +#SET(CMAKE_CXX_FLAGS_RELEASE "-O2") + +FIND_PROGRAM(UNAME NAMES uname) +EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") + MESSAGE("add -DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +MESSAGE("CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}") ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DSLP_DEBUG") ADD_DEFINITIONS("-DLOG_TAG=\"SMARTCARD_SERVICE_CLIENT\"") -ADD_LIBRARY(${CLIENT_LIB} SHARED ${SRCS}) -SET_TARGET_PROPERTIES(${CLIENT_LIB} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER}) -TARGET_LINK_LIBRARIES(${CLIENT_LIB} ${pkgs_client_LDFLAGS}) +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) -SET(EXPORT_HEADER +SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR}) +SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${VERSION}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_client_LDFLAGS}) + +SET(EXPORT_HEADER ../common/include/smartcard-types.h ../common/include/ByteArray.h ../common/include/Debug.h @@ -41,11 +84,8 @@ SET(EXPORT_HEADER # include/ ) -CONFIGURE_FILE(${CLIENT_LIB}.pc.in ${CLIENT_LIB}.pc @ONLY) - -INSTALL(FILES ${CLIENT_LIB}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) -INSTALL(TARGETS ${CLIENT_LIB} DESTINATION ${LIB_INSTALL_DIR}) - +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) FOREACH(hfile ${EXPORT_HEADER}) - INSTALL(FILES ${hfile} DESTINATION include/${CLIENT_LIB}) + INSTALL(FILES ${hfile} DESTINATION include/${LIB_NAME}) ENDFOREACH(hfile) diff --git a/client/ClientChannel.cpp b/client/ClientChannel.cpp index 7ecab0f..4102925 100644 --- a/client/ClientChannel.cpp +++ b/client/ClientChannel.cpp @@ -14,11 +14,15 @@ * limitations under the License. */ +/* standard library header */ #include #include #include #include +/* SLP library header */ + +/* local header */ #include "Debug.h" #include "ClientChannel.h" #include "ReaderHelper.h" @@ -167,6 +171,7 @@ namespace smartcard_service_api gint ret; GError *error = NULL; + if (proxy == NULL) { _ERR("dbus proxy is not initialized yet"); throw ErrorIllegalState(SCARD_ERROR_NOT_INITIALIZED); @@ -177,7 +182,9 @@ namespace smartcard_service_api GPOINTER_TO_UINT(context), GPOINTER_TO_UINT(handle), &ret, NULL, &error) == true) { - if (ret != SCARD_ERROR_OK) { + if (ret == SCARD_ERROR_OK) { + channelNum = -1; + } else { _ERR("smartcard_service_channel_call_close_channel_sync failed, [%d]", ret); THROW_ERROR(ret); } @@ -246,13 +253,14 @@ namespace smartcard_service_api NULL, &error) == true) { if (rv == SCARD_ERROR_OK) { - GDBusHelper::convertVariantToByteArray(var_response, result); + GDBusHelper::convertVariantToByteArray(var_response, transmitResponse); + result = transmitResponse; } else { - _ERR("smartcard_service_session_call_get_atr_sync failed, [%d]", rv); + _ERR("smartcard_service_session_call_transmit failed, [%d]", rv); THROW_ERROR(rv); } } else { - _ERR("smartcard_service_session_call_get_atr_sync failed, [%s]", error->message); + _ERR("smartcard_service_session_call_transmit failed, [%s]", error->message); g_error_free(error); throw ErrorIO(SCARD_ERROR_IPC_FAILED); @@ -316,94 +324,258 @@ namespace smartcard_service_api using namespace smartcard_service_api; -EXTERN_API int channel_close(channel_h handle, channel_close_cb callback, void *userParam) +EXTERN_API int channel_close_sync(channel_h handle) { - int result = -1; + int result = SCARD_ERROR_OK; CHANNEL_EXTERN_BEGIN; - result = channel->close((closeChannelCallback)callback, userParam); + + try + { + channel->closeSync(); + } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + } + catch (...) + { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + } + CHANNEL_EXTERN_END; return result; } -EXTERN_API int channel_transmit(channel_h handle, unsigned char *command, - unsigned int length, channel_transmit_cb callback, void *userParam) +EXTERN_API int channel_transmit_sync(channel_h handle, unsigned char *command, + unsigned int cmd_len, unsigned char **response, unsigned int *resp_len) { - int result = -1; + int result = SCARD_ERROR_OK; + + if (command == NULL || cmd_len == 0 || response == NULL || resp_len == NULL) + return SCARD_ERROR_UNKNOWN; CHANNEL_EXTERN_BEGIN; - ByteArray temp; - temp.assign(command, length); - result = channel->transmit(temp, (transmitCallback)callback, userParam); + try + { + ByteArray temp, resp; + + temp.assign(command, cmd_len); + channel->transmitSync(temp, resp); + + if (resp.size() > 0) + { + *response = (unsigned char *)calloc(resp.size(), sizeof(unsigned char)); + *resp_len = resp.size(); + memcpy(*response, resp.getBuffer(), *resp_len); + } + } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + *resp_len = 0; + } + catch (...) + { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + *resp_len = 0; + } + CHANNEL_EXTERN_END; return result; } -EXTERN_API void channel_close_sync(channel_h handle) +EXTERN_API int channel_is_basic_channel(channel_h handle, bool* is_basic_channel) { + int result = SCARD_ERROR_OK; + CHANNEL_EXTERN_BEGIN; + try { - channel->closeSync(); + *is_basic_channel = channel->isBasicChannel(); + } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); } catch (...) { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; } + CHANNEL_EXTERN_END; + + return result; } -EXTERN_API int channel_transmit_sync(channel_h handle, unsigned char *command, - unsigned int cmd_len, unsigned char **response, unsigned int *resp_len) +EXTERN_API int channel_is_closed(channel_h handle, bool* is_closed) { - int result = -1; + int result = SCARD_ERROR_OK; - if (command == NULL || cmd_len == 0 || response == NULL || resp_len == NULL) - return result; + CHANNEL_EXTERN_BEGIN; + + try + { + *is_closed = channel->isClosed(); + } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + } + catch (...) + { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + } + + CHANNEL_EXTERN_END; + + return result; +} + +EXTERN_API int channel_get_select_response(channel_h handle, + unsigned char **buffer, size_t *length) +{ + int result = SCARD_ERROR_OK; CHANNEL_EXTERN_BEGIN; - ByteArray temp, resp; - temp.assign(command, cmd_len); + try + { + ByteArray response = channel->getSelectResponse(); + uint8_t* get_buffer = response.getBuffer(); + + *length = response.size(); + + if (*length > 0) + { + *buffer = (unsigned char *)calloc(*length, sizeof(unsigned char)); + if(*buffer == NULL || get_buffer == NULL) + { + *length = 0; + return SCARD_ERROR_NOT_ENOUGH_RESOURCE; + } + + memcpy(*buffer, get_buffer, *length); + } + } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + *length = 0; + } + catch (...) + { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + *length = 0; + } + + CHANNEL_EXTERN_END; + + return result; +} + +EXTERN_API int channel_get_transmit_response(channel_h handle, + unsigned char **buffer, size_t *length) +{ + int result = SCARD_ERROR_OK; + + CHANNEL_EXTERN_BEGIN; try { - result = channel->transmitSync(temp, resp); - if (resp.size() > 0) + ByteArray response; + + response = channel->getTransmitResponse(); + + *length = response.size(); + + if (*length > 0) { - *resp_len = resp.size(); - *response = (unsigned char *)calloc(1, *resp_len); - memcpy(*response, resp.getBuffer(), *resp_len); + *buffer = (unsigned char *)calloc(*length, sizeof(unsigned char)); + memcpy(*buffer, response.getBuffer(), *length); } } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + *length = 0; + } catch (...) { - result = -1; + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + *length = 0; } + CHANNEL_EXTERN_END; return result; } -EXTERN_API bool channel_is_basic_channel(channel_h handle) +EXTERN_API int channel_get_session(channel_h handle, int *session_handle) { - bool result = false; + int result = SCARD_ERROR_OK; + session_h session = NULL; CHANNEL_EXTERN_BEGIN; - result = channel->isBasicChannel(); + + try + { + session = channel->getSession(); + //*session_handle = (int)session; + } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + } + catch (...) + { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + } + CHANNEL_EXTERN_END; return result; } -EXTERN_API bool channel_is_closed(channel_h handle) +EXTERN_API int channel_select_next(channel_h handle, bool *pSuccess) { - bool result = false; + int result = SCARD_ERROR_OK; CHANNEL_EXTERN_BEGIN; - result = channel->isClosed(); + + try + { + *pSuccess = channel->selectNext(); + } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + } + catch (...) + { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + } + CHANNEL_EXTERN_END; return result; @@ -420,39 +592,30 @@ EXTERN_API unsigned int channel_get_select_response_length(channel_h handle) return result; } -EXTERN_API bool channel_get_select_response(channel_h handle, - unsigned char *buffer, unsigned int length) +EXTERN_API int channel_close(channel_h handle, channel_close_cb callback, void *userParam) { - bool result = false; - - if (buffer == NULL || length == 0) - { - return result; - } + int result = -1; CHANNEL_EXTERN_BEGIN; - ByteArray response; - - response = channel->getSelectResponse(); - if (response.size() > 0) - { - memcpy(buffer, response.getBuffer(), MIN(length, response.size())); - result = true; - } + result = channel->close((closeChannelCallback)callback, userParam); CHANNEL_EXTERN_END; return result; } -EXTERN_API session_h channel_get_session(channel_h handle) +EXTERN_API int channel_transmit(channel_h handle, unsigned char *command, + unsigned int length, channel_transmit_cb callback, void *userParam) { - session_h session = NULL; + int result = -1; CHANNEL_EXTERN_BEGIN; - session = channel->getSession(); + ByteArray temp; + + temp.assign(command, length); + result = channel->transmit(temp, (transmitCallback)callback, userParam); CHANNEL_EXTERN_END; - return session; + return result; } EXTERN_API void channel_destroy_instance(channel_h handle) diff --git a/client/ClientGDBus.cpp b/client/ClientGDBus.cpp index f2c572e..eb1eb2f 100644 --- a/client/ClientGDBus.cpp +++ b/client/ClientGDBus.cpp @@ -14,8 +14,12 @@ * limitations under the License. */ +/* standard library header */ #include +/* SLP library header */ + +/* local header */ #include "smartcard-types.h" #include "Debug.h" #include "ByteArray.h" @@ -23,6 +27,16 @@ using namespace std; +/* below functions will be called when dlopen or dlclose is called */ +void __attribute__ ((constructor)) lib_init() +{ + g_type_init(); +} + +void __attribute__ ((destructor)) lib_fini() +{ +} + namespace smartcard_service_api { } /* namespace smartcard_service_api */ diff --git a/client/Reader.cpp b/client/Reader.cpp index 1b1d0e5..2a9cac1 100644 --- a/client/Reader.cpp +++ b/client/Reader.cpp @@ -14,10 +14,14 @@ * limitations under the License. */ +/* standard library header */ #include #include #include +/* SLP library header */ + +/* local header */ #include "Debug.h" #include "Reader.h" #include "Session.h" @@ -235,66 +239,130 @@ namespace smartcard_service_api using namespace smartcard_service_api; -EXTERN_API const char *reader_get_name(reader_h handle) +EXTERN_API int reader_get_name(reader_h handle, char** reader_name) { - const char *name = NULL; + int result = SCARD_ERROR_OK; READER_EXTERN_BEGIN; - name = reader->getName(); + + try + { + *reader_name = g_strdup(reader->getName()); + } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + } + catch (...) + { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + } + READER_EXTERN_END; - return name; + return result; } -EXTERN_API se_service_h reader_get_se_service(reader_h handle) +EXTERN_API int reader_is_secure_element_present(reader_h handle, bool* is_present) { - se_service_h service = NULL; + int result = SCARD_ERROR_OK; READER_EXTERN_BEGIN; - service = (se_service_h)reader->getSEService(); + + try + { + *is_present = reader->isSecureElementPresent(); + } + catch (...) + { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + } + READER_EXTERN_END; - return service; + return result; } -EXTERN_API bool reader_is_secure_element_present(reader_h handle) +EXTERN_API int reader_open_session_sync(reader_h handle, int *session_handle) { - bool result = false; + session_h session; + int result = SCARD_ERROR_OK; READER_EXTERN_BEGIN; - result = reader->isSecureElementPresent(); + + try + { + session = (session_h)reader->openSessionSync(); + //*session_handle = (int)session; + } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + *session_handle = 0; + } + catch (...) + { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + *session_handle = 0; + } + READER_EXTERN_END; return result; } -EXTERN_API int reader_open_session(reader_h handle, reader_open_session_cb callback, void *userData) +EXTERN_API int reader_close_sessions(reader_h handle) { - int result = -1; + int result = SCARD_ERROR_OK; READER_EXTERN_BEGIN; - result = reader->openSession((openSessionCallback)callback, userData); + + try + { + reader->closeSessions(); + } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + } + catch (...) + { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + } + READER_EXTERN_END; return result; } -EXTERN_API session_h reader_open_session_sync(reader_h handle) + +EXTERN_API se_service_h reader_get_se_service(reader_h handle) { - session_h result = NULL; + se_service_h service = NULL; READER_EXTERN_BEGIN; - result = (session_h)reader->openSessionSync(); + service = (se_service_h)reader->getSEService(); READER_EXTERN_END; - return result; + return service; } -EXTERN_API void reader_close_sessions(reader_h handle) +EXTERN_API int reader_open_session(reader_h handle, reader_open_session_cb callback, void *userData) { + int result = -1; + READER_EXTERN_BEGIN; - reader->closeSessions(); + result = reader->openSession((openSessionCallback)callback, userData); READER_EXTERN_END; + + return result; } EXTERN_API void reader_destroy_instance(reader_h handle) diff --git a/client/SEService.cpp b/client/SEService.cpp index 60a6336..3ebee77 100644 --- a/client/SEService.cpp +++ b/client/SEService.cpp @@ -20,11 +20,10 @@ #include #include -/* SLP library header */ - /* local header */ #include "Debug.h" #include "SEService.h" +#include "ClientChannel.h" #include "Reader.h" #include "ClientGDBus.h" @@ -33,11 +32,13 @@ #endif #define SHUTDOWN_DELAY 500000 /* us */ +#define VERSION "3.0" namespace smartcard_service_api { SEService::SEService() : SEServiceHelper(), - handle(-1), context(NULL), handler(NULL), listener(NULL) + handle(-1), context(NULL), handler(NULL), listener(NULL), + version(VERSION) { proxy = NULL; } @@ -45,7 +46,7 @@ namespace smartcard_service_api SEService::SEService(void *user_data, serviceConnected handler) throw(ErrorIO &, ErrorIllegalParameter &) : SEServiceHelper(), handle(-1), - listener(NULL) + listener(NULL), version(VERSION) { initialize(user_data, handler); } @@ -53,33 +54,42 @@ namespace smartcard_service_api SEService::SEService(void *user_data, SEServiceListener *listener) throw(ErrorIO &, ErrorIllegalParameter &) : SEServiceHelper(), handle(-1), - handler(NULL) + handler(NULL), version(VERSION) { initialize(user_data, listener); } - SEService::~SEService() + SEService::SEService(void *user_data) + throw(ErrorIO &, ErrorIllegalParameter &, ExceptionBase &) : + SEServiceHelper(), handle(-1), + handler(NULL), version(VERSION) { - uint32_t i; + initializeSync(user_data); + } + SEService::~SEService() + { try { + size_t i; + shutdownSync(); + + for (i = 0; i < readers.size(); i++) + { + delete (Reader *)readers[i]; + } + + readers.clear(); } - catch(ExceptionBase &e) + catch (ExceptionBase &e) { _ERR("EXCEPTION : %s", e.what()); } - catch(...) + catch (...) { _ERR("EXCEPTION!!!"); } - - for (i = 0; i < readers.size(); i++) - { - delete (Reader *)readers[i]; - } - readers.clear(); } SEService *SEService::createInstance(void *user_data, @@ -293,6 +303,64 @@ namespace smartcard_service_api return result; } + int SEService::_initialize_sync() throw(ErrorIO &, ExceptionBase &) + { + gint result; + guint handle; + GError *error = NULL; + GVariant *readers = NULL; + SEService *service = (SEService *)this; + + _BEGIN(); + + /* init default context */ + + proxy = smartcard_service_se_service_proxy_new_for_bus_sync( + G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, + "org.tizen.SmartcardService", + "/org/tizen/SmartcardService/SeService", + NULL, &error); + if (proxy == NULL) + { + _ERR("Can not create proxy : %s", error->message); + g_error_free(error); + return false; + } + + g_signal_connect(proxy, "reader-inserted", + G_CALLBACK(&SEService::reader_inserted), this); + + g_signal_connect(proxy, "reader-removed", + G_CALLBACK(&SEService::reader_removed), this); + + /* request reader */ + if(smartcard_service_se_service_call_se_service_sync( + (SmartcardServiceSeService *)proxy, &result, &handle, &readers, NULL, &error) == true) + { + if (result == SCARD_ERROR_OK) + { + service->connected = true; + service->handle = handle; + service->parseReaderInformation(readers); + } + else + { + throw ExceptionBase(result); + } + } + else + { + _ERR("smartcard_service_se_service_call_se_service failed, [%s]", error->message); + g_error_free(error); + + result = SCARD_ERROR_IPC_FAILED; + } + + _END(); + + return result; + } + bool SEService::initialize(void *context, serviceConnected handler) throw(ErrorIO &, ErrorIllegalParameter &) { @@ -321,20 +389,29 @@ namespace smartcard_service_api return _initialize(); } + bool SEService::initializeSync(void *context) + throw(ErrorIO &, ErrorIllegalParameter &, ExceptionBase &) + { + this->context = context; + + _initialize_sync(); + return true; + } + bool SEService::parseReaderInformation(GVariant *variant) { Reader *reader = NULL; GVariantIter *iter; - gsize count; guint handle; gchar *name; g_variant_get(variant, "a(us)", &iter); - count = g_variant_iter_n_children(iter); while (g_variant_iter_loop(iter, "(us)", &handle, &name) == true) { + SECURE_LOGD("Reader : name [%s], handle [%08x]", name, handle); + /* add readers */ reader = new Reader((void *)this->handle, name, GUINT_TO_POINTER(handle)); if (reader == NULL) @@ -360,20 +437,36 @@ namespace smartcard_service_api void *handle = NULL; Reader *reader = NULL; char name[100]; + const uint8_t *buffer = NULL; + for (i = 0; i < count && offset < data.size(); i++) { memset(name, 0, sizeof(name)); - memcpy(&len, data.getBuffer(offset), sizeof(len)); + buffer = data.getBuffer(offset); + if(buffer == NULL) + continue; + + memcpy(&len, buffer, sizeof(len)); offset += sizeof(len); - memcpy(name, data.getBuffer(offset), len); + buffer = data.getBuffer(offset); + if(buffer == NULL) + return false; + + memcpy(name, buffer, len); offset += len; - memcpy(&handle, data.getBuffer(offset), sizeof(handle)); + buffer = data.getBuffer(offset); + if(buffer == NULL) + return false; + + memcpy(&handle, buffer, sizeof(handle)); offset += sizeof(handle); + SECURE_LOGD("Reader [%d] : name [%s], handle [%p]", i, name, handle); + /* add readers */ reader = new Reader(context, name, handle); if (reader == NULL) @@ -404,7 +497,8 @@ namespace smartcard_service_api using namespace smartcard_service_api; -EXTERN_API se_service_h se_service_create_instance(void *user_data, se_service_connected_cb callback) +EXTERN_API se_service_h se_service_create_instance(void *user_data, + se_service_connected_cb callback) { SEService *service; @@ -420,8 +514,9 @@ EXTERN_API se_service_h se_service_create_instance(void *user_data, se_service_c return (se_service_h)service; } -EXTERN_API se_service_h se_service_create_instance_with_event_callback(void *user_data, - se_service_connected_cb connected, se_service_event_cb event, se_sesrvice_error_cb error) +EXTERN_API se_service_h se_service_create_instance_with_event_callback( + void *user_data, se_service_connected_cb connected, + se_service_event_cb event, se_sesrvice_error_cb error) { SEService *service; @@ -437,6 +532,46 @@ EXTERN_API se_service_h se_service_create_instance_with_event_callback(void *use return (se_service_h)service; } +EXTERN_API se_service_h se_service_create_instance_sync(void *user_data, + int *result) +{ + SEService *service; + + try + { + service = new SEService(user_data); + } + catch (ExceptionBase &e) + { + *result = e.getErrorCode(); + service = NULL; + } + catch (...) + { + *result = SCARD_ERROR_UNKNOWN; + service = NULL; + } + + return (se_service_h)service; +} + +EXTERN_API int se_service_get_version(se_service_h handle, char **version_str) +{ + int ret = 0; + + if (version_str == NULL) { + return SCARD_ERROR_ILLEGAL_PARAM; + } + + SE_SERVICE_EXTERN_BEGIN; + + *version_str = g_strdup(service->getVersion()); + + SE_SERVICE_EXTERN_END; + + return ret; +} + EXTERN_API int se_service_get_readers_count(se_service_h handle) { int count = 0; @@ -453,9 +588,9 @@ EXTERN_API int se_service_get_readers_count(se_service_h handle) return count; } -EXTERN_API bool se_service_get_readers(se_service_h handle, reader_h *readers, int *count) +EXTERN_API int se_service_get_readers(se_service_h handle, int **readers, int *count) { - bool result = false; + int result = 0; SE_SERVICE_EXTERN_BEGIN; @@ -464,16 +599,26 @@ EXTERN_API bool se_service_get_readers(se_service_h handle, reader_h *readers, i int temp = 0; temp_readers = service->getReaders(); - - for (i = 0; i < temp_readers.size() && i < (size_t)*count; i++) + if(temp_readers.size() > 0) { - if (temp_readers[i]->isSecureElementPresent()) + *readers = (int *)calloc(temp_readers.size(), sizeof(int)); + + if(*readers == NULL) + { + *count = 0; + return SCARD_ERROR_NOT_ENOUGH_RESOURCE; + } + + for (i = 0; i < temp_readers.size(); i++) { - readers[i] = (reader_h)temp_readers[i]; - temp++; + if (temp_readers[i]->isSecureElementPresent()) + { + //(*readers)[i] = (int)temp_readers[i]; + temp++; + } } + *count = temp; } - *count = temp; SE_SERVICE_EXTERN_END; @@ -502,11 +647,15 @@ EXTERN_API void se_service_shutdown(se_service_h handle) SE_SERVICE_EXTERN_END; } -EXTERN_API void se_service_destroy_instance(se_service_h handle) +EXTERN_API int se_service_destroy_instance(se_service_h handle) { + int result = 0; + SE_SERVICE_EXTERN_BEGIN; delete service; SE_SERVICE_EXTERN_END; + + return result; } diff --git a/client/Session.cpp b/client/Session.cpp index 88fb349..ca5624f 100644 --- a/client/Session.cpp +++ b/client/Session.cpp @@ -144,11 +144,12 @@ namespace smartcard_service_api CallbackParam *param = (CallbackParam *)user_data; Session *session; openChannelCallback callback; - gint result; + gint result = SCARD_ERROR_UNKNOWN; + gint channel_number; guint channel_id; GVariant *var_response; GError *error = NULL; - Channel *channel; + Channel *channel = NULL; _INFO("MSG_REQUEST_OPEN_CHANNEL"); @@ -162,7 +163,7 @@ namespace smartcard_service_api if (smartcard_service_session_call_open_channel_finish( SMARTCARD_SERVICE_SESSION(source_object), - &result, &channel_id, &var_response, + &result, &channel_id, &channel_number, &var_response, res, &error) == true) { if (result == SCARD_ERROR_OK) { ByteArray response; @@ -400,11 +401,17 @@ namespace smartcard_service_api return count; } - Channel *Session::openChannelSync(int id, const ByteArray &aid) throw (ExceptionBase &, ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &) { + return openChannelSync(id, aid, 0x00); + } + + Channel *Session::openChannelSync(int id, const ByteArray &aid, unsigned char P2) + throw (ExceptionBase &, ErrorIO &, ErrorIllegalState &, + ErrorIllegalParameter &, ErrorSecurity &) + { Channel *channel = NULL; if (getReader()->isSecureElementPresent() == true) @@ -412,6 +419,7 @@ namespace smartcard_service_api gint ret; GVariant *var_aid = NULL, *var_response = NULL; guint channel_id; + gint channel_number; GError *error = NULL; var_aid = GDBusHelper::convertByteArrayToVariant(aid); @@ -420,7 +428,7 @@ namespace smartcard_service_api (SmartcardServiceSession *)proxy, GPOINTER_TO_UINT(context), GPOINTER_TO_UINT(handle), - (guint)id, var_aid, &ret, &channel_id, + (guint)id, var_aid, (guint8)P2, &ret, &channel_id, &channel_number, &var_response, NULL, &error) == true) { if (ret == SCARD_ERROR_OK && channel_id != 0) { ByteArray response; @@ -430,7 +438,7 @@ namespace smartcard_service_api /* create new instance of channel */ channel = new ClientChannel(context, - this, channel_id, + this, channel_number, response, (void *)channel_id); if (channel != NULL) { @@ -484,7 +492,7 @@ namespace smartcard_service_api (SmartcardServiceSession *)proxy, GPOINTER_TO_UINT(context), GPOINTER_TO_UINT(handle), - (guint)id, var_aid, NULL, + (guint)id, var_aid, 0, NULL, &Session::session_open_channel_cb, param); result = SCARD_ERROR_OK; @@ -502,7 +510,14 @@ namespace smartcard_service_api throw (ExceptionBase &, ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &) { - return openChannelSync(0, aid); + return openChannelSync(0, aid, 0x00); + } + + Channel *Session::openBasicChannelSync(const ByteArray &aid, unsigned char P2) + throw (ExceptionBase &, ErrorIO &, ErrorIllegalState &, + ErrorIllegalParameter &, ErrorSecurity &) + { + return openChannelSync(0, aid, P2); } Channel *Session::openBasicChannelSync(const unsigned char *aid, unsigned int length) @@ -511,7 +526,16 @@ namespace smartcard_service_api { ByteArray temp(aid, length); - return openBasicChannelSync(temp); + return openBasicChannelSync(temp, 0x00); + } + + Channel *Session::openBasicChannelSync(const unsigned char *aid, unsigned int length, unsigned char P2) + throw (ExceptionBase &, ErrorIO &, ErrorIllegalState &, + ErrorIllegalParameter &, ErrorSecurity &) + { + ByteArray temp(aid, length); + + return openBasicChannelSync(temp, P2); } int Session::openBasicChannel(const ByteArray &aid, openChannelCallback callback, void *userData) @@ -531,7 +555,14 @@ namespace smartcard_service_api throw (ExceptionBase &, ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &) { - return openChannelSync(1, aid); + return openChannelSync(1, aid, 0x00); + } + + Channel *Session::openLogicalChannelSync(const ByteArray &aid, unsigned char P2) + throw (ExceptionBase &, ErrorIO &, ErrorIllegalState &, + ErrorIllegalParameter &, ErrorSecurity &) + { + return openChannelSync(1, aid, P2); } Channel *Session::openLogicalChannelSync(const unsigned char *aid, unsigned int length) @@ -540,7 +571,16 @@ namespace smartcard_service_api { ByteArray temp(aid, length); - return openLogicalChannelSync(temp); + return openLogicalChannelSync(temp, 0x00); + } + + Channel *Session::openLogicalChannelSync(const unsigned char *aid, unsigned int length, unsigned char P2) + throw (ExceptionBase &, ErrorIO &, ErrorIllegalState &, + ErrorIllegalParameter &, ErrorSecurity &) + { + ByteArray temp(aid, length); + + return openLogicalChannelSync(temp, P2); } int Session::openLogicalChannel(const ByteArray &aid, openChannelCallback callback, void *userData) @@ -572,132 +612,261 @@ namespace smartcard_service_api using namespace smartcard_service_api; -EXTERN_API reader_h session_get_reader(session_h handle) +EXTERN_API int session_get_reader(session_h handle, int* reader_handle) { + int result = SCARD_ERROR_OK; reader_h reader = NULL; SESSION_EXTERN_BEGIN; + + try + { reader = session->getReader(); + //*reader_handle = (int)reader; + } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + *reader_handle = 0; + } + catch (...) + { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + *reader_handle = 0; + } + SESSION_EXTERN_END; - return reader; + return result; } -EXTERN_API int session_get_atr(session_h handle, session_get_atr_cb callback, void *userData) +EXTERN_API int session_is_closed(session_h handle, bool* is_closed) { - int result = -1; + int result = SCARD_ERROR_OK; SESSION_EXTERN_BEGIN; - result = session->getATR((getATRCallback)callback, userData); + + try + { + *is_closed = session->isClosed(); + } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + } + catch (...) + { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + } + SESSION_EXTERN_END; return result; } -EXTERN_API int session_close(session_h handle, session_close_session_cb callback, void *userData) +EXTERN_API int session_close_channels(session_h handle) { - int result = -1; + int result = SCARD_ERROR_OK; SESSION_EXTERN_BEGIN; - result = session->close((closeSessionCallback)callback, userData); + + try + { + session->closeChannels(); + } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + } + catch (...) + { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + } + SESSION_EXTERN_END; return result; } -EXTERN_API bool session_is_closed(session_h handle) +EXTERN_API int session_get_atr_sync(session_h handle, unsigned char **buffer, unsigned int *length) { - bool result = false; + ByteArray temp; + int result = SCARD_ERROR_OK; SESSION_EXTERN_BEGIN; - result = session->isClosed(); + + try + { + temp = session->getATRSync(); + + if (temp.size() > 0) + { + *buffer = (unsigned char *)calloc(temp.size(), sizeof(char)); + *length = temp.size(); + + memcpy(*buffer, temp.getBuffer(), *length); + } + } + catch (ErrorIllegalState &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + + if(result == SCARD_ERROR_OPERATION_NOT_SUPPORTED) + { + *length = 0; + result = SCARD_ERROR_OK; + } + } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + *length = 0; + } + catch (...) + { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + *length = 0; + } + SESSION_EXTERN_END; return result; } -EXTERN_API void session_close_channels(session_h handle) +EXTERN_API int session_close_sync(session_h handle) { + int result = SCARD_ERROR_OK; + SESSION_EXTERN_BEGIN; - session->closeChannels(); + + try + { + session->closeSync(); + } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + } + catch (...) + { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + } + SESSION_EXTERN_END; + + return result; } -EXTERN_API int session_open_basic_channel(session_h handle, unsigned char *aid, - unsigned int length, session_open_channel_cb callback, void *userData) +EXTERN_API int session_open_basic_channel_sync(session_h handle, unsigned char *aid, + unsigned int length, unsigned char P2, int* channel_handle) { - int result = -1; + int result = SCARD_ERROR_OK; SESSION_EXTERN_BEGIN; - result = session->openBasicChannel(aid, length, (openChannelCallback)callback, userData); + + try + { + //*channel_handle = (int)session->openBasicChannelSync(aid, length, P2); + } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + *channel_handle = 0; + } + catch (...) + { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + *channel_handle = 0; + } + SESSION_EXTERN_END; return result; } -EXTERN_API int session_open_logical_channel(session_h handle, unsigned char *aid, - unsigned int length, session_open_channel_cb callback, void *userData) +EXTERN_API int session_open_logical_channel_sync(session_h handle, unsigned char *aid, + unsigned int length, unsigned char P2, int* channel_handle) { - int result = -1; + int result = SCARD_ERROR_OK; SESSION_EXTERN_BEGIN; - result = session->openLogicalChannel(aid, length, (openChannelCallback)callback, userData); + + try + { + //*channel_handle = (int)session->openLogicalChannelSync(aid, length, P2); + } + catch (ExceptionBase &e) + { + _ERR("Error occur : %s\n", e.what()); + result = e.getErrorCode(); + *channel_handle = 0; + } + catch (...) + { + _ERR("Error occur : unknown error\n"); + result = SCARD_ERROR_UNKNOWN; + *channel_handle = 0; + } + SESSION_EXTERN_END; return result; } -EXTERN_API void session_destroy_instance(session_h handle) -{ -} - -EXTERN_API int session_get_atr_sync(session_h handle, unsigned char **buffer, unsigned int *length) +EXTERN_API int session_get_atr(session_h handle, session_get_atr_cb callback, void *userData) { - ByteArray temp; int result = -1; - if (buffer == NULL || length == NULL) - return result; - SESSION_EXTERN_BEGIN; - temp = session->getATRSync(); - if (temp.size() > 0) - { - *length = temp.size(); - *buffer = (unsigned char *)calloc(1, *length); - memcpy(*buffer, temp.getBuffer(), *length); - - result = 0; - } + result = session->getATR((getATRCallback)callback, userData); SESSION_EXTERN_END; return result; } -EXTERN_API void session_close_sync(session_h handle) +EXTERN_API int session_close(session_h handle, session_close_session_cb callback, void *userData) { + int result = -1; + SESSION_EXTERN_BEGIN; - session->closeSync(); + result = session->close((closeSessionCallback)callback, userData); SESSION_EXTERN_END; + + return result; } -EXTERN_API channel_h session_open_basic_channel_sync(session_h handle, unsigned char *aid, unsigned int length) +EXTERN_API int session_open_basic_channel(session_h handle, unsigned char *aid, + unsigned int length, session_open_channel_cb callback, void *userData) { - channel_h result = NULL; + int result = -1; SESSION_EXTERN_BEGIN; - result = session->openBasicChannelSync(aid, length); + result = session->openBasicChannel(aid, length, (openChannelCallback)callback, userData); SESSION_EXTERN_END; return result; } -EXTERN_API channel_h session_open_logical_channel_sync(session_h handle, unsigned char *aid, unsigned int length) +EXTERN_API int session_open_logical_channel(session_h handle, unsigned char *aid, + unsigned int length, session_open_channel_cb callback, void *userData) { - channel_h result = NULL; + int result = -1; SESSION_EXTERN_BEGIN; - result = session->openLogicalChannelSync(aid, length); + result = session->openLogicalChannel(aid, length, (openChannelCallback)callback, userData); SESSION_EXTERN_END; return result; @@ -713,3 +882,8 @@ EXTERN_API size_t session_get_channel_count(session_h handle) return result; } + +EXTERN_API void session_destroy_instance(session_h handle) +{ +} + diff --git a/client/include/ClientChannel.h b/client/include/ClientChannel.h index 9b94394..a4e75ee 100644 --- a/client/include/ClientChannel.h +++ b/client/include/ClientChannel.h @@ -17,11 +17,12 @@ #ifndef CLIENTCHANNEL_H_ #define CLIENTCHANNEL_H_ -#ifdef USE_AUTOSTART +/* standard library header */ #include -#endif -#include "Debug.h" +/* SLP library header */ + +/* local header */ #include "smartcard-types.h" #ifdef __cplusplus #include "Channel.h" @@ -31,7 +32,7 @@ #ifdef __cplusplus namespace smartcard_service_api { - class EXPORT ClientChannel: public Channel + class ClientChannel: public Channel { private: void *context; @@ -41,16 +42,17 @@ namespace smartcard_service_api ClientChannel(void *context, Session *session, int channelNum, const ByteArray &selectResponse, void *handle); ~ClientChannel(); -#ifdef USE_AUTOSTART + static void channel_transmit_cb(GObject *source_object, GAsyncResult *res, gpointer user_data); static void channel_close_cb(GObject *source_object, GAsyncResult *res, gpointer user_data); -#endif + public: int close(closeChannelCallback callback, void *userParam); int transmit(const ByteArray &command, transmitCallback callback, void *userParam); + bool selectNext(){ return false; } void closeSync() throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &, @@ -59,6 +61,8 @@ namespace smartcard_service_api throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &); + void *getHandle(){ return handle; } + friend class Session; }; } /* namespace smartcard_service_api */ @@ -70,21 +74,25 @@ extern "C" { #endif /* __cplusplus */ -bool channel_is_basic_channel(channel_h handle); -bool channel_is_closed(channel_h handle); - -unsigned int channel_get_select_response_length(channel_h handle); -bool channel_get_select_response(channel_h handle, unsigned char *buffer, - unsigned int length); -session_h channel_get_session(channel_h handle); -void channel_destroy_instance(channel_h handle) __attribute__((deprecated)); +int channel_is_basic_channel(channel_h handle, bool* is_basic_channel); +int channel_is_closed(channel_h handle, bool* is_closed ); +int channel_get_session(channel_h handle, int *session_handle); +int channel_close_sync(channel_h handle); +int channel_transmit_sync(channel_h handle, unsigned char *command, + unsigned int cmd_len, unsigned char **response, unsigned int *resp_len); +int channel_get_select_response(channel_h handle, + unsigned char **buffer, size_t* length); +int channel_get_transmit_response(channel_h handle, + unsigned char **buffer, size_t* length); +int channel_select_next(channel_h hChannel, bool *pSuccess); +//// int channel_close(channel_h handle, channel_close_cb callback, void *userParam); int channel_transmit(channel_h handle, unsigned char *command, unsigned int length, channel_transmit_cb callback, void *userParam); -void channel_close_sync(channel_h handle); -int channel_transmit_sync(channel_h handle, unsigned char *command, - unsigned int cmd_len, unsigned char **response, unsigned int *resp_len); +unsigned int channel_get_select_response_length(channel_h handle); +void channel_destroy_instance(channel_h handle) __attribute__((deprecated)); + #ifdef __cplusplus } diff --git a/client/include/ClientGDBus.h b/client/include/ClientGDBus.h index 6630d14..c111874 100644 --- a/client/include/ClientGDBus.h +++ b/client/include/ClientGDBus.h @@ -17,8 +17,12 @@ #ifndef CLIENTGDBUS_H_ #define CLIENTGDBUS_H_ +/* standard library header */ #include +/* SLP library header */ + +/* local header */ #include "GDBusHelper.h" #include "smartcard-service-gdbus.h" diff --git a/client/include/Reader.h b/client/include/Reader.h index f2f0103..876d0b8 100644 --- a/client/include/Reader.h +++ b/client/include/Reader.h @@ -17,12 +17,13 @@ #ifndef READER_H_ #define READER_H_ -#ifdef USE_AUTOSTART +/* standard library header */ #include #include -#endif -#include "Debug.h" +/* SLP library header */ + +/* local header */ #include "smartcard-types.h" #ifdef __cplusplus #include "ReaderHelper.h" @@ -32,7 +33,7 @@ #ifdef __cplusplus namespace smartcard_service_api { - class EXPORT Reader: public ReaderHelper + class Reader: public ReaderHelper { private: void *context; @@ -43,10 +44,8 @@ namespace smartcard_service_api ~Reader(); inline void unavailable() { present = false; } -#ifdef USE_AUTOSTART static void reader_open_session_cb(GObject *source_object, GAsyncResult *res, gpointer user_data); -#endif public: void closeSessions() @@ -57,6 +56,8 @@ namespace smartcard_service_api throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &); + void *getHandle(){ return handle; } + friend class SEService; }; } /* namespace smartcard_service_api */ @@ -68,13 +69,15 @@ extern "C" { #endif /* __cplusplus */ -const char *reader_get_name(reader_h handle); -se_service_h reader_get_se_service(reader_h handle); -bool reader_is_secure_element_present(reader_h handle); +int reader_get_name(reader_h handle, char** reader_name); +int reader_is_secure_element_present(reader_h handle, bool* is_present); +int reader_open_session_sync(reader_h handle, int *session_handle); +int reader_close_sessions(reader_h handle); +/// + int reader_open_session(reader_h handle, reader_open_session_cb callback, void *userData); -session_h reader_open_session_sync(reader_h handle); -void reader_close_sessions(reader_h handle); +se_service_h reader_get_se_service(reader_h handle); __attribute__((deprecated)) void reader_destroy_instance(reader_h handle); #ifdef __cplusplus diff --git a/client/include/SEService.h b/client/include/SEService.h index ade4068..cb7672d 100644 --- a/client/include/SEService.h +++ b/client/include/SEService.h @@ -17,12 +17,13 @@ #ifndef SESERVICE_H_ #define SESERVICE_H_ -#ifdef USE_AUTOSTART +/* standard library header */ #include #include -#endif -#include "Debug.h" +/* SLP library header */ + +/* local header */ #include "smartcard-types.h" #ifdef __cplusplus #include "SEServiceListener.h" @@ -36,7 +37,7 @@ namespace smartcard_service_api { typedef void (*serviceConnected)(SEServiceHelper *service, void *context); - class EXPORT SEService : public SEServiceHelper + class SEService : public SEServiceHelper { private: unsigned int handle; @@ -44,22 +45,25 @@ namespace smartcard_service_api serviceConnected handler; SEServiceListener *listener; void *proxy; + const char *version; + SEService(); void addReader(unsigned int handle, const char *name); bool parseReaderInformation(unsigned int count, const ByteArray &data); -#ifdef USE_AUTOSTART bool parseReaderInformation(GVariant *variant); -#endif + bool _initialize() throw(ErrorIO &); bool initialize(void *context, serviceConnected handler) throw(ErrorIO &, ErrorIllegalParameter &); bool initialize(void *context, SEServiceListener *listener) throw(ErrorIO &, ErrorIllegalParameter &); - SEService *initializeSync(void *context, serviceConnected handler) - throw(ErrorIO &, ErrorIllegalParameter &); -#ifdef USE_AUTOSTART + int _initialize_sync() + throw(ErrorIO &, ExceptionBase &); + bool initializeSync(void *context) + throw(ErrorIO &, ErrorIllegalParameter &, ExceptionBase &); + static void reader_inserted(GObject *source_object, guint reader_id, gchar *reader_name, gpointer user_data); @@ -70,12 +74,14 @@ namespace smartcard_service_api GAsyncResult *res, gpointer user_data); static void se_service_cb(GObject *source_object, GAsyncResult *res, gpointer user_data); -#endif + public: SEService(void *user_data, serviceConnected handler) throw(ErrorIO &, ErrorIllegalParameter &); SEService(void *user_data, SEServiceListener *listener) throw(ErrorIO &, ErrorIllegalParameter &); + SEService(void *user_data) + throw(ErrorIO &, ErrorIllegalParameter &, ExceptionBase &); ~SEService(); static SEService *createInstance(void *user_data, SEServiceListener *listener) @@ -85,6 +91,7 @@ namespace smartcard_service_api void shutdown(); void shutdownSync(); + const char *getVersion() const { return version; } }; } /* namespace smartcard_service_api */ #endif /* __cplusplus */ @@ -100,11 +107,16 @@ se_service_h se_service_create_instance(void *user_data, se_service_h se_service_create_instance_with_event_callback(void *user_data, se_service_connected_cb connected, se_service_event_cb event, se_sesrvice_error_cb error); + +se_service_h se_service_create_instance_sync(void *user_data, int* result); +int se_service_get_version(se_service_h handle, char **version_str); int se_service_get_readers_count(se_service_h handle); -bool se_service_get_readers(se_service_h handle, reader_h *readers, int *count); +int se_service_get_readers(se_service_h handle, int **readers, int *count); + bool se_service_is_connected(se_service_h handle); void se_service_shutdown(se_service_h handle); -void se_service_destroy_instance(se_service_h handle); +int se_service_destroy_instance(se_service_h handle); + #ifdef __cplusplus } diff --git a/client/include/SEServiceListener.h b/client/include/SEServiceListener.h index 886b918..9cfc01b 100644 --- a/client/include/SEServiceListener.h +++ b/client/include/SEServiceListener.h @@ -17,13 +17,17 @@ #ifndef SESERVICELISTENER_H_ #define SESERVICELISTENER_H_ -#include "Debug.h" +/* standard library header */ + +/* SLP library header */ + +/* local header */ namespace smartcard_service_api { class SEServiceHelper; - class EXPORT SEServiceListener + class SEServiceListener { public: virtual void serviceConnected(SEServiceHelper *service, diff --git a/client/include/Session.h b/client/include/Session.h index 5eff455..7d530e3 100644 --- a/client/include/Session.h +++ b/client/include/Session.h @@ -17,11 +17,12 @@ #ifndef SESSION_H_ #define SESSION_H_ -#ifdef USE_AUTOSTART +/* standard library header */ #include -#endif -#include "Debug.h" +/* SLP library header */ + +/* local header */ #include "smartcard-types.h" #ifdef __cplusplus #include "SessionHelper.h" @@ -32,7 +33,7 @@ namespace smartcard_service_api { class Reader; - class EXPORT Session : public SessionHelper + class Session : public SessionHelper { private: void *context; @@ -43,18 +44,21 @@ namespace smartcard_service_api ~Session(); int openChannel(int id, const ByteArray &aid, openChannelCallback callback, void *userData); + Channel *openChannelSync(int id, const ByteArray &aid) throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &); -#ifdef USE_AUTOSTART + Channel *openChannelSync(int id, const ByteArray &aid, unsigned char P2) + throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &, + ErrorIllegalParameter &, ErrorSecurity &); + static void session_get_atr_cb(GObject *source_object, GAsyncResult *res, gpointer user_data); static void session_open_channel_cb(GObject *source_object, GAsyncResult *res, gpointer user_data); static void session_close_cb(GObject *source_object, GAsyncResult *res, gpointer user_data); -#endif public: void closeChannels() @@ -90,9 +94,26 @@ namespace smartcard_service_api Channel *openLogicalChannelSync(const unsigned char *aid, unsigned int length) throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &, + ErrorIllegalParameter &, ErrorSecurity &); + + Channel *openBasicChannelSync(const ByteArray &aid, unsigned char P2) + throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &, + ErrorIllegalParameter &, ErrorSecurity &); + + Channel *openBasicChannelSync(const unsigned char *aid, unsigned int length, unsigned char P2) + throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &, + ErrorIllegalParameter &, ErrorSecurity &); + + Channel *openLogicalChannelSync(const ByteArray &aid, unsigned char P2) + throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &, + ErrorIllegalParameter &, ErrorSecurity &); + + Channel *openLogicalChannelSync(const unsigned char *aid, unsigned int length, unsigned char P2) + throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &); size_t getChannelCount() const; + void *getHandle(){ return handle; } friend class Reader; }; @@ -105,31 +126,29 @@ extern "C" { #endif /* __cplusplus */ -reader_h session_get_reader(session_h handle); -bool session_is_closed(session_h handle); -__attribute__((deprecated)) void session_destroy_instance(session_h handle); -void session_close_channels(session_h handle); +int session_get_reader(session_h handle, int* reader_handle); +int session_is_closed(session_h handle, bool* is_closed); +int session_close_channels(session_h handle); +int session_get_atr_sync(session_h handle, unsigned char **buffer, unsigned int *length); +int session_close_sync(session_h handle); +int session_open_basic_channel_sync(session_h handle, unsigned char *aid, + unsigned int length, unsigned char P2, int* channel_handle); +int session_open_logical_channel_sync(session_h handle, unsigned char *aid, + unsigned int length, unsigned char P2, int* channel_handle); +/// int session_get_atr(session_h handle, session_get_atr_cb callback, void *userData); int session_close(session_h handle, session_close_session_cb callback, void *userData); - int session_open_basic_channel(session_h handle, unsigned char *aid, unsigned int length, session_open_channel_cb callback, void *userData); int session_open_logical_channel(session_h handle, unsigned char *aid, unsigned int length, session_open_channel_cb callback, void *userData); +size_t session_get_channel_count(session_h handle); +__attribute__((deprecated)) void session_destroy_instance(session_h handle); -int session_get_atr_sync(session_h handle, unsigned char **buffer, - unsigned int *length); -void session_close_sync(session_h handle); - -channel_h session_open_basic_channel_sync(session_h handle, - unsigned char *aid, unsigned int length); -channel_h session_open_logical_channel_sync(session_h handle, - unsigned char *aid, unsigned int length); -size_t session_get_channel_count(session_h handle); #ifdef __cplusplus } diff --git a/client/include/smartcard-service.h b/client/include/smartcard-service.h index a79163d..354e11f 100644 --- a/client/include/smartcard-service.h +++ b/client/include/smartcard-service.h @@ -18,7 +18,9 @@ #define SMARTCARD_SERVICE_H_ #include "smartcard-types.h" +#ifdef __cplusplus #include "Exception.h" +#endif #include "SEService.h" #include "Reader.h" #include "Session.h" diff --git a/client/smartcard-service.pc b/client/smartcard-service.pc new file mode 100644 index 0000000..fb0b732 --- /dev/null +++ b/client/smartcard-service.pc @@ -0,0 +1,13 @@ +# Package Information for pkg-config + +prefix=/usr +exec_prefix=${prefix}/bin +includedir=${prefix}/include +libdir=${prefix}/lib + +Name: smartcard-service +Description: Make flags of Common library of Smartcard service +Version: 1.0 +Requires: glib-2.0 dlog +Libs: -L${libdir} -lsmartcard-service +Cflags: -I${includedir}/smartcard-service \ No newline at end of file diff --git a/client/smartcard-service.pc.in b/client/smartcard-service.pc.in deleted file mode 100644 index 3590877..0000000 --- a/client/smartcard-service.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix}/bin -libdir=@LIB_INSTALL_DIR@ -includedir=@INCLUDE_INSTALL_DIR@/@PROJECT_NAME@ - -Name: @PROJECT_NAME@ -Description: library of Smartcard service -Version: @FULLVER@ -Requires: glib-2.0 dlog -Libs: -L${libdir} -l@PROJECT_NAME@ -Cflags: -I${includedir} diff --git a/common/APDUHelper.cpp b/common/APDUHelper.cpp index ae5589c..d962e21 100644 --- a/common/APDUHelper.cpp +++ b/common/APDUHelper.cpp @@ -80,6 +80,68 @@ namespace smartcard_service_api case (unsigned char)0x92 : /* extra information */ break; + /* Warning processing */ + case (unsigned char)0x62 : /* State of non-volatile memory is unchanged (further qualification in SW2) */ + break; + + case (unsigned char)0x63 : /* State of non-volatile memory has changed (further qualification in SW2) */ + break; + +#if 0 + case (unsigned char)0x61 : /* SW2 encodes the number of data bytes still available */ + break; + + + /* Execution error */ + case (unsigned char)0x64 : /* State of non-volatile memory is unchanged (further qualification in SW2) */ + result = -1; + break; + + case (unsigned char)0x65 : /* State of non-volatile memory has changed (further qualification in SW2) */ + result = -1; + break; + + case (unsigned char)0x66 : /* Security-related issues */ + result = -1; + break; + + /* Checking error */ + case (unsigned char)0x67 : /* SW2:00, Wrong length; no further indication */ + result = -1; + break; + + case (unsigned char)0x68 : /* Functions in CLA not supported (further qualification in SW2) */ + result = -1; + break; + + case (unsigned char)0x69 : /* Command not allowed (further qualification in SW2) */ + result = -1; + break; + + case (unsigned char)0x6A : /* Wrong parameters P1-P2 (further qualification in SW2) */ + result = -1; + break; + + case (unsigned char)0x6B : /* SW2:00, Wrong parameters P1-P2 */ + result = -1; + break; + + case (unsigned char)0x6C : /* Wrong Le field; SW2 encodes the exact number of available data bytes */ + result = -1; + break; + + case (unsigned char)0x6D : /* SW2:00, Instruction code not supported or invalid */ + result = -1; + break; + + case (unsigned char)0x6E : /* SW2:00, Class not supported */ + result = -1; + break; + + case (unsigned char)0x6F : /* SW2:00, No precise diagnosis */ + result = -1; + break; +#endif default : result *= -1; break; @@ -94,7 +156,9 @@ namespace smartcard_service_api if (response.size() >= 2) { - status = ResponseHelper::parseStatusWord(response.getBuffer((response.size() - 2))); + const uint8_t* buffer = response.getBuffer((response.size() - 2)); + if(buffer != NULL) + status = ResponseHelper::parseStatusWord(buffer); } return status; @@ -142,6 +206,7 @@ namespace smartcard_service_api bool APDUCommand::setCommand(const ByteArray &command) { bool result = false; + const uint8_t *buffer; uint32_t offset = 0; uint32_t lengthSize = 1; @@ -150,7 +215,13 @@ namespace smartcard_service_api return false; } - memcpy(&header, command.getBuffer(offset), sizeof(header)); + buffer = command.getBuffer(offset); + if(buffer == NULL) + { + return false; + } + + memcpy(&header, buffer, sizeof(header)); offset += sizeof(header); if (isExtendedLength) @@ -171,6 +242,9 @@ namespace smartcard_service_api else { length = command.at(offset); + if (length == 0) { + length = 256; + } offset += 1; } @@ -197,7 +271,7 @@ namespace smartcard_service_api else { if (command.at(offset) == 0) - setMaxResponseSize(APDUCommand::LE_MAX); + setMaxResponseSize(256); else setMaxResponseSize(command.at(offset)); @@ -228,7 +302,6 @@ namespace smartcard_service_api { case INS_TERMINAL_PROFILE : case INS_FETCH : - case INS_ENVELOPE : case INS_TERMINAL_RESPONSE : result = true; break; @@ -450,7 +523,7 @@ namespace smartcard_service_api switch (command) { case COMMAND_OPEN_LOGICAL_CHANNEL : - apdu.setCommand(0, APDUCommand::INS_MANAGE_CHANNEL, 0, 0, ByteArray::EMPTY, APDUCommand::LE_MAX); + apdu.setCommand(0, APDUCommand::INS_MANAGE_CHANNEL, 0, 0, ByteArray::EMPTY, 1); apdu.getBuffer(result); break; @@ -470,7 +543,7 @@ namespace smartcard_service_api break; case COMMAND_SELECT_BY_DF_NAME : - apdu.setCommand(0, APDUCommand::INS_SELECT_FILE, APDUCommand::P1_SELECT_BY_DF_NAME, APDUCommand::P2_SELECT_GET_FCP, data, 0); + apdu.setCommand(0, APDUCommand::INS_SELECT_FILE, APDUCommand::P1_SELECT_BY_DF_NAME, APDUCommand::P2_SELECT_GET_FCI, data, 0); apdu.getBuffer(result); break; diff --git a/common/AccessCondition.cpp b/common/AccessCondition.cpp index 563da7d..d68f028 100644 --- a/common/AccessCondition.cpp +++ b/common/AccessCondition.cpp @@ -14,8 +14,12 @@ * limitations under the License. */ +/* standard library header */ #include +/* SLP library header */ + +/* local header */ #include "Debug.h" #include "SimpleTLV.h" #include "AccessControlList.h" @@ -46,8 +50,17 @@ namespace smartcard_service_api cmd = *(unsigned int *)command.getBuffer(); for (item = listFilters.begin(); item != listFilters.end(); item++) { - mask = *(unsigned int *)item->second.getBuffer(); - rule = *(unsigned int *)item->first.getBuffer(); + unsigned int *temp1 = NULL; + unsigned int *temp2 = NULL; + + temp1 = (unsigned int *)item->second.getBuffer(); + temp2 = (unsigned int *)item->first.getBuffer(); + + if(temp1 == NULL || temp2 == NULL) + continue; + + mask = *temp1; + rule = *temp2; if ((cmd & mask) == rule) { @@ -65,6 +78,27 @@ namespace smartcard_service_api return result; } + void AccessRule::printAccessRules() const + { + if (listFilters.size() > 0) + { + vector >::const_iterator item; + + _DBG(" +---- Granted APDUs"); + + for (item = listFilters.begin(); item != listFilters.end(); item++) + { + _DBG(" +----- APDU : %s, Mask : %s", item->first.toString().c_str(), item->second.toString().c_str()); + } + } + else + { + _DBG(" +---- APDU Access ALLOW : %s", apduRule ? "ALWAYS" : "NEVER"); + } + + _DBG(" +---- NFC Access ALLOW : %s", nfcRule ? "ALWAYS" : "NEVER"); + } + bool AccessRule::isAuthorizedNFCAccess(void) const { return nfcRule; @@ -133,6 +167,28 @@ namespace smartcard_service_api return result; } + void AccessCondition::printAccessConditions() const + { + _DBG(" +-- Access Condition"); + + if (mapRules.size() > 0) + { + map::const_iterator item; + + for (item = mapRules.begin(); item != mapRules.end(); item++) + { + ByteArray temp = item->first; + + _DBG(" +--- hash : %s", (temp == AccessControlList::ALL_DEVICE_APPS) ? "All device applications" : temp.toString().c_str()); + item->second.printAccessRules(); + } + } + else + { + _DBG(" +--- no rule found"); + } + } + void AccessCondition::setAPDUAccessRule(const ByteArray &certHash, bool rule) { diff --git a/common/AccessControlList.cpp b/common/AccessControlList.cpp index 2122eed..40121d8 100644 --- a/common/AccessControlList.cpp +++ b/common/AccessControlList.cpp @@ -166,6 +166,15 @@ namespace smartcard_service_api result = rule->isAuthorizedAPDUAccess(command); } _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", "All device applications"); + goto END; + } + + size_t i; + + _INFO("no rule found, aid [%s]", aid.toString().c_str()); + + for (i = 0; i < certHashes.size(); i++) { + _INFO(" hash[%d] [%s]", i, certHashes[i].toString().c_str()); } END : @@ -216,9 +225,35 @@ END : if (rule != NULL) { result = rule->isAuthorizedNFCAccess(); _INFO("rule found (%s): [%s:%s]", result ? "accept" : "deny", "All SE Applications", "All device applications"); + goto END; } + size_t i; + + _INFO("no rule found, aid [%s]", aid.toString().c_str()); + + for (i = 0; i < certHashes.size(); i++) { + _INFO(" hash[%d] [%s]", i, certHashes[i].toString().c_str()); + } END : return result; } + + void AccessControlList::printAccessControlList() const + { + ByteArray temp; + map::const_iterator iterMap; + + _DBG("========================== Access Control Rules ============================"); + for (iterMap = mapConditions.begin(); iterMap != mapConditions.end(); iterMap++) + { + temp = iterMap->first; + + _DBG("+ aid : %s", (temp == DEFAULT_SE_APP) ? "Default Application" : (temp == ALL_SE_APPS) ? "All SE Applications" : temp.toString().c_str()); + + iterMap->second.printAccessConditions(); + } + _DBG("============================================================================"); + } + } /* namespace smartcard_service_api */ diff --git a/common/ByteArray.cpp b/common/ByteArray.cpp index 181125c..95ac12b 100644 --- a/common/ByteArray.cpp +++ b/common/ByteArray.cpp @@ -14,11 +14,15 @@ * limitations under the License. */ +/* standard library header */ #include #include #include #include +/* SLP library header */ + +/* local header */ #include "Debug.h" #include "ByteArray.h" @@ -296,8 +300,18 @@ namespace smartcard_service_api return buffer[index]; } + const string ByteArray::toString() const { +#ifdef TO_STRING_ALL + return toString(true); +#else + return toString(false); +#endif + } + + const string ByteArray::toString(bool entire) const + { stringstream ss; if (length > 0) @@ -308,7 +322,7 @@ namespace smartcard_service_api bool ellipsis = false; count = length; - if (count > 20) + if (entire == false && count > 20) { count = 20; ellipsis = true; @@ -349,6 +363,8 @@ namespace smartcard_service_api fwrite(buffer, 1, length, file); fflush(file); fclose(file); + + SECURE_LOGD("file has written, file [%s], length[%d]", filePath, length); } else { @@ -357,4 +373,3 @@ namespace smartcard_service_api } } /* namespace smartcard_service_api */ - diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 1b5fc13..6469fb2 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -1,44 +1,72 @@ -INCLUDE_DIRECTORIES(include) - -FIND_PROGRAM(GDBUS_CODEGEN NAMES gdbus-codegen) -EXEC_PROGRAM(${GDBUS_CODEGEN} ARGS - " --generate-c-code ${CMAKE_CURRENT_SOURCE_DIR}/smartcard-service-gdbus" - " --c-namespace SmartcardService" - " --interface-prefix org.tizen.SmartcardService." - " ${CMAKE_CURRENT_SOURCE_DIR}/smartcard-service-gdbus.xml" -) +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(smartcard-service-common CXX) + +SET(LIB_NAME "smartcard-service-common") +SET(VERSION_MAJOR 1) +SET(VERSION ${VERSION_MAJOR}.0.0) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} COMMON_SRCS) +AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SRCS) +#IF("${CMAKE_BUILD_TYPE}" STREQUAL "") +# SET(CMAKE_BUILD_TYPE "Debug") +#ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") +#MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") + +INCLUDE(FindPkgConfig) pkg_check_modules(pkgs_common REQUIRED glib-2.0 gio-unix-2.0 dlog aul libssl pkgmgr pkgmgr-info) + +MESSAGE("${LIB_NAME} ld flag : ${pkgs_common_LDFLAGS}") + FOREACH(flag ${pkgs_common_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}") ENDFOREACH(flag) -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS}") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -finstrument-functions -fPIC") +#SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +#SET(CMAKE_C_FLAGS_RELEASE "-O2") + +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS} -finstrument-functions -std=c++0x") +#SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") +#SET(CMAKE_CXX_FLAGS_RELEASE "-O2") + +FIND_PROGRAM(UNAME NAMES uname) +EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") + MESSAGE("add -DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DSLP_DEBUG") +ADD_DEFINITIONS("-DUSE_UNIX_DOMAIN") ADD_DEFINITIONS("-DLOG_TAG=\"SMARTCARD_SERVICE_COMMON\"") -SET(CMAKE_C_FLAGS "${EXTRA_CXXFLAGS}") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) + +SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR}) +SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${VERSION}) -ADD_LIBRARY(${COMMON_LIB} SHARED ${COMMON_SRCS}) -SET_TARGET_PROPERTIES(${COMMON_LIB} PROPERTIES VERSION ${FULLVER} SOVERSION ${MAJORVER}) -TARGET_LINK_LIBRARIES(${COMMON_LIB} ${pkgs_common_LDFLAGS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_common_LDFLAGS}) -SET(EXPORT_HEADER +SET(EXPORT_HEADER include/smartcard-types.h include/Debug.h include/Exception.h include/ByteArray.h include/Lock.h - include/Synchronous.h + include/Synchronous.h include/TerminalInterface.h include/Terminal.h include/SignatureHelper.h ) -CONFIGURE_FILE(${COMMON_LIB}.pc.in ${COMMON_LIB}.pc @ONLY) -INSTALL(FILES ${COMMON_LIB}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) -INSTALL(TARGETS ${COMMON_LIB} DESTINATION ${LIB_INSTALL_DIR}) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) FOREACH(hfile ${EXPORT_HEADER}) - INSTALL(FILES ${hfile} DESTINATION include/${COMMON_LIB}) + INSTALL(FILES ${hfile} DESTINATION include/${LIB_NAME}) ENDFOREACH(hfile) diff --git a/common/EFDIR.cpp b/common/EFDIR.cpp index 3735d75..e6035e5 100644 --- a/common/EFDIR.cpp +++ b/common/EFDIR.cpp @@ -14,8 +14,12 @@ * limitations under the License. */ +/* standard library header */ #include +/* SLP library header */ + +/* local header */ #include "Debug.h" #include "EFDIR.h" #include "APDUHelper.h" diff --git a/common/FCI.cpp b/common/FCI.cpp index d4d1bf2..253f05e 100644 --- a/common/FCI.cpp +++ b/common/FCI.cpp @@ -14,10 +14,14 @@ * limitations under the License. */ +/* standard library header */ #include #include #include +/* SLP library header */ + +/* local header */ #include "Debug.h" #include "FCI.h" #include "SimpleTLV.h" @@ -77,7 +81,7 @@ namespace smartcard_service_api } /* parse... */ - tlv.setTLVBuffer(fcpBuffer.getBuffer(), fcpBuffer.size()); + tlv.setTLVBuffer(fcpBuffer); if (tlv.decodeTLV()) { @@ -130,6 +134,7 @@ namespace smartcard_service_api case 0x84 : /* DF name */ { + SECURE_LOGD("0x%02X : DF name : %s", tlv.getTag(), tlv.getValue().toString().c_str()); // ByteArray value = tlv.getValue(); } break; @@ -143,6 +148,7 @@ namespace smartcard_service_api case 0x86 : /* Security attribute in proprietary format */ { + SECURE_LOGD("0x%02X : Security attribute in proprietary format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); // ByteArray value = tlv.getValue(); } break; @@ -185,36 +191,42 @@ namespace smartcard_service_api case 0x8B : /* Security attribute referencing the expanded format */ { + SECURE_LOGD("0x%02X : Security attribute referencing the expanded format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); // ByteArray value = tlv.getValue(); } break; case 0x8C : /* Security attribute in compact format */ { + SECURE_LOGD("0x%02X : Security attribute in compact format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); // ByteArray value = tlv.getValue(); } break; case 0x8D : /* Identifier of an EF containing security environment templates */ { + SECURE_LOGD("0x%02X : Identifier of an EF containing security environment templates : %s", tlv.getTag(), tlv.getValue().toString().c_str()); // ByteArray value = tlv.getValue(); } break; case 0x8E : /* Channel security attribute */ { + SECURE_LOGD("0x%02X : Channel security attribute : %s", tlv.getTag(), tlv.getValue().toString().c_str()); // ByteArray value = tlv.getValue(); } break; case 0xA0 : /* Security attribute template for data objects */ { + SECURE_LOGD("0x%02X : Security attribute template for data objects : %s", tlv.getTag(), tlv.getValue().toString().c_str()); // ByteArray value = tlv.getValue(); } break; case 0xA1 : /* Security attribute template in proprietary format */ { + SECURE_LOGD("0x%02X : Security attribute template in proprietary format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); // ByteArray value = tlv.getValue(); } break; @@ -235,6 +247,7 @@ namespace smartcard_service_api case 0xAB : /* Security attribute template in expanded format */ { + SECURE_LOGD("0x%02X : Security attribute template in expanded format : %s", tlv.getTag(), tlv.getValue().toString().c_str()); // ByteArray value = tlv.getValue(); } break; @@ -248,6 +261,7 @@ namespace smartcard_service_api case 0xC6 : /* PIN status template DO */ { + SECURE_LOGD("0x%02X : PIN status template DO : %s", tlv.getTag(), tlv.getValue().toString().c_str()); // ByteArray value = tlv.getValue(); } break; diff --git a/common/FileObject.cpp b/common/FileObject.cpp index b56c696..efbc110 100644 --- a/common/FileObject.cpp +++ b/common/FileObject.cpp @@ -14,8 +14,13 @@ * limitations under the License. */ +/* standard library header */ #include +#include +/* SLP library header */ + +/* local header */ #include "Debug.h" #include "FileObject.h" #include "APDUHelper.h" @@ -101,10 +106,7 @@ namespace smartcard_service_api ret = resp.getStatus(); - if (setSelectResponse(result) == true) - { - opened = true; - } + setSelectResponse(result); } else { @@ -238,13 +240,19 @@ namespace smartcard_service_api return 0; } +#define MAX_SINGLE_LEN 256 + int FileObject::readBinary(unsigned int sfi, unsigned int offset, unsigned int length, ByteArray &result) { ByteArray command, response; APDUCommand apdu; int ret; - apdu.setCommand(0, APDUCommand::INS_READ_BINARY, offset, 0, ByteArray::EMPTY, length); + /* FIXME : fix calculating length */ + apdu.setCommand(0, APDUCommand::INS_READ_BINARY, + (offset >> 8) & 0x7F, offset & 0x00FF, + ByteArray::EMPTY, (length > MAX_SINGLE_LEN - 1) ? 0 : length); + apdu.getBuffer(command); ret = channel->transmitSync(command, response); @@ -273,6 +281,23 @@ namespace smartcard_service_api return ret; } + int FileObject::readBinary(unsigned int sfi, unsigned int length, ByteArray &result) + { + int ret; + size_t offset = 0; + ByteArray temp; + + do { + ret = readBinary(sfi, offset, length - offset, temp); + if (ret >= SCARD_ERROR_OK) { + result += temp; + offset += temp.size(); + } + } while (ret >= SCARD_ERROR_OK && offset < length); + + return ret; + } + int FileObject::writeBinary(unsigned int sfi, const ByteArray &data, unsigned int offset, unsigned int length) { ByteArray command, response; @@ -305,4 +330,32 @@ namespace smartcard_service_api return ret; } + + int FileObject::writeBinary(unsigned int sfi, const ByteArray &data) + { + int result; + size_t offset = 0, len; + ByteArray temp; + + do { + len = MIN(data.size() - offset, MAX_SINGLE_LEN); + temp.setBuffer(data.getBuffer(offset), len); + result = writeBinary(sfi, temp, offset, len); + if (result >= SCARD_ERROR_OK) { + offset += len; + } + } while (result >= SCARD_ERROR_OK && offset < data.size()); + + return result; + } + + int FileObject::readBinaryAll(unsigned int sfi, ByteArray &result) + { + int ret; + + ret = readBinary(sfi, getFCP()->getFileSize(), result); + + return ret; + } + } /* namespace smartcard_service_api */ diff --git a/common/GPACE.cpp b/common/GPACE.cpp index ca1d0d7..3aa3ba7 100644 --- a/common/GPACE.cpp +++ b/common/GPACE.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "Debug.h" #include "GPACE.h" #include "GPARAACL.h" diff --git a/common/GPARAACL.cpp b/common/GPARAACL.cpp index 0f3b8fc..95a9f65 100644 --- a/common/GPARAACL.cpp +++ b/common/GPARAACL.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "Debug.h" #include "GPARAACL.h" #include "GPARAM.h" @@ -287,6 +292,8 @@ namespace smartcard_service_api { _INFO("access rules are not changed. skip update"); } + + printAccessControlList(); } else { _ERR("transmitSync failed, %x", result); } diff --git a/common/GPARAM.cpp b/common/GPARAM.cpp index 2990cf9..2c81baf 100644 --- a/common/GPARAM.cpp +++ b/common/GPARAM.cpp @@ -14,6 +14,12 @@ * limitations under the License. */ +/* standard library header */ +#include + +/* SLP library header */ + +/* local header */ #include "Debug.h" #include "GPARAM.h" #include "APDUHelper.h" @@ -29,7 +35,7 @@ namespace smartcard_service_api { - static unsigned char aid_aram[] = { 0xA0, 0x00, 0x00, 0x01, 0x51, 0x41, 0x43, 0x4C, 00 }; + static unsigned char aid_aram[] = { 0xA0, 0x00, 0x00, 0x01, 0x51, 0x41, 0x43, 0x4C, 0x00 }; static ByteArray AID_ARAM(ARRAY_AND_SIZE(aid_aram)); #define GET_DATA_ALL 0 @@ -132,6 +138,49 @@ namespace smartcard_service_api return result; } + int getLengthAndValue(const ByteArray &data, ByteArray &value) + { + int result = -1; + int offset = 0; + + if (data.isEmpty() == true) { + return result; + } + + if (data.at(offset) == 0xFF && data.at(offset + 1) == 0x40) { + uint8_t count; + + offset += 2; + count = data.at(offset); + + offset += 1; + if (count & 0x80) { + int i; + + count &= ~0x80; + result = 0; + + for (i = 0; i < count; i++) { + result = (result << 8) | data.at(offset + i); + } + + offset += i; + } else { + result = count; + } + + if (result > 0) { + value.assign(data.getBuffer(offset), + MIN((uint32_t)result, + data.size() - offset)); + } + } else { + _ERR("invalid tag"); + } + + return result; + } + int GPARAM::getDataAll(ByteArray &data) { int result; @@ -141,37 +190,31 @@ namespace smartcard_service_api result = doCommand(channel, GET_DATA_ALL, response); if (result >= SCARD_ERROR_OK) { - ISO7816BERTLV tlv(response); - - if (tlv.decodeTLV() == true && - tlv.getTag() == ARAM_TAG_ALL_AR) { - unsigned int length = tlv.size(); - - if (length > 0){ - data = tlv.getValue(); - - while (length > data.size()) { - result = doCommand(channel, GET_DATA_NEXT, response); - if (result >= SCARD_ERROR_OK) { - data += response; - } else { - _ERR("generateCommand failed, [%d]", result); - data.clear(); - break; - } + int length; + + length = getLengthAndValue(response, data); + if (length > 0){ + while (length > (int)data.size()) { + result = doCommand(channel, GET_DATA_NEXT, response); + if (result >= SCARD_ERROR_OK) { + data += response; + } else { + _ERR("generateCommand failed, [%d]", result); + data.clear(); + break; } - - _DBG("data[%d] : %s", data.size(), data.toString().c_str()); - } else { - _INFO("Response-ALL-AR-DO is empty"); - data.clear(); } + + _DBG("data[%d] : %s", data.size(), data.toString().c_str()); + } else if (length == 0) { + _INFO("Response-ALL-AR-DO is empty"); + data.clear(); } else { - _ERR("decodeTLV failed, %s", response.toString().c_str()); - result = SCARD_ERROR_ILLEGAL_PARAM; + _ERR("invalid result, %s", response.toString().c_str()); + result = SCARD_ERROR_UNAVAILABLE; } } else { - _ERR("generateCommand failed, [%d]", result); + _ERR("doCommand failed, [%d]", result); } _END(); diff --git a/common/GPARFACL.cpp b/common/GPARFACL.cpp index 1f45cb2..84b3938 100644 --- a/common/GPARFACL.cpp +++ b/common/GPARFACL.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "Debug.h" #include "GPARFACL.h" #include "PKCS15ODF.h" @@ -53,7 +58,12 @@ namespace smartcard_service_api PKCS15 pkcs15(channel); /* basically, all requests will be accepted when PKCS #15 doesn't exist or global platform OID is not placed */ +#if 1 /* FOR ORANGE */ + /* for Orange, every requests will be denied in same cases */ allGranted = false; +#else + allGranted = true; +#endif result = pkcs15.select(); if (result >= SCARD_ERROR_OK) @@ -61,7 +71,6 @@ namespace smartcard_service_api PKCS15ODF *odf; result = SCARD_ERROR_OK; - allGranted = true; if ((odf = pkcs15.getODF()) != NULL) { @@ -72,26 +81,43 @@ namespace smartcard_service_api result = loadAccessControl(channel, dodf); if (result == SCARD_ERROR_OK) { + printAccessControlList(); } else { +#if 1 /* FOR ORANGE */ + _ERR("loadAccessControl failed, every request will be denied."); +#else _INFO("loadAccessControl failed, every request will be accepted."); +#endif result = SCARD_ERROR_OK; } } else { +#if 1 /* FOR ORANGE */ + _ERR("dodf null, every request will be denied."); +#else _INFO("dodf null, every request will be accepted."); +#endif } } else { +#if 1 /* FOR ORANGE */ + _ERR("odf null, every request will be denied."); +#else _INFO("odf null, every request will be accepted."); +#endif } } else { - _ERR("failed to open PKCS15, every request will be denied."); +#if 1 /* FOR ORANGE */ + _ERR("failed to open PKCS#15, every request will be denied."); +#else + _INFO("failed to open PKCS#15, every request will be accepted."); +#endif } _END(); @@ -112,7 +138,7 @@ namespace smartcard_service_api _DBG("oid path : %s", path.toString().c_str()); file.select(NumberStream::getLittleEndianNumber(path)); - file.readBinary(0, 0, file.getFCP()->getFileSize(), data); + file.readBinaryAll(0, data); _DBG("data : %s", data.toString().c_str()); @@ -182,7 +208,7 @@ namespace smartcard_service_api ByteArray data, aid; file.select(NumberStream::getLittleEndianNumber(path)); - file.readBinary(0, 0, file.getFCP()->getFileSize(), data); + file.readBinaryAll(0, data); _DBG("data : %s", data.toString().c_str()); @@ -380,9 +406,10 @@ namespace smartcard_service_api } else { - _INFO("access denied for all applications, aid : %s", condition.getAID().toString().c_str()); + /* empty rule, it means allow for all application */ + _INFO("access allowed for all applications, aid : %s", condition.getAID().toString().c_str()); - condition.setAccessCondition(false); + condition.setAccessCondition(true); break; } } @@ -402,7 +429,7 @@ namespace smartcard_service_api ByteArray data; file.select(NumberStream::getLittleEndianNumber(path)); - file.readBinary(0, 0, file.getFCP()->getFileSize(), data); + file.readBinaryAll(0, data); _DBG("data : %s", data.toString().c_str()); diff --git a/common/ISO7816BERTLV.cpp b/common/ISO7816BERTLV.cpp index babd635..afe1933 100644 --- a/common/ISO7816BERTLV.cpp +++ b/common/ISO7816BERTLV.cpp @@ -14,9 +14,13 @@ * limitations under the License. */ +/* standard library header */ #include #include +/* SLP library header */ + +/* local header */ #include "ISO7816BERTLV.h" namespace smartcard_service_api @@ -89,34 +93,38 @@ namespace smartcard_service_api int ISO7816BERTLV::decodeLength(const unsigned char *buffer) { - if (buffer[0] & 0x80) + uint8_t offset = 0; + uint8_t count = buffer[offset]; + + offset++; + + if (count & 0x80) { - uint8_t count = (buffer[0] & 0x7F); uint8_t i; + count &= ~0x80; + /* count will be less than 5 */ if (count > 4) return -1; - count++; - - for (i = 1; i < count; i++) + for (i = 0; i < count; i++) { /* if big endian */ - currentL = (currentL << 8) | buffer[i]; + currentL = (currentL << 8) | buffer[offset + i]; /* if little endian */ - /* currentL = currentL | (buffer[i] << (8 * (i - 1))); */ + /* currentL = currentL | (buffer[offset + i] << (8 * (i - 1))); */ } - return count; + offset += i; } else { - currentL = buffer[0]; - - return 1; + currentL = count; } + + return offset; } int ISO7816BERTLV::decodeValue(const unsigned char *buffer) diff --git a/common/OpensslHelper.cpp b/common/OpensslHelper.cpp index 17f485d..9712d60 100644 --- a/common/OpensslHelper.cpp +++ b/common/OpensslHelper.cpp @@ -14,12 +14,16 @@ * limitations under the License. */ +/* standard library header */ #include #include #include #include #include +/* SLP library header */ + +/* local header */ #include "Debug.h" #include "ByteArray.h" #include "OpensslHelper.h" @@ -38,6 +42,9 @@ namespace smartcard_service_api } b64 = BIO_new(BIO_f_base64()); + if(b64 == NULL) + return false; + bmem = BIO_new(BIO_s_mem()); if (newLineChar == false) @@ -88,6 +95,12 @@ namespace smartcard_service_api memset(temp, 0, length); b64 = BIO_new(BIO_f_base64()); + if(b64 == NULL) + { + delete []temp; + return false; + } + bmem = BIO_new_mem_buf((void *)buffer.getBuffer(), length); if (newLineChar == false) BIO_set_flags(b64, BIO_FLAGS_BASE64_NO_NL); @@ -96,12 +109,17 @@ namespace smartcard_service_api length = BIO_read(bmem, temp, length); BIO_free_all(bmem); - - result.assign((unsigned char *)temp, length); + if(length > 0) + { + result.assign((unsigned char *)temp, length); + ret = true; + } + else + { + ret = false; + } delete []temp; - - ret = true; } else { diff --git a/common/PKCS15.cpp b/common/PKCS15.cpp index 674c684..613e58a 100644 --- a/common/PKCS15.cpp +++ b/common/PKCS15.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "Debug.h" #include "APDUHelper.h" #include "EFDIR.h" @@ -23,7 +28,7 @@ namespace smartcard_service_api { static unsigned char aid[] = { 0xA0, 0x00, 0x00, 0x00, 0x63, 0x50, 0x4B, 0x43, 0x53, 0x2D, 0x31, 0x35 }; - ByteArray PKCS15::PKCS15_AID(ARRAY_AND_SIZE(aid)); + const ByteArray PKCS15::PKCS15_AID(ARRAY_AND_SIZE(aid)); PKCS15::PKCS15(Channel *channel) : PKCS15Object(channel), odf(NULL) @@ -48,7 +53,7 @@ namespace smartcard_service_api { int ret; - ret = PKCS15Object::select(PKCS15::PKCS15_AID); + ret = PKCS15Object::select(PKCS15_AID); if (ret >= SCARD_ERROR_OK) { _DBG("response : %s", selectResponse.toString().c_str()); diff --git a/common/PKCS15CDF.cpp b/common/PKCS15CDF.cpp new file mode 100644 index 0000000..7664d0d --- /dev/null +++ b/common/PKCS15CDF.cpp @@ -0,0 +1,264 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* standard library header */ + +/* SLP library header */ + +/* local header */ +#include "Debug.h" +#include "NumberStream.h" +#include "PKCS15CDF.h" +#include "SimpleTLV.h" + +namespace smartcard_service_api +{ + PKCS15CDF::PKCS15CDF(unsigned int fid, Channel *channel) : + PKCS15Object(channel) + { + int ret = 0; + + if ((ret = select(fid)) >= SCARD_ERROR_OK) + { + ByteArray cdfData, extra; + + _DBG("response : %s", selectResponse.toString().c_str()); + + ret = readBinaryAll(0, cdfData); + if (ret == SCARD_ERROR_OK) + { + _DBG("cdfData : %s", cdfData.toString().c_str()); + + parseData(cdfData); + } + else + { + _ERR("readBinary failed, [%d]", ret); + } + } + else + { + _ERR("select failed, [%d]", ret); + } + } + + PKCS15CDF::PKCS15CDF(const ByteArray &path, Channel *channel) : + PKCS15Object(channel) + { + int ret = 0; + + if ((ret = select(path)) >= SCARD_ERROR_OK) + { + ByteArray cdfData, extra; + + _DBG("response : %s", selectResponse.toString().c_str()); + + ret = readBinaryAll(0, cdfData); + if (ret == SCARD_ERROR_OK) + { + _DBG("cdfData : %s", cdfData.toString().c_str()); + + parseData(cdfData); + } + else + { + _ERR("readBinary failed, [%d]", ret); + } + } + else + { + _ERR("select failed, [%d]", ret); + } + } + + PKCS15CDF::~PKCS15CDF() + { + } + + bool PKCS15CDF::parseData(const ByteArray &data) + { + int result; + char* buffer; + SimpleTLV tlv(data); + + while (tlv.decodeTLV()) + { + CertificateType *cert; + + _DBG("0x%02X [%d] : %s", tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str()); + + cert = new CertificateType(); + + tlv.enterToValueTLV(); + if (tlv.decodeTLV()) + { + _DBG("Common Object Attributes"); + + /* Common Object Attributes */ + tlv.enterToValueTLV(); + while (tlv.decodeTLV()) + { + switch (tlv.getTag()) + { + case (unsigned int)0x0C : /* label : OCTET STRING */ + buffer = (char *)tlv.getValue().getBuffer(); + if(buffer != NULL) + { + _DBG("label : %s", buffer); + cert->label.assign(buffer, tlv.getValue().getLength()); + } + break; + + case (unsigned int)0x03 : /* flags : BIT STRING */ + /* 0 : private, 1 : modifiable */ + _DBG("flag : %s", tlv.getValue()[0] ? "modifiable" : "private"); + cert->modifiable = (tlv.getValue()[0] == 1); + break; + + default : + _DBG("0x%02X [%d] : %s", tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str()); + break; + } + } + tlv.returnToParentTLV(); + } + + if (tlv.decodeTLV()) + { + _DBG("Common Certificate Attributes"); + + /* Common Certificate Attributes */ + tlv.enterToValueTLV(); + while (tlv.decodeTLV()) + { + switch (tlv.getTag()) + { + case (unsigned int)0x04 : /* iD : OCTET STRING */ + _DBG("id : %s", tlv.getValue().toString().c_str()); + cert->id = tlv.getValue(); + break; + + case (unsigned int)0x01 : /* Authority : BOOLEAN */ + _DBG("authority : %s", tlv.getValue().toString().c_str()); + cert->authority = tlv.getValue()[0]; + break; + + case (unsigned int)0xA1 : /* ??? : ??? */ + tlv.enterToValueTLV(); + if (tlv.decodeTLV()) { + _DBG(" 0x%02X [%d] : %s", tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str()); + tlv.enterToValueTLV(); + if (tlv.decodeTLV()) { + _DBG(" 0x%02X [%d] : %s", tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str()); + tlv.enterToValueTLV(); + if (tlv.decodeTLV()) { + _DBG(" 0x%02X [%d] : %s", tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str()); + tlv.enterToValueTLV(); + if (tlv.decodeTLV()) { + _DBG(" 0x%02X [%d] : %s", tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str()); + } + tlv.returnToParentTLV(); + } + if (tlv.decodeTLV()) { + _DBG(" 0x%02X [%d] : %s", tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str()); + } + tlv.returnToParentTLV(); + } + tlv.returnToParentTLV(); + } + tlv.returnToParentTLV(); + break; + + default : + _DBG("0x%02X [%d] : %s", tlv.getTag(), tlv.size(), tlv.getValue().toString().c_str()); + break; + } + } + tlv.returnToParentTLV(); + } + + if (tlv.decodeTLV()) + { + _DBG("Certificate Attributes"); + + /* Path or Object */ + tlv.enterToValueTLV(); + if (tlv.decodeTLV()) + { + tlv.enterToValueTLV(); + if (tlv.decodeTLV()) + { + /* PATH */ + tlv.enterToValueTLV(); + while (tlv.decodeTLV()) + { + switch (tlv.getTag()) + { + case (unsigned int)0x04 : /* path : OCTET STRING */ + cert->path = tlv.getValue(); + _DBG("path : %s", cert->path.toString().c_str()); + break; + + case (unsigned int)0x02 : /* index : INTEGER */ + cert->index = NumberStream::getBigEndianNumber(tlv.getValue()); + _DBG("index : %d", cert->index); + break; + + case (unsigned int)0x80 : /* length : INTEGER */ + cert->length = NumberStream::getBigEndianNumber(tlv.getValue()); + _DBG("length : %d", cert->length); + break; + } + } + tlv.returnToParentTLV(); + + FileObject file(channel); + + result = file.select(cert->path, true); + if (result >= SCARD_ERROR_OK) { + result = file.readBinary(0, cert->length, cert->certificate); + if (result >= SCARD_ERROR_OK) { + _DBG("certificate[%d] : %s", cert->certificate.size(), cert->certificate.toString().c_str()); + } else { + _ERR("readBinary failed, [%x]", result); + } + } else { + _ERR("select failed, [%x]", result); + } + + } + tlv.returnToParentTLV(); + } + tlv.returnToParentTLV(); + } + tlv.returnToParentTLV(); + + listCertType.push_back(cert); + } + + _INFO("listCertType.size() = %d", listCertType.size()); + + return (listCertType.size() > 0); + } + + const CertificateType *PKCS15CDF::getCertificateType(int index) const + { + if (index < 0 || index >= (int)listCertType.size()) + return NULL; + + return listCertType[index]; + } +} /* namespace smartcard_service_api */ diff --git a/common/PKCS15DODF.cpp b/common/PKCS15DODF.cpp index 50cf11a..ea1cde6 100644 --- a/common/PKCS15DODF.cpp +++ b/common/PKCS15DODF.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "Debug.h" #include "PKCS15DODF.h" #include "SimpleTLV.h" @@ -31,9 +36,9 @@ namespace smartcard_service_api _DBG("response : %s", selectResponse.toString().c_str()); - if ((ret = readBinary(0, 0, getFCP()->getFileSize(), dodfData)) == 0) + if ((ret = readBinaryAll(0, dodfData)) == 0) { - _DBG("odfData : %s", dodfData.toString().c_str()); + _DBG("dodfData : %s", dodfData.toString().c_str()); parseData(dodfData); } @@ -59,7 +64,7 @@ namespace smartcard_service_api _DBG("response : %s", selectResponse.toString().c_str()); - if ((ret = readBinary(0, 0, getFCP()->getFileSize(), dodfData)) == 0) + if ((ret = readBinaryAll(0, dodfData)) == 0) { _DBG("dodfData : %s", dodfData.toString().c_str()); diff --git a/common/PKCS15ODF.cpp b/common/PKCS15ODF.cpp index a0beb7c..53ff3d7 100644 --- a/common/PKCS15ODF.cpp +++ b/common/PKCS15ODF.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "Debug.h" #include "PKCS15ODF.h" #include "SimpleTLV.h" @@ -21,18 +26,23 @@ namespace smartcard_service_api { + static const unsigned int ODF_FID = 0x3150; + + static const unsigned int TAG_DODF = (unsigned int)0xA7; + static const unsigned int TAG_CDF = (unsigned int)0xA5; + PKCS15ODF::PKCS15ODF(Channel *channel) : - PKCS15Object(channel), dodf(NULL) + PKCS15Object(channel), cdf(NULL), dodf(NULL) { int ret = 0; - if ((ret = select(PKCS15ODF::ODF_FID)) >= SCARD_ERROR_OK) + if ((ret = select(ODF_FID)) >= SCARD_ERROR_OK) { ByteArray odfData, extra; _DBG("response : %s", selectResponse.toString().c_str()); - if ((ret = readBinary(0, 0, getFCP()->getFileSize(), odfData)) == 0) + if ((ret = readBinaryAll(0, odfData)) == 0) { _DBG("odfData : %s", odfData.toString().c_str()); @@ -55,7 +65,7 @@ namespace smartcard_service_api int ret = 0; ByteArray odfData; - if ((ret = readBinary(0, 0, 0, odfData)) == 0) + if ((ret = readBinaryAll(0, odfData)) == 0) { _DBG("odfData : %s", odfData.toString().c_str()); @@ -85,7 +95,7 @@ namespace smartcard_service_api { switch (tlv.getTag()) { - case (unsigned int)0xA7 ://PKCS15ODF::TAG_DODF : + case TAG_DODF : { ByteArray dodf; @@ -100,11 +110,11 @@ namespace smartcard_service_api } break; - case (unsigned int)0xA5 ://PKCS15ODF::TAG_TOKENINFO : + case TAG_CDF : { ByteArray tokeninfo; - _DBG("TAG_TOKENINFO"); + _DBG("TAG_CDF"); tokeninfo = PKCS15Object::getOctetStream(tlv.getValue()); @@ -134,13 +144,13 @@ namespace smartcard_service_api if (dodf == NULL) { - item = dataList.find((unsigned int)0xA7/*PKCS15ODF::TAG_DODF*/); + item = dataList.find(TAG_DODF); if (item != dataList.end()) { NumberStream num(item->second); unsigned int fid = num.getLittleEndianNumber(); - _DBG("fid [%X]", fid); + _DBG("dodf fid [%X]", fid); dodf = new PKCS15DODF(fid, channel); if (dodf != NULL && dodf->isClosed() == true) @@ -162,4 +172,37 @@ namespace smartcard_service_api return dodf; } + PKCS15CDF *PKCS15ODF::getCDF() + { + map::iterator item; + + if (cdf == NULL) + { + item = dataList.find(TAG_CDF); + if (item != dataList.end()) + { + NumberStream num(item->second); + unsigned int fid = num.getLittleEndianNumber(); + + _DBG("cdf fid [%X]", fid); + + cdf = new PKCS15CDF(fid, channel); + if (cdf != NULL && cdf->isClosed() == true) + { + _ERR("failed to open CDF"); + + delete cdf; + cdf = NULL; + } + } + else + { + _ERR("[%02X] is not found. total [%d]", TAG_CDF, dataList.size()); + } + } + + _DBG("cdf [%p]", cdf); + + return cdf; + } } /* namespace smartcard_service_api */ diff --git a/common/PKCS15OID.cpp b/common/PKCS15OID.cpp index a927fd8..2c46c24 100644 --- a/common/PKCS15OID.cpp +++ b/common/PKCS15OID.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "Debug.h" #include "PKCS15.h" #include "PKCS15OID.h" @@ -49,6 +54,7 @@ namespace smartcard_service_api if (tlv.decodeTLV() == true && tlv.getTag() == 0x0C) /* ?? */ { name = tlv.getValue(); + SECURE_LOGD("name : %s", name.toString().c_str()); } tlv.returnToParentTLV(); } diff --git a/common/PKCS15Object.cpp b/common/PKCS15Object.cpp index 8559aa7..6c4c790 100644 --- a/common/PKCS15Object.cpp +++ b/common/PKCS15Object.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "Debug.h" #include "SimpleTLV.h" #include "PKCS15Object.h" diff --git a/common/PKCS15Path.cpp b/common/PKCS15Path.cpp index a219c3d..0e28b13 100644 --- a/common/PKCS15Path.cpp +++ b/common/PKCS15Path.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "PKCS15Path.h" namespace smartcard_service_api diff --git a/common/PKCS15TokenInfo.cpp b/common/PKCS15TokenInfo.cpp index 37722b8..259d939 100644 --- a/common/PKCS15TokenInfo.cpp +++ b/common/PKCS15TokenInfo.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "PKCS15TokenInfo.h" namespace smartcard_service_api diff --git a/common/Serializable.cpp b/common/Serializable.cpp index b5ac3ed..f4daec8 100644 --- a/common/Serializable.cpp +++ b/common/Serializable.cpp @@ -14,6 +14,11 @@ * limitations under the License. */ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "Serializable.h" namespace smartcard_service_api diff --git a/common/SignatureHelper.cpp b/common/SignatureHelper.cpp index d0c97ba..62bdc1e 100644 --- a/common/SignatureHelper.cpp +++ b/common/SignatureHelper.cpp @@ -22,10 +22,8 @@ #include #include #include -#include /* SLP library header */ -#include "package-manager.h" #include "pkgmgr-info.h" #include "aul.h" @@ -40,31 +38,16 @@ namespace smartcard_service_api { - uid_t ProcGetUsrBypid(int pid) - { - char buf[255]; - int ret; - uid_t uid; - struct stat dir_stats; - snprintf(buf, sizeof(buf), "/proc/%d", pid); - ret = stat(buf, &dir_stats); - if (ret < 0) - uid = (uid_t) - 1; - else - uid = dir_stats.st_uid; - return uid; - } - int SignatureHelper::getPackageName(int pid, char *package, size_t length) { return aul_app_get_pkgname_bypid(pid, package, length); } - const ByteArray SignatureHelper::getCertificationHash(const char *packageName, uid_t uid) + const ByteArray SignatureHelper::getCertificationHash(const char *packageName) { ByteArray result; int ret = 0; - pkgmgr_certinfo_h handle = NULL; + pkgmgrinfo_certinfo_h handle = NULL; pkgmgrinfo_appinfo_h handle_appinfo; char *pkgid = NULL; @@ -82,17 +65,19 @@ namespace smartcard_service_api } pkgmgrinfo_appinfo_destroy_appinfo(handle_appinfo); - if ((ret = pkgmgr_pkginfo_create_certinfo(&handle)) == 0) + SECURE_LOGD("package name : %s, package id : %s", packageName, pkgid); + + if ((ret = pkgmgrinfo_pkginfo_create_certinfo(&handle)) == 0) { - if ((ret = pkgmgr_pkginfo_load_certinfo(pkgid, handle, uid)) == 0) + if (0) { int type; - for (type = (int)PM_AUTHOR_ROOT_CERT; type <= (int)PM_DISTRIBUTOR2_SIGNER_CERT; type++) + for (type = (int)PMINFO_AUTHOR_ROOT_CERT; type <= (int)PMINFO_DISTRIBUTOR2_SIGNER_CERT; type++) { const char *value = NULL; - if ((ret = pkgmgr_pkginfo_get_cert_value(handle, (pkgmgr_cert_type)type, &value)) == 0) + if ((ret = pkgmgrinfo_pkginfo_get_cert_value(handle, (pkgmgrinfo_cert_type)type, &value)) == 0) { if (value != NULL && strlen(value) > 0) { @@ -111,7 +96,7 @@ namespace smartcard_service_api _ERR("pkgmgr_pkginfo_load_certinfo failed [%d]", ret); } - pkgmgr_pkginfo_destroy_certinfo(handle); + pkgmgrinfo_pkginfo_destroy_certinfo(handle); } else { @@ -126,11 +111,10 @@ namespace smartcard_service_api ByteArray result; int error = 0; char pkgName[256] = { 0, }; - uid_t uid = ProcGetUsrBypid(pid); if ((error = aul_app_get_pkgname_bypid(pid, pkgName, sizeof(pkgName))) == 0) { - result = getCertificationHash(pkgName, uid); + result = getCertificationHash(pkgName); } else { @@ -145,11 +129,10 @@ namespace smartcard_service_api bool result = false; int error = 0; char pkgName[256] = { 0, }; - uid_t uid = ProcGetUsrBypid(pid); if ((error = aul_app_get_pkgname_bypid(pid, pkgName, sizeof(pkgName))) == 0) { - result = getCertificationHashes(pkgName, certHashes, uid); + result = getCertificationHashes(pkgName, certHashes); } else { @@ -159,38 +142,40 @@ namespace smartcard_service_api return result; } - bool SignatureHelper::getCertificationHashes(const char *packageName, vector &certHashes, uid_t uid) + bool SignatureHelper::getCertificationHashes(const char *packageName, vector &certHashes) { bool result = false; int ret = 0; - pkgmgr_certinfo_h handle = NULL; + pkgmgrinfo_certinfo_h handle = NULL; pkgmgrinfo_appinfo_h handle_appinfo; char *pkgid = NULL; - if(pkgmgrinfo_appinfo_get_appinfo(packageName, &handle_appinfo) != PMINFO_R_OK) + if (pkgmgrinfo_appinfo_get_appinfo(packageName, &handle_appinfo) != PMINFO_R_OK) { _ERR("pkgmgrinfo_appinfo_get_appinfo fail"); return result; } - if(pkgmgrinfo_appinfo_get_pkgid(handle_appinfo, &pkgid) != PMINFO_R_OK) + if (pkgmgrinfo_appinfo_get_pkgid(handle_appinfo, &pkgid) != PMINFO_R_OK) { pkgmgrinfo_appinfo_destroy_appinfo(handle_appinfo); _ERR("pkgmgrinfo_appinfo_get_pkgid fail"); return result; } - if ((ret = pkgmgr_pkginfo_create_certinfo(&handle)) == 0) + SECURE_LOGD("package name : %s, package id : %s", packageName, pkgid); + + if ((ret = pkgmgrinfo_pkginfo_create_certinfo(&handle)) == 0) { - if ((ret = pkgmgr_pkginfo_load_certinfo(pkgid, handle, uid)) == 0) + if (0) { int type; - for (type = (int)PM_AUTHOR_ROOT_CERT; type <= (int)PM_DISTRIBUTOR2_SIGNER_CERT; type++) + for (type = (int)PMINFO_AUTHOR_ROOT_CERT; type <= (int)PMINFO_DISTRIBUTOR2_SIGNER_CERT; type++) { const char *value = NULL; - if ((ret = pkgmgr_pkginfo_get_cert_value(handle, (pkgmgr_cert_type)type, &value)) == 0) + if ((ret = pkgmgrinfo_pkginfo_get_cert_value(handle, (pkgmgrinfo_cert_type)type, &value)) == 0) { if (value != NULL && strlen(value) > 0) { @@ -219,7 +204,7 @@ namespace smartcard_service_api pkgmgrinfo_appinfo_destroy_appinfo(handle_appinfo); - pkgmgr_pkginfo_destroy_certinfo(handle); + pkgmgrinfo_pkginfo_destroy_certinfo(handle); } else { @@ -236,12 +221,15 @@ using namespace smartcard_service_api; certiHash *__signature_helper_vector_to_linked_list(vector &certHashes) { vector::iterator item; - certiHash *head, *tail, *tmp; + certiHash *head, *tail; + uint8_t* buffer = NULL; head = tail = NULL; for (item = certHashes.begin(); item != certHashes.end(); item++) { + certiHash *tmp = NULL; + if ((tmp = (certiHash *)calloc(1, sizeof(certiHash))) == NULL) goto ERROR; @@ -253,7 +241,15 @@ certiHash *__signature_helper_vector_to_linked_list(vector &certHashe goto ERROR; } - memcpy(tmp->value, (*item).getBuffer(), tmp->length); + buffer = (*item).getBuffer(); + if(buffer == NULL) + { + free(tmp->value); + free(tmp); + continue; + } + + memcpy(tmp->value, buffer, tmp->length); tmp->next = NULL; if (head == NULL) @@ -266,11 +262,14 @@ certiHash *__signature_helper_vector_to_linked_list(vector &certHashe tail = tmp; } } + return head; ERROR : _ERR("alloc fail"); + certiHash *tmp; + while (head) { tmp = head; @@ -283,7 +282,7 @@ ERROR : return NULL; } -EXTERN_API int signature_helper_get_certificate_hashes(const char *packageName, uid_t uid, certiHash **hash) +EXTERN_API int signature_helper_get_certificate_hashes(const char *packageName, certiHash **hash) { int ret = -1; vector hashes; @@ -291,7 +290,7 @@ EXTERN_API int signature_helper_get_certificate_hashes(const char *packageName, if (packageName == NULL) return ret; - if (SignatureHelper::getCertificationHashes(packageName, hashes, uid) == true) + if (SignatureHelper::getCertificationHashes(packageName, hashes) == true) { *hash = __signature_helper_vector_to_linked_list(hashes); ret = 0; diff --git a/common/include/APDUHelper.h b/common/include/APDUHelper.h index 94ffd0a..8b44a71 100644 --- a/common/include/APDUHelper.h +++ b/common/include/APDUHelper.h @@ -17,12 +17,16 @@ #ifndef APDUHELPER_H_ #define APDUHELPER_H_ -#include "Debug.h" +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "ByteArray.h" namespace smartcard_service_api { - class EXPORT ResponseHelper + class ResponseHelper { private: ByteArray response; @@ -71,7 +75,7 @@ namespace smartcard_service_api // static char *getErrorString(); }; - class EXPORT APDUCommand + class APDUCommand { private: typedef struct _command_header_t @@ -130,6 +134,7 @@ namespace smartcard_service_api // static const unsigned char P1_ = (unsigned char)0x; static const unsigned char P2_SELECT_GET_FCP = (unsigned char)0x04; + static const unsigned char P2_SELECT_GET_FCI = (unsigned char)0x00; // static const unsigned char P2_ = (unsigned char)0x; static const unsigned char CLA_CHANNEL_STANDARD = (unsigned char)0x00; @@ -167,7 +172,7 @@ namespace smartcard_service_api bool getBuffer(ByteArray &array) const; }; - class EXPORT APDUHelper + class APDUHelper { public: static const int COMMAND_OPEN_LOGICAL_CHANNEL = 1; diff --git a/common/include/AccessCondition.h b/common/include/AccessCondition.h index 689eacd..6f33cca 100644 --- a/common/include/AccessCondition.h +++ b/common/include/AccessCondition.h @@ -17,9 +17,13 @@ #ifndef ACCESSCONDITION_H_ #define ACCESSCONDITION_H_ +/* standard library header */ #include #include +/* SLP library header */ + +/* local header */ #include "ByteArray.h" using namespace std; @@ -33,6 +37,8 @@ namespace smartcard_service_api bool nfcRule; vector > listFilters; + void printAccessRules() const; + public : AccessRule() : apduRule(true), nfcRule(true) {} @@ -58,6 +64,8 @@ namespace smartcard_service_api ByteArray aid; map mapRules; + void printAccessConditions() const; + public : AccessCondition() {} @@ -82,6 +90,7 @@ namespace smartcard_service_api AccessRule *getAccessRule(const ByteArray &certHash); const AccessRule *getAccessRule(const ByteArray &certHash) const; + friend class AccessControlList; }; diff --git a/common/include/AccessControlList.h b/common/include/AccessControlList.h index 6f2b56f..77a90ba 100644 --- a/common/include/AccessControlList.h +++ b/common/include/AccessControlList.h @@ -17,9 +17,13 @@ #ifndef ACCESSCONTROLLIST_H_ #define ACCESSCONTROLLIST_H_ +/* standard library header */ #include #include +/* SLP library header */ + +/* local header */ #include "ByteArray.h" #include "Channel.h" #include "AccessCondition.h" @@ -38,6 +42,8 @@ namespace smartcard_service_api const ByteArray &hash) const; AccessCondition &getAccessCondition(const ByteArray &aid); + void printAccessControlList() const; + public: static ByteArray ALL_SE_APPS; static ByteArray DEFAULT_SE_APP; @@ -51,6 +57,9 @@ namespace smartcard_service_api int updateACL(Channel *channel) { return loadACL(channel); } void releaseACL(); + /* FIXME ??? */ + inline bool hasConditions() const { return mapConditions.size() > 0; } + virtual bool isAuthorizedAccess(const ByteArray &aid, const ByteArray &certHash) const; virtual bool isAuthorizedAccess(const unsigned char *aidBuffer, diff --git a/common/include/ByteArray.h b/common/include/ByteArray.h index c6e1052..84a8c8f 100644 --- a/common/include/ByteArray.h +++ b/common/include/ByteArray.h @@ -17,11 +17,15 @@ #ifndef BYTEARRAY_H_ #define BYTEARRAY_H_ +/* standard library header */ #include #include #include -#include "Debug.h" +/* SLP library header */ + +/* local header */ +//#include "Serializable.h" #define ARRAY_AND_SIZE(x) (uint8_t *)(&x), sizeof(x) @@ -29,7 +33,7 @@ using namespace std; namespace smartcard_service_api { - class EXPORT ByteArray //: public Serializable + class ByteArray //: public Serializable { protected: uint8_t *buffer; @@ -78,6 +82,7 @@ namespace smartcard_service_api uint8_t operator [](size_t index) const; inline bool isEmpty() const { return (buffer == (void *)0 || length == 0); } + const string toString(bool entire) const; const string toString() const; }; diff --git a/common/include/Channel.h b/common/include/Channel.h index da0b472..8358142 100644 --- a/common/include/Channel.h +++ b/common/include/Channel.h @@ -17,7 +17,11 @@ #ifndef CHANNEL_H_ #define CHANNEL_H_ -#include "Debug.h" +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "Synchronous.h" #include "ByteArray.h" #include "Exception.h" @@ -30,10 +34,11 @@ namespace smartcard_service_api unsigned int length, int error, void *userParam); typedef void (*closeChannelCallback)(int error, void *userParam); - class EXPORT Channel : public Synchronous + class Channel : public Synchronous { protected : ByteArray selectResponse; + ByteArray transmitResponse; SessionHelper *session; int channelNum; @@ -49,6 +54,7 @@ namespace smartcard_service_api inline bool isClosed() const throw() { return (channelNum < 0); } inline const ByteArray getSelectResponse() const throw() { return selectResponse; } + inline const ByteArray getTransmitResponse() const throw() { return transmitResponse; } inline SessionHelper *getSession() const throw() { return session; } virtual int close(closeChannelCallback callback, void *userParam) = 0; diff --git a/common/include/Debug.h b/common/include/Debug.h index edcf921..bb829ef 100644 --- a/common/include/Debug.h +++ b/common/include/Debug.h @@ -17,13 +17,13 @@ #ifndef DEBUG_H_ #define DEBUG_H_ +/* standard library header */ #include +/* SLP library header */ #include "dlog.h" -#ifndef EXPORT -#define EXPORT __attribute__((visibility("default"))) -#endif +/* local header */ #define COLOR_BLACK "\033[0;30m" #define COLOR_RED "\033[0;31m" @@ -66,14 +66,14 @@ #define _BEGIN() \ do \ { \ - LOGD(COLOR_BLUE"BEGIN >>>>"COLOR_END); \ + LOGD(COLOR_BLUE "BEGIN >>>>" COLOR_END); \ } \ while (0) #define _END() \ do \ { \ - LOGD(COLOR_BLUE"END <<<<"COLOR_END); \ + LOGD(COLOR_BLUE "END <<<<" COLOR_END); \ } \ while (0) diff --git a/common/include/EFDIR.h b/common/include/EFDIR.h index 9314fe4..c19eec9 100644 --- a/common/include/EFDIR.h +++ b/common/include/EFDIR.h @@ -17,8 +17,12 @@ #ifndef EFDIR_H_ #define EFDIR_H_ +/* standard library header */ #include +/* SLP library header */ + +/* local header */ #include "FileObject.h" using namespace std; diff --git a/common/include/Exception.h b/common/include/Exception.h index 8b33ae2..cb59d1d 100644 --- a/common/include/Exception.h +++ b/common/include/Exception.h @@ -20,7 +20,6 @@ #include #include -#include "Debug.h" #include "smartcard-types.h" #define THROW_ERROR(errorCode) \ @@ -67,7 +66,7 @@ namespace smartcard_service_api { - class EXPORT ExceptionBase : public std::exception + class ExceptionBase : public std::exception { protected : int errorCode; @@ -84,7 +83,7 @@ namespace smartcard_service_api } }; - class EXPORT ErrorIO : public ExceptionBase + class ErrorIO : public ExceptionBase { private : unsigned char sw[2]; @@ -131,7 +130,7 @@ namespace smartcard_service_api } }; - class EXPORT ErrorSecurity : public ExceptionBase + class ErrorSecurity : public ExceptionBase { public : ErrorSecurity(int errorCode) throw() @@ -157,7 +156,7 @@ namespace smartcard_service_api } }; - class EXPORT ErrorIllegalState : public ExceptionBase + class ErrorIllegalState : public ExceptionBase { public : ErrorIllegalState(int errorCode) throw() @@ -191,7 +190,7 @@ namespace smartcard_service_api } }; - class EXPORT ErrorIllegalParameter : public ExceptionBase + class ErrorIllegalParameter : public ExceptionBase { public : ErrorIllegalParameter(int errorCode) throw() @@ -217,7 +216,7 @@ namespace smartcard_service_api } }; - class EXPORT ThrowError + class ThrowError { public : static void throwError(int errorCode) diff --git a/common/include/FCI.h b/common/include/FCI.h index a0e6d8a..1b303e5 100644 --- a/common/include/FCI.h +++ b/common/include/FCI.h @@ -17,8 +17,12 @@ #ifndef FCI_H_ #define FCI_H_ +/* standard library header */ #include +/* SLP library header */ + +/* local header */ #include "ByteArray.h" namespace smartcard_service_api diff --git a/common/include/FileObject.h b/common/include/FileObject.h index 3f879bb..c377dbf 100644 --- a/common/include/FileObject.h +++ b/common/include/FileObject.h @@ -17,9 +17,12 @@ #ifndef FILEOBJECT_H_ #define FILEOBJECT_H_ +/* standard library header */ #include -#include "Debug.h" +/* SLP library header */ + +/* local header */ #include "ProviderHelper.h" #include "ByteArray.h" #include "FCI.h" @@ -29,7 +32,7 @@ using namespace std; namespace smartcard_service_api { - class EXPORT FileObject : public ProviderHelper + class FileObject : public ProviderHelper { private: FCI fci; @@ -76,7 +79,11 @@ namespace smartcard_service_api int searchRecord(unsigned int sfi, const ByteArray &searchParam, vector &result); int readBinary(unsigned int sfi, unsigned int offset, unsigned int length, ByteArray &result); + int readBinary(unsigned int sfi, unsigned int length, ByteArray &result); int writeBinary(unsigned int sfi, const ByteArray &data, unsigned int offset, unsigned int length); + int writeBinary(unsigned int sfi, const ByteArray &data); + + int readBinaryAll(unsigned int sfi, ByteArray &result); }; } /* namespace smartcard_service_api */ diff --git a/common/include/GDBusHelper.h b/common/include/GDBusHelper.h index 73edb10..a32c269 100644 --- a/common/include/GDBusHelper.h +++ b/common/include/GDBusHelper.h @@ -19,7 +19,6 @@ #include -#include "Debug.h" #include "ByteArray.h" namespace smartcard_service_api @@ -32,7 +31,7 @@ namespace smartcard_service_api void *user_param; }; - class EXPORT GDBusHelper + class GDBusHelper { public : static void convertVariantToByteArray(GVariant *var, diff --git a/common/include/GPACE.h b/common/include/GPACE.h index c69f59f..5300dfd 100644 --- a/common/include/GPACE.h +++ b/common/include/GPACE.h @@ -17,7 +17,11 @@ #ifndef GPACE_H_ #define GPACE_H_ -#include "Debug.h" +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "smartcard-types.h" #ifdef __cplusplus #include "AccessControlList.h" @@ -26,7 +30,7 @@ #ifdef __cplusplus namespace smartcard_service_api { - class EXPORT GPACE : public AccessControlList + class GPACE : public AccessControlList { private : AccessControlList *acl; diff --git a/common/include/GPARAACL.h b/common/include/GPARAACL.h index dbfb5f3..4038b41 100644 --- a/common/include/GPARAACL.h +++ b/common/include/GPARAACL.h @@ -17,6 +17,11 @@ #ifndef GPARAACL_H_ #define GPARAACL_H_ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "smartcard-types.h" #ifdef __cplusplus #include "AccessControlList.h" diff --git a/common/include/GPARAM.h b/common/include/GPARAM.h index 2cf6621..d4b3116 100644 --- a/common/include/GPARAM.h +++ b/common/include/GPARAM.h @@ -17,8 +17,12 @@ #ifndef GPARAM_H_ #define GPARAM_H_ +/* standard library header */ #include +/* SLP library header */ + +/* local header */ #include "FileObject.h" using namespace std; diff --git a/common/include/GPARFACL.h b/common/include/GPARFACL.h index c612e22..396adbe 100644 --- a/common/include/GPARFACL.h +++ b/common/include/GPARFACL.h @@ -17,6 +17,11 @@ #ifndef GPARFACL_H_ #define GPARFACL_H_ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "smartcard-types.h" #ifdef __cplusplus #include "AccessControlList.h" diff --git a/common/include/ISO7816BERTLV.h b/common/include/ISO7816BERTLV.h index 82cb043..d5a0cd7 100644 --- a/common/include/ISO7816BERTLV.h +++ b/common/include/ISO7816BERTLV.h @@ -17,6 +17,11 @@ #ifndef ISO7816BERTLV_H_ #define ISO7816BERTLV_H_ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "ByteArray.h" #include "TLVHelper.h" diff --git a/common/include/Lock.h b/common/include/Lock.h index 0339d08..6328016 100644 --- a/common/include/Lock.h +++ b/common/include/Lock.h @@ -17,13 +17,16 @@ #ifndef LOCK_H_ #define LOCK_H_ -#include +/* standard library header */ -#include "Debug.h" +/* SLP library header */ + +/* local header */ +#include "pthread.h" namespace smartcard_service_api { - class EXPORT Lock + class Lock { public: virtual ~Lock() {}; @@ -46,9 +49,9 @@ namespace smartcard_service_api #define TOKENPASTE(x, y) x ## y #define TOKENPASTE2(x, y) TOKENPASTE(x, y) #define SCOPE_LOCK(X) \ - if (const AutoLockHelper& TOKENPASTE2(lock_, __LINE__) = makeAutoLock(X)) + if (AutoLockHelper TOKENPASTE2(lock_, __LINE__) = makeAutoLock(X)) - class EXPORT AutoLockHelper + class AutoLockHelper { public: inline operator bool() const @@ -58,7 +61,7 @@ namespace smartcard_service_api }; template - class EXPORT AutoLock : public AutoLockHelper + class AutoLock : public AutoLockHelper { private: T *lock; diff --git a/common/include/NumberStream.h b/common/include/NumberStream.h index 26f10e3..74b1f8b 100644 --- a/common/include/NumberStream.h +++ b/common/include/NumberStream.h @@ -17,6 +17,11 @@ #ifndef NUMBERSTREAM_H_ #define NUMBERSTREAM_H_ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "ByteArray.h" namespace smartcard_service_api diff --git a/common/include/OpensslHelper.h b/common/include/OpensslHelper.h index 87b55b0..05cd2c2 100644 --- a/common/include/OpensslHelper.h +++ b/common/include/OpensslHelper.h @@ -14,8 +14,12 @@ * limitations under the License. */ +/* standard library header */ #include +/* SLP library header */ + +/* local header */ #include "ByteArray.h" #ifndef OPENSSLHELPER_H_ diff --git a/common/include/PKCS15.h b/common/include/PKCS15.h index e7bbb7c..568036e 100644 --- a/common/include/PKCS15.h +++ b/common/include/PKCS15.h @@ -17,9 +17,12 @@ #ifndef PKCS15_H_ #define PKCS15_H_ +/* standard library header */ #include -#include "Debug.h" +/* SLP library header */ + +/* local header */ #include "PKCS15Object.h" #include "PKCS15ODF.h" @@ -27,7 +30,7 @@ using namespace std; namespace smartcard_service_api { - class EXPORT PKCS15: public PKCS15Object + class PKCS15: public PKCS15Object { private: map recordElement; @@ -36,7 +39,7 @@ namespace smartcard_service_api int selectFromEFDIR(); public: - static ByteArray PKCS15_AID; + static const ByteArray PKCS15_AID; PKCS15(Channel *channel); PKCS15(Channel *channel, const ByteArray &selectResponse); diff --git a/common/include/PKCS15CDF.h b/common/include/PKCS15CDF.h new file mode 100644 index 0000000..aa9e336 --- /dev/null +++ b/common/include/PKCS15CDF.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PKCS15CDF_H_ +#define PKCS15CDF_H_ + +/* standard library header */ + +/* SLP library header */ + +/* local header */ +#include "PKCS15Object.h" +#include "PKCS15OID.h" + +namespace smartcard_service_api +{ + class CertificateType + { + public : + /* Common Object Attributes */ + string label; + bool modifiable; + + /* Common Certificate Attributes */ + ByteArray id; + int authority; + + /* Certificate Attributes */ + ByteArray path; + int index; + size_t length; + ByteArray certificate; + }; + + class PKCS15CDF : public PKCS15Object + { + private: + vector listCertType; + + bool parseData(const ByteArray &data); + + public: + PKCS15CDF(unsigned int fid, Channel *channel); + PKCS15CDF(const ByteArray &path, Channel *channel); + ~PKCS15CDF(); + + inline size_t getCount() const { return listCertType.size(); } + const CertificateType *getCertificateType(int index) const; + }; + +} /* namespace smartcard_service_api */ +#endif /* PKCS15DODF_H_ */ diff --git a/common/include/PKCS15DODF.h b/common/include/PKCS15DODF.h index 7dfb5ea..9364245 100644 --- a/common/include/PKCS15DODF.h +++ b/common/include/PKCS15DODF.h @@ -17,6 +17,11 @@ #ifndef PKCS15DODF_H_ #define PKCS15DODF_H_ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "PKCS15Object.h" #include "PKCS15OID.h" diff --git a/common/include/PKCS15ODF.h b/common/include/PKCS15ODF.h index 27a1b18..a886f33 100644 --- a/common/include/PKCS15ODF.h +++ b/common/include/PKCS15ODF.h @@ -17,9 +17,14 @@ #ifndef PKCS15ODF_H_ #define PKCS15ODF_H_ +/* standard library header */ #include +/* SLP library header */ + +/* local header */ #include "FileObject.h" +#include "PKCS15CDF.h" #include "PKCS15DODF.h" using namespace std; @@ -29,16 +34,12 @@ namespace smartcard_service_api class PKCS15ODF : public PKCS15Object { private: - bool parseData(const ByteArray &data); + PKCS15CDF *cdf; PKCS15DODF *dodf; - public: - static const unsigned int ODF_FID = 0x3150; - - static const unsigned int TAG_DODF = (unsigned int)0xA7; - static const unsigned int TAG_TOKENINFO = (unsigned int)0xA5; + bool parseData(const ByteArray &data); -// PKCS15ODF(); + public: PKCS15ODF(Channel *channel); PKCS15ODF(Channel *channel, const ByteArray &selectResponse); ~PKCS15ODF(); @@ -46,9 +47,10 @@ namespace smartcard_service_api int getPuKDFPath(ByteArray &path); int getPrKDFPath(ByteArray &path); int getAODFPath(ByteArray &path); - int getCDFFPath(ByteArray &path); + int getCDFPath(ByteArray &path); int getDODFPath(ByteArray &path); + PKCS15CDF *getCDF(); PKCS15DODF *getDODF(); }; diff --git a/common/include/PKCS15OID.h b/common/include/PKCS15OID.h index 9ba3073..248150b 100644 --- a/common/include/PKCS15OID.h +++ b/common/include/PKCS15OID.h @@ -17,6 +17,11 @@ #ifndef PKCS15OID_H_ #define PKCS15OID_H_ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "ByteArray.h" namespace smartcard_service_api diff --git a/common/include/PKCS15Object.h b/common/include/PKCS15Object.h index e5d78d2..df76f72 100644 --- a/common/include/PKCS15Object.h +++ b/common/include/PKCS15Object.h @@ -17,9 +17,13 @@ #ifndef PKCS15OBJECT_H_ #define PKCS15OBJECT_H_ +/* standard library header */ #include #include +/* SLP library header */ + +/* local header */ #include "FileObject.h" #include "PKCS15Path.h" diff --git a/common/include/PKCS15Path.h b/common/include/PKCS15Path.h index b5a964b..52f3894 100644 --- a/common/include/PKCS15Path.h +++ b/common/include/PKCS15Path.h @@ -17,6 +17,11 @@ #ifndef PKCS15Path_H_ #define PKCS15Path_H_ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "ByteArray.h" namespace smartcard_service_api diff --git a/common/include/PKCS15TokenInfo.h b/common/include/PKCS15TokenInfo.h index 5ebba70..9f3ff80 100644 --- a/common/include/PKCS15TokenInfo.h +++ b/common/include/PKCS15TokenInfo.h @@ -17,6 +17,11 @@ #ifndef PKCS15TOKENINFO_H_ #define PKCS15TOKENINFO_H_ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "PKCS15Object.h" namespace smartcard_service_api diff --git a/common/include/ProviderHelper.h b/common/include/ProviderHelper.h index 2c004ea..7418b6c 100644 --- a/common/include/ProviderHelper.h +++ b/common/include/ProviderHelper.h @@ -17,6 +17,11 @@ #ifndef PROVIDERHELPER_H_ #define PROVIDERHELPER_H_ +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "Channel.h" namespace smartcard_service_api diff --git a/common/include/ReaderHelper.h b/common/include/ReaderHelper.h index e3c0b8d..259044a 100644 --- a/common/include/ReaderHelper.h +++ b/common/include/ReaderHelper.h @@ -17,10 +17,13 @@ #ifndef READERHELPER_H_ #define READERHELPER_H_ +/* standard library header */ #include #include -#include "Debug.h" +/* SLP library header */ + +/* local header */ #include "Synchronous.h" #include "SessionHelper.h" @@ -33,7 +36,7 @@ namespace smartcard_service_api typedef void (*openSessionCallback)(SessionHelper *session, int error, void *userData); - class EXPORT ReaderHelper : public Synchronous + class ReaderHelper : public Synchronous { protected: SEServiceHelper *seService; diff --git a/common/include/SEServiceHelper.h b/common/include/SEServiceHelper.h index 999c293..4afbfcb 100644 --- a/common/include/SEServiceHelper.h +++ b/common/include/SEServiceHelper.h @@ -17,9 +17,12 @@ #ifndef SESERVICEHELPER_H_ #define SESERVICEHELPER_H_ +/* standard library header */ #include -#include "Debug.h" +/* SLP library header */ + +/* local header */ #include "Synchronous.h" #include "ReaderHelper.h" @@ -27,7 +30,7 @@ using namespace std; namespace smartcard_service_api { - class EXPORT SEServiceHelper : public Synchronous + class SEServiceHelper : public Synchronous { protected: vector readers; diff --git a/common/include/Serializable.h b/common/include/Serializable.h index 98ada48..a138cd6 100644 --- a/common/include/Serializable.h +++ b/common/include/Serializable.h @@ -17,12 +17,11 @@ #ifndef SERIALIZABLE_H_ #define SERIALIZABLE_H_ -#include "Debug.h" #include "ByteArray.h" namespace smartcard_service_api { - class EXPORT Serializable + class Serializable { virtual const ByteArray serialize() const = 0; virtual void deserialize(const ByteArray &buffer) = 0; diff --git a/common/include/SessionHelper.h b/common/include/SessionHelper.h index 513790e..3e220e6 100644 --- a/common/include/SessionHelper.h +++ b/common/include/SessionHelper.h @@ -17,9 +17,12 @@ #ifndef SESSIONHELPER_H_ #define SESSIONHELPER_H_ +/* standard library header */ #include -#include "Debug.h" +/* SLP library header */ + +/* local header */ #include "Synchronous.h" #include "ByteArray.h" #include "Channel.h" @@ -35,7 +38,7 @@ namespace smartcard_service_api typedef void (*closeSessionCallback)(int error, void *userData); typedef void (*getChannelCountCallback)(unsigned count, int error, void *userData); - class EXPORT SessionHelper : public Synchronous + class SessionHelper : public Synchronous { protected: ReaderHelper *reader; @@ -85,6 +88,22 @@ namespace smartcard_service_api virtual Channel *openLogicalChannelSync(const unsigned char *aid, unsigned int length) throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &, ErrorIllegalParameter &, ErrorSecurity &) = 0; + + virtual Channel *openBasicChannelSync(const ByteArray &aid, unsigned char P2) + throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &, + ErrorIllegalParameter &, ErrorSecurity &) = 0; + + virtual Channel *openBasicChannelSync(const unsigned char *aid, unsigned int length, unsigned char P2) + throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &, + ErrorIllegalParameter &, ErrorSecurity &) = 0; + + virtual Channel *openLogicalChannelSync(const ByteArray &aid, unsigned char P2) + throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &, + ErrorIllegalParameter &, ErrorSecurity &) = 0; + + virtual Channel *openLogicalChannelSync(const unsigned char *aid, unsigned int length, unsigned char P2) + throw(ExceptionBase &, ErrorIO &, ErrorIllegalState &, + ErrorIllegalParameter &, ErrorSecurity &) = 0; }; } /* namespace smartcard_service_api */ diff --git a/common/include/SignatureHelper.h b/common/include/SignatureHelper.h index 65e9b26..f65844c 100644 --- a/common/include/SignatureHelper.h +++ b/common/include/SignatureHelper.h @@ -17,29 +17,32 @@ #ifndef SIGNATUREHELPER_H_ #define SIGNATUREHELPER_H_ +/* standard library header */ #ifdef __cplusplus #include -#include "ByteArray.h" #endif /* __cplusplus */ -#include +/* SLP library header */ -#include "Debug.h" +/* local header */ #include "smartcard-types.h" +#ifdef __cplusplus +#include "ByteArray.h" +#endif /* __cplusplus */ #ifdef __cplusplus using namespace std; namespace smartcard_service_api { - class EXPORT SignatureHelper + class SignatureHelper { public: static int getPackageName(int pid, char *package, size_t length); - static const ByteArray getCertificationHash(const char *packageName, uid_t uid); + static const ByteArray getCertificationHash(const char *packageName); static const ByteArray getCertificationHash(int pid); static bool getCertificationHashes(int pid, vector &certHashes); - static bool getCertificationHashes(const char *packageName, vector &certHashes, uid_t uid); + static bool getCertificationHashes(const char *packageName, vector &certHashes); }; } /* namespace smartcard_service_api */ diff --git a/common/include/Synchronous.h b/common/include/Synchronous.h index c228171..479b902 100644 --- a/common/include/Synchronous.h +++ b/common/include/Synchronous.h @@ -17,13 +17,16 @@ #ifndef SYNCHRONOUS_H_ #define SYNCHRONOUS_H_ +/* standard library header */ #include -#include "Debug.h" +/* SLP library header */ + +/* local header */ namespace smartcard_service_api { - class EXPORT Synchronous + class Synchronous { protected: pthread_mutex_t syncMutex; diff --git a/common/include/Terminal.h b/common/include/Terminal.h index 0e3db4a..c26003a 100644 --- a/common/include/Terminal.h +++ b/common/include/Terminal.h @@ -17,7 +17,11 @@ #ifndef TERMINAL_H_ #define TERMINAL_H_ -#include "Debug.h" +/* standard library header */ + +/* SLP library header */ + +/* local header */ #include "ByteArray.h" #include "Synchronous.h" @@ -28,7 +32,7 @@ namespace smartcard_service_api typedef void (*terminalTransmitCallback)(const unsigned char *buffer, unsigned int length, int error, void *userParam); typedef void (*terminalGetATRCallback)(const unsigned char *buffer, unsigned int length, int error, void *userParam); - class EXPORT Terminal : public Synchronous + class Terminal : public Synchronous { protected: terminalNotificationCallback statusCallback; diff --git a/common/include/TerminalInterface.h b/common/include/TerminalInterface.h index 47d7171..311b43a 100644 --- a/common/include/TerminalInterface.h +++ b/common/include/TerminalInterface.h @@ -17,6 +17,12 @@ #ifndef TERMINALINTERFACE_H_ #define TERMINALINTERFACE_H_ +/* standard library header */ + +/* SLP library header */ + +/* local header */ + //typedef unsigned int terminal_handle_h; // //typedef enum diff --git a/common/smartcard-service-common.pc b/common/smartcard-service-common.pc new file mode 100644 index 0000000..0c1c83a --- /dev/null +++ b/common/smartcard-service-common.pc @@ -0,0 +1,13 @@ +# Package Information for pkg-config + +prefix=/usr +exec_prefix=${prefix}/bin +includedir=${prefix}/include +libdir=${prefix}/lib + +Name: smartcard-service-common +Description: Make flags of Common library of Smartcard service +Version: 1.0 +Requires: glib-2.0 dlog +Libs: -L${libdir} -lsmartcard-service-common +Cflags: -I${includedir}/smartcard-service-common \ No newline at end of file diff --git a/common/smartcard-service-common.pc.in b/common/smartcard-service-common.pc.in deleted file mode 100644 index 7eba9e2..0000000 --- a/common/smartcard-service-common.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix}/bin -libdir=@LIB_INSTALL_DIR@ -includedir=@INCLUDE_INSTALL_DIR@/@COMMON_LIB@ - -Name: @COMMON_LIB@ -Description: Common library of Smartcard service -Version: @FULLVER@ -Requires: glib-2.0 dlog -Libs: -L${libdir} -l@COMMON_LIB@ -Cflags: -I${includedir} diff --git a/common/smartcard-service-gdbus.xml b/common/smartcard-service-gdbus.xml index cc8b21a..e98e9d0 100755 --- a/common/smartcard-service-gdbus.xml +++ b/common/smartcard-service-gdbus.xml @@ -68,8 +68,10 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/server/smartcard-daemon.cpp b/server/smartcard-daemon.cpp index cb9c75f..3c2890a 100644 --- a/server/smartcard-daemon.cpp +++ b/server/smartcard-daemon.cpp @@ -123,6 +123,12 @@ int main(int argc, char *argv[]) daemonize(); #endif + if (!g_thread_supported()) { + g_thread_init(NULL); + } + + g_type_init(); + main_loop = g_main_new(TRUE); id = g_bus_own_name(G_BUS_TYPE_SYSTEM, diff --git a/server/smartcard-service-server.xml b/server/smartcard-service-server.xml index 82c673a..fe64adb 100644 --- a/server/smartcard-service-server.xml +++ b/server/smartcard-service-server.xml @@ -1,15 +1,11 @@ - + Sangsoo Lee Wonkyu Kwon Smartcard Service Server + + + + + diff --git a/smartcard-service-common.manifest b/smartcard-service-common.manifest new file mode 100644 index 0000000..ca37499 --- /dev/null +++ b/smartcard-service-common.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/smartcard-service-devel.manifest b/smartcard-service-devel.manifest new file mode 100644 index 0000000..ca37499 --- /dev/null +++ b/smartcard-service-devel.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/smartcard-service-server.manifest b/smartcard-service-server.manifest new file mode 100644 index 0000000..8a64a46 --- /dev/null +++ b/smartcard-service-server.manifest @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/smartcard-service.manifest b/smartcard-service.manifest new file mode 100644 index 0000000..ca37499 --- /dev/null +++ b/smartcard-service.manifest @@ -0,0 +1,6 @@ + + + + + + diff --git a/test-client/CMakeLists.txt b/test-client/CMakeLists.txt index 05b2d24..434f147 100644 --- a/test-client/CMakeLists.txt +++ b/test-client/CMakeLists.txt @@ -1,23 +1,48 @@ -LINK_DIRECTORIES(${CMAKE_BINARY_DIR}) -INCLUDE_DIRECTORIES(include) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/common/include) -INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/client/include) +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) + +PROJECT(smartcard-test-client CXX) + +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common/include) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../client/include) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) #AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ SRCS) SET(SRCS "${CMAKE_CURRENT_SOURCE_DIR}/test-client-sync.cpp") #SET(SRCS "${CMAKE_CURRENT_SOURCE_DIR}/test-client.cpp") +IF("${CMAKE_BUILD_TYPE}" STREQUAL "") + SET(CMAKE_BUILD_TYPE "Release") +ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") + +INCLUDE(FindPkgConfig) pkg_check_modules(pkgs_test_client REQUIRED glib-2.0 dlog) + FOREACH(flag ${pkgs_test_client_CFLAGS}) SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${flag}") ENDFOREACH(flag) -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS}") MESSAGE("CHECK MODULE in ${PROJECT_NAME} ${pkgs_test_client_LDFLAGS}") +# this for NFC flag + +SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} -pipe -fomit-frame-pointer -Wall -Wno-trigraphs -fno-strict-aliasing -Wl,-zdefs -fvisibility=hidden -std=c++0x") +SET(ARM_CXXFLAGS "${ARM_CXXLAGS} -mapcs -mno-sched-prolog -mabi=aapcs-linux -Uarm -fno-common -fpic") +SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CXXFLAGS}") +SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +FIND_PROGRAM(UNAME NAMES uname) +EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") +IF("${ARCH}" MATCHES "^arm.*") + ADD_DEFINITIONS("-DTARGET") + MESSAGE("add -DTARGET") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARM_CXXFLAGS}") +ENDIF() + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +#ADD_DEFINITIONS("-DSLP_DEBUG") ADD_DEFINITIONS("-DLOG_TAG=\"SMARTCARD_SERVICE_TEST\"") ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_test_client_LDFLAGS} ${COMMON_LIB} ${CLIENT_LIB}) - -INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_test_client_LDFLAGS} "-L../common" "-lsmartcard-service-common" "-L../client" "-lsmartcard-service" "-pie -ldl") +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/apps/smartcard-service-server/bin) -- 2.7.4