CKM: Read ckm data dir location from tzplatform_config 73/56773/3
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 12 Jan 2016 12:24:40 +0000 (13:24 +0100)
committerBartlomiej Grzelewski <b.grzelewski@samsung.com>
Thu, 14 Jan 2016 13:24:01 +0000 (14:24 +0100)
[Problem] Key-manager reads data dir location from tzplatform_config.
Security-tests have the path hardcoded.
[Solution] Make security-tests read data dir location from tzplatform_config as
well.

[Verification] Run ckm-tests

Change-Id: I3e5c6f98bc34c27664218972e6ee76139b0a12e7

packaging/security-tests.spec
src/ckm/CMakeLists.txt
src/ckm/async-api.cpp
src/ckm/capi-testcases.cpp
src/ckm/initial-values.cpp
src/ckm/main.cpp

index 6591537..f5f67d9 100644 (file)
@@ -32,6 +32,9 @@ Requires: perf
 Requires: gdb
 Requires: key-manager-listener
 
+%global ckm_test_dir %{?TZ_SYS_SHARE:%TZ_SYS_SHARE/ckm-test/}%{!?TZ_SYS_SHARE:/usr/share/ckm-test/}
+%global ckm_rw_data_dir %{?TZ_SYS_DATA:%TZ_SYS_DATA/ckm/}%{!?TZ_SYS_DATA:/opt/data/ckm/}
+
 %description
 Security tests repository - for tests that can't be kept together with code.
 
@@ -51,7 +54,9 @@ cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} \
 %endif
         -DCMAKE_VERBOSE_MAKEFILE=ON       \
         -DCYNARA_DB_DIR=%{_localstatedir}/cynara/db \
-        -DAPP_USER="security_test_user"
+        -DAPP_USER="security_test_user" \
+        -DCKM_TEST_DIR=%{ckm_test_dir} \
+        -DCKM_RW_DATA_DIR=%{ckm_rw_data_dir}
 make %{?jobs:-j%jobs}
 
 %install
@@ -110,7 +115,7 @@ echo "security-tests postinst done ..."
 /usr/bin/cynara-test
 /usr/bin/ckm-tests
 /usr/bin/ckm-integration-tests
-/usr/share/ckm-test/*
+%{ckm_test_dir}/*
 /etc/security-tests
 /usr/lib/security-tests/cynara-tests/plugins/single-policy/*
 /usr/lib/security-tests/cynara-tests/plugins/multiple-policy/*
index d623ad3..7ffa6a2 100644 (file)
@@ -27,6 +27,9 @@ ELSE (DEFINED SECURITY_MDFPP_STATE_ENABLED)
     MESSAGE("SECURITY_MDFPP_STATE_ENABLE DISABLED !")
 ENDIF (DEFINED SECURITY_MDFPP_STATE_ENABLED)
 
+ADD_DEFINITIONS("-DCKM_TEST_DIR=\"${CKM_TEST_DIR}\"")
+ADD_DEFINITIONS("-DCKM_RW_DATA_DIR=\"${CKM_RW_DATA_DIR}\"")
+
 # Dependencies
 PKG_CHECK_MODULES(CKM_DEP
     libsmack
@@ -75,7 +78,7 @@ INSTALL(FILES
     XML_2_okay.xml
     XML_3_wrong.xml
     device_key.xml
-    DESTINATION /usr/share/ckm-test
+    DESTINATION ${CKM_TEST_DIR}
     )
 
 # C compilation
index 7e222b3..37472b3 100644 (file)
@@ -405,7 +405,7 @@ public:
 
 CKM::PKCS12ShPtr loadPkcs()
 {
-    std::ifstream is("/usr/share/ckm-test/pkcs.p12");
+    std::ifstream is(CKM_TEST_DIR "/pkcs.p12");
     std::istreambuf_iterator<char> begin(is), end;
     std::vector<char> buff(begin, end);
 
index bb1f40c..284b68a 100644 (file)
@@ -2044,7 +2044,7 @@ RUNNER_TEST(T3095_CAPI_TYPE_load_cert_file)
 }
 
 RUNNER_TEST(T3096_CAPI_TYPE_load_p12_file) {
-       const char *p12file = "/usr/share/ckm-test/capi-t3096.p12";
+       const char *p12file = CKM_TEST_DIR "/capi-t3096.p12";
        const char *password = "password";
 
        int temp;
@@ -2096,7 +2096,7 @@ RUNNER_TEST(T3096_CAPI_TYPE_load_p12_file) {
 }
 
 RUNNER_TEST(T3097_CAPI_TYPE_load_p12_file2) {
-       const char *p12file = "/usr/share/ckm-test/capi-t3096.p12";
+       const char *p12file = CKM_TEST_DIR "/capi-t3096.p12";
        const char *password = "password";
 
        int temp;
@@ -2173,7 +2173,7 @@ RUNNER_TEST(T3102_CAPI_PKCS12_negative_wrong_password)
        ckmc_pkcs12_s *ppkcs12 = NULL;
        int temp;
        RUNNER_ASSERT_MSG(
-                       CKMC_ERROR_INVALID_FORMAT == (temp = ckmc_pkcs12_load("/usr/share/ckm-test/test1801.pkcs12", wrong_passwd, &ppkcs12)),
+                       CKMC_ERROR_INVALID_FORMAT == (temp = ckmc_pkcs12_load(CKM_TEST_DIR "/test1801.pkcs12", wrong_passwd, &ppkcs12)),
                        CKMCReadableError(temp));
 }
 
@@ -2182,7 +2182,7 @@ RUNNER_TEST(T3103_CAPI_PKCS12_add_bundle_with_chain_certs)
        ckmc_pkcs12_s *ppkcs12 = NULL;
        int temp;
        RUNNER_ASSERT_MSG(
-                       CKMC_ERROR_NONE == (temp = ckmc_pkcs12_load("/usr/share/ckm-test/pkcs.p12", NULL, &ppkcs12)),
+                       CKMC_ERROR_NONE == (temp = ckmc_pkcs12_load(CKM_TEST_DIR "/pkcs.p12", NULL, &ppkcs12)),
                        CKMCReadableError(temp));
 
        RUNNER_ASSERT_MSG(NULL != ppkcs12->cert, "no certificate in PKCS12");
index 73c6357..e6b4443 100644 (file)
@@ -69,20 +69,19 @@ std::string XML_3_EXPECTED_KEY_2_RSA    = aliasWithLabel(ckmc_owner_id_system, "
 std::string XML_3_EXPECTED_CERT_1       = aliasWithLabel(ckmc_owner_id_system, "test3-cert1");
 std::string XML_3_EXPECTED_DATA_1       = aliasWithLabel(ckmc_owner_id_system, "test3-data1");
 
-
 std::string format_src_path(const char *file)
 {
-    return std::string("/usr/share/ckm-test/") + std::string(file);
+    return std::string(CKM_TEST_DIR) + std::string(file);
 }
 
 std::string format_dest_key_path(const char *file)
 {
-    return std::string("/opt/data/ckm/") + std::string(file);
+    return std::string(CKM_RW_DATA_DIR) + std::string(file);
 }
 
 std::string format_dest_path(const char *file)
 {
-    return std::string("/opt/data/ckm/initial_values/") + std::string(file);
+    return std::string(CKM_RW_DATA_DIR) + std::string( "/initial_values/") + std::string(file);
 }
 
 void copy_file(const std::string &from, const std::string &to)
index 06694ec..7a9a1a3 100644 (file)
@@ -48,7 +48,7 @@ RUNNER_TEST(A_T0011_OpenSSL_not_init_client_parse_PKCS) {
     stop_service(MANAGER);
     start_service(MANAGER);
 
-    std::ifstream is("/usr/share/ckm-test/pkcs.p12");
+    std::ifstream is(CKM_TEST_DIR "/pkcs.p12");
     std::istreambuf_iterator<char> begin(is), end;
     std::vector<char> buff(begin, end);
 
@@ -2811,7 +2811,7 @@ RUNNER_TEST(T1800_init)
 }
 
 RUNNER_TEST(T1801_parse_PKCS12) {
-    std::ifstream is("/usr/share/ckm-test/test1801.pkcs12");
+    std::ifstream is(CKM_TEST_DIR "/test1801.pkcs12");
     std::istreambuf_iterator<char> begin(is), end;
     std::vector<char> buff(begin, end);
 
@@ -2840,7 +2840,7 @@ RUNNER_TEST(T1801_parse_PKCS12) {
 }
 
 RUNNER_TEST(T1802_negative_wrong_password) {
-    std::ifstream is("/usr/share/ckm-test/test1801.pkcs12");
+    std::ifstream is(CKM_TEST_DIR "/test1801.pkcs12");
     std::istreambuf_iterator<char> begin(is), end;
     std::vector<char> buff(begin, end);
 
@@ -2854,7 +2854,7 @@ RUNNER_TEST(T1802_negative_wrong_password) {
 }
 
 RUNNER_TEST(T1803_negative_broken_buffer) {
-    std::ifstream is("/usr/share/ckm-test/test1801.pkcs12");
+    std::ifstream is(CKM_TEST_DIR "/test1801.pkcs12");
     std::istreambuf_iterator<char> begin(is), end;
     std::vector<char> buff(begin, end);
 
@@ -2873,7 +2873,7 @@ RUNNER_TEST(T1803_negative_broken_buffer) {
 RUNNER_TEST(T1804_add_PKCS_collision_with_existing_alias)
 {
     auto manager = CKM::Manager::create();
-    std::ifstream is("/usr/share/ckm-test/pkcs.p12");
+    std::ifstream is(CKM_TEST_DIR "/pkcs.p12");
     std::istreambuf_iterator<char> begin(is), end;
     std::vector<char> buff(begin, end);
 
@@ -2921,7 +2921,7 @@ RUNNER_TEST(T1804_add_PKCS_collision_with_existing_alias)
 RUNNER_TEST(T1805_add_bundle_with_chain_certificates)
 {
     auto manager = CKM::Manager::create();
-    std::ifstream is("/usr/share/ckm-test/pkcs.p12");
+    std::ifstream is(CKM_TEST_DIR "/pkcs.p12");
     std::istreambuf_iterator<char> begin(is), end;
     std::vector<char> buff(begin, end);
 
@@ -3253,7 +3253,7 @@ RUNNER_TEST(T1812_get_pkcs12_password_tests)
     CKM::Alias alias = sharedDatabase("t1812alias1");
 
     auto manager = CKM::Manager::create();
-    std::ifstream is("/usr/share/ckm-test/pkcs.p12");
+    std::ifstream is(CKM_TEST_DIR "/pkcs.p12");
     std::istreambuf_iterator<char> begin(is), end;
     std::vector<char> buff(begin, end);