summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyungwook Tak <k.tak@samsung.com>2016-07-15 10:42:35 (GMT)
committerKyungwook Tak <k.tak@samsung.com>2016-07-15 10:54:39 (GMT)
commit25dec26957850ba42687ffff35fc226039405654 (patch)
tree2d6dc55b841c1a74bfcb74c1bcaf7a8b4fe92434
parentf4b4d4ebf5a8d8c40e060238856a6560a2e20e1d (diff)
downloadlibwebappenc-25dec26957850ba42687ffff35fc226039405654.zip
libwebappenc-25dec26957850ba42687ffff35fc226039405654.tar.gz
libwebappenc-25dec26957850ba42687ffff35fc226039405654.tar.bz2
Apply boost test frameworkrefs/changes/45/80245/2
run with sdb root on : wae_tests --run_test=SYSTEM run with sdb root off : wae_tests --run_test=USER Change-Id: I0792e1e649f5e36c6f8715047f5ba5fd9ec48ecf Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
-rw-r--r--CMakeLists.txt13
-rw-r--r--LICENSE.BSL-1.023
-rw-r--r--packaging/libwebappenc.spec11
-rw-r--r--srcs/CMakeLists.txt56
-rw-r--r--tests/CMakeLists.txt106
-rw-r--r--tests/colour_log_formatter.cpp268
-rw-r--r--tests/colour_log_formatter.h62
-rw-r--r--tests/internals.cpp352
-rw-r--r--tests/main.cpp28
-rw-r--r--tests/non-normals.cpp70
-rw-r--r--tests/normals.cpp50
-rw-r--r--tests/test-common.cpp55
-rw-r--r--tests/test-common.h51
-rw-r--r--tests/test-helper.cpp178
-rw-r--r--tests/test-helper.h33
-rw-r--r--tests/wae_tests.c923
16 files changed, 1297 insertions, 982 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8d396a8..84dd0d5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -59,8 +59,8 @@ ADD_DEFINITIONS("-DBINDIR=\"${BINDIR}\"")
ADD_DEFINITIONS("-DINSTALLER_LABEL=\"${INSTALLER_LABEL}\"")
# IF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
- ADD_DEFINITIONS("-DTIZEN_DEBUG_ENABLE")
- ADD_DEFINITIONS("-DBUILD_TYPE_DEBUG")
+ ADD_DEFINITIONS("-DTIZEN_DEBUG_ENABLE")
+ ADD_DEFINITIONS("-DBUILD_TYPE_DEBUG")
# ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
CONFIGURE_FILE(packaging/lib${PROJECT_NAME}.manifest.in lib${PROJECT_NAME}.manifest @ONLY)
@@ -69,8 +69,8 @@ CONFIGURE_FILE(packaging/lib${PROJECT_NAME}-test.manifest.in lib${PROJECT_NAME}-
################# common configurations for srcs and test ######################
SET(DEPENDENTS "openssl dlog key-manager libtzplatform-config")
PKG_CHECK_MODULES(WEB_APP_ENC_DEPS
- REQUIRED
- ${DEPENDENTS}
+ REQUIRED
+ ${DEPENDENTS}
)
@@ -81,10 +81,11 @@ SET(PC_LDFLAGS -l${PROJECT_NAME})
#SET(PC_CFLAGS -I\${includedir})
############################ Target Setting ################################
-SET(TARGET_WEBAPPENC ${PROJECT_NAME})
+SET(TARGET_WAE ${PROJECT_NAME})
SET(TARGET_WAE_INITIALIZER wae_initializer)
SET(TARGET_WAE_ENCRYPTER wae_encrypter)
-SET(TARGET_WEBAPPENC_TEST wae_tests)
+SET(TARGET_WAE_TEST wae_tests)
+SET(TARGET_WAE_TEST_COMMON wae_tests_common)
############################ Add Sub Directories ################################
ADD_SUBDIRECTORY(srcs)
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/packaging/libwebappenc.spec b/packaging/libwebappenc.spec
index a3e95b4..ed5434a 100644
--- a/packaging/libwebappenc.spec
+++ b/packaging/libwebappenc.spec
@@ -3,7 +3,7 @@ Summary: Web application encryption service
Version: 0.1.0
Release: 1
Group: Security/Libraries
-License: Apache-2.0
+License: Apache-2.0 and BSL-1.0
Source0: %{name}-%{version}.tar.gz
Requires(post): /sbin/ldconfig
@@ -20,6 +20,7 @@ Web application encryption and decryption service
%package devel
Summary: Web application encryption service (development files)
+License: Apache-2.0
Group: Security/Development
Requires: %{name} = %{version}-%{release}
@@ -28,8 +29,10 @@ Web application encryption and decryption service (development files)
%package test
Summary: Web application encryption service (test)
+License: Apache-2.0 and BSL-1.0
Group: Security/Development
-Requires: %{name} = %{version}-%{release}
+BuildRequires: boost-devel
+Requires: %{name} = %{version}-%{release}
%description test
Web application encryption and decryption service (test)
@@ -82,6 +85,7 @@ fi
%files
%manifest %{name}.manifest
%license LICENSE
+%license LICENSE.BSL-1.0
%{_libdir}/%{name}.so.*
%{_unitdir}/webappenc-initializer.service
%{_unitdir}/multi-user.target.wants/webappenc-initializer.service
@@ -96,4 +100,7 @@ fi
%files test
%manifest %{name}-test.manifest
+%license LICENSE
+%license LICENSE.BSL-1.0
%{bin_dir}/wae_tests
+%{_libdir}/libwae_tests_common.so*
diff --git a/srcs/CMakeLists.txt b/srcs/CMakeLists.txt
index 9eb766c..b95531b 100644
--- a/srcs/CMakeLists.txt
+++ b/srcs/CMakeLists.txt
@@ -3,34 +3,34 @@
################################################################################
SET(WEB_APP_ENC_SOURCES
- ${CMAKE_CURRENT_SOURCE_DIR}/web_app_enc.c
- ${CMAKE_CURRENT_SOURCE_DIR}/key_handler.c
- ${CMAKE_CURRENT_SOURCE_DIR}/crypto_service.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/web_app_enc.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/key_handler.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/crypto_service.c
)
INCLUDE_DIRECTORIES(
- ${PROJECT_SOURCE_DIR}/include
- ${WEB_APP_ENC_DEPS_INCLUDE_DIRS}
+ ${PROJECT_SOURCE_DIR}/include
+ ${WEB_APP_ENC_DEPS_INCLUDE_DIRS}
)
-ADD_LIBRARY(${TARGET_WEBAPPENC} SHARED ${WEB_APP_ENC_SOURCES})
+ADD_LIBRARY(${TARGET_WAE} SHARED ${WEB_APP_ENC_SOURCES})
-SET_TARGET_PROPERTIES(${TARGET_WEBAPPENC} PROPERTIES
- SOVERSION ${SO_VERSION}
- VERSION ${VERSION}
- COMPILE_FLAGS "-D_GNU_SOURCE"
+SET_TARGET_PROPERTIES(${TARGET_WAE} PROPERTIES
+ SOVERSION ${SO_VERSION}
+ VERSION ${VERSION}
+ COMPILE_FLAGS "-D_GNU_SOURCE"
)
-TARGET_LINK_LIBRARIES(${TARGET_WEBAPPENC}
- pthread
- ${WEB_APP_ENC_DEPS_LIBRARIES}
+TARGET_LINK_LIBRARIES(${TARGET_WAE}
+ pthread
+ ${WEB_APP_ENC_DEPS_LIBRARIES}
)
-INSTALL(TARGETS ${TARGET_WEBAPPENC}
- DESTINATION ${LIBDIR})
+INSTALL(TARGETS ${TARGET_WAE}
+ DESTINATION ${LIBDIR})
INSTALL(FILES ${PROJECT_SOURCE_DIR}/include/web_app_enc.h
- DESTINATION ${INCLUDEDIR})
+ DESTINATION ${INCLUDEDIR})
################################################################################
@@ -39,30 +39,28 @@ INSTALL(FILES ${PROJECT_SOURCE_DIR}/include/web_app_enc.h
SET(WAE_INITIALIZER_SOURCES
- ${CMAKE_CURRENT_SOURCE_DIR}/wae_initializer.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/wae_initializer.c
)
INCLUDE_DIRECTORIES(
- ${PROJECT_SOURCE_DIR}/include
- ${WEB_APP_ENC_DEPS_INCLUDE_DIRS}
+ ${PROJECT_SOURCE_DIR}/include
+ ${WEB_APP_ENC_DEPS_INCLUDE_DIRS}
)
# -fPIE and -pie flag is added for ASLR
SET_SOURCE_FILES_PROPERTIES(
- ${WAE_INITIALIZER_SOURCES}
- PROPERTIES
- COMPILE_FLAGS "-D_GNU_SOURCE -fvisibility=hidden -fPIE")
+ ${WAE_INITIALIZER_SOURCES}
+ PROPERTIES
+ COMPILE_FLAGS "-D_GNU_SOURCE -fvisibility=hidden -fPIE")
ADD_EXECUTABLE(${TARGET_WAE_INITIALIZER} ${WAE_INITIALIZER_SOURCES})
TARGET_LINK_LIBRARIES(${TARGET_WAE_INITIALIZER}
- pthread
- ${WEB_APP_ENC_DEPS_LIBRARIES}
- ${TARGET_WEBAPPENC}
- -pie
+ pthread
+ ${WEB_APP_ENC_DEPS_LIBRARIES}
+ ${TARGET_WAE}
+ -pie
)
-INSTALL(TARGETS ${TARGET_WAE_INITIALIZER}
- DESTINATION ${BINDIR})
-
+INSTALL(TARGETS ${TARGET_WAE_INITIALIZER} DESTINATION ${BINDIR})
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index e1d0d6d..7c9e2c9 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,37 +1,99 @@
-################################################################################
-# for wae_tests
-################################################################################
+# Copyright (c) 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.
+# 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 CMakeLists.txt
+# @author Kyungwook Tak (k.tak@samsung.com)
+# @brief cmake for test program
+#
+ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK)
+#### test common library ####
+PKG_CHECK_MODULES(${TARGET_WAE_TEST_COMMON}_DEP
+ REQUIRED
+)
-SET(WEB_APP_ENC_TEST_SOURCES
- ${CMAKE_CURRENT_SOURCE_DIR}/wae_tests.c
+SET(${TARGET_WAE_TEST_COMMON}_SRCS
+ colour_log_formatter.cpp
+ test-common.cpp
)
INCLUDE_DIRECTORIES(
- ${WEB_APP_ENC_DEPS_INCLUDE_DIRS}
- ${CMAKE_CURRENT_SOURCE_DIR}
- ${PROJECT_SOURCE_DIR}/include
- ${PROJECT_SOURCE_DIR}/srcs
+ SYSTEM
+ ${${TARGET_WAE_TEST_COMMON}_DEP_INCLUDE_DIRS}
)
-ADD_EXECUTABLE(${TARGET_WEBAPPENC_TEST} ${WEB_APP_ENC_TEST_SOURCES})
+INCLUDE_DIRECTORIES(
+ .
+)
+ADD_LIBRARY(${TARGET_WAE_TEST_COMMON} SHARED ${${TARGET_WAE_TEST_COMMON}_SRCS})
+
+SET_TARGET_PROPERTIES(${TARGET_WAE_TEST_COMMON}
+ PROPERTIES
+ COMPILE_FLAGS "-D_GNU_SOURCE -fvisibility=default"
+)
-TARGET_LINK_LIBRARIES(${TARGET_WEBAPPENC_TEST}
- ${WEB_APP_ENC_DEPS_LIBRARIES}
- ${TARGET_WEBAPPENC}
+TARGET_LINK_LIBRARIES(${TARGET_WAE_TEST_COMMON}
+ ${${TARGET_WAE_TEST_COMMON}_DEP_LIBRARIES}
+ -lboost_unit_test_framework
)
+INSTALL(TARGETS ${TARGET_WAE_TEST_COMMON} DESTINATION ${LIBDIR})
-INSTALL(TARGETS ${TARGET_WEBAPPENC_TEST}
- DESTINATION ${BINDIR}
- PERMISSIONS OWNER_READ
- OWNER_WRITE
- OWNER_EXECUTE
- GROUP_READ
- GROUP_EXECUTE
- WORLD_READ
- WORLD_EXECUTE
+#### main test program ####
+PKG_CHECK_MODULES(${TARGET_WAE_TEST}_DEP
+ REQUIRED
)
+SET(${TARGET_WAE_TEST}_SRCS
+ main.cpp
+ non-normals.cpp
+ normals.cpp
+ internals.cpp
+ test-helper.cpp
+)
+
+INCLUDE_DIRECTORIES(
+ SYSTEM
+ ${${TARGET_WAE_TEST}_DEP_INCLUDE_DIRS}
+)
+INCLUDE_DIRECTORIES(
+ ${PROJECT_SOURCE_DIR}/include
+ ${PROJECT_SOURCE_DIR}/srcs
+ .
+)
+
+ADD_EXECUTABLE(${TARGET_WAE_TEST} ${${TARGET_WAE_TEST}_SRCS})
+
+TARGET_LINK_LIBRARIES(${TARGET_WAE_TEST}
+ ${${TARGET_WAE_TEST}_DEP_LIBRARIES}
+ ${TARGET_WAE_TEST_COMMON}
+ ${TARGET_WAE}
+ -lboost_unit_test_framework
+ -ldl
+)
+
+
+INSTALL(TARGETS ${TARGET_WAE_TEST}
+ DESTINATION ${BINDIR}
+ PERMISSIONS
+ OWNER_READ
+ OWNER_WRITE
+ OWNER_EXECUTE
+ GROUP_READ
+ GROUP_EXECUTE
+ WORLD_READ
+ WORLD_EXECUTE
+)
diff --git a/tests/colour_log_formatter.cpp b/tests/colour_log_formatter.cpp
new file mode 100644
index 0000000..50bd43c
--- /dev/null
+++ b/tests/colour_log_formatter.cpp
@@ -0,0 +1,268 @@
+/*
+ * Boost Software License - Version 1.0 - August 17th, 2003
+ *
+ * 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.
+ */
+#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>
+
+// ************************************************************************** //
+// ************** colour_log_formatter ************** //
+// ************************************************************************** //
+
+using namespace boost::unit_test;
+namespace Wae {
+namespace Test {
+
+namespace {
+
+const char *GREEN_BEGIN = "\033[0;32m";
+const char *RED_BEGIN = "\033[0;31m";
+const char *CYAN_BEGIN = "\033[0;36m";
+const char *BOLD_YELLOW_BEGIN = "\033[1;33m";
+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") << "..." << std::endl;
+}
+
+//____________________________________________________________________________//
+
+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 << std::endl
+ << "Compiler: " << BOOST_COMPILER << std::endl
+ << "STL : " << BOOST_STDLIB << std::endl
+ << "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 Test
+} // namespace Wae
+
+//____________________________________________________________________________//
+
diff --git a/tests/colour_log_formatter.h b/tests/colour_log_formatter.h
new file mode 100644
index 0000000..7c5dee3
--- /dev/null
+++ b/tests/colour_log_formatter.h
@@ -0,0 +1,62 @@
+/*
+ * Boost Software License - Version 1.0 - August 17th, 2003
+ *
+ * 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.
+ */
+#pragma once
+
+#include <boost/test/unit_test_log_formatter.hpp>
+
+namespace Wae {
+namespace Test {
+
+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;
+};
+
+}
+}
diff --git a/tests/internals.cpp b/tests/internals.cpp
new file mode 100644
index 0000000..5d6ca2c
--- /dev/null
+++ b/tests/internals.cpp
@@ -0,0 +1,352 @@
+/*
+ * Copyright (c) 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.
+ * 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 internals.cpp
+ * @author Dongsun Lee (ds73.lee@samsung.com)
+ * Kyungwook Tak (k.tak@samsung.com)
+ * @version 2.0
+ * @brief internal functions test
+ */
+#include "web_app_enc.h"
+
+#include <cstring>
+#include <unistd.h>
+
+#include <boost/test/unit_test.hpp>
+
+#include "key_handler.h"
+#include "crypto_service.h"
+
+#include "test-common.h"
+
+BOOST_AUTO_TEST_SUITE(SYSTEM)
+
+BOOST_AUTO_TEST_SUITE(INTERNALS)
+
+BOOST_AUTO_TEST_CASE(encrypt_decrypt_app_dek)
+{
+ const char *private_key =
+ "-----BEGIN RSA PRIVATE KEY-----\n"
+ "MIIEpgIBAAKCAQEA0kWtjpRO7Zh2KX2naVE/BDJdrfwK9xexfNA0MkY2VJ4J2AKM\n"
+ "YTj1D1jntceryupCEHOvP3rum+WsFvPXduz9+VKnSsSqj4jcTUubtpDUGA5G79Iq\n"
+ "LEPFuSBaqI8Uwkzd08pE+s30oaJDnNazMhSq8JkqBPoCCwtUs73ruE9VbtsBO/kT\n"
+ "lASIAfe8nXqcJLcDQgWYhizjJw0Pi6d74oCwS2OTvQDNvsXfFnA0ZJEEYw/rZLir\n"
+ "j7OHoOjz+Sh5N+1uA3Up6SPPEbHuP6L12YxqHdy7gnJXodLhvE/cR4SN9VW7+qmC\n"
+ "MBjmLkBejGrEX3STS9sLI7MZHu9Y26dwuYb4+wIDAQABAoIBAQCwxqV/vc2RUGDe\n"
+ "xuXM0+IvrAw37jJlw4SS0xNexMp+XxMViCbuwYy851h96azS/himbiuCKd6aL/96\n"
+ "mGunbtyiFEvSvv5Jh5z2Wr9BQAcfZjla+4w7BIsg9UNifE/OfgLsQBu34xhsHtfK\n"
+ "7nFehCOl/I5n+qtnD5KZPe0DWacQdwY4vEAj6YyXdb2bBg+MiwE9KVxGEIUDbklh\n"
+ "Is70JXczjLZCS+lIpOKh0/lbZmBZePoUbVTtS+GvtPTpQC/aTHRkwGoEtuPEWpbL\n"
+ "0Q1d6zO+vDJVLJlb5FF2haghs8IlqAxkkPjeUTNye+WktRrDQxmPu/blbxQrygfq\n"
+ "Au5tBnsxAoGBAOiVtcpg32puo3Yq2Y78oboe9PuHaQP0d3DhwP3/7J0BeNslpjW7\n"
+ "E1LWsVsCanxTE8XPUdFfAWgMk7lQqESN0wawGmSmWk+eQPZdjHanBaC8vh7aKjo6\n"
+ "q9FdT1DKjrRi23QyDco3f3E7hvM93IAAhw1ikNu8DT19JAxtdeMh5WAZAoGBAOdw\n"
+ "6neEvIFXh3RWEv2/GKVhVR8mxDqxmuFdXpOF+YWsK0Tg4uC8jm9kUGnwXgT2Mjke\n"
+ "oAwYAFcRbHQQGsxy/vkV16kv4aurTE2hMpjeXCAakwV0Pi2w1f9WnDokjgORkOmc\n"
+ "+QK9I8egdFPMVDfQjhLslhSUY0Eb4qcJ6q9WxfQzAoGBANSsAFybk+7oWAO3TtQW\n"
+ "YXOk1vIgcYAyS/0mEKixGZS/QdlxZbf/5b17nxTO8rvX416fIftG2ixgQ7vR6us0\n"
+ "m9+jq56ZFj9zP4eHJudf9h9yNo5TgwVXnMCGh/4iGbcMJgrrsfxUHu5VNiK5UCSj\n"
+ "VtqAZGDoZVryUMIkXQVhezIRAoGBAN7QUIqcGbcUA24257Wu4hVlrUN+WPCAyDEr\n"
+ "aL/x/ZV5eXaoYwQlw6LuGpTDOmDgfN2M5FyARuOL/LOIRaSLGXnIU4WoeUSCd8VM\n"
+ "6Z9Og7bMnrpjfPEUDBH02hcH1kkNPUwLOZgva2Dm0tdSIcpSWFVTu/E4Io4uQHi8\n"
+ "DVqc2ZsNAoGBAJT76ezXNSSv8hnrKqTpwgTicpqhRZ3eFQjyl4HRL26AJMKv++x8\n"
+ "4/IsVIwxaHzpbN3nnCjmAHV4gX9YpxVnvYcZflC9WZeDkwNMLmPYb3Zg27EzSMfQ\n"
+ "8yrfWJZo3qobipcHf1yohAt4fHk9kUKtPHEwp0xKe//rfhswLb3VCzvQ\n"
+ "-----END RSA PRIVATE KEY-----";
+
+ const char *public_key =
+ "-----BEGIN PUBLIC KEY-----\n"
+ "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0kWtjpRO7Zh2KX2naVE/\n"
+ "BDJdrfwK9xexfNA0MkY2VJ4J2AKMYTj1D1jntceryupCEHOvP3rum+WsFvPXduz9\n"
+ "+VKnSsSqj4jcTUubtpDUGA5G79IqLEPFuSBaqI8Uwkzd08pE+s30oaJDnNazMhSq\n"
+ "8JkqBPoCCwtUs73ruE9VbtsBO/kTlASIAfe8nXqcJLcDQgWYhizjJw0Pi6d74oCw\n"
+ "S2OTvQDNvsXfFnA0ZJEEYw/rZLirj7OHoOjz+Sh5N+1uA3Up6SPPEbHuP6L12Yxq\n"
+ "Hdy7gnJXodLhvE/cR4SN9VW7+qmCMBjmLkBejGrEX3STS9sLI7MZHu9Y26dwuYb4\n"
+ "+wIDAQAB\n"
+ "-----END PUBLIC KEY-----";
+
+ std::vector<unsigned char> dek(32, 0);
+
+ unsigned char *_encrypted = nullptr;
+ size_t _encrypted_len = 0;
+ int ret = encrypt_app_dek(reinterpret_cast<const unsigned char *>(public_key),
+ strlen(public_key), dek.data(), dek.size(), &_encrypted,
+ &_encrypted_len);
+ auto encrypted = Wae::Test::bytearr_to_vec(_encrypted, _encrypted_len);
+ free(_encrypted);
+
+ BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE, "Failed to encrypt_app_dek. ec: " << ret);
+
+ unsigned char *_decrypted = nullptr;
+ size_t _decrypted_len = 0;
+ ret = decrypt_app_dek(reinterpret_cast<const unsigned char *>(private_key),
+ strlen(private_key), nullptr, encrypted.data(), encrypted.size(),
+ &_decrypted, &_decrypted_len);
+ auto decrypted = Wae::Test::bytearr_to_vec(_decrypted, _decrypted_len);
+ free(_decrypted);
+
+ BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE, "Failed to decrypt_app_dek. ec: " << ret);
+
+ BOOST_REQUIRE_MESSAGE(dek == decrypted,
+ "encrypted/decrypted dek isn't valid. "
+ "dek(" << Wae::Test::bytes_to_hex(dek) << ") "
+ "decrypted(" << Wae::Test::bytes_to_hex(decrypted) << ")");
+}
+
+BOOST_AUTO_TEST_CASE(encrypt_decrypt_aes_cbc)
+{
+ std::vector<unsigned char> plaintext = {
+ 'a', 'b', 'c', 'a', 'b', 'c', 'x', 'y',
+ 'o', 'q', '2', 'e', 'v', '0', '1', 'x'
+ };
+
+ size_t dek_len = 32;
+ std::vector<unsigned char> dek(dek_len, 0);
+
+ int ret = _get_random(dek.size(), dek.data());
+ BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE, "Failed to get random");
+
+ unsigned char *_encrypted = nullptr;
+ size_t _encrypted_len = 0;
+ ret = encrypt_aes_cbc(dek.data(), dek.size(), plaintext.data(), plaintext.size(),
+ &_encrypted, &_encrypted_len);
+ auto encrypted = Wae::Test::bytearr_to_vec(_encrypted, _encrypted_len);
+ free(_encrypted);
+
+ BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE, "Failed to encrypt_aes_cbc. ec: " << ret);
+
+ unsigned char *_decrypted = nullptr;
+ size_t _decrypted_len = 0;
+ ret = decrypt_aes_cbc(dek.data(), dek.size(), encrypted.data(), encrypted.size(),
+ &_decrypted, &_decrypted_len);
+ auto decrypted = Wae::Test::bytearr_to_vec(_decrypted, _decrypted_len);
+ free(_decrypted);
+
+ BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE, "Failed to decrypt_aes_cbc. ec: " << ret);
+ BOOST_REQUIRE_MESSAGE(plaintext == decrypted,
+ "decrypted plaintext isn't valid. "
+ "plaintext(" << Wae::Test::bytes_to_hex(plaintext) << ") "
+ "decrypted(" << Wae::Test::bytes_to_hex(decrypted) << ")");
+}
+
+BOOST_AUTO_TEST_CASE(cache)
+{
+ const char *pkg1 = "pkg1";
+ const char *pkg2 = "pkg2";
+ const char *pkg3 = "pkg3";
+ const char *pkgDummy = "dummy";
+
+ std::vector<unsigned char> dek1(32, 1);
+ std::vector<unsigned char> dek2(32, 2);
+ std::vector<unsigned char> dek3(32, 3);
+
+ _initialize_cache();
+
+ _add_app_dek_to_cache(pkg1, dek1.data());
+ _add_app_dek_to_cache(pkg2, dek2.data());
+ _add_app_dek_to_cache(pkg3, dek3.data());
+
+ size_t dek_len = 32;
+ unsigned char *_cached = _get_app_dek_from_cache(pkg1);
+ auto cached = Wae::Test::bytearr_to_vec(_cached, dek_len);
+
+ BOOST_REQUIRE_MESSAGE(cached == dek1,
+ "cached dek isn't valid! "
+ "dek(" << Wae::Test::bytes_to_hex(dek1) << ") "
+ "cached(" << Wae::Test::bytes_to_hex(cached) << ")");
+
+ _cached = _get_app_dek_from_cache(pkg2);
+ cached = Wae::Test::bytearr_to_vec(_cached, dek_len);
+
+ BOOST_REQUIRE_MESSAGE(cached == dek2,
+ "cached dek isn't valid! "
+ "dek(" << Wae::Test::bytes_to_hex(dek2) << ") "
+ "cached(" << Wae::Test::bytes_to_hex(cached) << ")");
+
+ _cached = _get_app_dek_from_cache(pkg3);
+ cached = Wae::Test::bytearr_to_vec(_cached, dek_len);
+
+ BOOST_REQUIRE_MESSAGE(cached == dek3,
+ "cached dek isn't valid! "
+ "dek(" << Wae::Test::bytes_to_hex(dek3) << ") "
+ "cached(" << Wae::Test::bytes_to_hex(cached) << ")");
+
+ _cached = _get_app_dek_from_cache(pkgDummy);
+ if (_cached) {
+ cached = Wae::Test::bytearr_to_vec(_cached, dek_len);
+ BOOST_REQUIRE_MESSAGE(false,
+ "wrong cached val is extracted by dummy pkg id. "
+ "val(" << Wae::Test::bytes_to_hex(cached) << ")");
+ }
+
+ _remove_app_dek_from_cache(pkg3);
+
+ _cached = _get_app_dek_from_cache(pkg3);
+ if (_cached) {
+ cached = Wae::Test::bytearr_to_vec(_cached, dek_len);
+ BOOST_REQUIRE_MESSAGE(false,
+ "app dek removed from cache but it's remained! "
+ "val(" << Wae::Test::bytes_to_hex(cached) << ")");
+ }
+
+ _initialize_cache();
+
+ _add_app_dek_to_cache(pkg1, dek1.data());
+
+ _cached = nullptr;
+ _cached = _get_app_dek_from_cache(pkg2);
+ if (_cached) {
+ cached = Wae::Test::bytearr_to_vec(_cached, dek_len);
+ BOOST_REQUIRE_MESSAGE(false,
+ "cache is initialized but something is remained! "
+ "val(" << Wae::Test::bytes_to_hex(cached) << ")");
+ }
+}
+
+BOOST_AUTO_TEST_CASE(read_write_encrypted_app_dek)
+{
+ const char *pkg_id = "write_test_pkg";
+
+ std::vector<unsigned char> dek(256, 0);
+
+ int ret = _write_encrypted_app_dek_to_file(pkg_id, dek.data(), dek.size());
+ BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE, "Failed to write_encrypted_app_dek_to_file. ec: " << ret);
+
+ unsigned char *_readed = nullptr;
+ size_t _readed_len = 0;
+ ret = _read_encrypted_app_dek_from_file(pkg_id, &_readed, &_readed_len);
+ auto readed = Wae::Test::bytearr_to_vec(_readed, _readed_len);
+ free(_readed);
+ BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE, "Failed to read_encrypted_app_dek_from_file. ec: " << ret);
+
+ BOOST_REQUIRE_MESSAGE(dek == readed,
+ "dek isn't match after write/read file. "
+ "dek(" << Wae::Test::bytes_to_hex(dek) << ") "
+ "readed(" << Wae::Test::bytes_to_hex(readed) << ")");
+}
+
+BOOST_AUTO_TEST_CASE(get_create_preloaded_app_dek_1)
+{
+ const char *pkg_id = "TEST_PKG_ID_FOR_CREATE";
+
+ unsigned char *_readed = nullptr;
+ size_t _readed_len = 0;
+ int ret = get_preloaded_app_dek(pkg_id, &_readed, &_readed_len);
+ auto readed = Wae::Test::bytearr_to_vec(_readed, _readed_len);
+ free(_readed);
+
+ BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NO_KEY,
+ "preloaded app dek to create is already exist. ec: " << ret);
+
+ unsigned char *_dek = nullptr;
+ size_t _dek_len = 0;
+ ret = create_preloaded_app_dek(pkg_id, &_dek, &_dek_len);
+ auto dek = Wae::Test::bytearr_to_vec(_dek, _dek_len);
+
+ BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE,
+ "Failed to create_preloaded_app_dek. ec: " << ret);
+
+ _readed = nullptr;
+ ret = get_preloaded_app_dek(pkg_id, &_readed, &_readed_len);
+ readed = Wae::Test::bytearr_to_vec(_readed, _readed_len);
+ free(_readed);
+
+ BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE,
+ "Failed to get_preloaded_app_dek. ec: " << ret);
+
+ BOOST_REQUIRE_MESSAGE(dek == readed,
+ "created/loaded dek is not matched! "
+ "created(" << Wae::Test::bytes_to_hex(dek) << ") "
+ "loaded(" << Wae::Test::bytes_to_hex(readed) << ")");
+}
+
+BOOST_AUTO_TEST_CASE(get_create_preloaded_app_dek_2)
+{
+ const char *pkg_id1 = "TEST_PKGID_1";
+ const char *pkg_id2 = "TEST_PKGID_2";
+
+ char path1[MAX_PATH_LEN] = {0, };
+ char path2[MAX_PATH_LEN] = {0, };
+ _get_preloaded_app_dek_file_path(pkg_id1, sizeof(path1), path1);
+ _get_preloaded_app_dek_file_path(pkg_id2, sizeof(path2), path2);
+
+ // remove old test data
+ remove_app_dek(pkg_id1, WAE_PRELOADED_APP);
+ remove_app_dek(pkg_id2, WAE_PRELOADED_APP);
+ unlink(path1);
+ unlink(path2);
+
+ // create 2 deks for preloaded app
+ unsigned char *_dek1 = nullptr;
+ size_t _dek_len1 = 0;
+ int ret = create_preloaded_app_dek(pkg_id1, &_dek1, &_dek_len1);
+ auto dek1 = Wae::Test::bytearr_to_vec(_dek1, _dek_len1);
+ free(_dek1);
+
+ BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE,
+ "Failed to create_preloaded_app_dek. ec: " << ret);
+
+ unsigned char *_dek2 = nullptr;
+ size_t _dek_len2 = 0;
+ ret = create_preloaded_app_dek(pkg_id2, &_dek2, &_dek_len2);
+ auto dek2 = Wae::Test::bytearr_to_vec(_dek2, _dek_len2);
+ free(_dek2);
+
+ BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE,
+ "Failed to create_preloaded_app_dek. ec: " << ret);
+
+ ret = load_preloaded_app_deks(true);
+ BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE,
+ "Failed to load_preloaded_app_deks. ec: " << ret);
+
+ unsigned char *_readed1 = nullptr;
+ size_t _readed_len1 = 0;
+ ret = get_app_dek(pkg_id1, WAE_PRELOADED_APP, &_readed1, &_readed_len1);
+ auto readed1 = Wae::Test::bytearr_to_vec(_readed1, _readed_len1);
+ free(_readed1);
+
+ BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE, "Failed to get_app_dek. ec: " << ret);
+
+ unsigned char *_readed2 = nullptr;
+ size_t _readed_len2 = 0;
+ ret = get_app_dek(pkg_id2, WAE_PRELOADED_APP, &_readed2, &_readed_len2);
+ auto readed2 = Wae::Test::bytearr_to_vec(_readed2, _readed_len2);
+ free(_readed2);
+
+ BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE, "Failed to get_app_dek. ec: " << ret);
+
+ BOOST_REQUIRE_MESSAGE(dek1 == readed1,
+ "readed dek and original isn't matched! "
+ "original(" << Wae::Test::bytes_to_hex(dek1) << ") "
+ "readed(" << Wae::Test::bytes_to_hex(readed1) << ")");
+
+ BOOST_REQUIRE_MESSAGE(dek2 == readed2,
+ "readed dek and original isn't matched! "
+ "original(" << Wae::Test::bytes_to_hex(dek2) << ") "
+ "readed(" << Wae::Test::bytes_to_hex(readed2) << ")");
+
+ ret = remove_app_dek(pkg_id1, WAE_PRELOADED_APP);
+ BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE,
+ "Failed remove app dek after used. ec: " << ret);
+
+ ret = remove_app_dek(pkg_id2, WAE_PRELOADED_APP);
+ BOOST_REQUIRE_MESSAGE(ret == WAE_ERROR_NONE,
+ "Failed remove app dek after used. ec: " << ret);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // INTERNALS
+
+BOOST_AUTO_TEST_SUITE_END() // SYSTEM
diff --git a/tests/main.cpp b/tests/main.cpp
new file mode 100644
index 0000000..2f52e03
--- /dev/null
+++ b/tests/main.cpp
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 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.
+ * 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.cpp
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ * @brief test main used boost test framework
+ */
+#define BOOST_TEST_MODULE WAE_INTERNAL_TEST
+
+#include <boost/test/unit_test.hpp>
+
+#include "test-common.h"
+
+BOOST_GLOBAL_FIXTURE(TestConfig);
diff --git a/tests/non-normals.cpp b/tests/non-normals.cpp
new file mode 100644
index 0000000..8667bfc
--- /dev/null
+++ b/tests/non-normals.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 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.
+ * 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 non-normals.cpp
+ * @author Dongsun Lee (ds73.lee@samsung.com)
+ * Kyungwook Tak (k.tak@samsung.com)
+ * @version 2.0
+ * @brief API test for preloaded/global apps
+ */
+#include "web_app_enc.h"
+
+#include <boost/test/unit_test.hpp>
+
+#include "test-helper.h"
+
+BOOST_AUTO_TEST_SUITE(SYSTEM)
+
+BOOST_AUTO_TEST_SUITE(GLOBAL_APP)
+
+BOOST_AUTO_TEST_CASE(add_get_remove_dek)
+{
+ Wae::Test::add_get_remove_dek(WAE_DOWNLOADED_GLOBAL_APP);
+}
+
+BOOST_AUTO_TEST_CASE(create_app_dek)
+{
+ Wae::Test::create_app_dek(WAE_DOWNLOADED_GLOBAL_APP);
+}
+
+BOOST_AUTO_TEST_CASE(encrypt_decrypt)
+{
+ Wae::Test::encrypt_decrypt_web_app(WAE_DOWNLOADED_GLOBAL_APP);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // GLOBAL_APP
+
+
+BOOST_AUTO_TEST_SUITE(PRELOADED_APP)
+
+BOOST_AUTO_TEST_CASE(add_get_remove_dek)
+{
+ Wae::Test::add_get_remove_dek(WAE_PRELOADED_APP);
+}
+
+BOOST_AUTO_TEST_CASE(create_app_dek)
+{
+ Wae::Test::create_app_dek(WAE_PRELOADED_APP);
+}
+
+BOOST_AUTO_TEST_CASE(encrypt_decrypt)
+{
+ Wae::Test::encrypt_decrypt_web_app(WAE_PRELOADED_APP);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // PRELOADED_APP
+
+BOOST_AUTO_TEST_SUITE_END() // SYSTEM
diff --git a/tests/normals.cpp b/tests/normals.cpp
new file mode 100644
index 0000000..2ce272e
--- /dev/null
+++ b/tests/normals.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 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.
+ * 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 normals.cpp
+ * @author Dongsun Lee (ds73.lee@samsung.com)
+ * Kyungwook Tak (k.tak@samsung.com)
+ * @version 2.0
+ * @brief test for normal downloaded app
+ */
+#include "web_app_enc.h"
+
+#include <boost/test/unit_test.hpp>
+
+#include "test-helper.h"
+
+BOOST_AUTO_TEST_SUITE(USER)
+
+BOOST_AUTO_TEST_SUITE(DOWNLOADED_APP);
+
+BOOST_AUTO_TEST_CASE(add_get_remove_dek)
+{
+ Wae::Test::add_get_remove_dek(WAE_DOWNLOADED_NORMAL_APP);
+}
+
+BOOST_AUTO_TEST_CASE(create_app_dek)
+{
+ Wae::Test::create_app_dek(WAE_DOWNLOADED_NORMAL_APP);
+}
+
+BOOST_AUTO_TEST_CASE(encrypt_decrypt_normal_app)
+{
+ Wae::Test::encrypt_decrypt_web_app(WAE_DOWNLOADED_NORMAL_APP);
+}
+
+BOOST_AUTO_TEST_SUITE_END() // DOWNLOADED_APP
+
+BOOST_AUTO_TEST_SUITE_END() // USER
diff --git a/tests/test-common.cpp b/tests/test-common.cpp
new file mode 100644
index 0000000..3e9e331
--- /dev/null
+++ b/tests/test-common.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 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.
+ * 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 test-common.cpp
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ */
+#include "test-common.h"
+
+#include <sstream>
+#include <iomanip>
+#include <string>
+
+namespace Wae {
+namespace Test {
+
+std::string bytes_to_hex(const std::vector<unsigned char> &bytes)
+{
+ std::stringstream ss;
+ ss << std::hex;
+
+ for (auto b : bytes)
+ ss << std::setw(2) << std::setfill('0') << static_cast<int>(b);
+
+ return ss.str();
+}
+
+std::vector<unsigned char> bytearr_to_vec(const unsigned char *bytes, size_t len)
+{
+ if (bytes == nullptr || len == 0)
+ return std::vector<unsigned char>();
+
+ std::vector<unsigned char> vec;
+
+ for (size_t i = 0; i < len; ++i)
+ vec.push_back(bytes[i]);
+
+ return vec;
+}
+
+} // namespace Test
+} // namespace Wae
diff --git a/tests/test-common.h b/tests/test-common.h
new file mode 100644
index 0000000..2c4c54e
--- /dev/null
+++ b/tests/test-common.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 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.
+ * 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 test-common.h
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ */
+#pragma once
+
+#include <vector>
+
+#include <boost/test/unit_test.hpp>
+#include <boost/test/unit_test_log.hpp>
+#include <boost/test/results_reporter.hpp>
+
+#include "colour_log_formatter.h"
+
+/* fixtures should be declared on outside of namespace */
+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 Wae::Test::colour_log_formatter);
+
+ BOOST_TEST_MESSAGE("run test program with --run_test=SYSTEM on sdb root turned ON");
+ BOOST_TEST_MESSAGE("run test program with --run_test=USER on sdb root turned OFF");
+ }
+};
+
+namespace Wae {
+namespace Test {
+
+std::string bytes_to_hex(const std::vector<unsigned char> &bytes);
+std::vector<unsigned char> bytearr_to_vec(const unsigned char *bytes, size_t len);
+
+} // namespace Test
+} // namespace Wae
diff --git a/tests/test-helper.cpp b/tests/test-helper.cpp
new file mode 100644
index 0000000..144299a
--- /dev/null
+++ b/tests/test-helper.cpp
@@ -0,0 +1,178 @@
+/*
+ * Copyright (c) 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.
+ * 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 test-helper.cpp
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ */
+#include "test-helper.h"
+
+#include <cstring>
+#include <vector>
+
+#include "key_handler.h"
+#include "crypto_service.h"
+
+#include "test-common.h"
+
+namespace Wae {
+namespace Test {
+
+void add_get_remove_dek(wae_app_type_e app_type)
+{
+ const char *pkg_id = "TEST_PKG_ID";
+
+ std::vector<unsigned char> dek(32, 0);
+
+ BOOST_REQUIRE(_get_random(dek.size(), dek.data()) == WAE_ERROR_NONE);
+
+ remove_app_dek(pkg_id, app_type);
+
+ int tmp = _add_dek_to_key_manager(pkg_id, app_type, dek.data(), dek.size());
+ BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE,
+ "Failed to _add_dek_to_key_manager. ec: " << tmp);
+
+ unsigned char *_stored_dek = nullptr;
+ size_t _stored_dek_len = 0;
+ tmp = get_app_dek(pkg_id, app_type, &_stored_dek, &_stored_dek_len);
+ BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE,
+ "Failed to get_app_dek. ec: " << tmp);
+
+ auto stored_dek = Wae::Test::bytearr_to_vec(_stored_dek, _stored_dek_len);
+ free(_stored_dek);
+
+ BOOST_REQUIRE_MESSAGE(stored_dek == dek, "stored dek and dek isn't matched!");
+
+ tmp = remove_app_dek(pkg_id, app_type);
+ BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE, "Failed to remove_app_dek. ec: " << tmp);
+
+ _stored_dek = nullptr;
+ tmp = get_app_dek(pkg_id, app_type, &_stored_dek, &_stored_dek_len);
+ if (_stored_dek)
+ free(_stored_dek);
+
+ BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NO_KEY,
+ "dek removed but it's remained still. ec: " << tmp);
+}
+
+void create_app_dek(wae_app_type_e app_type)
+{
+ const char *pkg_id = "TEST_PKG_ID";
+
+ remove_app_dek(pkg_id, app_type);
+
+ unsigned char *_dek = nullptr;
+ size_t _dek_len = 0;
+
+ int tmp = create_app_dek(pkg_id, app_type, &_dek, &_dek_len);
+ BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE,
+ "Failed to create_app_dek. ec: " << tmp);
+
+ auto dek = Wae::Test::bytearr_to_vec(_dek, _dek_len);
+ free(_dek);
+
+ unsigned char *_stored_dek = nullptr;
+ size_t _stored_dek_len = 0;
+ tmp = get_app_dek(pkg_id, app_type, &_stored_dek, &_stored_dek_len);
+ BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE, "Failed to get_app_dek. ec: " << tmp);
+ auto stored_dek = bytearr_to_vec(_stored_dek, _stored_dek_len);
+ free(_stored_dek);
+
+ BOOST_REQUIRE_MESSAGE(stored_dek == dek,
+ "stored dek and dek isn't matched! "
+ "stored_dek(" << Wae::Test::bytes_to_hex(stored_dek) << ") "
+ "dek(" << Wae::Test::bytes_to_hex(dek) << ")");
+
+ remove_app_dek(pkg_id, app_type);
+}
+
+void encrypt_decrypt_web_app(wae_app_type_e app_type)
+{
+ const char *pkg_id1 = "testpkg_for_normal";
+ const char *pkg_id2 = "testpkg_for_global";
+ const char *pkg_id3 = "testpkg_for_preloaded";
+
+ const char *pkg_id = nullptr;
+ switch (app_type) {
+ case WAE_DOWNLOADED_NORMAL_APP:
+ pkg_id = pkg_id1;
+ break;
+
+ case WAE_DOWNLOADED_GLOBAL_APP:
+ pkg_id = pkg_id2;
+ break;
+
+ case WAE_PRELOADED_APP:
+ default:
+ pkg_id = pkg_id3;
+ break;
+ }
+
+ // remove old test data
+ wae_remove_app_dek(pkg_id, app_type);
+
+ if (app_type == WAE_PRELOADED_APP)
+ _clear_app_deks_loaded();
+
+ std::vector<unsigned char> plaintext = {
+ 'a', 'b', 'c', 'a', 'b', 'c', 'x', 'y',
+ 'o', 'q', '2', 'e', 'v', '0', '1', 'x'
+ };
+
+ // test for downloaded web application
+ unsigned char *_encrypted = nullptr;
+ size_t _enc_len = 0;
+ int tmp = wae_encrypt_web_application(pkg_id, app_type, plaintext.data(),
+ plaintext.size(), &_encrypted, &_enc_len);
+ BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE,
+ "Failed to wae_encrypt_web_application. ec: " << tmp);
+ free(_encrypted);
+
+ // encrypt test twice
+ tmp = wae_encrypt_web_application(pkg_id, app_type, plaintext.data(),
+ plaintext.size(), &_encrypted, &_enc_len);
+ BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE,
+ "Failed to wae_encrypt_web_application second time. ec: " << tmp);
+
+ auto encrypted = bytearr_to_vec(_encrypted, _enc_len);
+ free(_encrypted);
+
+ _remove_app_dek_from_cache(pkg_id);
+
+ if (app_type == WAE_PRELOADED_APP)
+ load_preloaded_app_deks(true);
+
+ unsigned char *_decrypted = nullptr;
+ size_t _dec_len = 0;
+ tmp = wae_decrypt_web_application(pkg_id, app_type, encrypted.data(),
+ encrypted.size(), &_decrypted, &_dec_len);
+ BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE,
+ "Failed to wae_decrypt_web_application. ec: " << tmp);
+
+ auto decrypted = bytearr_to_vec(_decrypted, _dec_len);
+
+ BOOST_REQUIRE_MESSAGE(plaintext == decrypted,
+ "plaintext and decrypted isn't matched! "
+ "plaintext(" << Wae::Test::bytes_to_hex(plaintext) << ") "
+ "decrypted(" << Wae::Test::bytes_to_hex(decrypted) << ")");
+
+ tmp = wae_remove_app_dek(pkg_id, app_type);
+ BOOST_REQUIRE_MESSAGE(tmp == WAE_ERROR_NONE,
+ "Failed to wae_remove_app_dek. ec: " << tmp);
+}
+
+} // namespace Test
+} // namespace Wae
diff --git a/tests/test-helper.h b/tests/test-helper.h
new file mode 100644
index 0000000..132ceae
--- /dev/null
+++ b/tests/test-helper.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 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.
+ * 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 test-helper.h
+ * @author Kyungwook Tak (k.tak@samsung.com)
+ * @version 1.0
+ */
+#pragma once
+
+#include "web_app_enc.h"
+
+namespace Wae {
+namespace Test {
+
+void add_get_remove_dek(wae_app_type_e app_type);
+void create_app_dek(wae_app_type_e app_type);
+void encrypt_decrypt_web_app(wae_app_type_e app_type);
+
+} // namespace Test
+} // namespace Wae
diff --git a/tests/wae_tests.c b/tests/wae_tests.c
deleted file mode 100644
index c724d21..0000000
--- a/tests/wae_tests.c
+++ /dev/null
@@ -1,923 +0,0 @@
-/*
- * Copyright (c) 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.
- * 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 wae_tests.c
- * @author Dongsun Lee (ds73.lee@samsung.com)
- * @version 1.0
- * @brief internal test cases for libwebappenc.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "web_app_enc.h"
-#include "key_handler.h"
-#include "crypto_service.h"
-
-#include <tzplatform_config.h>
-
-static int tc_seq = 0;
-static int tc_succ = 0;
-static int tc_fail = 0;
-
-#define FPRINTF(format, args...) fprintf(stdout, format, ##args)
-
-static int RUNTC(int (*tc_method)(), const char *tc_name)
-{
- int ret = WAE_ERROR_NONE;
- FPRINTF("[%02d:%s]started...\n", tc_seq, tc_name);
- ret = tc_method();
-
- if (ret == WAE_ERROR_NONE) {
- FPRINTF("[%02d:%s]ended. SUCCESS\n\n", tc_seq, tc_name);
- tc_succ++;
- } else {
- FPRINTF("[%02d:%s]ended. FAIL. error=%d\n\n", tc_seq, tc_name, ret);
- tc_fail++;
- }
-
- tc_seq++;
- return ret;
-}
-
-static void PRINT_TC_SUMMARY()
-{
- FPRINTF("\n");
- FPRINTF("===============================================\n");
- FPRINTF(" TOTAL = %d, SUCCESS = %d, FAIL = %d\n", tc_seq, tc_succ, tc_fail);
- FPRINTF("===============================================\n");
-}
-
-void _print_binary_to_hex(const char *msg, unsigned char *bin, size_t len)
-{
- size_t i = 0;
- FPRINTF("%s", msg);
-
- for (i = 0; i < len; i++) {
- FPRINTF("%02x", bin[i]);
- }
-
- FPRINTF("\n");
-}
-
-int _compare_binary(const unsigned char *b1, size_t b1Len, const unsigned char *b2, size_t b2Len)
-{
- size_t i = 0;
-
- if (b1Len != b2Len)
- return b1Len - b2Len;
-
- for (i = 0; i < b1Len; i++) {
- if (b1[i] != b2[i])
- return b1[i] - b2[i];
- }
-
- return 0;
-}
-
-//=================================================================================
-// tests for crypto_service.h
-//=================================================================================
-int wae_tc_encrypt_decrypt_app_dek()
-{
- int ret = WAE_ERROR_NONE;
- unsigned char dek[32];
- unsigned char *encryptedDek = NULL;
- size_t encryptedDekLen = 0;
- unsigned char *decryptedDek = NULL;
- size_t decryptedDekLen = 0;
-
- const char *priKey =
- "-----BEGIN RSA PRIVATE KEY-----\n"
- "MIIEpgIBAAKCAQEA0kWtjpRO7Zh2KX2naVE/BDJdrfwK9xexfNA0MkY2VJ4J2AKM\n"
- "YTj1D1jntceryupCEHOvP3rum+WsFvPXduz9+VKnSsSqj4jcTUubtpDUGA5G79Iq\n"
- "LEPFuSBaqI8Uwkzd08pE+s30oaJDnNazMhSq8JkqBPoCCwtUs73ruE9VbtsBO/kT\n"
- "lASIAfe8nXqcJLcDQgWYhizjJw0Pi6d74oCwS2OTvQDNvsXfFnA0ZJEEYw/rZLir\n"
- "j7OHoOjz+Sh5N+1uA3Up6SPPEbHuP6L12YxqHdy7gnJXodLhvE/cR4SN9VW7+qmC\n"
- "MBjmLkBejGrEX3STS9sLI7MZHu9Y26dwuYb4+wIDAQABAoIBAQCwxqV/vc2RUGDe\n"
- "xuXM0+IvrAw37jJlw4SS0xNexMp+XxMViCbuwYy851h96azS/himbiuCKd6aL/96\n"
- "mGunbtyiFEvSvv5Jh5z2Wr9BQAcfZjla+4w7BIsg9UNifE/OfgLsQBu34xhsHtfK\n"
- "7nFehCOl/I5n+qtnD5KZPe0DWacQdwY4vEAj6YyXdb2bBg+MiwE9KVxGEIUDbklh\n"
- "Is70JXczjLZCS+lIpOKh0/lbZmBZePoUbVTtS+GvtPTpQC/aTHRkwGoEtuPEWpbL\n"
- "0Q1d6zO+vDJVLJlb5FF2haghs8IlqAxkkPjeUTNye+WktRrDQxmPu/blbxQrygfq\n"
- "Au5tBnsxAoGBAOiVtcpg32puo3Yq2Y78oboe9PuHaQP0d3DhwP3/7J0BeNslpjW7\n"
- "E1LWsVsCanxTE8XPUdFfAWgMk7lQqESN0wawGmSmWk+eQPZdjHanBaC8vh7aKjo6\n"
- "q9FdT1DKjrRi23QyDco3f3E7hvM93IAAhw1ikNu8DT19JAxtdeMh5WAZAoGBAOdw\n"
- "6neEvIFXh3RWEv2/GKVhVR8mxDqxmuFdXpOF+YWsK0Tg4uC8jm9kUGnwXgT2Mjke\n"
- "oAwYAFcRbHQQGsxy/vkV16kv4aurTE2hMpjeXCAakwV0Pi2w1f9WnDokjgORkOmc\n"
- "+QK9I8egdFPMVDfQjhLslhSUY0Eb4qcJ6q9WxfQzAoGBANSsAFybk+7oWAO3TtQW\n"
- "YXOk1vIgcYAyS/0mEKixGZS/QdlxZbf/5b17nxTO8rvX416fIftG2ixgQ7vR6us0\n"
- "m9+jq56ZFj9zP4eHJudf9h9yNo5TgwVXnMCGh/4iGbcMJgrrsfxUHu5VNiK5UCSj\n"
- "VtqAZGDoZVryUMIkXQVhezIRAoGBAN7QUIqcGbcUA24257Wu4hVlrUN+WPCAyDEr\n"
- "aL/x/ZV5eXaoYwQlw6LuGpTDOmDgfN2M5FyARuOL/LOIRaSLGXnIU4WoeUSCd8VM\n"
- "6Z9Og7bMnrpjfPEUDBH02hcH1kkNPUwLOZgva2Dm0tdSIcpSWFVTu/E4Io4uQHi8\n"
- "DVqc2ZsNAoGBAJT76ezXNSSv8hnrKqTpwgTicpqhRZ3eFQjyl4HRL26AJMKv++x8\n"
- "4/IsVIwxaHzpbN3nnCjmAHV4gX9YpxVnvYcZflC9WZeDkwNMLmPYb3Zg27EzSMfQ\n"
- "8yrfWJZo3qobipcHf1yohAt4fHk9kUKtPHEwp0xKe//rfhswLb3VCzvQ\n"
- "-----END RSA PRIVATE KEY-----";
- const char *pubKey =
- "-----BEGIN PUBLIC KEY-----\n"
- "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0kWtjpRO7Zh2KX2naVE/\n"
- "BDJdrfwK9xexfNA0MkY2VJ4J2AKMYTj1D1jntceryupCEHOvP3rum+WsFvPXduz9\n"
- "+VKnSsSqj4jcTUubtpDUGA5G79IqLEPFuSBaqI8Uwkzd08pE+s30oaJDnNazMhSq\n"
- "8JkqBPoCCwtUs73ruE9VbtsBO/kTlASIAfe8nXqcJLcDQgWYhizjJw0Pi6d74oCw\n"
- "S2OTvQDNvsXfFnA0ZJEEYw/rZLirj7OHoOjz+Sh5N+1uA3Up6SPPEbHuP6L12Yxq\n"
- "Hdy7gnJXodLhvE/cR4SN9VW7+qmCMBjmLkBejGrEX3STS9sLI7MZHu9Y26dwuYb4\n"
- "+wIDAQAB\n"
- "-----END PUBLIC KEY-----";
-
- ret = encrypt_app_dek((const unsigned char *) pubKey, strlen(pubKey),
- dek, sizeof(dek), &encryptedDek, &encryptedDekLen);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: encrypt_app_dek. ret=%d\n", ret);
- ret = WAE_ERROR_CRYPTO;
- goto error;
- }
-
- ret = decrypt_app_dek((const unsigned char *) priKey, strlen(priKey), NULL,
- encryptedDek, encryptedDekLen, &decryptedDek, &decryptedDekLen);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: decrypt_app_dek. ret=%d\n", ret);
- ret = WAE_ERROR_CRYPTO;
- goto error;
- }
-
- _print_binary_to_hex("...ORIG DEK= ", dek, sizeof(dek));
- _print_binary_to_hex("...ENC DEK= ", encryptedDek, encryptedDekLen);
- _print_binary_to_hex("...DEC DEK= ", decryptedDek, decryptedDekLen);
-
- if (_compare_binary(dek, sizeof(dek), decryptedDek, decryptedDekLen) != 0) {
- FPRINTF("...FAIL: ORIG DEK != decrypted DEK\n");
- ret = WAE_ERROR_CRYPTO;
- goto error;
- }
-
- ret = WAE_ERROR_NONE;
-
-error:
- if (encryptedDek != NULL)
- free(encryptedDek);
-
- if (decryptedDek != NULL)
- free(decryptedDek);
-
- return ret;
-}
-
-int wae_tc_encrypt_decrypt_aes_cbc()
-{
- int ret = WAE_ERROR_NONE;
-
- unsigned char dek[32] = {0, };
- size_t keyLen = 32;
- const char *plaintext = "adbdfdfdfdfdererfdfdfererfdrerfdrer";
- size_t plaintextLen = strlen(plaintext);
- unsigned char *encrypted = NULL;
- size_t encLen = 0;
- unsigned char *decrypted = NULL;
- size_t decLen = 0;
- char decrypted_str[1024] = {0, };
-
- ret = _get_random(keyLen, dek);
-
- ret = encrypt_aes_cbc(dek, keyLen, (const unsigned char *)plaintext, plaintextLen, &encrypted, &encLen);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: encrypt_aes_cbc. ret=%d\n", ret);
- ret = WAE_ERROR_CRYPTO;
- goto error;
- }
-
- ret = decrypt_aes_cbc(dek, keyLen, encrypted, encLen, &decrypted, &decLen);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: decrypt_aes_cbc. ret=%d\n", ret);
- ret = WAE_ERROR_CRYPTO;
- goto error;
- }
-
- if (plaintextLen != decLen) {
- FPRINTF("...FAIL: plaintextLen(%d) != decLen(%d)\n", (int) plaintextLen, (int) decLen);
- ret = WAE_ERROR_CRYPTO;
- goto error;
- }
-
- memcpy(decrypted_str, decrypted, decLen);
- FPRINTF("...plaintext = %s\n", plaintext);
- FPRINTF("...decrypted = %s\n", decrypted_str);
-
- if (strcmp(plaintext, decrypted_str) != 0) {
- FPRINTF("...FAIL: plaintext(%s) != decrypted(%s)\n", plaintext, decrypted_str);
- ret = WAE_ERROR_CRYPTO;
- goto error;
- }
-
-error:
- if (encrypted != NULL)
- free(encrypted);
-
- if (decrypted != NULL)
- free(decrypted);
-
- return ret;
-}
-
-//=================================================================================
-// tests for key_handler.h
-//=================================================================================
-int wae_tc_cache()
-{
- int ret = WAE_ERROR_NONE;
-
- const char *pkg1 = "pkg1";
- const char *pkg2 = "pkg2";
- const char *pkg3 = "pkg3";
- const char *pkgDummy = "dummy";
-
- unsigned char dek1[32] = {1, };
- unsigned char dek2[32] = {2, };
- unsigned char dek3[32] = {3, };
- unsigned char *retDek = NULL;
-
- _initialize_cache();
-
- _add_app_dek_to_cache(pkg1, dek1);
- _add_app_dek_to_cache(pkg2, dek2);
- _add_app_dek_to_cache(pkg3, dek3);
-
- retDek = NULL;
- retDek = _get_app_dek_from_cache(pkg1);
-
- if (retDek == NULL || _compare_binary(dek1, 32, retDek, 32) != 0) {
- FPRINTF("failed in cache. Diffent DEK1\n");
- ret = WAE_ERROR_UNKNOWN;
- goto error;
- }
-
- _print_binary_to_hex("...DEK1 : ", dek1, 32);
- _print_binary_to_hex("...Returen DEK1 : ", retDek, 32);
-
- retDek = NULL;
- retDek = _get_app_dek_from_cache(pkg2);
-
- if (retDek == NULL || _compare_binary(dek2, 32, retDek, 32) != 0) {
- FPRINTF("failed in cache. Diffent DEK2\n");
- ret = WAE_ERROR_UNKNOWN;
- goto error;
- }
-
- _print_binary_to_hex("...DEK2 : ", dek2, 32);
- _print_binary_to_hex("...Returen DEK1 : ", retDek, 32);
-
- retDek = NULL;
- retDek = _get_app_dek_from_cache(pkg3);
-
- if (retDek == NULL || _compare_binary(dek3, 32, retDek, 32) != 0) {
- FPRINTF("failed in cache. Diffent DEK3\n");
- ret = WAE_ERROR_UNKNOWN;
- goto error;
- }
-
- _print_binary_to_hex("...DEK3 : ", dek3, 32);
- _print_binary_to_hex("...Returen DEK3 : ", retDek, 32);
-
- retDek = NULL;
- retDek = _get_app_dek_from_cache(pkgDummy);
-
- if (retDek != NULL) {
- FPRINTF("failed in cache. Wrong DEK_DUMMY1 returned\n");
- _print_binary_to_hex("retured wrong DEK : ", retDek, 32);
- ret = WAE_ERROR_UNKNOWN;
- goto error;
- }
-
- _remove_app_dek_from_cache(pkg3);
- retDek = NULL;
- retDek = _get_app_dek_from_cache(pkg3);
-
- if (retDek != NULL) {
- FPRINTF("fail to remove app dek from cache\n");
- ret = WAE_ERROR_UNKNOWN;
- goto error;
- }
-
- _initialize_cache();
-
- _add_app_dek_to_cache(pkg1, dek1);
-
- retDek = NULL;
- retDek = _get_app_dek_from_cache(pkg2);
-
- if (retDek != NULL) {
- FPRINTF("failed in cache. Wrong DEK_DUMMY2 returned\n");
- _print_binary_to_hex("retured wrong DEK : ", retDek, 32);
- ret = WAE_ERROR_UNKNOWN;
- goto error;
- }
-
- ret = WAE_ERROR_NONE;
-
-error:
- return ret;
-}
-
-int wae_tc_get_random()
-{
- int ret = WAE_ERROR_NONE;
-
- size_t rand_len = 32;
- unsigned char random[32] = {0, };
-
- ret = _get_random(rand_len, random);
-
- _print_binary_to_hex("...RANDOM = ", random, sizeof(random));
-
- return ret;
-}
-
-int wae_tc_get_alias()
-{
- int ret = WAE_ERROR_NONE;
-
- const char *pkgId = "TEST_PKG_ID";
- char alias[256] = {0, };
-
- _get_alias(pkgId, WAE_DOWNLOADED_NORMAL_APP, true, alias, sizeof(alias));
- FPRINTF("...pkgid=%s, alias for normal for save. app=%s\n", pkgId, alias);
-
- _get_alias(pkgId, WAE_DOWNLOADED_NORMAL_APP, false, alias, sizeof(alias));
- FPRINTF("...pkgid=%s, alias for normal for get. app=%s\n", pkgId, alias);
-
- _get_alias(pkgId, WAE_DOWNLOADED_GLOBAL_APP, true, alias, sizeof(alias));
- FPRINTF("...pkgid=%s, alias for global app=%s\n", pkgId, alias);
-
- _get_alias(pkgId, WAE_PRELOADED_APP, true, alias, sizeof(alias));
- FPRINTF("...pkgid=%s, alias for preloaded app=%s\n", pkgId, alias);
-
- return ret;
-}
-
-int _wae_tc_add_get_remove_dek(wae_app_type_e appType)
-{
- int ret = WAE_ERROR_NONE;
-
- const char *pkgId = "TEST_PKG_ID";
-
- size_t dekLen = 32;
- unsigned char dek[32] = {0, };
- size_t storedDekLen = 0;
- unsigned char *storedDek = NULL;
-
- ret = _get_random(dekLen, dek);
-
- remove_app_dek(pkgId, appType);
-
- ret = _add_dek_to_key_manager(pkgId, appType, dek, dekLen);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: _add_dek_to_key_manager. ret=%d\n", ret);
- goto error;
- }
-
- ret = get_app_dek(pkgId, appType, &storedDek, &storedDekLen);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: get_app_dek. ret=%d\n", ret);
- goto error;
- }
-
- if (_compare_binary(dek, dekLen, storedDek, storedDekLen) != 0) {
- ret = WAE_ERROR_KEY_MANAGER;
- FPRINTF("...FAIL: DEK != STORED_DEK.\n");
- goto error;
- }
-
- ret = remove_app_dek(pkgId, appType);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: remove_app_dek. ret=%d\n", ret);
- goto error;
- }
-
- ret = get_app_dek(pkgId, appType, &storedDek, &storedDekLen);
-
- if (ret == WAE_ERROR_NONE) {
- ret = WAE_ERROR_UNKNOWN;
- FPRINTF("...FAIL: APP DEK still exists in key_manager.\n");
- goto error;
- }
-
- ret = WAE_ERROR_NONE;
-
-error:
- if (storedDek != NULL)
- free(storedDek);
-
- return ret;
-}
-
-int wae_tc_add_get_remove_dek_for_normal_app()
-{
- return _wae_tc_add_get_remove_dek(WAE_DOWNLOADED_NORMAL_APP);
-}
-
-int wae_tc_add_get_remove_dek_for_global_app()
-{
- return _wae_tc_add_get_remove_dek(WAE_DOWNLOADED_GLOBAL_APP);
-}
-
-int wae_tc_add_get_remove_dek_for_preloaded_app()
-{
- return _wae_tc_add_get_remove_dek(WAE_PRELOADED_APP);
-}
-
-int wae_tc_get_preloaded_app_dek_file_path()
-{
- int ret = WAE_ERROR_NONE;
-
- const char *pkgId = "test_pkg";
- const char *expectedPath = tzplatform_mkpath4(TZ_SYS_SHARE,
- "wae", "app_dek", "WAE_APP_DEK_test_pkg.adek");
- char path[256];
-
- FPRINTF("...expected path : %s\n", expectedPath);
- ret = _get_preloaded_app_dek_file_path(pkgId, sizeof(path), path);
- FPRINTF("...returned path : %s\n", path);
-
- if (ret != WAE_ERROR_NONE || strncmp(expectedPath, path, strlen(expectedPath)) != 0) {
- ret = WAE_ERROR_UNKNOWN;
- goto error;
- }
-
-error:
- return ret;
-}
-
-int wae_tc_extract_pkg_id_from_file_name()
-{
- int ret = WAE_ERROR_NONE;
- const char *fileName = "WAE_APP_DEK_test_pkg.adek";
- const char *expectedPkgId = "test_pkg";
- char pkgId[100];
-
- ret = _extract_pkg_id_from_file_name(fileName, pkgId);
- FPRINTF("...expected pkgId: %s\n", expectedPkgId);
- FPRINTF("...returned pkgId: %s\n", pkgId);
-
- if (ret != WAE_ERROR_NONE || strncmp(expectedPkgId, pkgId, strlen(expectedPkgId)) != 0) {
- ret = WAE_ERROR_UNKNOWN;
- goto error;
- }
-
-error:
- return ret;
-
-}
-
-int wae_tc_read_write_encrypted_app_dek()
-{
- int ret = WAE_ERROR_NONE;
- const char *pkgId = "write_test_pkg";
- unsigned char dek[256];
- unsigned char *readDek = NULL;
- size_t readDekLen = 0;
-
- ret = _write_encrypted_app_dek_to_file(pkgId, dek, sizeof(dek));
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("Fail to _write_encrypted_app_dek_to_file. pkgId=%s\n", pkgId);
- goto error;
- }
-
- ret = _read_encrypted_app_dek_from_file(pkgId, &readDek, &readDekLen);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("Fail to _read_encrypted_app_dek_from_file. pkgId=%s\n", pkgId);
- goto error;
- }
-
- _print_binary_to_hex("...ORIG DEK= ", dek, sizeof(dek));
- _print_binary_to_hex("...READ DEK= ", readDek, readDekLen);
-
- if (_compare_binary(dek, sizeof(dek), readDek, readDekLen) != 0) {
- ret = WAE_ERROR_UNKNOWN;
- FPRINTF("...FAIL: DEK != read_DEK.\n");
- goto error;
- }
-
-error:
- if (readDek != NULL)
- free(readDek);
-
- return ret;
-}
-
-
-int _wae_tc_create_app_dek(wae_app_type_e appType)
-{
- int ret = WAE_ERROR_NONE;
-
- const char *pkgId = "TEST_PKG_ID";
- unsigned char *dek = NULL;
- size_t dekLen = 0;
-
- size_t storedDekLen = 0;
- unsigned char *storedDek = NULL;
-
- remove_app_dek(pkgId, appType);
-
- ret = create_app_dek(pkgId, appType, &dek, &dekLen);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: create_app_dek. ret=%d\n", ret);
- goto error;
- }
-
- ret = get_app_dek(pkgId, appType, &storedDek, &storedDekLen);
-
- if (ret != WAE_ERROR_NONE) {
- ret = WAE_ERROR_KEY_MANAGER;
- FPRINTF("...FAIL: get_app_dek. ret=%d\n", ret);
- goto error;
- }
-
- _print_binary_to_hex("...CREATED DEK = ", dek, dekLen);
- _print_binary_to_hex("...STORED DEK = ", storedDek, storedDekLen);
-
- if (_compare_binary(dek, dekLen, storedDek, storedDekLen) != 0) {
- ret = WAE_ERROR_FILE;
- FPRINTF("...FAIL: DEK != STORED_DEK.\n");
- goto error;
- }
-
- remove_app_dek(pkgId, appType);
-
- ret = WAE_ERROR_NONE;
-
-error:
- if (dek != NULL)
- free(dek);
-
- if (storedDek != NULL)
- free(storedDek);
-
- return ret;
-}
-
-int wae_tc_create_app_dek_for_normal_app()
-{
- return _wae_tc_create_app_dek(WAE_DOWNLOADED_NORMAL_APP);
-}
-
-int wae_tc_create_app_dek_for_global_app()
-{
- return _wae_tc_create_app_dek(WAE_DOWNLOADED_GLOBAL_APP);
-}
-
-int wae_tc_create_app_dek_for_preloaded_app()
-{
- return _wae_tc_create_app_dek(WAE_PRELOADED_APP);
-}
-
-int wae_tc_get_create_preloaded_app_dek()
-{
- int ret = WAE_ERROR_NONE;
-
- const char *pkgId = "TEST_PKG_ID_FOR_CREATE";
- unsigned char *dek = NULL;
- unsigned char *readDek = NULL;
- size_t readDekLen = 0;
- size_t dekLen = 0;
-
- ret = get_preloaded_app_dek(pkgId, &readDek, &readDekLen);
-
- if (ret != WAE_ERROR_NO_KEY) {
- FPRINTF("...FAIL: There should be no APP DEK. get_preloaded_app_dek. ret=%d\n", ret);
- ret = WAE_ERROR_FILE;
- goto error;
- }
-
- ret = create_preloaded_app_dek(pkgId, &dek, &dekLen);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: create_preloaded_app_dek. ret=%d\n", ret);
- goto error;
- }
-
- ret = get_preloaded_app_dek(pkgId, &readDek, &readDekLen);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: get_preloaded_app_dek. ret=%d\n", ret);
- goto error;
- }
-
- _print_binary_to_hex("...CREATED DEK = ", dek, dekLen);
- _print_binary_to_hex("...READ DEK = ", readDek, readDekLen);
-
- if (_compare_binary(dek, dekLen, readDek, readDekLen) != 0) {
- ret = WAE_ERROR_FILE;
- FPRINTF("...FAIL: DEK != READ_DEK.\n");
- goto error;
- }
-
- ret = WAE_ERROR_NONE;
-
-error:
- if (dek != NULL)
- free(dek);
-
- if (readDek != NULL)
- free(readDek);
-
- return ret;
-}
-
-int wae_tc_load_preloaded_app_deks()
-{
- int ret = WAE_ERROR_NONE;
-
- const char *pkgId1 = "TEST_PKGID_1";
- unsigned char *dek1 = NULL;
- size_t dekLen1 = 0;
- unsigned char *readDek1 = NULL;
- size_t readDekLen1 = 0;
- char path1[MAX_PATH_LEN] = {0, };
-
- const char *pkgId2 = "TEST_PKGID_2";
- unsigned char *dek2 = NULL;
- size_t dekLen2 = 0;
- unsigned char *readDek2 = NULL;
- size_t readDekLen2 = 0;
- char path2[MAX_PATH_LEN] = {0, };
-
- _get_preloaded_app_dek_file_path(pkgId1, sizeof(path1), path1);
- _get_preloaded_app_dek_file_path(pkgId2, sizeof(path2), path2);
-
- // remove old test data
- remove_app_dek(pkgId1, WAE_PRELOADED_APP);
- remove_app_dek(pkgId2, WAE_PRELOADED_APP);
- unlink(path1);
- unlink(path2);
-
- // create 2 dek for preloaded app
- ret = create_preloaded_app_dek(pkgId1, &dek1, &dekLen1);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: create_preloaded_app_dek. ret=%d\n", ret);
- goto error;
- }
-
- ret = create_preloaded_app_dek(pkgId2, &dek2, &dekLen2);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: create_preloaded_app_dek. ret=%d\n", ret);
- goto error;
- }
-
- // load_preloaded_app_deks
- ret = load_preloaded_app_deks(true);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: load_preloaded_app_deks. ret=%d\n", ret);
- goto error;
- }
-
- // get_app_dek
- ret = get_app_dek(pkgId1, WAE_PRELOADED_APP, &readDek1, &readDekLen1);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: get_app_dek. ret=%d\n", ret);
- goto error;
- }
-
- ret = get_app_dek(pkgId2, WAE_PRELOADED_APP, &readDek2, &readDekLen2);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: get_app_dek. ret=%d\n", ret);
- goto error;
- }
-
- _print_binary_to_hex("...CREATED DEK1 = ", dek1, dekLen1);
- _print_binary_to_hex("...READ DEK1 = ", readDek1, readDekLen1);
-
- if (_compare_binary(dek1, dekLen1, readDek1, readDekLen1) != 0) {
- ret = WAE_ERROR_FILE;
- FPRINTF("...FAIL: DEK1 != READ_DEK1.\n");
- goto error;
- }
-
- _print_binary_to_hex("...CREATED DEK2 = ", dek2, dekLen2);
- _print_binary_to_hex("...READ DEK2 = ", readDek2, readDekLen2);
-
- if (_compare_binary(dek2, dekLen2, readDek2, readDekLen2) != 0) {
- ret = WAE_ERROR_FILE;
- FPRINTF("...FAIL: DEK2 != READ_DEK2.\n");
- goto error;
- }
-
- // remove_app_dek
- remove_app_dek(pkgId1, WAE_PRELOADED_APP);
- remove_app_dek(pkgId2, WAE_PRELOADED_APP);
-
- ret = WAE_ERROR_NONE;
-
-error:
- if (dek1 != NULL)
- free(dek1);
-
- if (readDek1 != NULL)
- free(readDek1);
-
- if (dek2 != NULL)
- free(dek2);
-
- if (readDek2 != NULL)
- free(readDek2);
-
- return ret;
-}
-
-int _wae_tc_encrypt_decrypt_web_app(wae_app_type_e appType)
-{
- int ret = WAE_ERROR_NONE;
-
- const char *pkgId1 = "testpkg_for_normal";
- const char *pkgId2 = "testpkg_for_global";
- const char *pkgId3 = "testpkg_for_preloaded";
- const char *pkgId = NULL;
- const char *plaintext = "adbdfdfdfdfdererfdfdfererfdrerfdrer";
- size_t plaintextLen = strlen(plaintext);
- unsigned char *encrypted = NULL;
- size_t encLen = 0;
- unsigned char *decrypted = NULL;
- size_t decLen = 0;
- char decrypted_str[1024] = {0, };
-
- switch (appType) {
- case WAE_DOWNLOADED_NORMAL_APP:
- pkgId = pkgId1;
- break;
-
- case WAE_DOWNLOADED_GLOBAL_APP:
- pkgId = pkgId2;
- break;
-
- case WAE_PRELOADED_APP:
- pkgId = pkgId3;
- break;
- }
-
- // remove old test data
- ret = wae_remove_app_dek(pkgId, appType);
-
- if (appType == WAE_PRELOADED_APP) {
- _clear_app_deks_loaded();
- }
-
- // test for downloaded web application
- ret = wae_encrypt_web_application(pkgId, appType,
- (const unsigned char *)plaintext, plaintextLen,
- &encrypted, &encLen);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: wae_encrypt_web_application. ret=%d\n", ret);
- goto error;
- }
-
- // encrypt test twice
- ret = wae_encrypt_web_application(pkgId, appType,
- (const unsigned char *)plaintext, plaintextLen,
- &encrypted, &encLen);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: wae_encrypt_web_application. ret=%d\n", ret);
- goto error;
- }
-
- _remove_app_dek_from_cache(pkgId);
-
- if (appType == WAE_PRELOADED_APP) {
- load_preloaded_app_deks(true);
- }
-
- ret = wae_decrypt_web_application(pkgId, appType, encrypted, encLen, &decrypted, &decLen);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: wae_decrypt_web_application. ret=%d\n", ret);
- goto error;
- }
-
- if (plaintextLen != decLen) {
- FPRINTF("...FAIL: plaintextLen(%d) != decLen(%d)\n", (int) plaintextLen, (int) decLen);
- ret = WAE_ERROR_CRYPTO;
- goto error;
- }
-
- memcpy(decrypted_str, decrypted, decLen);
- FPRINTF("...plaintext(downloaded) = %s\n", plaintext);
- FPRINTF("...decrypted(downloaded) = %s\n", decrypted_str);
-
- if (strcmp(plaintext, decrypted_str) != 0) {
- FPRINTF("...FAIL: plaintext(%s) != decrypted(%s)\n", plaintext, decrypted_str);
- ret = WAE_ERROR_CRYPTO;
- goto error;
- }
-
- ret = wae_remove_app_dek(pkgId, appType);
-
- if (ret != WAE_ERROR_NONE) {
- FPRINTF("...FAIL: wae_remove_app_dek. ret=%d\n", ret);
- goto error;
- }
-
-error:
- if (encrypted != NULL)
- free(encrypted);
-
- if (decrypted != NULL)
- free(decrypted);
-
- return ret;
-}
-
-int wae_tc_encrypt_decrypt_normal_app()
-{
- return _wae_tc_encrypt_decrypt_web_app(WAE_DOWNLOADED_NORMAL_APP);
-}
-
-int wae_tc_encrypt_decrypt_global_app()
-{
- return _wae_tc_encrypt_decrypt_web_app(WAE_DOWNLOADED_GLOBAL_APP);
-}
-
-int wae_tc_encrypt_decrypt_preloaded_app()
-{
- return _wae_tc_encrypt_decrypt_web_app(WAE_PRELOADED_APP);
-}
-
-
-int run_test_cases(char *test_mode)
-{
- if (strcmp(test_mode, "system") == 0) {
- RUNTC(wae_tc_encrypt_decrypt_app_dek, "wae_tc_encrypt_decrypt_app_dek");
- RUNTC(wae_tc_encrypt_decrypt_aes_cbc, "wae_tc_encrypt_decrypt_aes_cbc");
- RUNTC(wae_tc_cache, "wae_tc_cache");
-
- RUNTC(wae_tc_get_random, "wae_tc_get_random");
- RUNTC(wae_tc_get_alias, "wae_tc_get_alias");
-
- RUNTC(wae_tc_add_get_remove_dek_for_global_app, "wae_tc_add_get_remove_dek_for_global_app");
- RUNTC(wae_tc_add_get_remove_dek_for_preloaded_app, "wae_tc_add_get_remove_dek_for_preloaded_app");
-
- RUNTC(wae_tc_get_preloaded_app_dek_file_path, "wae_tc_get_preloaded_app_dek_file_path");
- RUNTC(wae_tc_extract_pkg_id_from_file_name, "wae_tc_extract_pkg_id_from_file_name");
- RUNTC(wae_tc_read_write_encrypted_app_dek, "wae_tc_read_write_encrypted_app_dek");
-
- RUNTC(wae_tc_create_app_dek_for_global_app, "wae_tc_create_app_dek_for_global_app");
- RUNTC(wae_tc_create_app_dek_for_preloaded_app, "wae_tc_create_app_dek_for_preloaded_app");
-
- RUNTC(wae_tc_get_create_preloaded_app_dek, "wae_tc_get_create_preloaded_app_dek");
- RUNTC(wae_tc_load_preloaded_app_deks, "wae_tc_load_preloaded_app_deks");
-
- RUNTC(wae_tc_encrypt_decrypt_global_app, "wae_tc_encrypt_decrypt_global_app");
- RUNTC(wae_tc_encrypt_decrypt_preloaded_app, "wae_tc_encrypt_decrypt_preloaded_app");
- } else {
- RUNTC(wae_tc_add_get_remove_dek_for_normal_app, "wae_tc_add_get_remove_dek_for_normal_app");
- RUNTC(wae_tc_create_app_dek_for_normal_app, "wae_tc_create_app_dek_for_normal_app");
- RUNTC(wae_tc_encrypt_decrypt_normal_app, "wae_tc_encrypt_decrypt_normal_app");
- }
-
- PRINT_TC_SUMMARY();
- return 0;
-}
-
-int main(int argc, char *argv[])
-{
- int ret = 0;
-
- if (argc != 2 || (strcmp(argv[1], "system") != 0 && strcmp(argv[1], "user"))) {
- FPRINTF("invalid command formant. command format : %s system|user\n", argv[0]);
- exit(1);
- }
-
- ret = run_test_cases(argv[1]);
-
- return ret;
-}