Prepare AceDB to handle all necessary information.
[Issue#] LINUXSWAP-211
[Problem] Separation ACE and WrtDB
[Cause] N/A
[Solution] AceDB extended
[Verification] To verify successfuly build repository
Change-Id: I5b55ae522dcdd944022a4ff1e23155b593b77632
}
}
-void AceDAO::setWidgetType(WidgetHandle handle, AppTypes widgetType)
-{
- Try {
- ScopedTransaction transaction(&AceDaoUtilities::m_databaseInterface);
-
- ACE_DB_INSERT(insert, AceSubjectType, &AceDaoUtilities::m_databaseInterface);
- AceSubjectType::Row row;
- row.Set_app_id(handle);
- row.Set_app_type(appTypeToInt(widgetType));
- insert->Values(row);
- insert->Execute();
- transaction.Commit();
- }
- Catch(DPL::DB::SqlConnection::Exception::Base) {
- ReThrowMsg(Exception::DatabaseError, "Failed in setWidgetType");
- }
-}
-
void AceDAO::setRequestedDevCaps(
WidgetHandle widgetHandle,
const RequestedDevCapsMap &permissions)
void AceDAO::removeAcceptedFeature(
WidgetHandle widgetHandle)
{
+ Try
+ {
+ ACE_DB_DELETE(del, AceAcceptedFeature,
+ &AceDaoUtilities::m_databaseInterface);
+ del->Where(Equals<AceAcceptedFeature::app_id>(widgetHandle));
+ del->Execute();
+ } Catch(DPL::DB::SqlConnection::Exception::Base) {
+ ReThrowMsg(Exception::DatabaseError, "Failed in removeAcceptedFeature");
+ }
+}
+
+void AceDAO::setWidgetType(WidgetHandle handle, AppTypes widgetType)
+{
Try {
- ACE_DB_DELETE(del, AceAcceptedFeature,
- &AceDaoUtilities::m_databaseInterface);
- del->Where(Equals<AceAcceptedFeature::app_id>(widgetHandle));
+ ScopedTransaction transaction(&AceDaoUtilities::m_databaseInterface);
+ ACE_DB_INSERT(insert, AceSubjectType, &AceDaoUtilities::m_databaseInterface);
+ AceSubjectType::Row row;
+ row.Set_app_id(handle);
+ row.Set_app_type(appTypeToInt(widgetType));
+ insert->Values(row);
+ insert->Execute();
+ transaction.Commit();
+ }
+ Catch(DPL::DB::SqlConnection::Exception::Base) {
+ ReThrowMsg(Exception::DatabaseError, "Failed in setWidgetType");
+ }
+}
+
+void AceDAO::registerWidgetInfo(WidgetHandle handle,
+ const WidgetRegisterInfo& info,
+ const WidgetCertificateDataList& dataList)
+{
+ Try
+ {
+ ACE_DB_INSERT(insert, WidgetInfo, &AceDaoUtilities::m_databaseInterface);
+ WidgetInfo::Row wi;
+ wi.Set_app_id(handle);
+ wi.Set_widget_type(static_cast<int>(info.type));
+ wi.Set_widget_id(info.widget_id);
+ wi.Set_widget_version(info.version);
+ wi.Set_author_name(info.authorName);
+ wi.Set_share_href(info.shareHref);
+ insert->Values(wi);
+ insert->Execute();
+
+ WidgetCertificateDataList::const_iterator it;
+ for (it = dataList.begin(); it != dataList.end(); ++it)
+ {
+ WidgetCertificateFingerprint::Row wcf;
+ wcf.Set_app_id(handle);
+ wcf.Set_owner(it->owner);
+ wcf.Set_chainid(it->chainId);
+ wcf.Set_type(it->type);
+ wcf.Set_md5_fingerprint(DPL::FromUTF8String(it->strMD5Fingerprint));
+ wcf.Set_sha1_fingerprint(DPL::FromUTF8String(it->strSHA1Fingerprint));
+ wcf.Set_common_name(it->strCommonName);
+ ACE_DB_INSERT(insert, WidgetCertificateFingerprint, &AceDaoUtilities::m_databaseInterface);
+ insert->Values(wcf);
+ insert->Execute();
+ }
+ } Catch(DPL::DB::SqlConnection::Exception::Base) {
+ ReThrowMsg(Exception::DatabaseError, "Failed in registerWidgetInfo");
+ }
+}
+
+void AceDAO::unregisterWidgetInfo(WidgetHandle handle)
+{
+ if(AceDAO::isWidgetInstalled(handle)) {
+ Try
+ {
+ ACE_DB_DELETE(del, WidgetInfo, &AceDaoUtilities::m_databaseInterface);
+ del->Where(Equals<WidgetInfo::app_id>(handle));
del->Execute();
+ } Catch(DPL::DB::SqlConnection::Exception::Base) {
+ ReThrowMsg(Exception::DatabaseError, "Failed in unregisterWidgetInfo");
+ }
+ }
+}
+
+bool AceDAO::isWidgetInstalled(WidgetHandle handle)
+{
+ Try {
+ ACE_DB_SELECT(select, WidgetInfo, &AceDaoUtilities::m_databaseInterface);
+ select->Where(Equals<WidgetInfo::app_id>(handle));
+ WidgetInfo::Select::RowList rows = select->GetRowList();
+ return !rows.empty() ? true : false;
} Catch(DPL::DB::SqlConnection::Exception::Base) {
- ReThrowMsg(Exception::DatabaseError, "Failed in removeAcceptedFeature");
+ ReThrowMsg(Exception::DatabaseError, "Failed in isWidgetInstalled");
}
}
#include <ace-dao-ro/AceDAOUtilities.h>
#include <ace-dao-ro/AceDAOConversions.h>
#include <ace-dao-ro/AceDatabase.h>
-#include <dpl/assert.h>
#include <dpl/foreach.h>
using namespace DPL::DB::ORM;
}
}
-AppTypes AceDAOReadOnly::getWidgetType(WidgetHandle handle)
-{
- Try {
- ACE_DB_SELECT(select, AceSubjectType, &AceDaoUtilities::m_databaseInterface);
- select->Where(Equals<AceSubjectType::app_id>(handle));
- std::list<AceSubjectType::Row> rows = select->GetRowList();
- if (rows.empty()) {
- return AppTypes::Unknown;
- }
- AceSubjectType::Row row = rows.front();
- return intToAppType(row.Get_app_type());
- }
- Catch(DPL::DB::SqlConnection::Exception::Base) {
- ReThrowMsg(Exception::DatabaseError, "Failed to getWidgetType");
- }
-}
-
OptionalExtendedPolicyResult AceDAOReadOnly::getPolicyResult(
const BaseAttributeSet &attributes)
{
}
}
-
-
void AceDAOReadOnly::getWidgetDevCapSettings(BasePermissionList *outputList)
{
if (NULL == outputList) {
}
}
+AppTypes AceDAOReadOnly::getWidgetType(WidgetHandle handle)
+{
+ Try {
+ ACE_DB_SELECT(select, AceSubjectType, &AceDaoUtilities::m_databaseInterface);
+ select->Where(Equals<AceSubjectType::app_id>(handle));
+ std::list<AceSubjectType::Row> rows = select->GetRowList();
+ if (rows.empty()) {
+ return AppTypes::Unknown;
+ }
+ AceSubjectType::Row row = rows.front();
+ return (static_cast<AppTypes>(row.Get_app_type()));
+ }
+ Catch(DPL::DB::SqlConnection::Exception::Base) {
+ ReThrowMsg(Exception::DatabaseError, "Failed to getWidgetType");
+ }
+}
+
+std::string AceDAOReadOnly::getVersion(WidgetHandle widgetHandle)
+{
+ Try
+ {
+ ACE_DB_SELECT(select, WidgetInfo, &AceDaoUtilities::m_databaseInterface);
+ select->Where(Equals<WidgetInfo::app_id>(widgetHandle));
+ WidgetInfo::Select::RowList rows = select->GetRowList();
+ DPL::OptionalString res;
+ if(!rows.empty()) {
+ res = rows.front().Get_widget_version();
+ return (res.IsNull() ? "" : DPL::ToUTF8String(*res));
+ } else {
+ LogDebug("Widget not installed");
+ return "";
+ }
+ } Catch(DPL::DB::SqlConnection::Exception::Base) {
+ ReThrowMsg(Exception::DatabaseError, "Failed to getVersion");
+ }
+}
+
+std::string AceDAOReadOnly::getAuthorName(WidgetHandle widgetHandle)
+{
+ Try
+ {
+ ACE_DB_SELECT(select, WidgetInfo, &AceDaoUtilities::m_databaseInterface);
+ select->Where(Equals<WidgetInfo::app_id>(widgetHandle));
+ WidgetInfo::Select::RowList rows = select->GetRowList();
+ DPL::OptionalString res;
+ if(!rows.empty()) {
+ res = rows.front().Get_author_name();
+ return (res.IsNull() ? "" : DPL::ToUTF8String(*res));
+ } else {
+ LogDebug("Widget not installed");
+ return "";
+ }
+ } Catch(DPL::DB::SqlConnection::Exception::Base) {
+ ReThrowMsg(Exception::DatabaseError, "Failed to getAuthorName");
+ }
+}
+
+std::string AceDAOReadOnly::getGUID(WidgetHandle widgetHandle)
+{
+ Try
+ {
+ ACE_DB_SELECT(select, WidgetInfo, &AceDaoUtilities::m_databaseInterface);
+ select->Where(Equals<WidgetInfo::app_id>(widgetHandle));
+ WidgetInfo::Select::RowList rows = select->GetRowList();
+ DPL::OptionalString res;
+ if(!rows.empty()) {
+ res = rows.front().Get_widget_id();
+ return (res.IsNull() ? "" : DPL::ToUTF8String(*res));
+ } else {
+ LogDebug("Widget not installed");
+ return "";
+ }
+ } Catch(DPL::DB::SqlConnection::Exception::Base) {
+ ReThrowMsg(Exception::DatabaseError, "Failed to getGUID");
+ }
+}
+
+WidgetCertificateCNList AceDAOReadOnly::getKeyCommonNameList(
+ WidgetHandle widgetHandle,
+ WidgetCertificateData::Owner owner,
+ WidgetCertificateData::Type type)
+{
+ Try {
+ ACE_DB_SELECT(select, WidgetCertificateFingerprint, &AceDaoUtilities::m_databaseInterface);
+ select->Where(And(And(
+ Equals<WidgetCertificateFingerprint::app_id>(widgetHandle),
+ Equals<WidgetCertificateFingerprint::owner>(owner)),
+ Equals<WidgetCertificateFingerprint::type>(type)));
+ WidgetCertificateFingerprint::Select::RowList rows = select->GetRowList();
+
+ WidgetCertificateCNList out;
+ FOREACH(it, rows)
+ {
+ DPL::Optional<DPL::String> cn = it->Get_common_name();
+ out.push_back(cn.IsNull() ? "" : DPL::ToUTF8String(*cn));
+ }
+ return out;
+ }
+ Catch(DPL::DB::SqlConnection::Exception::Base) {
+ ReThrowMsg(Exception::DatabaseError, "Failed to getKeyCommonNameList");
+ }
+}
+
+FingerPrintList AceDAOReadOnly::getKeyFingerprints(
+ WidgetHandle widgetHandle,
+ WidgetCertificateData::Owner owner,
+ WidgetCertificateData::Type type)
+{
+ Try
+ {
+ ACE_DB_SELECT(select, WidgetCertificateFingerprint, &AceDaoUtilities::m_databaseInterface);
+ select->Where(And(And(
+ Equals<WidgetCertificateFingerprint::app_id>(widgetHandle),
+ Equals<WidgetCertificateFingerprint::owner>(owner)),
+ Equals<WidgetCertificateFingerprint::type>(type)));
+ WidgetCertificateFingerprint::Select::RowList rows = select->GetRowList();
+
+ FingerPrintList keys;
+ FOREACH(it, rows)
+ {
+ DPL::Optional<DPL::String> sha1 = it->Get_sha1_fingerprint();
+ if (!sha1.IsNull())
+ keys.push_back(DPL::ToUTF8String(*sha1));
+ DPL::Optional<DPL::String> md5 = it->Get_md5_fingerprint();
+ if (!md5.IsNull())
+ keys.push_back(DPL::ToUTF8String(*md5));
+ }
+ return keys;
+ }
+ Catch(DPL::DB::SqlConnection::Exception::Base) {
+ ReThrowMsg(Exception::DatabaseError, "Failed to getKeyFingerprints");
+ }
+}
+
+std::string AceDAOReadOnly::getShareHref(WidgetHandle widgetHandle)
+{
+ Try
+ {
+ ACE_DB_SELECT(select, WidgetInfo, &AceDaoUtilities::m_databaseInterface);
+ select->Where(Equals<WidgetInfo::app_id>(widgetHandle));
+ WidgetInfo::Select::RowList rows = select->GetRowList();
+
+ if(rows.empty())
+ ThrowMsg(Exception::DatabaseError, "Cannot find widget. Handle: " << widgetHandle);
+
+ DPL::Optional<DPL::String> value = rows.front().Get_share_href();
+ std::string ret = "";
+ if(!value.IsNull())
+ ret = DPL::ToUTF8String(*value);
+ return ret;
+ }
+ Catch(DPL::DB::SqlConnection::Exception::Base) {
+ ReThrowMsg(Exception::DatabaseError, "Failed to getShareHref");
+ }
+}
+
}
+++ /dev/null
-/*
- * Copyright (c) 2011 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 common_dao_types.h
- * @author Michal Ciepielski (m.ciepielski@samsung.com)
- * @version 1.0
- * @brief This file contains the implementation of common data types for wrtdb
- */
-
-#include <dpl/wrt-dao-ro/common_dao_types.h>
-
-#include <dpl/log/log.h>
-
-namespace WrtDB {
-} // namespace WrtDB
static void getAttributes(BaseAttributeSet *attributes);
- // widget type
- static AppTypes getWidgetType(WidgetHandle handle);
-
// Getter for device capabilities that are requested in widgets config.
//
// Additional boolean flag means whether widget will always get
WidgetHandle widgetHandle,
FeatureNameVector *featureVector);
+ static AppTypes getWidgetType(WidgetHandle handle);
+ static std::string getVersion(WidgetHandle widgetHandle);
+ static std::string getAuthorName(WidgetHandle widgetHandle);
+ static std::string getGUID(WidgetHandle widgetHandle);
+
+ static WidgetCertificateCNList getKeyCommonNameList(
+ WidgetHandle widgetHandle,
+ WidgetCertificateData::Owner owner,
+ WidgetCertificateData::Type type);
+ static FingerPrintList getKeyFingerprints(
+ WidgetHandle widgetHandle,
+ WidgetCertificateData::Owner owner,
+ WidgetCertificateData::Type type);
+
+ static std::string getShareHref(WidgetHandle widgetHandle);
+
protected:
static int promptDecisionToInt(PromptDecision decision);
static PromptDecision intToPromptDecision(int decision);
*
* @file common_dao_types.h
* @author Bartlomiej Grzelewski (b.grzelewski@samsung.com)
- * @version 1.0
+ * @version 1.1
* @brief This file contains the declaration of common data types for ace database.
*/
#ifndef ACE_SRC_CONFIGURATION_COMMON_DAO_TYPES_H_
#define ACE_SRC_CONFIGURATION_COMMON_DAO_TYPES_H_
#include <list>
+#include <dpl/optional_typedefs.h>
+#include <dpl/string.h>
+#include "AppTypes.h"
typedef int WidgetHandle;
typedef std::list<WidgetHandle> WidgetHandleList;
+namespace AceDB {
+
+enum {
+ INVALID_PLUGIN_HANDLE = -1
+};
+typedef int DbPluginHandle;
+
+struct WidgetRegisterInfo {
+ AppTypes type;
+ DPL::OptionalString widget_id;
+ DPL::OptionalString authorName;
+ DPL::OptionalString version;
+ DPL::OptionalString shareHref;
+};
+
+typedef std::list <std::string> WidgetCertificateCNList;
+
+struct WidgetCertificateData {
+ enum Owner { AUTHOR, DISTRIBUTOR, UNKNOWN };
+ enum Type { ROOT, ENDENTITY };
+
+ Owner owner;
+ Type type;
+
+ int chainId;
+ std::string strMD5Fingerprint;
+ std::string strSHA1Fingerprint;
+ DPL::String strCommonName;
+
+ bool operator== (const WidgetCertificateData& certData) const {
+ return certData.chainId == chainId &&
+ certData.owner == owner &&
+ certData.strCommonName == strCommonName &&
+ certData.strMD5Fingerprint == strMD5Fingerprint &&
+ certData.strSHA1Fingerprint == strSHA1Fingerprint;
+ }
+};
+typedef std::list<WidgetCertificateData> WidgetCertificateDataList;
+
+typedef std::list<std::string> FingerPrintList;
+
+typedef std::list<std::string> CertificateChainList;
+class IWacSecurity {
+ public:
+ virtual ~IWacSecurity();
+ virtual const WidgetCertificateDataList& getCertificateList() const = 0;
+ virtual bool isRecognized() const = 0;
+ virtual bool isDistributorSigned() const = 0;
+ virtual bool isWacSigned() const = 0;
+ virtual void getCertificateChainList(CertificateChainList& list) const = 0;
+};
+
+} //namespace AceDB
+
#endif /* ACE_SRC_CONFIGURATION_COMMON_DAO_TYPES_H_ */
static void removeAcceptedFeature(WidgetHandle widgetHandle);
+ static void registerWidgetInfo(WidgetHandle handle,
+ const WidgetRegisterInfo& info,
+ const WidgetCertificateDataList& dataList);
+ static void unregisterWidgetInfo(WidgetHandle handle);
+ static bool isWidgetInstalled(WidgetHandle handle);
+
} __attribute__ ((deprecated));
}
#endif /* ACEDAO_H_ */
TABLE_CONSTRAINTS(unique(app_id))
CREATE_TABLE_END()
+CREATE_TABLE(WidgetInfo)
+ COLUMN_NOT_NULL(app_id, INTEGER, PRIMARY KEY)
+ COLUMN(widget_type, INT, DEFAULT 1)
+ COLUMN(widget_id, VARCHAR(256), DEFAULT '')
+ COLUMN(widget_version, VARCHAR(256), DEFAULT '')
+ COLUMN(author_name, VARCHAR(256), DEFAULT '')
+ COLUMN(share_href, VARCHAR(256), DEFAULT '')
+CREATE_TABLE_END()
+
+CREATE_TABLE(WidgetCertificateFingerprint)
+ COLUMN_NOT_NULL(app_id, INT,)
+ COLUMN_NOT_NULL(owner, INT,)
+ COLUMN_NOT_NULL(chainid, INT,)
+ COLUMN_NOT_NULL(type, INT,)
+ COLUMN(md5_fingerprint, VARCHAR(64),)
+ COLUMN(sha1_fingerprint, VARCHAR(64),)
+ COLUMN(common_name, VARCHAR(64),)
+ TABLE_CONSTRAINTS(
+ PRIMARY KEY (app_id, chainid, owner, type)
+ FOREIGN KEY (app_id) REFERENCES WidgetInfo (app_id) ON DELETE CASCADE
+ )
+CREATE_TABLE_END()
+
SQL(
COMMIT;
)
Tizen
} ace_widget_type_t;
+struct widget_info {
+ ace_widget_type_t type;
+ ace_string_t id;
+ ace_string_t version;
+ ace_string_t author;
+ ace_string_t shareHerf;
+};
+
+typedef enum
+{
+ AUTHOR,
+ DISTRIBUTOR,
+ UNKNOWN
+} ace_cert_owner_t;
+
+typedef enum
+{
+ ROOT,
+ ENDENTITY
+} ace_cert_type_t;
+
+typedef struct certificate_data {
+ ace_cert_owner_t owner;
+ ace_cert_type_t type;
+ int chain_id;
+ ace_string_t md5_fp;
+ ace_string_t sha1_fp;
+ ace_string_t common_name;
+} ace_certificate_data;
+
+/*
+ * Register widget info into database.
+ * @param cert_data NULL terminated list of widget certificates
+ */
+
+ace_return_t ace_register_widget(ace_widget_handle_t handle,
+ struct widget_info* info,
+ ace_certificate_data* cert_data[]);
+
+ace_return_t ace_unregister_widget(ace_widget_handle_t handle);
+
+ace_return_t ace_is_widget_installed(ace_widget_handle_t handle, bool *installed);
+
/*
* Sets widget type. Use in installer to determine which policy will be used
* by ACE for this widget.
return ACE_OK;
}
+ace_return_t ace_register_widget(ace_widget_handle_t handle,
+ struct widget_info *info,
+ ace_certificate_data* cert_data[])
+{
+ LogDebug("enter");
+ AceDB::WidgetRegisterInfo wri;
+ wri.type = to_db_app_type(info->type);
+
+ //TODO: type should be only in WidgetInfo database table
+ ace_set_widget_type(handle, info->type);
+
+ if (info->id)
+ wri.widget_id = DPL::FromUTF8String(info->id);
+ if (info->version)
+ wri.version = DPL::FromUTF8String(info->version);
+ if (info->author)
+ wri.authorName = DPL::FromUTF8String(info->author);
+ if (info->shareHerf)
+ wri.shareHref = DPL::FromUTF8String(info->shareHerf);
+
+ AceDB::WidgetCertificateDataList dataList;
+ AceDB::WidgetCertificateData wcd;
+ ace_certificate_data* cd;
+ int i = 0;
+ while (cert_data[i] != NULL)
+ {
+ cd = cert_data[i++]; //increment
+ switch(cd->type) {
+ case ROOT:
+ wcd.type = AceDB::WidgetCertificateData::Type::ROOT;
+ break;
+ case ENDENTITY:
+ wcd.type = AceDB::WidgetCertificateData::Type::ENDENTITY;
+ break;
+ }
+ switch(cd->owner) {
+ case AUTHOR:
+ wcd.owner = AceDB::WidgetCertificateData::Owner::AUTHOR;
+ break;
+ case DISTRIBUTOR:
+ wcd.owner = AceDB::WidgetCertificateData::Owner::DISTRIBUTOR;
+ break;
+ case UNKNOWN: default:
+ wcd.owner = AceDB::WidgetCertificateData::Owner::UNKNOWN;
+ break;
+ }
+ wcd.chainId = cd->chain_id;
+ if (cd->md5_fp)
+ wcd.strMD5Fingerprint = cd->md5_fp;
+ if (cd->sha1_fp)
+ wcd.strSHA1Fingerprint = cd->sha1_fp;
+ if (cd->common_name)
+ wcd.strCommonName = DPL::FromUTF8String(cd->common_name);
+ dataList.push_back(wcd);
+ }
+ LogDebug("All data set. Inserting into database.");
+
+ Try {
+ AceDB::AceDAO::registerWidgetInfo((WidgetHandle)(handle), wri, dataList);
+ LogDebug("AceDB entry done");
+ } Catch(AceDB::AceDAOReadOnly::Exception::DatabaseError) {
+ return ACE_INTERNAL_ERROR;
+ }
+ return ACE_OK;
+}
+
+ace_return_t ace_unregister_widget(ace_widget_handle_t handle)
+{
+ Try {
+ AceDB::AceDAO::unregisterWidgetInfo((WidgetHandle)(handle));
+ } Catch(AceDB::AceDAOReadOnly::Exception::DatabaseError) {
+ return ACE_INTERNAL_ERROR;
+ }
+ return ACE_OK;
+}
+
+ace_return_t ace_is_widget_installed(ace_widget_handle_t handle, bool *installed)
+{
+ Try {
+ *installed = AceDB::AceDAO::isWidgetInstalled((WidgetHandle)(handle));
+ } Catch(AceDB::AceDAOReadOnly::Exception::DatabaseError) {
+ return ACE_INTERNAL_ERROR;
+ }
+ return ACE_OK;
+}
+
ace_return_t ace_set_widget_type(ace_widget_handle_t handle,
ace_widget_type_t type)
{