[Release] wrt-installer_0.1.9
[platform/framework/web/wrt-installer.git] / src / jobs / widget_install / task_certify.cpp
old mode 100755 (executable)
new mode 100644 (file)
index dbfc7cd..6b0040f
@@ -33,7 +33,6 @@
 #include <widget_install/widget_install_errors.h>
 #include <widget_install/widget_install_context.h>
 #include <dpl/log/log.h>
-#include <wrt_error.h>
 #include <dpl/wrt-dao-ro/global_config.h>
 #include "wac_widget_id.h"
 
@@ -54,8 +53,8 @@ using namespace WrtDB;
 namespace {
 const std::string LABEL_NEW_LINE = "<br>";
 const std::string LABEL_NEW_LINE_2 = "<br><br>";
-const std::string UNTRUSTED_WIDGET ="It is an Untrusted Widget";
-const char *QUESTION ="Do you wanto to install?";
+const std::string UNTRUSTED_WIDGET = "It is an Untrusted Widget";
+const char *QUESTION = "Do you wanto to install?";
 
 WidgetCertificateData toWidgetCertificateData(const SignatureData &data,
                                               bool root)
@@ -79,7 +78,7 @@ WidgetCertificateData toWidgetCertificateData(const SignatureData &data,
     }
 
     Assert(certificate && !certificate->getCommonName().IsNull() &&
-            "CommonName is Null");
+           "CommonName is Null");
 
     result.strCommonName = *certificate->getCommonName();
 
@@ -99,17 +98,15 @@ namespace Jobs {
 namespace WidgetInstall {
 TaskCertify::TaskCertify(InstallerContext &inCont) :
     DPL::TaskDecl<TaskCertify>(this),
-    m_contextData(inCont),
-    WidgetInstallPopup(inCont)
+    WidgetInstallPopup(inCont),
+    m_contextData(inCont)
 {
-    /* This is temporary comment for certi error
-       After security-server, cert-svc release, should remove comment
     AddStep(&TaskCertify::stepSignature);
-    */
 
     // Block until fixed popup issues
     if (!GlobalSettings::PopupsTestModeEnabled()
-            && !m_installContext.m_quiet && !isTizenWebApp()) {
+        && !m_installContext.m_quiet && !isTizenWebApp())
+    {
         AddStep(&TaskCertify::stepWarningPopup);
         AddStep(&TaskCertify::stepWarningPopupAnswer);
         AddStep(&TaskCertify::stepAuthorInfoPopup);
@@ -133,14 +130,14 @@ void TaskCertify::processDistributorSignature(const SignatureData &data,
     CertificateCollection collection;
     collection.load(data.getCertList());
     Assert(collection.sort() &&
-            "Certificate collection can't sort");
+           "Certificate collection can't sort");
 
     Assert(collection.isChain() &&
            "Certificate collection is not able to create chain. "
            "It is not possible to verify this signature.");
 
     m_contextData.wacSecurity.getCertificateChainListRef().push_back(
-            collection);
+        collection);
 
     if (first) {
         m_contextData.wacSecurity.getCertificateListRef().push_back(
@@ -177,7 +174,7 @@ void TaskCertify::processAuthorSignature(const SignatureData &data)
            "It is not possible to verify this signature.");
 
     m_contextData.wacSecurity.getAuthorsCertificateChainListRef().push_back(
-            collection);
+        collection);
 
     FOREACH(it, dnsIdentity){
         if (widgetId.matchHost(*it)) {
@@ -191,7 +188,8 @@ void TaskCertify::stepSignature()
 {
     LogInfo("================ Step: <<Signature>> ENTER ===============");
 
-    std::string widgetPath = m_contextData.locations->getTemporaryRootDir() + "/";
+    std::string widgetPath = m_contextData.locations->getTemporaryRootDir() +
+        "/";
 
     SignatureFileInfoSet signatureFiles;
     SignatureFinder signatureFinder(widgetPath);
@@ -219,20 +217,34 @@ void TaskCertify::stepSignature()
             xml.initialize(data, GlobalConfig::GetSignatureXmlSchema());
             xml.read(data);
 
-            WrtSignatureValidator::AppType appType = WrtSignatureValidator::WAC20;
+            WrtSignatureValidator::AppType appType =
+                WrtSignatureValidator::WAC20;
 
-            if (m_installContext.widgetConfig.webAppType == APP_TYPE_TIZENWEBAPP) {
+            if (m_installContext.widgetConfig.webAppType ==
+                APP_TYPE_TIZENWEBAPP)
+            {
                 appType = WrtSignatureValidator::TIZEN;
             }
 
+            WrtSignatureValidator::Result result;
+
             WrtSignatureValidator validator(
-                appType,
-                !GlobalSettings::OCSPTestModeEnabled(),
-                !GlobalSettings::CrlTestModeEnabled(),
-                complianceMode);
+                    appType,
+                    !GlobalSettings::
+                    OCSPTestModeEnabled(),
+                    !GlobalSettings::
+                    CrlTestModeEnabled(),
+                    complianceMode);
+
+            result = validator.check(data, widgetPath);
 
-            WrtSignatureValidator::Result result =
-                validator.check(data, widgetPath);
+            if (m_contextData.widgetConfig.packagingType
+                == WrtDB::PKG_TYPE_DIRECTORY_WEB_APP)
+            {
+                // In directory installation mode, the validation is skipped.
+
+                result = WrtSignatureValidator::SIGNATURE_VERIFIED;
+            }
 
             if (result == WrtSignatureValidator::SIGNATURE_REVOKED) {
                 LogWarning("Certificate is REVOKED");
@@ -252,7 +264,9 @@ void TaskCertify::stepSignature()
                     m_contextData.wacSecurity.isDistributorSigned())
                 {
                     processAuthorSignature(data);
-                } else if (result == WrtSignatureValidator::SIGNATURE_DISREGARD) {
+                } else if (result ==
+                           WrtSignatureValidator::SIGNATURE_DISREGARD)
+                {
                     continue;
                 }
             } else {
@@ -269,8 +283,7 @@ void TaskCertify::stepSignature()
             std::string realMEID;
             TapiHandle *tapiHandle = tel_init(NULL);
             char *meid = tel_get_misc_me_sn_sync(tapiHandle);
-            if (meid)
-            {
+            if (meid) {
                 realMEID = meid;
                 free(meid);
             }
@@ -322,11 +335,11 @@ void TaskCertify::stepSignature()
 void TaskCertify::createInstallPopup(PopupType type, const std::string &label)
 {
     m_contextData.job->Pause();
-    if(m_popup)
+    if (m_popup) {
         destroyPopup();
+    }
     bool ret = createPopup();
-    if(ret)
-    {
+    if (ret) {
         loadPopup(type, label);
         showPopup();
     }
@@ -407,9 +420,9 @@ std::string TaskCertify::createAuthorWidgetInfo() const
 void TaskCertify::stepAuthorInfoPopup()
 {
     LogInfo("Step:: <<Author Popup Information>>");
-        std::string label
-            = createAuthorWidgetInfo() + LABEL_NEW_LINE_2 + QUESTION;
-        createInstallPopup(PopupType::WIDGET_AUTHOR_INFO, label);
+    std::string label
+        = createAuthorWidgetInfo() + LABEL_NEW_LINE_2 + QUESTION;
+    createInstallPopup(PopupType::WIDGET_AUTHOR_INFO, label);
 }
 
 void TaskCertify::stepFinalize()
@@ -421,12 +434,11 @@ void TaskCertify::stepFinalize()
         "Widget Certification Check Finished");
 }
 
-
 void TaskCertify::stepWarningPopupAnswer()
 {
     LogInfo("Step: <<Warning Popup Answer>>");
     if (false == m_contextData.wacSecurity.isDistributorSigned() &&
-            WRT_POPUP_BUTTON_CANCEL == m_installCancel)
+        WRT_POPUP_BUTTON_CANCEL == m_installCancel)
     {
         LogWarning("User does not agreed to install unsigned widgets!");
         m_installCancel = WRT_POPUP_BUTTON;
@@ -438,7 +450,7 @@ void TaskCertify::stepWarningPopupAnswer()
 void TaskCertify::stepAuthorInfoPopupAnswer()
 {
     LogInfo("Step: <<Author Info Popup Answer>>");
-    if ( WRT_POPUP_BUTTON_CANCEL == m_installCancel) {
+    if (WRT_POPUP_BUTTON_CANCEL == m_installCancel) {
         LogWarning("User does not agreed to install widget!");
         m_installCancel = WRT_POPUP_BUTTON;
         destroyPopup();
@@ -450,8 +462,10 @@ bool TaskCertify::isTizenWebApp() const
 {
     bool ret = FALSE;
     if (m_installContext.widgetConfig.webAppType.appType
-            == WrtDB::AppType::APP_TYPE_TIZENWEBAPP)
+        == WrtDB::AppType::APP_TYPE_TIZENWEBAPP)
+    {
         ret = TRUE;
+    }
 
     return ret;
 }