static const std::string EndUser = "END_USER_";
static const std::string RetList = "RL_";
static const std::string GroupNameTest = "GroupNameTest";
+static const std::string GroupNameSystem = "9c8dfbd4.0";
CertSvcString wrapperCertsvcStringNew(std::string originStr, int *retVal)
{
{
int result;
- BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
-
CertSvcString cStrPath = wrapperCertsvcStringNew(path, &result);
BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
certsvc_string_free(cStrPath);
certsvc_string_free(cStrPass);
certsvc_string_free(cStrAlias);
- certsvc_instance_free(instance);
}
void importCertFromFileToStoreRetList(
CertSvcStoreCertList *certList = NULL;
size_t length = 0;
- BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
-
CertSvcString cStrPath = wrapperCertsvcStringNew(path, &result);
BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
certsvc_string_free(cStrPath);
certsvc_string_free(cStrPass);
certsvc_string_free(cStrAlias);
- certsvc_instance_free(instance);
}
void getCertListFromStore(CertStoreType storeType, int isRootApp, CertSvcStoreCertList **certList, int expected)
int result;
size_t length = 0;
- BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
-
result = certsvc_pkcs12_get_certificate_list_from_store(
instance,
storeType,
BOOST_CHECK(certList);
BOOST_CHECK(length > 0);
}
-
- certsvc_instance_free(instance);
}
void freeCertList(CertSvcStoreCertList *certList)
{
- BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
-
int result = certsvc_pkcs12_free_certificate_list_loaded_from_store(instance, &certList);
BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
BOOST_CHECK(!certList);
-
- certsvc_instance_free(instance);
}
void getCertListFromStoreAndFree(CertStoreType storeType, int isRootApp, int expected)
int result;
int count = 0;
- BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
-
while (certList)
{
result = certsvc_pkcs12_get_certificate_from_store(
certList = certList->next;
count++;
}
-
- certsvc_instance_free(instance);
}
void getEndUserCertListFromStores(
int result;
size_t length = 0;
- BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
-
result = certsvc_pkcs12_get_end_user_certificate_list_from_store(
instance,
storeType,
} else {
BOOST_CHECK_EQUAL(length, 0);
}
-
- certsvc_instance_free(instance);
}
void getRootCertListFromStores(
int result;
size_t length = 0;
- BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
-
result = certsvc_pkcs12_get_root_certificate_list_from_store(
instance,
storeType,
} else {
BOOST_CHECK_EQUAL(length, 0);
}
+}
- certsvc_instance_free(instance);
+void getCertificateInfoFromStore(
+ CertStoreType storeType,
+ CertSvcString gNameStr,
+ bool isBuffer,
+ int expected)
+{
+ int result;
+ size_t certLength = 0;
+ char *certBuffer = NULL;
+
+ result = certsvc_pkcs12_get_certificate_info_from_store(
+ instance,
+ storeType,
+ gNameStr,
+ isBuffer ? &certBuffer : NULL,
+ &certLength);
+
+ BOOST_CHECK_EQUAL(result, expected);
+
+ if (expected == CERTSVC_SUCCESS) {
+ BOOST_CHECK(certBuffer);
+ BOOST_CHECK(certLength > 0);
+ free(certBuffer);
+ } else {
+ BOOST_CHECK(!certBuffer);
+ BOOST_CHECK_EQUAL(certLength, 0);
+ }
+}
+
+void getAliasNameForCertificateInStore(
+ CertStoreType storeType,
+ CertSvcString gNameStr,
+ int expected)
+{
+ int result;
+ char *alias = NULL;
+
+ result = certsvc_pkcs12_get_alias_name_for_certificate_in_store(
+ instance,
+ storeType,
+ gNameStr,
+ &alias);
+
+ BOOST_CHECK_EQUAL(result, expected);
+
+ if (expected == CERTSVC_SUCCESS) {
+ BOOST_CHECK(alias);
+ BOOST_CHECK(strlen(alias) > 0);
+ free(alias);
+ } else if (expected == CERTSVC_FAIL) {
+ BOOST_CHECK(alias);
+ BOOST_CHECK(strlen(alias) == 0);
+ } else {
+ BOOST_CHECK(!alias);
+ }
+
+}
+
+void setCertStatusToStore(
+ CertStoreType storeType,
+ int isRootApp,
+ CertSvcString gNameStr,
+ CertStatus status,
+ int expected)
+{
+ int result;
+
+ result = certsvc_pkcs12_set_certificate_status_to_store(
+ instance,
+ storeType,
+ isRootApp,
+ gNameStr,
+ status);
+
+ BOOST_CHECK_EQUAL(result, expected);
+}
+
+void getCertStatusFromStore(
+ CertStoreType storeType,
+ CertSvcString gNameStr,
+ CertStatus *status,
+ int expected)
+{
+ int result;
+
+ result = certsvc_pkcs12_get_certificate_status_from_store(
+ instance,
+ storeType,
+ gNameStr,
+ status);
+
+ BOOST_CHECK_EQUAL(result, expected);
}
BOOST_AUTO_TEST_SUITE(VCORE_API_PKCS12_TEST)
std::string path, pass, alias;
pass = ServerCert::ServerPass;
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
for (auto storeType: storeTypeMap)
{
path = ServerCert::PemWithoutPassPath;
alias = PfxPrefix + Chain + storeType.first;
importCertFromFileToStore(storeType.second, path, pass, alias, CERTSVC_SUCCESS);
}
+
+ certsvc_instance_free(instance);
}
NEGATIVE_TEST_CASE(T_import_cert_from_to_individual_store_error)
std::string path;
std::string alias = PemPrefix + std::to_string(PEM_CRT);
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
path = ServerCert::PemInvalidCert;
importCertFromFileToStore(WIFI_STORE, path, std::string(), alias, CERTSVC_FAIL);
path = ServerCert::P12WithoutPassPath;
importCertFromFileToStore(WIFI_STORE, path, std::string(), alias, CERTSVC_WRONG_ARGUMENT);
+ certsvc_instance_free(instance);
}
POSITIVE_TEST_CASE(T_certsvc_pkcs12_import_from_file_to_store_ret_list)
std::string alias, path, pass;
pass = ServerCert::ServerPass;
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
for (auto storeType: storeTypeMap)
{
path = ServerCert::P12WithoutPassPath;
true,
CERTSVC_SUCCESS);
}
+
+ certsvc_instance_free(instance);
}
NEGATIVE_TEST_CASE(T_certsvc_pkcs12_import_from_file_to_store_ret_list_error)
std::string path = ServerCert::P12WithPassPath;
std::string alias = P12Prefix + std::to_string(P12_END_USER);
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
importCertFromFileToStoreRetList(
WIFI_STORE,
path,
alias,
true,
CERTSVC_FAIL);
+
+ certsvc_instance_free(instance);
}
POSITIVE_TEST_CASE(T_certsvc_pkcs12_get_certificate_list_from_stores)
{
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
getCertListFromStoreAndFree(ALL_STORE, DISABLED, CERTSVC_SUCCESS);
getCertListFromStoreAndFree(ALL_STORE, ENABLED, CERTSVC_SUCCESS);
getCertListFromStoreAndFree(storeType.second, DISABLED, CERTSVC_SUCCESS);
getCertListFromStoreAndFree(storeType.second, ENABLED, CERTSVC_SUCCESS);
}
+
+ certsvc_instance_free(instance);
}
NEGATIVE_TEST_CASE(T_certsvc_pkcs12_get_certificate_list_from_none_store)
{
CertSvcStoreCertList *certList = NULL;
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
getCertListFromStore(NONE_STORE, DISABLED, &certList, CERTSVC_INVALID_STORE_TYPE);
getCertListFromStore(NONE_STORE, ENABLED, &certList, CERTSVC_INVALID_STORE_TYPE);
CertSvcStoreCertList *certList1;
getCertListFromStore(WIFI_STORE, DISABLED, &certList1, CERTSVC_WRONG_ARGUMENT);
+ certsvc_instance_free(instance);
}
POSITIVE_TEST_CASE(T_certsvc_pkcs12_get_certificate_from_store)
{
CertSvcStoreCertList *certList = NULL;
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
getCertListFromStore(WIFI_STORE, DISABLED, &certList, CERTSVC_SUCCESS);
CertSvcStoreCertList *certListOrig = certList;
checkCertListFromStore(certList);
freeCertList(certListOrig);
+
+ certsvc_instance_free(instance);
}
NEGATIVE_TEST_CASE(T_certsvc_pkcs12_get_certificate_from_store_wrong_argument)
{
const CertStoreType validStoreType = (CertStoreType)(WIFI_STORE | VPN_STORE | EMAIL_STORE);
CertSvcStoreCertList *certList = NULL;
+
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
getEndUserCertListFromStores(&certList, validStoreType, CERTSVC_SUCCESS);
freeCertList(certList);
+
+ certsvc_instance_free(instance);
}
NEGATIVE_TEST_CASE(T_certsvc_pkcs12_get_end_user_certificate_list_from_store_invalid_argument)
{
CertSvcStoreCertList *certList;
+
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
getEndUserCertListFromStores(&certList, WIFI_STORE, CERTSVC_WRONG_ARGUMENT);
certList = NULL;
getEndUserCertListFromStores(&certList, NONE_STORE, CERTSVC_INVALID_STORE_TYPE);
getEndUserCertListFromStores(&certList, SYSTEM_STORE, CERTSVC_WRONG_ARGUMENT);
getEndUserCertListFromStores(&certList, ALL_STORE, CERTSVC_WRONG_ARGUMENT);
+
+ certsvc_instance_free(instance);
}
POSITIVE_TEST_CASE(T_certsvc_pkcs12_get_root_certificate_list_from_stores)
{
const CertStoreType validStoreType = (CertStoreType)(WIFI_STORE | VPN_STORE | EMAIL_STORE);
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
CertSvcStoreCertList *certList = NULL;
getRootCertListFromStores(&certList, validStoreType, CERTSVC_SUCCESS);
freeCertList(certList);
certList = NULL;
getRootCertListFromStores(&certList, ALL_STORE, CERTSVC_SUCCESS);
freeCertList(certList);
+
+ certsvc_instance_free(instance);
}
NEGATIVE_TEST_CASE(T_certsvc_pkcs12_get_root_certificate_list_from_store_wrong_argument)
{
CertSvcStoreCertList *certList;
+
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
getRootCertListFromStores(&certList, WIFI_STORE, CERTSVC_WRONG_ARGUMENT);
certList = NULL;
getRootCertListFromStores(&certList, NONE_STORE, CERTSVC_INVALID_STORE_TYPE);
+
+ certsvc_instance_free(instance);
}
NEGATIVE_TEST_CASE(T_certsvc_pkcs12_free_certificate_list_loaded_from_store_wrong_argument)
certsvc_instance_free(instance);
}
+POSITIVE_TEST_CASE(T_certsvc_pkcs12_get_certificate_info_from_store)
+{
+ int result;
+ CertSvcStoreCertList *certList = NULL;
+
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
+ getCertListFromStore(WIFI_STORE, ENABLED, &certList, CERTSVC_SUCCESS);
+ BOOST_CHECK(certList);
+ BOOST_CHECK_EQUAL(strlen(certList->gname), 40);
+
+ CertSvcString gNameStr = wrapperCertsvcStringNew(certList->gname, &result);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+
+ getCertificateInfoFromStore(WIFI_STORE, gNameStr, true, CERTSVC_SUCCESS);
+
+ certsvc_string_free(gNameStr);
+ freeCertList(certList);
+ certsvc_instance_free(instance);
+}
+
+NEGATIVE_TEST_CASE(T_certsvc_pkcs12_get_certificate_info_from_store)
+{
+ int result;
+
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
+ CertSvcString gNameStr = wrapperCertsvcStringNew(GroupNameTest, &result);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+
+ getCertificateInfoFromStore(WIFI_STORE, gNameStr, false, CERTSVC_WRONG_ARGUMENT);
+ getCertificateInfoFromStore(NONE_STORE, gNameStr, true, CERTSVC_INVALID_STORE_TYPE);
+ getCertificateInfoFromStore(WIFI_STORE, gNameStr, true, CERTSVC_FAIL);
+
+ certsvc_string_free(gNameStr);
+ certsvc_instance_free(instance);
+}
+
+POSITIVE_TEST_CASE(T_certsvc_pkcs12_get_alias_name_for_certificate_in_store)
+{
+ int result;
+ CertSvcStoreCertList *certList = NULL;
+
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
+ getCertListFromStore(WIFI_STORE, ENABLED, &certList, CERTSVC_SUCCESS);
+ BOOST_CHECK(certList);
+ BOOST_CHECK_EQUAL(strlen(certList->gname), 40);
+
+ CertSvcString gNameStr = wrapperCertsvcStringNew(certList->gname, &result);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+
+ getAliasNameForCertificateInStore(WIFI_STORE, gNameStr, CERTSVC_SUCCESS);
+
+ certsvc_string_free(gNameStr);
+ freeCertList(certList);
+ certsvc_instance_free(instance);
+}
+
+NEGATIVE_TEST_CASE(T_certsvc_pkcs12_get_alias_name_for_certificate_in_store)
+{
+ int result;
+
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
+ CertSvcString gNameStr = wrapperCertsvcStringNew(GroupNameTest, &result);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+
+ getAliasNameForCertificateInStore(NONE_STORE, gNameStr, CERTSVC_INVALID_STORE_TYPE);
+ getAliasNameForCertificateInStore(WIFI_STORE, gNameStr, CERTSVC_FAIL);
+
+ certsvc_string_free(gNameStr);
+
+ gNameStr.privateHandler = NULL;
+
+ getAliasNameForCertificateInStore(WIFI_STORE, gNameStr, CERTSVC_WRONG_ARGUMENT);
+
+ certsvc_instance_free(instance);
+}
+
+POSITIVE_TEST_CASE(T_certsvc_pkcs12_set_and_get_certificate_status_to_store)
+{
+ int result;
+ CertSvcStoreCertList *certList = NULL;
+ CertStatus status = ENABLED;
+
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
+ getCertListFromStore(WIFI_STORE, ENABLED, &certList, CERTSVC_SUCCESS);
+ BOOST_CHECK(certList);
+ BOOST_CHECK_EQUAL(strlen(certList->gname), 40);
+
+ CertSvcString gNameStr = wrapperCertsvcStringNew(certList->gname, &result);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+
+ setCertStatusToStore(WIFI_STORE, ENABLED, gNameStr, DISABLED, CERTSVC_SUCCESS);
+
+ getCertStatusFromStore(WIFI_STORE, gNameStr, &status, CERTSVC_SUCCESS);
+ BOOST_CHECK_EQUAL(status, DISABLED);
+
+ setCertStatusToStore(WIFI_STORE, ENABLED, gNameStr, ENABLED, CERTSVC_SUCCESS);
+
+ getCertStatusFromStore(WIFI_STORE, gNameStr, &status, CERTSVC_SUCCESS);
+ BOOST_CHECK_EQUAL(status, ENABLED);
+
+ CertSvcString gNameSystemStr = wrapperCertsvcStringNew(GroupNameSystem, &result);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+
+ setCertStatusToStore(SYSTEM_STORE, ENABLED, gNameSystemStr, DISABLED, CERTSVC_SUCCESS);
+
+ getCertStatusFromStore(SYSTEM_STORE, gNameSystemStr, &status, CERTSVC_SUCCESS);
+ BOOST_CHECK_EQUAL(status, DISABLED);
+
+ setCertStatusToStore(SYSTEM_STORE, ENABLED, gNameSystemStr, ENABLED, CERTSVC_SUCCESS);
+
+ getCertStatusFromStore(SYSTEM_STORE, gNameSystemStr, &status, CERTSVC_SUCCESS);
+ BOOST_CHECK_EQUAL(status, ENABLED);
+
+ certsvc_string_free(gNameStr);
+ certsvc_string_free(gNameSystemStr);
+ freeCertList(certList);
+ certsvc_instance_free(instance);
+}
+
+NEGATIVE_TEST_CASE(T_certsvc_pkcs12_set_certificate_status_to_store)
+{
+ int result;
+ CertStatus invalidStatus = (CertStatus) -1;
+
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
+ CertSvcString gNameStr = wrapperCertsvcStringNew(GroupNameTest, &result);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+
+ CertSvcString invalidNameStr = wrapperCertsvcStringNew(std::string(), &result);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+
+ setCertStatusToStore(NONE_STORE, ENABLED, gNameStr, DISABLED, CERTSVC_INVALID_STORE_TYPE);
+ setCertStatusToStore(WIFI_STORE, ENABLED, gNameStr, invalidStatus, CERTSVC_INVALID_STATUS);
+ setCertStatusToStore(WIFI_STORE, ENABLED, gNameStr, DISABLED, CERTSVC_FAIL);
+ setCertStatusToStore(WIFI_STORE, ENABLED, invalidNameStr, DISABLED, CERTSVC_WRONG_ARGUMENT);
+ setCertStatusToStore(SYSTEM_STORE, ENABLED, gNameStr, DISABLED, CERTSVC_FAIL);
+
+ certsvc_string_free(gNameStr);
+ certsvc_instance_free(instance);
+}
+
+NEGATIVE_TEST_CASE(T_certsvc_pkcs12_get_certificate_status_to_store)
+{
+ int result;
+ CertStatus status = DISABLED;
+
+ BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
+
+ CertSvcString gNameStr = wrapperCertsvcStringNew(GroupNameTest, &result);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+
+ CertSvcString invalidNameStr = wrapperCertsvcStringNew(std::string(), &result);
+ BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
+
+ getCertStatusFromStore(NONE_STORE, gNameStr, &status, CERTSVC_INVALID_STORE_TYPE);
+ BOOST_CHECK_EQUAL(status, DISABLED);
+
+ getCertStatusFromStore(WIFI_STORE, invalidNameStr, &status, CERTSVC_WRONG_ARGUMENT);
+ BOOST_CHECK_EQUAL(status, DISABLED);
+
+ getCertStatusFromStore(WIFI_STORE, gNameStr, &status, CERTSVC_FAIL);
+ BOOST_CHECK_EQUAL(status, DISABLED);
+
+ certsvc_string_free(gNameStr);
+ certsvc_instance_free(instance);
+}
+
POSITIVE_TEST_CASE(T_certsvc_pkcs12_delete_certificate_from_store)
{
int result;
BOOST_REQUIRE_EQUAL(certsvc_instance_new(&instance), CERTSVC_SUCCESS);
- CertSvcString gNameStr = wrapperCertsvcStringNew(GroupNameTest.c_str(), &result);
+ CertSvcString gNameStr = wrapperCertsvcStringNew(GroupNameTest, &result);
BOOST_CHECK_EQUAL(result, CERTSVC_SUCCESS);
result = certsvc_pkcs12_delete_certificate_from_store(instance, NONE_STORE, gNameStr);
result = certsvc_pkcs12_delete_certificate_from_store(instance, VPN_STORE, gNameStr);
BOOST_CHECK_EQUAL(result, CERTSVC_WRONG_ARGUMENT);
- gNameStr = wrapperCertsvcStringNew(GroupNameTest.c_str(), &result);
+ gNameStr = wrapperCertsvcStringNew(GroupNameTest, &result);
result = certsvc_pkcs12_delete_certificate_from_store(instance, VPN_STORE, gNameStr);
BOOST_CHECK_EQUAL(result, CERTSVC_FAIL);