Let the import function return list with real aliases 88/150788/2
authorPiotr Sawicki <p.sawicki2@partner.samsung.com>
Mon, 18 Sep 2017 13:59:15 +0000 (15:59 +0200)
committerPiotr Sawicki <p.sawicki2@partner.samsung.com>
Mon, 18 Sep 2017 14:04:15 +0000 (16:04 +0200)
To be consistent with certsvc_pkcs12_load_certificate_list_from_store(),
the new function certsvc_pkcs12_import_from_file_to_store_ret_list()
should return the list of intermediate certificates with aliases taken
from an imported certificate chain.

Change-Id: I22d31c59fc8943b9e08113a6ac290bfe1867a1eb

src/vcore/pkcs12.cpp

index 3e0cc70..5734004 100644 (file)
@@ -296,9 +296,9 @@ int installChainCert(CertStoreType storeType,
                                         const std::string &cert,
                                         const std::string &gname,
                                         const std::string &endCertGname,
+                                        const std::string &commonName,
                                         CertType type)
 {
-       std::string commonName = getCommonName(type, cert);
        return vcore_client_install_certificate_to_store(
                           storeType,
                           gname.c_str(),
@@ -710,19 +710,19 @@ int insertToStore(CertStoreType storeTypes,
                }
 
                for (size_t i = 0; i < ncerts; i++) {
-                       if (i == ncerts - 1)
-                               result = installChainCert(storeType, certChainBuffer[i], certChainName[i], endCertName,
-                                                                                 P12_TRUSTED);
-                       else
-                               result = installChainCert(storeType, certChainBuffer[i], certChainName[i], endCertName,
-                                                                                 P12_INTERMEDIATE);
+                       CertType type = (i == ncerts - 1) ? P12_TRUSTED : P12_INTERMEDIATE;
+
+                       std::string commonName = getCommonName(type, certChainBuffer[i]);
+
+                       result = installChainCert(storeType, certChainBuffer[i], certChainName[i], endCertName,
+                                                                                 commonName, type);
 
                        if (result != CERTSVC_SUCCESS) {
                                LogError("Failed to install the ca certificates. result : " << result);
                                return result;
                        }
 
-                       int res = appendStoreListNode(certList, length, certChainName[i], alias, storeType);
+                       int res = appendStoreListNode(certList, length, certChainName[i], commonName, storeType);
                        if (res != CERTSVC_SUCCESS) {
                                LogError("Failed to append store list node.");
                                return result;