From b9c2fb174dc62f77ac7c95f0c7f772d3b4e00481 Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Fri, 22 May 2015 12:01:51 +0200 Subject: [PATCH] CKM: Make TA2000 and TA2010 independent [Problem] Because of dependency between TA2000 and TA2010 the latter fails after introduction of CKMAsyncAPIEnv. [Solution] Made tests independent. [Verification] Run tests: ckm-tests --group=CKM_ASYNC_API Change-Id: I6a218c1c36e4f2f7c9725b74bdf94b5ae4a56559 --- src/ckm/async-api.cpp | 95 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 57 insertions(+), 38 deletions(-) diff --git a/src/ckm/async-api.cpp b/src/ckm/async-api.cpp index 3b74ea3..7e790f0 100644 --- a/src/ckm/async-api.cpp +++ b/src/ckm/async-api.cpp @@ -347,6 +347,41 @@ public: } }; +CKM::Alias alias_PKCS_exportable = "async-test-PKCS-export"; +CKM::Alias alias_PKCS_not_exportable = "async-test-PKCS-no-export"; + +CKM::PKCS12ShPtr loadPkcs() +{ + std::ifstream is("/usr/share/ckm-test/pkcs.p12"); + std::istreambuf_iterator begin(is), end; + std::vector buff(begin, end); + + CKM::RawBuffer buffer(buff.size()); + memcpy(buffer.data(), buff.data(), buff.size()); + + auto pkcs = CKM::PKCS12::create(buffer, CKM::Password()); + RUNNER_ASSERT_MSG( + NULL != pkcs.get(), + "Error in PKCS12::create()"); + + auto cert = pkcs->getCertificate(); + RUNNER_ASSERT_MSG( + NULL != cert.get(), + "Error in PKCS12::getCertificate()"); + + auto key = pkcs->getKey(); + RUNNER_ASSERT_MSG( + NULL != key.get(), + "Error in PKCS12::getKey()"); + + auto caVector = pkcs->getCaCertificateShPtrVector(); + RUNNER_ASSERT_MSG( + 2 == caVector.size(), + "Wrong size of vector"); + + return pkcs; +} + } // namespace anonymous @@ -1217,67 +1252,35 @@ RUNNER_TEST(TA1920_deny_access, CKMAsyncAPIEnv) } } -namespace -{ -CKM::Alias alias_PKCS_exportable = "async-test-PKCS-export"; -CKM::Alias alias_PKCS_not_exportable = "async-test-PKCS-no-export"; -} - RUNNER_TEST(TA2000_PKCS_add_bundle_with_chain_certs, CKMAsyncAPIEnv) { DBCleanup dbc; - auto manager = CKM::Manager::create(); - std::ifstream is("/usr/share/ckm-test/pkcs.p12"); - std::istreambuf_iterator begin(is), end; - std::vector buff(begin, end); - - CKM::RawBuffer buffer(buff.size()); - memcpy(buffer.data(), buff.data(), buff.size()); - - auto pkcs = CKM::PKCS12::create(buffer, CKM::Password()); - RUNNER_ASSERT_MSG( - NULL != pkcs.get(), - "Error in PKCS12::create()"); - - auto cert = pkcs->getCertificate(); - RUNNER_ASSERT_MSG( - NULL != cert.get(), - "Error in PKCS12::getCertificate()"); - - auto key = pkcs->getKey(); - RUNNER_ASSERT_MSG( - NULL != key.get(), - "Error in PKCS12::getKey()"); - - auto caVector = pkcs->getCaCertificateShPtrVector(); - RUNNER_ASSERT_MSG( - 2 == caVector.size(), - "Wrong size of vector"); + auto pkcs = loadPkcs(); // save to the CKM CKM::Policy exportable; CKM::Policy notExportable(CKM::Password(), false); test_positive(&ManagerAsync::savePKCS12, - alias_PKCS_exportable, + dbc.alias(alias_PKCS_exportable.c_str()), pkcs, exportable, exportable); test_negative(&ManagerAsync::savePKCS12, CKM_API_ERROR_DB_ALIAS_EXISTS, - alias_PKCS_exportable, + dbc.alias(alias_PKCS_exportable.c_str()), pkcs, exportable, exportable); test_positive(&ManagerAsync::savePKCS12, - alias_PKCS_not_exportable, + dbc.alias(alias_PKCS_not_exportable.c_str()), pkcs, notExportable, notExportable); test_negative(&ManagerAsync::savePKCS12, CKM_API_ERROR_DB_ALIAS_EXISTS, - alias_PKCS_not_exportable, + dbc.alias(alias_PKCS_not_exportable.c_str()), pkcs, notExportable, notExportable); @@ -1286,7 +1289,23 @@ RUNNER_TEST(TA2000_PKCS_add_bundle_with_chain_certs, CKMAsyncAPIEnv) RUNNER_TEST(TA2010_PKCS_get, CKMAsyncAPIEnv) { DBCleanup dbc; - auto manager = CKM::Manager::create(); + + auto pkcs = loadPkcs(); + + // save to the CKM + CKM::Policy exportable; + CKM::Policy notExportable(CKM::Password(), false); + + test_positive(&ManagerAsync::savePKCS12, + dbc.alias(alias_PKCS_exportable.c_str()), + pkcs, + exportable, + exportable); + test_positive(&ManagerAsync::savePKCS12, + dbc.alias(alias_PKCS_not_exportable.c_str()), + pkcs, + notExportable, + notExportable); // fail - no entry test_negative(&ManagerAsync::getPKCS12, -- 2.7.4