Don't ignore alias during the import of certificates from PEM 52/147752/4
authorPiotr Sawicki <p.sawicki2@partner.samsung.com>
Tue, 5 Sep 2017 11:18:42 +0000 (13:18 +0200)
committerPiotr Sawicki <p.sawicki2@partner.samsung.com>
Thu, 7 Sep 2017 08:33:24 +0000 (10:33 +0200)
Change-Id: Ide059aed684845e1875ec32a75c063df5266b888

src/vcore/pkcs12.cpp
tests/pkcs12/new_test_cases.cpp

index e80c334..d2ec9d8 100644 (file)
@@ -244,13 +244,13 @@ int installChainCert(CertStoreType storeType,
 }
 int installCert(CertStoreType storeType,
                                const std::string &cert,
-                               const std::string &gname)
+                               const std::string &gname,
+                               const std::string &alias)
 {
-       std::string commonName = getCommonName(PEM_CRT, cert);
        return vcore_client_install_certificate_to_store(
                           storeType,
                           gname.c_str(),
-                          commonName.c_str(),
+                          alias.c_str(),
                           NULL,
                           NULL,
                           cert.c_str(),
@@ -653,7 +653,8 @@ int insertToStore(CertStoreType storeTypes,
        return CERTSVC_SUCCESS;
 }
 
-int insertToStorePEM(CertStoreType storeTypes, const std::string &path, const std::string &gname)
+int insertToStorePEM(CertStoreType storeTypes, const std::string &path, const std::string &gname,
+                                        const std::string &alias)
 {
        std::string content = readFromFile(path);
 
@@ -674,7 +675,7 @@ int insertToStorePEM(CertStoreType storeTypes, const std::string &path, const st
                if (!hasStore(storeTypes, storeType))
                        continue;
 
-               int result = installCert(storeType, parsed, gname);
+               int result = installCert(storeType, parsed, gname, alias);
 
                if (result != CERTSVC_SUCCESS) {
                        LogError("Failed to install PEM/CRT to db store : " << storeType << " result : " << result);
@@ -730,7 +731,7 @@ int pkcs12_import_from_file_to_store(CertStoreType storeTypes,
 
        if (strcasecmp(suffix.c_str(), ".pem") == 0 || strcasecmp(suffix.c_str(), ".crt") == 0) {
                std::string gnamePEM = generateGname();
-               result = insertToStorePEM(storeTypes, path, gnamePEM);
+               result = insertToStorePEM(storeTypes, path, gnamePEM, alias);
 
                if (result != CERTSVC_SUCCESS)
                        LogError("Failed to install PEM/CRT file to store. gname : " << gnamePEM << " result : " << result);
index b16fb03..69ac7b7 100644 (file)
@@ -951,3 +951,4 @@ RUNNER_TEST(CERTSVC_PKCS12_1028_certsvc_set_cert_to_disabled_and_get_status_for_
 
        FREE_INSTANCE
 }
+