[Installer] Fixed save certification to pkgmgr
authorSoyoung Kim <sy037.kim@samsung.com>
Fri, 2 Nov 2012 11:12:42 +0000 (20:12 +0900)
committerSoyoung Kim <sy037.kim@samsung.com>
Mon, 5 Nov 2012 08:02:42 +0000 (17:02 +0900)
[Issue#]  N/A
[Problem] There is only one certi info in pkgmgr.
[Cause] N/A
[Solution] Fixed logic.

src/jobs/widget_install/task_certificates.cpp
src/jobs/widget_install/task_certificates.h

index 7285b50..a302b64 100755 (executable)
@@ -49,8 +49,30 @@ TaskCertificates::TaskCertificates(InstallerContext& context) :
 void TaskCertificates::StepSetCertiInfo()
 {
     LogDebug("StepSetCertiInfo");
+
+    if (pkgmgr_installer_create_certinfo_set_handle(&m_pkgHandle) < 0) {
+        LogError("pkgmgrInstallerCreateCertinfoSetHandle fail");
+        ThrowMsg(Exceptions::SetCertificateInfoFailed,
+                "Failed to create certificate handle");
+    }
+
     SetCertiInfo(SIGNATURE_AUTHOR);
     SetCertiInfo(SIGNATURE_DISTRIBUTOR);
+
+    if ((pkgmgr_installer_save_certinfo(
+                    const_cast<char*>(DPL::ToUTF8String(
+                            *m_context.widgetConfig.pkgname).c_str()),
+                    m_pkgHandle)) < 0) {
+        LogError("pkgmgrInstallerSaveCertinfo fail");
+        ThrowMsg(Exceptions::SetCertificateInfoFailed,
+                "Failed to Installer Save Certinfo");
+    } else {
+        LogDebug("Succeed to save Certinfo");
+    }
+
+    if (pkgmgr_installer_destroy_certinfo_set_handle(m_pkgHandle) < 0) {
+        LogError("pkgmgrInstallerDestroyCertinfoSetHandle fail");
+    }
 }
 
 void TaskCertificates::SetCertiInfo(CertificateSource source)
@@ -59,8 +81,6 @@ void TaskCertificates::SetCertiInfo(CertificateSource source)
     CertificateChainList certificateChainList;
     m_context.wacSecurity.getCertificateChainList(certificateChainList, source);
 
-    pkgmgr_instcertinfo_h handle;
-
     FOREACH(it, certificateChainList)
     {
         LogDebug("Insert certinfo to pkgmgr db");
@@ -74,6 +94,7 @@ void TaskCertificates::SetCertiInfo(CertificateSource source)
 
         ValidationCore::CertificateList list = chain.getCertificateList();
 
+
         FOREACH(certIt, list) 
         {
             ValidationCore::Crypto::Hash::SHA1 sha1;
@@ -81,60 +102,42 @@ void TaskCertificates::SetCertiInfo(CertificateSource source)
             sha1.Finish();
             std::string sha1String = sha1.ToBase64String();
 
-            if (pkgmgr_installer_create_certinfo_set_handle(&handle)< 0) {
-                LogError("pkgmgrInstallerCreateCertinfoSetHandle fail");
-                ThrowMsg(Exceptions::SetCertificateInfoFailed,
-                        "Failed to create certificate handle");
-            }
-
-            if (source == SIGNATURE_DISTRIBUTOR) {
-                if((pkgmgr_installer_set_cert_value(
-                                handle,
-                                PM_SET_DISTRIBUTOR_SIGNER_CERT,
-                                const_cast<char*>(sha1String.c_str()))) < 0) {
-                    LogError("pkgmgrInstallerSetCertValue fail");
-                    ThrowMsg(Exceptions::SetCertificateInfoFailed,
-                            "Failed to Set CertValue");
+            if ((*certIt)->isRootCert()) {
+                if (source == SIGNATURE_DISTRIBUTOR) {
+                    LogDebug("Set SIGNATURE_DISTRIBUTOR ");
+                    if((pkgmgr_installer_set_cert_value(
+                                    m_pkgHandle,
+                                    PM_SET_DISTRIBUTOR_ROOT_CERT,
+                                    const_cast<char*>(sha1String.c_str()))) < 0) {
+                        LogError("pkgmgrInstallerSetCertValue fail");
+                        ThrowMsg(Exceptions::SetCertificateInfoFailed,
+                                "Failed to Set CertValue");
+                    }
                 }
-            }
-            else {
-                if((pkgmgr_installer_set_cert_value(
-                                handle,
-                                PM_SET_AUTHOR_SIGNER_CERT,
-                                const_cast<char*>(sha1String.c_str()))) < 0) {
-                    LogError("pkgmgrInstallerSetCertValue fail");
-                    ThrowMsg(Exceptions::SetCertificateInfoFailed,
-                            "Failed to Installer Set CertValue");
+                else {
+                    LogDebug("set SIGNATURE_AUTHOR");
+                    if((pkgmgr_installer_set_cert_value(
+                                    m_pkgHandle,
+                                    PM_SET_AUTHOR_ROOT_CERT,
+                                    const_cast<char*>(sha1String.c_str()))) < 0) {
+                        LogError("pkgmgrInstallerSetCertValue fail");
+                        ThrowMsg(Exceptions::SetCertificateInfoFailed,
+                                "Failed to Installer Set CertValue");
+                    }
                 }
             }
-
-            if ((pkgmgr_installer_save_certinfo(
-                            const_cast<char*>(DPL::ToUTF8String(
-                                    *m_context.widgetConfig.pkgname).c_str()),
-                            handle)) < 0) {
-                LogError("pkgmgrInstallerSaveCertinfo fail");
-                ThrowMsg(Exceptions::SetCertificateInfoFailed,
-                        "Failed to Installer Save Certinfo");
-            } else {
-                LogDebug("Succeed to save Certinfo");
-            }
-
-            if (pkgmgr_installer_destroy_certinfo_set_handle(handle) < 0) {
-                LogError("pkgmgrInstallerDestroyCertinfoSetHandle fail");
-            }
         }
     }
 }
 
 void TaskCertificates::StepAbortCertiInfo()
 {
-    pkgmgr_instcertinfo_h handle;
-
     if ((pkgmgr_installer_delete_certinfo(
-            const_cast<char*>(DPL::ToUTF8String(
-                *m_context.widgetConfig.pkgname).c_str()))) < 0) {
+                    const_cast<char*>(DPL::ToUTF8String(
+                            *m_context.widgetConfig.pkgname).c_str()))) < 0) {
         LogError("pkgmgr_installer_delete_certinfo fail");
     }
 }
-}
-}
+
+} //namespace WidgetInstall
+} //namespace Jobs
index 5193929..8a377d6 100755 (executable)
@@ -45,6 +45,8 @@ class TaskCertificates:
     void StepAbortCertiInfo();
     void SetCertiInfo(CertificateSource source);
 
+    pkgmgr_instcertinfo_h m_pkgHandle;
+
   public:
     TaskCertificates(InstallerContext& context);
 };