Fix certificate manager failure after factory reset

Private key file is pre-generated during startup of service
for CSR generation as it is time consuming operation.

Noticed after factory reset when writing private key it is
trying to create file to non existing directory.

Modified to create parent directory structure before creating
private key file

Signed-off-by: Marri Devender Rao <devenrao@in.ibm.com>
Change-Id: Ida296a0ed139aee0d594870b7d71e376f5b5f7c8
diff --git a/certs_manager.cpp b/certs_manager.cpp
index 06ddf68..59808c1 100644
--- a/certs_manager.cpp
+++ b/certs_manager.cpp
@@ -32,6 +32,21 @@
     unitToRestart(std::move(unit)), certInstallPath(std::move(installPath)),
     certParentInstallPath(fs::path(certInstallPath).parent_path())
 {
+    // create parent certificate path if not existing
+    try
+    {
+        if (!fs::exists(certParentInstallPath))
+        {
+            fs::create_directories(certParentInstallPath);
+        }
+    }
+    catch (fs::filesystem_error& e)
+    {
+        log<level::ERR>("Failed to create directory", entry("ERR=%s", e.what()),
+                        entry("DIRECTORY=%s", certParentInstallPath.c_str()));
+        report<InternalFailure>();
+    }
+
     // Generating RSA private key file if certificate type is server/client
     if (certType != AUTHORITY)
     {