Ace database fulfill implemented
authorAndrzej Surdej <a.surdej@samsung.com>
Wed, 17 Oct 2012 16:47:36 +0000 (18:47 +0200)
committerAndrzej Surdej <a.surdej@samsung.com>
Fri, 16 Nov 2012 13:24:11 +0000 (14:24 +0100)
[Issue#] LINUXSWAP-211
[Problem] Separation WrtDB and AceDB
[Cause] Security should not use WrtDB. Instead of it AceDB should be used.
[Solution] Implemented filling extended AceDB while widget installation.
[SCMRequest] Commit require security-server change:
http://slp-info.sec.samsung.net/gerrit/#/c/100182/

To verify build repository and check if nothing wrong happend.
Run wrt-tests-w3c and plugins tests widget.
Results should be the same as before.
This commit functionalities can be tested commonly with
http://slp-info.sec.samsung.net/gerrit/#/c/100623/
with the method provided in that commit

Change-Id: Id5cc4791fea3504b5a161cfc55887ab3f112ffec

packaging/wrt-installer.spec
src/CMakeLists.txt
src/jobs/widget_install/ace_registration.cpp [new file with mode: 0644]
src/jobs/widget_install/ace_registration.h [new file with mode: 0644]
src/jobs/widget_install/task_database.cpp
src/jobs/widget_install/task_database.h
src/jobs/widget_uninstall/task_db_update.cpp

index 3e516b4..8f09b4e 100644 (file)
@@ -17,9 +17,8 @@ BuildRequires:  pkgconfig(dpl-event-efl)
 BuildRequires:  pkgconfig(dpl-utils-efl)
 BuildRequires:  pkgconfig(dpl-wrt-dao-ro)
 BuildRequires:  pkgconfig(dpl-wrt-dao-rw)
-BuildRequires:  pkgconfig(ecore-x)
-BuildRequires:  pkgconfig(security)
 BuildRequires:  pkgconfig(security-install)
+BuildRequires:  pkgconfig(ecore-x)
 BuildRequires:  pkgconfig(xmlsec1)
 BuildRequires:  pkgconfig(libidn)
 BuildRequires:  pkgconfig(libiri)
index c9d8e96..fd79466 100644 (file)
@@ -66,6 +66,7 @@ SET(INSTALLER_SOURCES
     ${INSTALLER_JOBS}/widget_install/task_unzip.cpp
     ${INSTALLER_JOBS}/widget_install/task_widget_config.cpp
     ${INSTALLER_JOBS}/widget_install/task_database.cpp
+    ${INSTALLER_JOBS}/widget_install/ace_registration.cpp
     ${INSTALLER_JOBS}/widget_install/task_file_manipulation.cpp
     ${INSTALLER_JOBS}/widget_install/task_smack.cpp
     ${INSTALLER_JOBS}/widget_install/task_ace_check.cpp
@@ -108,7 +109,6 @@ PKG_CHECK_MODULES(INSTALLER_STATIC_DEP
     openssl
     dpl-efl
     cert-svc-vcore
-    security-core
     dpl-event-efl
     dpl-utils-efl
     dpl-wrt-dao-ro
diff --git a/src/jobs/widget_install/ace_registration.cpp b/src/jobs/widget_install/ace_registration.cpp
new file mode 100644 (file)
index 0000000..00165f1
--- /dev/null
@@ -0,0 +1,139 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/**
+ * @file    ace_registration.cpp
+ * @author  Andrzej Surdej (a.surdej@gmail.com)
+ * @version 1.0
+ * @brief   Translate structures to ace api - implementation file
+ */
+
+#include <ace_registration.h>
+#include <dpl/log/log.h>
+#include <dpl/foreach.h>
+#include <ace_api_install.h>
+
+namespace {
+
+char* toAceString(const DPL::OptionalString& os)
+{
+    if (!os.IsNull())
+        return strdup(DPL::ToUTF8String(*os).c_str());
+    else
+        return NULL;
+}
+
+char* toAceString(const std::string& str)
+{
+    if (!str.empty())
+        return strdup(str.c_str());
+    else
+        return NULL;
+}
+
+} //anonymous namespace
+
+namespace AceApi {
+
+bool registerAceWidget(const WrtDB::DbWidgetHandle& widgetHandle,
+                               const WrtDB::WidgetRegisterInfo& widgetConfig,
+                               const WrtDB::WidgetCertificateDataList& certList)
+{
+    LogDebug("Updating Ace database");
+    struct widget_info wi;
+    DPL::OptionalString os;
+
+    switch(widgetConfig.webAppType.appType)
+    {
+        case WrtDB::APP_TYPE_WAC20:
+            wi.type = WAC20;
+            break;
+        case WrtDB::APP_TYPE_TIZENWEBAPP:
+            wi.type = Tizen;
+            break;
+        default:
+            LogError("Unknown application type");
+            return false;
+    }
+
+    wi.id = toAceString(widgetConfig.configInfo.widget_id);
+    wi.version = toAceString(widgetConfig.configInfo.version);
+    wi.author = toAceString(widgetConfig.configInfo.authorName);
+    wi.shareHerf = strdup(widgetConfig.shareHref.c_str());
+    LogDebug("Basic data converted. Certificates begin.");
+
+    //one more element for NULL termination
+    LogDebug("Found: " << certList.size() << " certificates");
+    ace_certificate_data** certData = new ace_certificate_data*[certList.size() + 1];
+    certData[certList.size()] = NULL; // last element set to NULL
+
+    int i = 0;
+    FOREACH(it, certList)
+    {
+        certData[i] = new ace_certificate_data;
+        switch (it->owner) {
+        case WrtDB::WidgetCertificateData::AUTHOR :
+            certData[i]->owner = AUTHOR;
+            break;
+        case WrtDB::WidgetCertificateData::DISTRIBUTOR :
+            certData[i]->owner = DISTRIBUTOR;
+            break;
+        default :
+            LogDebug("Unknown owner type of cert");
+            certData[i]->owner = UNKNOWN;
+        }
+        switch (it->type) {
+            case WrtDB::WidgetCertificateData::ENDENTITY :
+                certData[i]->type = ENDENTITY;
+                break;
+            case WrtDB::WidgetCertificateData::ROOT :
+                certData[i]->type = ROOT;
+                break;
+            default :
+                LogError("Unknown type of cert");
+                certData[i]->type = ENDENTITY;
+        }
+        certData[i]->chain_id = it->chainId;
+
+        certData[i]->md5_fp = toAceString(it->strMD5Fingerprint);
+        certData[i]->sha1_fp = toAceString(it->strSHA1Fingerprint);
+        certData[i]->common_name = toAceString(DPL::ToUTF8String(it->strCommonName));
+        ++i;
+    }
+
+    LogDebug("Registerign widget in ace");
+    ace_return_t retval = ACE_ACE_UNKNOWN_ERROR;
+    retval = ace_register_widget(
+        static_cast<ace_widget_handle_t>(widgetHandle), &wi, certData);
+
+    //clean up - WidgetInfo
+    free(wi.author);
+    free(wi.id);
+    free(wi.shareHerf);
+    free(wi.version);
+
+    //free cert list
+    i = 0;
+    while (certData[i] != NULL) {
+        free(certData[i]->common_name);
+        free(certData[i]->md5_fp);
+        free(certData[i]->sha1_fp);
+        delete certData[i];
+        ++i;
+    }
+    delete[] certData;
+    return retval == ACE_OK;
+}
+}
diff --git a/src/jobs/widget_install/ace_registration.h b/src/jobs/widget_install/ace_registration.h
new file mode 100644 (file)
index 0000000..2f4a3b0
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    Licensed under the Apache License, Version 2.0 (the "License");
+ *    you may not use this file except in compliance with the License.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+/**
+ * @file    ace_registration.h
+ * @author  Andrzej Surdej (a.surdej@gmail.com)
+ * @version 1.0
+ * @brief   Translate structures to ace api - header file
+ */
+#ifndef WRT_SRC_INSTALLER_CORE_ACE_REGISTRATION_H_
+#define WRT_SRC_INSTALLER_CORE_ACE_REGISTRATION_H_
+
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+
+namespace AceApi {
+
+bool registerAceWidget(const WrtDB::DbWidgetHandle& widgetHandle,
+                       const WrtDB::WidgetRegisterInfo& widgetConfig,
+                       const WrtDB::WidgetCertificateDataList& certList);
+
+}
+
+#endif /* WRT_SRC_INSTALLER_CORE_ACE_REGISTRATION_H_ */
+
index f861c85..4f800bb 100644 (file)
 #include <widget_install/job_widget_install.h>
 #include <widget_install/widget_install_errors.h>
 #include <widget_install/widget_install_context.h>
-//#include <dpl/wrt-dao-ro/config_parser_data.h>
 #include <dpl/wrt-dao-rw/widget_dao.h>
 #include <dpl/foreach.h>
 #include <dpl/utils/wrt_utility.h>
 #include <dpl/log/log.h>
 #include <dpl/assert.h>
-//#include <dpl/wrt-dao-ro/global_config.h>
 #include <string>
 #include <sstream>
+#include <ace_api_install.h>
+#include <ace_registration.h>
 
 using namespace WrtDB;
 
@@ -42,15 +42,18 @@ namespace Jobs {
 namespace WidgetInstall {
 TaskDatabase::TaskDatabase(InstallerContext& context) :
     DPL::TaskDecl<TaskDatabase>(this),
-    m_context(context)
+    m_context(context),
+    m_handleToRemove(INVALID_WIDGET_HANDLE),
+    m_handle(INVALID_WIDGET_HANDLE)
 {
     AddStep(&TaskDatabase::StepRegisterExternalFiles);
-    AddStep(&TaskDatabase::StepDBInsert);
+    AddStep(&TaskDatabase::StepWrtDBInsert);
+    AddStep(&TaskDatabase::StepAceDBInsert);
 
     AddAbortStep(&TaskDatabase::StepAbortDBInsert);
 }
 
-void TaskDatabase::StepDBInsert()
+void TaskDatabase::StepWrtDBInsert()
 {
     Try
     {
@@ -59,11 +62,15 @@ void TaskDatabase::StepDBInsert()
 
         if (m_context.existingWidgetInfo.isExist) //update
         {
+            m_handleToRemove = WidgetDAOReadOnly::getHandle(
+                m_context.locations->getPkgname());
             LogInfo("Registering widget... (update)");
             WidgetDAO::registerOrUpdateWidget(
                     m_context.locations->getPkgname(),
                     m_context.widgetConfig,
                     m_context.wacSecurity);
+            m_handle = WidgetDAOReadOnly::getHandle(
+                m_context.locations->getPkgname());
         }
         else //new installation
         {
@@ -72,6 +79,8 @@ void TaskDatabase::StepDBInsert()
                     m_context.locations->getPkgname(),
                     m_context.widgetConfig,
                     m_context.wacSecurity);
+            m_handle = WidgetDAOReadOnly::getHandle(
+                m_context.locations->getPkgname());
         }
 
         FOREACH (cap, m_context.staticPermittedDevCaps) {
@@ -91,6 +100,27 @@ void TaskDatabase::StepDBInsert()
         LogError("Database failure!");
         ReThrowMsg(Exceptions::InsertNewWidgetFailed, "Database failure!");
     }
+}
+
+void TaskDatabase::StepAceDBInsert()
+{
+    LogDebug("Inserting Ace database entry. New handle: " << m_handle);
+    if (INVALID_WIDGET_HANDLE != m_handleToRemove) {
+        LogDebug("Removing old insallation. Handle: " << m_handleToRemove);
+        if (ACE_OK != ace_unregister_widget(
+                static_cast<ace_widget_handle_t>(m_handleToRemove)))
+        {
+            LogWarning("Error while removing ace entry for previous insallation");
+        };
+    }
+
+    if(!AceApi::registerAceWidget(m_handle, m_context.widgetConfig,
+                                  m_context.wacSecurity.getCertificateList()))
+    {
+        LogError("ace database insert failed");
+        ThrowMsg(Exceptions::NotAllowed, "Update failure. ace_register_widget failed");
+    }
+    LogDebug("Ace data inserted");
 
     m_context.job->UpdateProgress(
         InstallerContext::INSTALL_NEW_DB_INSERT,
@@ -145,13 +175,18 @@ void TaskDatabase::StepAbortDBInsert()
     Try
     {
         WidgetDAO::unregisterWidget(m_context.locations->getPkgname());
-
         LogDebug("Cleaning DB successful!");
     }
     Catch(DPL::DB::SqlConnection::Exception::Base)
     {
         LogError("Failed to handle StepAbortDBClean!");
     }
+
+    ace_unregister_widget(static_cast<ace_widget_handle_t>(m_handle));
+    // Remove also old one. If it was already updated nothing wrong will happen,
+    // but if not old widget will be removed.
+    if (INVALID_WIDGET_HANDLE != m_handleToRemove)
+        ace_unregister_widget(static_cast<ace_widget_handle_t>(m_handle));
 }
 
 } //namespace WidgetInstall
index ce01985..4e23a55 100644 (file)
@@ -24,6 +24,7 @@
 #define INSTALLER_CORE_JOS_WIDGET_INSTALL_TASK_DATABASE_H
 
 #include <dpl/task.h>
+#include <dpl/wrt-dao-ro/common_dao_types.h>
 
 class InstallerContext;
 
@@ -35,8 +36,14 @@ class TaskDatabase:
   private:
     InstallerContext& m_context;
 
-    void StepDBInsert();
+    //TODO: temporary needed until security-server start to use pkgName instead
+    //of widget handle
+    WrtDB::DbWidgetHandle m_handleToRemove;
+    WrtDB::DbWidgetHandle m_handle;
+
     void StepRegisterExternalFiles();
+    void StepWrtDBInsert();
+    void StepAceDBInsert();
 
     void StepAbortDBInsert();
 
index b18feb0..d3f2c93 100644 (file)
 #include <widget_uninstall/task_db_update.h>
 #include <widget_uninstall/job_widget_uninstall.h>
 #include <widget_uninstall/widget_uninstall_errors.h>
+#include <dpl/wrt-dao-ro/widget_dao_read_only.h>
+#include <ace_api_install.h>
 
 #include <dpl/assert.h>
+#include <ace-common/ace_api_common.h>
 
 using namespace WrtDB;
 
@@ -45,6 +48,9 @@ void TaskDbUpdate::StepDbUpdate()
 {
     Try
     {
+        //TODO: widget handle should not be used any more
+        ace_unregister_widget(static_cast<ace_widget_handle_t>(
+            WidgetDAOReadOnly::getHandle(m_context.locations->getPkgname())));
         WidgetDAO::unregisterWidget(m_context.locations->getPkgname());
 
         LogDebug("Unregistered widget successfully!");