summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt149
-rw-r--r--LICENSE (renamed from LICENSE.APLv2)0
-rw-r--r--LICENSE.BSL-1.023
-rw-r--r--NOTICE4
-rw-r--r--cryptsvc.pc.in10
-rw-r--r--gadget/CMakeLists.txt40
-rw-r--r--gadget/duid-gadget.c54
-rw-r--r--[-rwxr-xr-x]include/SecCryptoSvc.h6
-rw-r--r--[-rwxr-xr-x]include/SecTzSvc.h0
-rw-r--r--packaging/libcryptsvc.changes9
-rw-r--r--[-rwxr-xr-x]packaging/libcryptsvc.spec57
-rw-r--r--[-rwxr-xr-x]srcs/SecCryptoSvc.c0
-rw-r--r--test/CMakeLists.txt32
-rw-r--r--test/colour_log_formatter.cc264
-rw-r--r--test/colour_log_formatter.h59
-rw-r--r--test/cs_test.cc64
-rw-r--r--test/device_info_test.cc42
-rw-r--r--test/main.cc42
18 files changed, 668 insertions, 187 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2cb8477..d030472 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,123 +1,90 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(cryptsvc C)
-
-SET(PREFIX ${CMAKE_INSTALL_PREFIX})
-SET(EXEC_PREFIX "\${prefix}")
-SET(INCLUDEDIR "\${prefix}/include")
-
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
-
-SET(pc_requires " openssl dlog libcrypto capi-system-info")
+PROJECT(cryptsvc)
INCLUDE(FindPkgConfig)
-pkg_check_modules(pkgs REQUIRED ${pc_requires})
-FOREACH(flag ${pkgs_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
+STRING(REGEX MATCH "([^.]*)" SO_VERSION "${VERSION}")
-SET(source_dir "./srcs")
-SET(include_dir "./include")
-SET(test_dir "./test")
+SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} -std=c++0x")
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_C_FLAGS_PROFILING "-g -O0 -pg -Wp,-U_FORITY_SOURCE")
+SET(CMAKE_CXX_FLAGS_PROFILING "-g -O0 -pg -Wp,-U_FORITY_SOURCE ${EXTRA_CXXFLAGS}")
+SET(CMAKE_C_FLAGS_DEBUG "-g -O0 -ggdb -Wp,-U_FORITY_SOURCE")
+SET(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -ggdb -Wp,-U_FORITY_SOURCE ${EXTRA_CXXFLAGS}")
+SET(CMAKE_C_FLAGS_RELEASE "-g -O2")
+SET(CMAKE_CXX_FLAGS_RELEASE "-g -O2 ${EXTRA_CXXFLAGS}")
-#ADD_DEFINITIONS("-DCTR_SUPPORT") # for using CTR mode
-#ADD_DEFINITIONS("-DCRYPT_SVC_LOG") # for debug
-#ADD_DEFINITIONS("-DCRYPTOSVC_TARGET") # to get DUK from Target
+SET(TARGET_CRYPTSVC ${PROJECT_NAME})
+SET(TARGET_DEVICE_INFO "device_info")
+SET(TARGET_GADGET "duid-gadget")
-##################################################################################################################
-# for libcryptsvc.so
-SET(SRCS
- ${source_dir}/SecCryptoSvc.c
-)
+IF("${ARCH}" MATCHES "arm")
+ ADD_DEFINITIONS("-DCRYPTOSVC_TARGET")
+ENDIF("${ARCH}" MATCHES "arm")
-SET(libcryptsvc_LDFLAGS "${pkgs_LDFLAGS}")
-SET(libcryptsvc_CFLAGS " ${CFLAGS} -fvisibility=hidden -g -fPIC -I${CMAKE_CURRENT_SOURCE_DIR}/include ")
-SET(libcryptsvc_CPPFLAGS " -DPIC ")
+########################################################################################
+# for libcryptsvc.so
+SET(CRYPTSVC_REQUIRES "libcrypto dlog")
+SET(DEVICE_INFO_REQUIRES "dlog capi-system-info")
+PKG_CHECK_MODULES(CS_DEP REQUIRED ${CRYPTSVC_REQUIRES})
-ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
+SET(CS_SRCS srcs/SecCryptoSvc.c)
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${libcryptsvc_LDFLAGS})
+INCLUDE_DIRECTORIES(
+ ${CS_DEP_INCLUDE_DIRS}
+ ${PROJECT_SOURCE_DIR}/include
+)
-IF("${ARCH}" MATCHES "arm")
-TARGET_LINK_LIBRARIES(${PROJECT_NAME})
-ENDIF("${ARCH}" MATCHES "arm")
+ADD_LIBRARY(${TARGET_CRYPTSVC} SHARED ${CS_SRCS})
SET_TARGET_PROPERTIES(
- ${PROJECT_NAME}
- PROPERTIES
- VERSION ${FULLVER}
- SOVERSION ${MAJORVER}
+ ${TARGET_CRYPTSVC}
+ PROPERTIES
+ COMPILE_FLAGS "-fPIC -fvisibility=hidden"
+ SOVERSION ${SO_VERSION}
+ VERSION ${VERSION}
)
-##################################################################################################################
-##################################################################################################################
-# for libdevice_info.so
-SET(SRCS_DEVICE_INFO
- ${source_dir}/device_info.c
-)
+TARGET_LINK_LIBRARIES(${TARGET_CRYPTSVC} ${CS_DEP_LIBRARIES})
-SET(libdevice_info_LDFLAGS "${pkgs_LDFLAGS}")
-SET(libdevice_info_CFLAGS " ${CFLAGS} ${CMAKE_C_FLAGS} -fvisibility=hidden -g -fPIC -I${CMAKE_CURRENT_SOURCE_DIR}/include ")
-SET(libdevice_info_CPPFLAGS " -DPIC ")
+INSTALL(TARGETS ${TARGET_CRYPTSVC} DESTINATION ${LIB_INSTALL_DIR})
-SET(LIBDEVICE_INFO_SO "device_info")
-ADD_LIBRARY(${LIBDEVICE_INFO_SO} SHARED ${SRCS_DEVICE_INFO})
+#########################################################################################
+# for libdevice_info.so
+PKG_CHECK_MODULES(DEVICE_INFO_DEP REQUIRED ${DEVICE_INFO_REQUIRES})
-TARGET_LINK_LIBRARIES(${LIBDEVICE_INFO_SO} ${libdevice_info_LDFLAGS} cryptsvc)
+SET(DEVICE_INFO_SRCS srcs/device_info.c)
-IF("${ARCH}" MATCHES "arm")
-TARGET_LINK_LIBRARIES(${LIBDEVICE_INFO_SO})
-ENDIF("${ARCH}" MATCHES "arm")
+INCLUDE_DIRECTORIES(
+ ${DEVICE_INFO_DEP_INCLUDE_DIRS}
+ ${CMAKE_CURRENT_SOURCE_DIR}/include
+)
+ADD_LIBRARY(${TARGET_DEVICE_INFO} SHARED ${DEVICE_INFO_SRCS})
SET_TARGET_PROPERTIES(
- ${LIBDEVICE_INFO_SO}
+ ${TARGET_DEVICE_INFO}
PROPERTIES
- VERSION ${FULLVER}
- SOVERSION ${MAJORVER}
+ COMPILE_FLAGS "-fPIC -fvisibility=hidden"
+ SOVERSION ${SO_VERSION}
+ VERSION ${VERSION}
)
-##################################################################################################################
+TARGET_LINK_LIBRARIES(${TARGET_DEVICE_INFO}
+ ${TARGET_CRYPTSVC}
+ ${DEVICE_INFO_DEP_LIBRARIES}
+ -lpthread
+)
-##################################################################################################################
-# for module_test
-#SET(module_test_SOURCES
- #${test_dir}/module_test.c
- #${source_dir}/CryptoSvc-debug.c
-#)
-
-#SET(module_test_CFLAGS " -fvisibility=hidden -I. -I${CMAKE_CURRENT_SOURCE_DIR}/include ")
-#SET(module_test_LDFALGS " -module -avoid-version ${pkgs_LDFLAGS} ")
-
-#ADD_EXECUTABLE(${test_dir}/module_test ${module_test_SOURCES})
-#TARGET_LINK_LIBRARIES(${test_dir}/module_test ${pkgs_LDFLAGS} cryptsvc)
-#SET_TARGET_PROPERTIES(${test_dir}/module_test PROPERTIES COMPILE_FLAGS "${module_test_CFLAGS} ")
-##################################################################################################################
-
-#FIND_PROGRAM(UNAME NAMES uname)
-#EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
-IF("${ARCH}" MATCHES "arm")
- #ADD_DEFINITIONS("-DTARGET")
- ADD_DEFINITIONS("-DCRYPTOSVC_TARGET")
- ADD_DEFINITIONS("-DCRYPTOSVC_TZ")
- #MESSAGE("add -DTARGET")
-ENDIF("${ARCH}" MATCHES "arm")
+INSTALL(TARGETS ${TARGET_DEVICE_INFO} DESTINATION ${LIB_INSTALL_DIR})
-SET(PC_NAME ${PROJECT_NAME})
-SET(PC_DESCRIPTION ${DESCRIPTION})
-SET(PC_LDFLAGS " -l${PROJECT_NAME} ")
-SET(PC_REQUIRED ${pc_requires})
-CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY)
+#########################################################################################
-INSTALL(FILES ${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR})
-INSTALL(TARGETS ${LIBDEVICE_INFO_SO} DESTINATION ${LIB_INSTALL_DIR})
-INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${INCLUDEDIR})
+SET(PC_REQUIRED ${CRYPTSVC_REQUIRES})
+CONFIGURE_FILE(${TARGET_CRYPTSVC}.pc.in ${TARGET_CRYPTSVC}.pc @ONLY)
-ADD_DEFINITIONS(-D_bool_cryptsvc)
+INSTALL(FILES ${TARGET_CRYPTSVC}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${INCLUDE_INSTALL_DIR})
ADD_SUBDIRECTORY(gadget)
+ADD_SUBDIRECTORY(test)
diff --git a/LICENSE.APLv2 b/LICENSE
index 1b461a0..1b461a0 100644
--- a/LICENSE.APLv2
+++ b/LICENSE
diff --git a/LICENSE.BSL-1.0 b/LICENSE.BSL-1.0
new file mode 100644
index 0000000..36b7cd9
--- /dev/null
+++ b/LICENSE.BSL-1.0
@@ -0,0 +1,23 @@
+Boost Software License - Version 1.0 - August 17th, 2003
+
+Permission is hereby granted, free of charge, to any person or organization
+obtaining a copy of the software and accompanying documentation covered by
+this license (the "Software") to use, reproduce, display, distribute,
+execute, and transmit the Software, and to prepare derivative works of the
+Software, and to permit third-parties to whom the Software is furnished to
+do so, all subject to the following:
+
+The copyright notices in the Software and this entire statement, including
+the above license grant, this restriction and the following disclaimer,
+must be included in all copies of the Software, in whole or in part, and
+all derivative works of the Software, unless such copies or derivative
+works are solely in the form of machine-executable object code generated by
+a source language processor.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
diff --git a/NOTICE b/NOTICE
deleted file mode 100644
index bfc3f5d..0000000
--- a/NOTICE
+++ /dev/null
@@ -1,4 +0,0 @@
-Copyright (c) Samsung Electronics Co., Ltd. All rights reserved.
-Except as noted, this software is licensed under Apache License, Version 2.
-Please, see the LICENSE.APLv2 file for Apache License terms and conditions.
-
diff --git a/cryptsvc.pc.in b/cryptsvc.pc.in
index be4fe2f..fef725f 100644
--- a/cryptsvc.pc.in
+++ b/cryptsvc.pc.in
@@ -1,13 +1,13 @@
# Package Information for pkg-config
-prefix=@PREFIX@
+prefix=@CMAKE_INSTALL_PREFIX@
libdir=@LIB_INSTALL_DIR@
-includedir=@INCLUDE_INSTALL_DIR@
+includedir=${prefix}/include
-Name: @PC_NAME@
+Name: cryptsvc
Description: @DESCRIPTION@
-Version: @FULLVER@
+Version: @VERSION@
Requires: @PC_REQUIRED@
-Libs: -L${libdir} @PC_LDFLAGS@
+Libs: -L${libdir} -lcryptsvc
Cflags: -I${includedir}
diff --git a/gadget/CMakeLists.txt b/gadget/CMakeLists.txt
index dcb40c9..0a9b713 100644
--- a/gadget/CMakeLists.txt
+++ b/gadget/CMakeLists.txt
@@ -1,28 +1,34 @@
-SET(GADGET duid-gadget)
+PKG_CHECK_MODULES(GADGET_DEP REQUIRED ${CRYPTSVC_REQUIRES})
+
SET(GADGET_SRCS
- duid-gadget.c
- ../srcs/SecCryptoSvc.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/duid-gadget.c
+ ${PROJECT_SOURCE_DIR}/srcs/SecCryptoSvc.c
)
SET(GADGET_VENDOR samsung)
SET(GADGET_DIR ${TZ_SYS_ETC})
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+INCLUDE_DIRECTORIES(
+ ${GADGET_DEP_INCLUDE_DIRS}
+ ${CMAKE_CURRENT_SOURCE_DIR}
+)
-INCLUDE(FindPkgConfig)
-PKG_CHECK_MODULES(GADGET_PKGS REQUIRED dlog openssl)
+SET(GADGET_CFLAGS "${GADGET_DEP_CFLAGS} -fPIE")
+SET(GADGET_CFLAGS "${GADGET_CFLAGS} -DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
+SET(GADGET_CFLAGS "${GADGET_CFLAGS} -DVENDOR=\"${GADGET_VENDOR}\"")
+SET(GADGET_CFLAGS "${GADGET_CFLAGS} -DAPP_NAME=\"${TARGET_GADGET}\"")
+SET(GADGET_CFLAGS "${GADGET_CFLAGS} -DAPP_DIR=\"${GADGET_DIR}\"")
-FOREACH(flag ${GADGET_PKGS_CFLAGS})
- SET(GADGET_CFLAGS "${GADGET_CFLAGS} ${flag} -fPIE")
-ENDFOREACH(flag)
+ADD_EXECUTABLE(${TARGET_GADGET} ${GADGET_SRCS})
-SET(GADGET_CFLAGS, "${GADGET_CFLAGS} -DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
-SET(GADGET_CFLAGS, "${GADGET_CFLAGS} -DVENDOR=\"${GADGET_VENDOR}\"")
-SET(GADGET_CFLAGS, "${GADGET_CFLAGS} -DAPP_NAME=\"${GADGET}\"")
-SET(GADGET_CFLAGS, "${GADGET_CFLAGS} -DAPP_DIR=\"${GADGET_DIR}\"")
+SET_TARGET_PROPERTIES(${TARGET_GADGET}
+ PROPERTIES
+ COMPILE_FLAGS "${GADGET_CFLAGS}"
+)
-ADD_EXECUTABLE(${GADGET} ${GADGET_SRCS})
-SET_TARGET_PROPERTIES(${GADGET} PROPERTIES COMPILE_FLAGS "${GADGET_CFLAGS}")
-TARGET_LINK_LIBRARIES(${GADGET} ${GADGET_PKGS_LDFLAGS} -pie)
+TARGET_LINK_LIBRARIES(${TARGET_GADGET}
+ ${GADGET_DEP_LDFLAGS}
+ -pie
+)
-INSTALL(TARGETS ${GADGET} DESTINATION ${GADGET_DIR} )
+INSTALL(TARGETS ${TARGET_GADGET} DESTINATION ${GADGET_DIR})
diff --git a/gadget/duid-gadget.c b/gadget/duid-gadget.c
index 48ff6f6..799b926 100644
--- a/gadget/duid-gadget.c
+++ b/gadget/duid-gadget.c
@@ -1,6 +1,5 @@
/*
- *
- * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,56 +17,21 @@
#include <stdio.h>
#include <stdlib.h>
-#include <string.h>
-
-#include <openssl/evp.h>
-#include <openssl/rand.h>
#include <SecCryptoSvc.h>
int main()
{
- const char *version = "1.0#";
- char info[] = {0xca, 0xfe, 0xbe, 0xbe, 0x78, 0x07, 0x02, 0x03};
-
- int ret = 0;
- int keyLen = 20;
- unsigned char *pKey = NULL;
- unsigned char *pDuid = NULL;
- char *pId = NULL;
- char *pKeyVersion = NULL;
-
- if (!(pKey = (unsigned char *)malloc(keyLen)))
- goto exit;
-
- if (!SecFrameGeneratePlatformUniqueKey(keyLen, pKey)) {
- fprintf(stderr, "Failed to get duid\n");
- goto exit;
- }
+ char *duid = GetDuid(20);
- if (!(pDuid = (unsigned char *)malloc(keyLen)))
- goto exit;
+ if (duid == NULL) {
+ fprintf(stderr, "Failed to get duid\n");
+ return 0;
+ }
- PKCS5_PBKDF2_HMAC_SHA1(info, 8, pKey, keyLen, 1, keyLen, pDuid);
+ printf("%s", duid);
- if (!(pId = Base64Encoding((char *)pDuid, keyLen)))
- goto exit;
+ free(duid);
- if (!(pKeyVersion = (char *)calloc(strlen(pId) + strlen(version) + 1, sizeof(char))))
- goto exit;
-
- strncpy(pKeyVersion, version, strlen(version));
- strncat(pKeyVersion, pId, strlen(pId));
- printf("%s", pKeyVersion);
-
- ret = 1;
-
-exit:
- free(pKey);
- free(pDuid);
- free(pId);
- free(pKeyVersion);
-
- return ret;
+ return 1;
}
-
diff --git a/include/SecCryptoSvc.h b/include/SecCryptoSvc.h
index 94182f5..7939d01 100755..100644
--- a/include/SecCryptoSvc.h
+++ b/include/SecCryptoSvc.h
@@ -25,6 +25,8 @@ extern "C"
{
#endif
+#include <stdbool.h>
+
//#ifdef OPENSSL_NO_ENGINE
//#error Do not use define <OPENSSL_NO_ENGINE>
//#else
@@ -56,10 +58,6 @@ typedef enum
SEC_CRYPTO_ERROR_7, //Internal error
} SecError;
*/
-//#ifndef bool
-#ifdef _bool_cryptsvc
-typedef enum {false, true} bool;
-#endif
#ifndef IN
#define IN
diff --git a/include/SecTzSvc.h b/include/SecTzSvc.h
index 5ac5886..5ac5886 100755..100644
--- a/include/SecTzSvc.h
+++ b/include/SecTzSvc.h
diff --git a/packaging/libcryptsvc.changes b/packaging/libcryptsvc.changes
deleted file mode 100644
index ea23bf9..0000000
--- a/packaging/libcryptsvc.changes
+++ /dev/null
@@ -1,9 +0,0 @@
-* Wed May 29 2013 Anas Nashif <anas.nashif@intel.com> accepted/tizen/20130529.151307@6017f13
-- Fixed package metadata and description
-
-* Wed May 29 2013 Xavier Roche <xavrock.os@gmail.com> accepted/tizen/20130520.103533@7632f8e
-- Fix hardcoded library path for 64b compatibility
-
-* Sat May 18 2013 Anas Nashif <anas.nashif@intel.com> submit/tizen/20130517.045135@2c7d7e2
-- -avoid-version not recognised by compiler
-
diff --git a/packaging/libcryptsvc.spec b/packaging/libcryptsvc.spec
index fd8cb95..a7d11b7 100755..100644
--- a/packaging/libcryptsvc.spec
+++ b/packaging/libcryptsvc.spec
@@ -1,14 +1,14 @@
-Name: libcryptsvc
+Name: libcryptsvc
Summary: Crypto Service Library
Version: 0.0.1
Release: 6
Group: Security/Libraries
-License: Apache-2.0
+License: Apache-2.0 and BSL-1.0
Source0: %{name}-%{version}.tar.gz
Source1001: libcryptsvc.manifest
BuildRequires: cmake
BuildRequires: pkgconfig(dlog)
-BuildRequires: pkgconfig(openssl)
+BuildRequires: pkgconfig(libcrypto)
BuildRequires: pkgconfig(capi-system-info)
BuildRequires: pkgconfig(libtzplatform-config)
@@ -18,23 +18,50 @@ Crypto Service Library.
%package devel
Summary: Crypto Service Library (Development)
Group: Security/Libraries
-Requires: %{name} = %{version}-%{release}
+Requires: %{name} = %{version}-%{release}
%description devel
Crypto Service Library (Development).
+%package test
+Summary: Testing for Crypto Service
+Group: Security/Testing
+BuildRequires: boost-devel
+Requires: boost-test
+Requires: %{name} = %{version}-%{release}
+
+%description test
+Testing for Crypto Service.
+
%prep
%setup -q
cp %{SOURCE1001} .
%build
-MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
+export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE"
+export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE"
+
+export CFLAGS="$CFLAGS -DTIZEN_ENGINEER_MODE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_ENGINEER_MODE"
+export FFLAGS="$FFLAGS -DTIZEN_ENGINEER_MODE"
+
+%ifarch %ix86
+export CFLAGS="$CFLAGS -DTIZEN_EMULATOR_MODE"
+export CXXFLAGS="$CXXFLAGS -DTIZEN_EMULATOR_MODE"
+export FFLAGS="$FFLAGS -DTIZEN_EMULATOR_MODE"
+%endif
+
+%{!?build_type:%define build_type "Release"}
+%cmake . \
+ -DCMAKE_BUILD_TYPE=%build_type \
%ifarch %ix86 x86_64
-%cmake . -DARCH=x86 \
+ -DARCH=x86 \
%else
-%cmake . -DARCH=arm \
+ -DARCH=arm \
%endif
- -DFULLVER=%{version} -DMAJORVER=${MAJORVER} -DDESCRIPTION="%{summary}" \
+ -DVERSION=%version \
+ -DDESCRIPTION="%summary" \
-DTZ_SYS_ETC=%TZ_SYS_ETC
make %{?jobs:-j%jobs}
@@ -49,11 +76,17 @@ make %{?jobs:-j%jobs}
%files
%manifest %{name}.manifest
-%license LICENSE.APLv2
-%{_libdir}/*.so*
-%attr(755,root,root) %{TZ_SYS_ETC}/duid-gadget
+%license LICENSE
+%license LICENSE.BSL-1.0
+%{_libdir}/libcryptsvc.so.*
+%{_libdir}/libdevice_info.so.*
+%{TZ_SYS_ETC}/duid-gadget
%files devel
-%manifest %{name}.manifest
%{_includedir}/*
+%{_libdir}/libcryptsvc.so
+%{_libdir}/libdevice_info.so
%{_libdir}/pkgconfig/cryptsvc.pc
+
+%files test
+%{_bindir}/cryptsvc-test
diff --git a/srcs/SecCryptoSvc.c b/srcs/SecCryptoSvc.c
index 44d5ce0..44d5ce0 100755..100644
--- a/srcs/SecCryptoSvc.c
+++ b/srcs/SecCryptoSvc.c
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 0000000..b39d6b0
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,32 @@
+SET(TARGET_CS_TEST cryptsvc-test)
+
+FIND_PACKAGE(Threads REQUIRED)
+ADD_DEFINITIONS("-DBOOST_TEST_DYN_LINK")
+
+PKG_CHECK_MODULES(CS_TEST_DEP REQUIRED ${CRYPTSVC_REQUIRES} ${DEVICE_INFO_REQUIRES})
+
+INCLUDE_DIRECTORIES(
+ ${CS_TEST_DEP_INCLUDE_DIRS}
+ ${PROJECT_SOURCE_DIR}/include
+ .
+)
+
+SET(CS_TEST_SRCS
+ colour_log_formatter.cc
+ main.cc
+ cs_test.cc
+ device_info_test.cc
+ ${PROJECT_SOURCE_DIR}/srcs/SecCryptoSvc.c
+ ${PROJECT_SOURCE_DIR}/srcs/device_info.c
+)
+
+ADD_EXECUTABLE(${TARGET_CS_TEST} ${CS_TEST_SRCS})
+
+TARGET_LINK_LIBRARIES(${TARGET_CS_TEST}
+ ${CS_TEST_DEP_LIBRARIES}
+ ${CMAKE_THREAD_LIBS_INIT}
+ boost_unit_test_framework
+ -ldl
+)
+
+INSTALL(TARGETS ${TARGET_CS_TEST} DESTINATION bin)
diff --git a/test/colour_log_formatter.cc b/test/colour_log_formatter.cc
new file mode 100644
index 0000000..9274c49
--- /dev/null
+++ b/test/colour_log_formatter.cc
@@ -0,0 +1,264 @@
+/*
+ * (C) Copyright Gennadiy Rozental 2005-2008.
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org/libs/test for the library home page.
+ */
+/*
+ * @file colour_log_formatter.cc
+ * @author Zofia Abramowska (z.abramowska@samsung.com)
+ * @version
+ * @brief
+ */
+#include "colour_log_formatter.h"
+
+#include <iostream>
+#include <string>
+
+#include <boost/test/unit_test_suite_impl.hpp>
+#include <boost/test/framework.hpp>
+#include <boost/test/utils/basic_cstring/io.hpp>
+#include <boost/test/utils/lazy_ostream.hpp>
+#include <boost/version.hpp>
+
+using namespace boost::unit_test;
+
+namespace cryptsvc {
+
+namespace {
+
+const char* BOLD_GREEN_BEGIN = "\033[1;32m";
+const char* BOLD_GREEN_END = "\033[m";
+const char* RED_BEGIN = "\033[0;31m";
+const char* RED_END = "\033[m";
+const char* PURPLE_BEGIN = "\033[0;35m";
+const char* PURPLE_END = "\033[m";
+const char* GREEN_BEGIN = "\033[0;32m";
+const char* GREEN_END = "\033[m";
+const char* CYAN_BEGIN = "\033[0;36m";
+const char* CYAN_END = "\033[m";
+const char* BOLD_RED_BEGIN = "\033[1;31m";
+const char* BOLD_RED_END = "\033[m";
+const char* BOLD_YELLOW_BEGIN = "\033[1;33m";
+const char* BOLD_YELLOW_END = "\033[m";
+const char* BOLD_GOLD_BEGIN = "\033[0;33m";
+const char* BOLD_GOLD_END = "\033[m";
+const char* BOLD_WHITE_BEGIN = "\033[1;37m";
+const char* BOLD_WHITE_END = "\033[m";
+const char* COLOR_END = "\033[m";
+
+const_string
+test_phase_identifier()
+{
+ return framework::is_initialized()
+ ? const_string( framework::current_test_case().p_name.get() )
+ : BOOST_TEST_L( "Test setup" );
+}
+
+const_string
+get_basename(const const_string &file_name) {
+ return basename(file_name.begin());
+}
+
+std::string
+get_basename(const std::string &file_name) {
+ return basename(file_name.c_str());
+}
+
+} // local namespace
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::log_start(
+ std::ostream& output,
+ counter_t test_cases_amount )
+{
+ if( test_cases_amount > 0 )
+ output << "Running " << test_cases_amount << " test "
+ << (test_cases_amount > 1 ? "cases" : "case") << "...\n";
+}
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::log_finish( std::ostream& ostr )
+{
+ ostr.flush();
+}
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::log_build_info( std::ostream& output )
+{
+ output << "Platform: " << BOOST_PLATFORM << '\n'
+ << "Compiler: " << BOOST_COMPILER << '\n'
+ << "STL : " << BOOST_STDLIB << '\n'
+ << "Boost : " << BOOST_VERSION/100000 << "."
+ << BOOST_VERSION/100 % 1000 << "."
+ << BOOST_VERSION % 100 << std::endl;
+}
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::test_unit_start(
+ std::ostream& output,
+ test_unit const& tu )
+{
+ if (tu.p_type_name->find(const_string("suite")) == 0) {
+ output << "Starting test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl;
+ } else {
+ output << "Running test " << tu.p_type_name << " \"" << tu.p_name << "\"" << std::endl;
+ }
+}
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::test_unit_finish(
+ std::ostream& output,
+ test_unit const& tu,
+ unsigned long elapsed )
+{
+ if (tu.p_type_name->find(const_string("suite")) == 0) {
+ output << "Finished test " << tu.p_type_name << " \"" << tu.p_name << "\""<< std::endl;
+ return;
+ }
+ std::string color = GREEN_BEGIN;
+ std::string status = "OK";
+ if (m_isTestCaseFailed) {
+ color = RED_BEGIN;
+ status = "FAIL";
+ }
+ output << "\t" << "[ " << color << status << COLOR_END << " ]";
+
+
+ output << ", " << CYAN_BEGIN << "time: ";
+ if( elapsed > 0 ) {
+ if( elapsed % 1000 == 0 )
+ output << elapsed/1000 << "ms";
+ else
+ output << elapsed << "mks";
+ } else {
+ output << "N/A";
+ }
+
+ output << COLOR_END << std::endl;
+ m_isTestCaseFailed = false;
+}
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::test_unit_skipped(
+ std::ostream& output,
+ test_unit const& tu )
+{
+ output << "Test " << tu.p_type_name << " \"" << tu.p_name << "\"" << "is skipped" << std::endl;
+}
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::log_exception(
+ std::ostream& output,
+ log_checkpoint_data const& checkpoint_data,
+ boost::execution_exception const& ex )
+{
+ boost::execution_exception::location const& loc = ex.where();
+ output << '\t' << BOLD_YELLOW_BEGIN << get_basename(loc.m_file_name)
+ << '(' << loc.m_line_num << "), ";
+
+ output << "fatal error in \""
+ << (loc.m_function.is_empty() ? test_phase_identifier() : loc.m_function ) << "\": ";
+
+ output << COLOR_END << ex.what();
+
+ if( !checkpoint_data.m_file_name.is_empty() ) {
+ output << '\n';
+ output << "\tlast checkpoint : " << get_basename(checkpoint_data.m_file_name)
+ << '(' << checkpoint_data.m_line_num << ")";
+ if( !checkpoint_data.m_message.empty() )
+ output << ": " << checkpoint_data.m_message;
+ }
+
+ output << std::endl;
+ m_isTestCaseFailed = true;
+}
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::log_entry_start(
+ std::ostream& output,
+ log_entry_data const& entry_data,
+ log_entry_types let )
+{
+ switch( let ) {
+ case BOOST_UTL_ET_INFO:
+ output << '\t' << entry_data.m_file_name << '(' << entry_data.m_line_num << "), ";
+ output << "info: ";
+ break;
+ case BOOST_UTL_ET_MESSAGE:
+ break;
+ case BOOST_UTL_ET_WARNING:
+ output << '\t' << get_basename(entry_data.m_file_name) << '(' << entry_data.m_line_num << "), ";
+ output << "warning in \"" << test_phase_identifier() << "\": ";
+ break;
+ case BOOST_UTL_ET_ERROR:
+ output << '\t' << BOLD_YELLOW_BEGIN << get_basename(entry_data.m_file_name)
+ << '(' << entry_data.m_line_num << "), ";
+ output << "error in \"" << test_phase_identifier() << "\": ";
+ m_isTestCaseFailed = true;
+ break;
+ case BOOST_UTL_ET_FATAL_ERROR:
+ output << '\t' << BOLD_YELLOW_BEGIN << get_basename(entry_data.m_file_name)
+ << '(' << entry_data.m_line_num << "), ";
+ output << " fatal error in \"" << test_phase_identifier() << "\": ";
+ m_isTestCaseFailed = true;
+ break;
+ }
+ output << COLOR_END;
+}
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::log_entry_value(
+ std::ostream& output,
+ const_string value )
+{
+ output << value;
+}
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::log_entry_value(
+ std::ostream& output,
+ lazy_ostream const& value )
+{
+ output << value;
+}
+
+//____________________________________________________________________________//
+
+void
+colour_log_formatter::log_entry_finish(
+ std::ostream& output )
+{
+ output << std::endl;
+}
+
+//____________________________________________________________________________//
+
+//____________________________________________________________________________//
+
+} // namespace cryptsvc
+
+//____________________________________________________________________________//
+
diff --git a/test/colour_log_formatter.h b/test/colour_log_formatter.h
new file mode 100644
index 0000000..a01bf8e
--- /dev/null
+++ b/test/colour_log_formatter.h
@@ -0,0 +1,59 @@
+/*
+ * (C) Copyright Gennadiy Rozental 2005-2008.
+ * Distributed under the Boost Software License, Version 1.0.
+ * (See accompanying file LICENSE_1_0.txt or copy at
+ * http://www.boost.org/LICENSE_1_0.txt)
+ *
+ * See http://www.boost.org/libs/test for the library home page.
+ */
+/*
+ * @file colour_log_formatter.h
+ * @author Zofia Abramowska (z.abramowska@samsung.com)
+ * @version
+ * @brief
+ */
+#pragma once
+#include <boost/test/unit_test_log_formatter.hpp>
+
+namespace cryptsvc {
+class colour_log_formatter : public boost::unit_test::unit_test_log_formatter {
+public:
+ // Formatter interface
+ colour_log_formatter() : m_isTestCaseFailed(false) {}
+ void log_start(
+ std::ostream&,
+ boost::unit_test::counter_t test_cases_amount );
+ void log_finish( std::ostream& );
+ void log_build_info( std::ostream& );
+
+ void test_unit_start(
+ std::ostream&,
+ boost::unit_test::test_unit const& tu );
+ void test_unit_finish(
+ std::ostream&,
+ boost::unit_test::test_unit const& tu,
+ unsigned long elapsed );
+ void test_unit_skipped(
+ std::ostream&,
+ boost::unit_test::test_unit const& tu );
+
+ void log_exception(
+ std::ostream&,
+ boost::unit_test::log_checkpoint_data const&,
+ boost::execution_exception const& ex );
+
+ void log_entry_start(
+ std::ostream&,
+ boost::unit_test::log_entry_data const&,
+ log_entry_types let );
+ void log_entry_value(
+ std::ostream&,
+ boost::unit_test::const_string value );
+ void log_entry_value(
+ std::ostream&,
+ boost::unit_test::lazy_ostream const& value );
+ void log_entry_finish( std::ostream& );
+private:
+ bool m_isTestCaseFailed;
+};
+} // namespace cryptsvc
diff --git a/test/cs_test.cc b/test/cs_test.cc
new file mode 100644
index 0000000..831802d
--- /dev/null
+++ b/test/cs_test.cc
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Kyungwook Tak <k.tak@samsung.com>
+ *
+ * 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
+ *
+ * @file cs_test.cc
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version
+ * @brief
+ */
+#include <iostream>
+
+#include <boost/test/unit_test.hpp>
+
+#include <SecCryptoSvc.h>
+
+BOOST_AUTO_TEST_SUITE(CRYPTO_SERVICE_TEST)
+
+BOOST_AUTO_TEST_CASE(PLATFORM_UNIQUE_KEY)
+{
+ constexpr unsigned int KeyLen = 16;
+ unsigned char cek[KeyLen] = {0};
+ char *encoded_cek = nullptr;
+
+ BOOST_REQUIRE_MESSAGE(SecFrameGeneratePlatformUniqueKey(KeyLen, cek),
+ "Failed to SecFrameGeneratePlatformUniqueKey.");
+
+ encoded_cek = Base64Encoding(
+ reinterpret_cast<char *>(cek),
+ static_cast<int>(KeyLen));
+ BOOST_REQUIRE_MESSAGE(encoded_cek != nullptr, "Failed to base64 encoding.");
+
+ std::cout << "base64 encoded platform unique key(with len 16): "
+ << encoded_cek << std::endl;
+}
+
+BOOST_AUTO_TEST_CASE(GETDUID_16)
+{
+ char *duid = GetDuid(16);
+ BOOST_REQUIRE_MESSAGE(duid != nullptr, "returned duid shouldn't be null");
+ std::cout << "duid: " << duid << std::endl;
+}
+
+BOOST_AUTO_TEST_CASE(GETDUID_20)
+{
+ char *duid = GetDuid(20);
+ BOOST_REQUIRE_MESSAGE(duid != nullptr, "returned duid shouldn't be null");
+ std::cout << "duid: " << duid << std::endl;
+}
+
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/device_info_test.cc b/test/device_info_test.cc
new file mode 100644
index 0000000..cf45f86
--- /dev/null
+++ b/test/device_info_test.cc
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Kyungwook Tak <k.tak@samsung.com>
+ *
+ * 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
+ *
+ * @file device_info_test.cc
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version
+ * @brief
+ */
+#include <iostream>
+
+#include <boost/test/unit_test.hpp>
+
+#include <device_info.h>
+
+BOOST_AUTO_TEST_SUITE(DEVICE_INFO_TEST)
+
+BOOST_AUTO_TEST_CASE(GET_DEVICE_ID)
+{
+ const char *device_id = get_device_id();
+
+ BOOST_REQUIRE_MESSAGE(device_id != nullptr,
+ "device id from get_device_id shouldn't be null");
+
+ std::cout << "device id from get_device_id: "
+ << device_id << std::endl;
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/main.cc b/test/main.cc
new file mode 100644
index 0000000..5321a9b
--- /dev/null
+++ b/test/main.cc
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Kyungwook Tak <k.tak@samsung.com>
+ *
+ * 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
+ *
+ * @file main.cc
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ * @brief cryptsvc test main
+ */
+#define BOOST_TEST_MODULE CRYPTO_SERVICE_TEST
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/unit_test_log.hpp>
+#include <boost/test/results_reporter.hpp>
+
+#include <colour_log_formatter.h>
+
+struct TestConfig {
+ TestConfig()
+ {
+ boost::unit_test::unit_test_log.set_threshold_level(boost::unit_test::log_test_units);
+ boost::unit_test::results_reporter::set_level(boost::unit_test::SHORT_REPORT);
+ boost::unit_test::unit_test_log.set_formatter(new cryptsvc::colour_log_formatter);
+ }
+
+ ~TestConfig() {}
+};
+
+BOOST_GLOBAL_FIXTURE(TestConfig);