From: jihoon.chung Date: Wed, 29 Aug 2012 06:28:27 +0000 (+0900) Subject: Update wrt-installer_0.0.53 X-Git-Tag: 2.0_alpha~2 X-Git-Url: http://review.tizen.org/git/?p=framework%2Fweb%2Fwrt-installer.git;a=commitdiff_plain;h=8ec41fa51d9e04f17c66ef90bbaa9711de29e342;hp=c4570c73c1e9eff27897540cccf3260b136eadc7 Update wrt-installer_0.0.53 --- diff --git a/debian/changelog b/debian/changelog index c5bc347..ff1aa77 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,12 @@ +wrt-installer (0.0.53) unstable; urgency=low + + * [Installer] Add encrypt task + + * Git : slp/pkgs/w/wrt-installer + * Tag : wrt-installer_0.0.53 + + -- Jihoon Chung Wed, 29 Aug 2012 13:43:57 +0900 + wrt-installer (0.0.52) unstable; urgency=low * [Engine] Support execution of backend library on multiple threads diff --git a/packaging/wrt-installer.spec b/packaging/wrt-installer.spec index 7ccdfbe..1f49c19 100644 --- a/packaging/wrt-installer.spec +++ b/packaging/wrt-installer.spec @@ -1,7 +1,7 @@ -#sbs-git:slp/pkgs/w/wrt-installer wrt-installer 0.0.52 +#sbs-git:slp/pkgs/w/wrt-installer wrt-installer 0.0.53 Name: wrt-installer Summary: Installer for tizen Webruntime -Version: 0.0.52 +Version: 0.0.53 Release: 1 Group: Development/Libraries License: Apache License, Version 2.0 @@ -35,6 +35,7 @@ BuildRequires: pkgconfig(utilX) BuildRequires: pkgconfig(wrt-plugins-types) BuildRequires: pkgconfig(tapi) BuildRequires: pkgconfig(shortcut) +BuildRequires: pkgconfig(dpl-encryption) %description Description: Wrt Installer for Tizen apps and Wac apps diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 42f35a5..b25090b 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -75,6 +75,7 @@ SET(INSTALLER_SOURCES ${INSTALLER_JOBS}/widget_install/task_update_files.cpp ${INSTALLER_JOBS}/widget_install/task_new_db_insert.cpp ${INSTALLER_JOBS}/widget_install/task_remove_backup.cpp + ${INSTALLER_JOBS}/widget_install/task_encrypt_resource.cpp ${INSTALLER_JOBS}/widget_install/wac_security.cpp ${INSTALLER_JOBS}/widget_install/widget_update_info.cpp ${INSTALLER_JOBS}/widget_install/widget_install_popup.cpp @@ -106,6 +107,7 @@ PKG_CHECK_MODULES(INSTALLER_STATIC_DEP dpl-utils-efl dpl-wrt-dao-ro dpl-wrt-dao-rw + dpl-encryption ace-install ecore-x xmlsec1 diff --git a/src/jobs/widget_install/job_widget_install.cpp b/src/jobs/widget_install/job_widget_install.cpp index 9dc31b0..24db446 100755 --- a/src/jobs/widget_install/job_widget_install.cpp +++ b/src/jobs/widget_install/job_widget_install.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -76,6 +77,9 @@ const char* REG_TIZENID_PATTERN = "^[-. a-zA-Z0-9_@+=]*$"; const int RESERVED_COUNT = 20; //number of chars reserved in name (e.g. for '.desktop') const int MAX_TIZENID_LENTH = 255 - RESERVED_COUNT; +static const DPL::String SETTING_VALUE_ENCRYPTION = L"encryption"; +static const DPL::String SETTING_VALUE_ENCRYPTION_ENABLE = L"enable"; + class InstallerTaskFail : public DPL::TaskDecl { @@ -148,7 +152,7 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath, m_installerContext.browserRequest, m_installerContext.widgetConfig.pType); WidgetUpdateInfo update = detectWidgetUpdate(configData); - + bool needEncryption = detectResourceEncryption(configData); // Configure installation ConfigureResult result = ConfigureInstallation(widgetPath, @@ -180,6 +184,9 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath, } AddTask(new TaskWidgetConfig(m_installerContext)); AddTask(new TaskCertify(m_installerContext)); + if (needEncryption) { + AddTask(new TaskEncryptResource(m_installerContext)); + } AddTask(new TaskDbUpdate(m_installerContext)); // TODO: Update progress information for this task @@ -757,5 +764,18 @@ WrtDB::PackagingType JobWidgetInstall::checkPackageType( return pType; } +bool JobWidgetInstall::detectResourceEncryption(const WrtDB::ConfigParserData &configData) +{ + FOREACH(it, configData.settingsList) + { + if (it->m_name == SETTING_VALUE_ENCRYPTION && + it->m_value == SETTING_VALUE_ENCRYPTION_ENABLE) { + LogDebug("resource need encryption"); + return true; + } + } + return false; +} + } //namespace WidgetInstall } //namespace Jobs diff --git a/src/jobs/widget_install/job_widget_install.h b/src/jobs/widget_install/job_widget_install.h index b1d0b1e..23b5b26 100644 --- a/src/jobs/widget_install/job_widget_install.h +++ b/src/jobs/widget_install/job_widget_install.h @@ -72,6 +72,7 @@ class JobWidgetInstall : WrtDB::PackagingType checkPackageType( const std::string &widgetSorce); + bool detectResourceEncryption(const WrtDB::ConfigParserData &configData); public: /** diff --git a/src/jobs/widget_install/task_db_update.cpp b/src/jobs/widget_install/task_db_update.cpp index 99fb5e7..4804bce 100644 --- a/src/jobs/widget_install/task_db_update.cpp +++ b/src/jobs/widget_install/task_db_update.cpp @@ -141,40 +141,32 @@ void TaskDbUpdate::StepDbUpdate() void TaskDbUpdate::StepRenamePath() { - std::ostringstream instDir; DPL::OptionalString pkgname = m_context.widgetConfig.pkgname; if (pkgname.IsNull()) { ThrowMsg(Exceptions::InternalError, "No Package name exists."); } + if (!_WrtUtilRemoveDir(m_context.installPath.c_str())) { + _WrtUtilChangeDir(GlobalConfig::GetUserInstalledWidgetPath()); + ThrowMsg(Exceptions::RemovingFolderFailure, + "Error occurs during removing existing folder"); + } + if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) { - instDir << GlobalConfig::GetUserInstalledWidgetPath() << "/"; - instDir << pkgname; - - LogDebug("Copy file from temp directory to " << instDir.str()); - if (!_WrtUtilRemoveDir(instDir.str().c_str())) { - _WrtUtilChangeDir(GlobalConfig::GetUserInstalledWidgetPath()); - ThrowMsg(Exceptions::RemovingFolderFailure, - "Error occurs during removing existing folder"); - } - if (rename(m_context.tempWidgetPath.c_str(), instDir.str().c_str()) < 0) { + LogDebug("Copy file from temp directory to " << + m_context.installPath); + + if (rename(m_context.tempWidgetPath.c_str(), + m_context.installPath.c_str()) < 0) { ThrowMsg(Exceptions::UnknownError, "Error occurs during renaming widget folder"); } } else { - instDir << GlobalConfig::GetUserInstalledWidgetPath() << "/"; - instDir << pkgname << "/"; - instDir << GlobalConfig::GetWidgetSrcPath(); - - LogDebug("Copy file from temp directory to " << instDir.str()); - if (!_WrtUtilRemoveDir(instDir.str().c_str())) { - _WrtUtilChangeDir(GlobalConfig::GetUserInstalledWidgetPath()); - ThrowMsg(Exceptions::RemovingFolderFailure, - "Error occurs during removing existing folder"); - } + LogDebug("Copy file from temp directory to " << + m_context.installPath); if (!m_context.browserRequest) { - if (rename(m_context.tempWidgetRoot.c_str(), instDir.str().c_str()) < 0) { + if (rename(m_context.tempWidgetRoot.c_str(), m_context.installPath.c_str()) < 0) { ThrowMsg(Exceptions::UnknownError, "Error occurs during renaming widget folder"); } diff --git a/src/jobs/widget_install/task_encrypt_resource.cpp b/src/jobs/widget_install/task_encrypt_resource.cpp new file mode 100644 index 0000000..6414eb7 --- /dev/null +++ b/src/jobs/widget_install/task_encrypt_resource.cpp @@ -0,0 +1,192 @@ +/* + * 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 task_ecnrypt_resource.cpp + * @author Soyoung Kim (sy037.kim@samsung.com) + * @version 1.0 + * @brief Implementation file for installer task encrypt resource + */ +#include "task_encrypt_resource.h" + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +using namespace WrtDB; +using namespace WRTEncryptor; + +namespace { +std::set& getSupportedForEncryption() +{ + static std::set encryptSet; + if (encryptSet.empty()) { + encryptSet.insert(".html"); + encryptSet.insert(".css"); + encryptSet.insert(".js"); + } + return encryptSet; +} + +bool isSupportedForEncryption(std::string file) +{ + size_t foundKey = file.rfind("."); + if (std::string::npos != foundKey) { + std::string mimeType = file.substr(foundKey); + return getSupportedForEncryption().count(mimeType) > 0; + } + return false; +} +} + +namespace Jobs { +namespace WidgetInstall { +TaskEncryptResource::TaskEncryptResource(InstallerContext& context) : + DPL::TaskDecl(this), + m_context(context) +{ + AddStep(&TaskEncryptResource::StepEncryptResource); +} + +void TaskEncryptResource::StepEncryptResource() +{ + LogDebug("Step Encrypt resource"); + m_resEnc = new ResourceEncryptor; + m_resEnc->CreateEncryptionKey(DPL::ToUTF8String(*m_context. + widgetConfig.pkgname)); + + if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) { + tempInstalledPath = m_context.tempWidgetPath; + } else { + tempInstalledPath = m_context.tempWidgetRoot; + } + + EncryptDirectory(tempInstalledPath); +} + +void TaskEncryptResource::EncryptDirectory(std::string path) +{ + DIR* pkgDir = opendir(path.c_str()); + if (!pkgDir) { + LogDebug("Package directory doesn't exist"); + ThrowMsg(Exceptions::InternalError, "Error occurs during read \ + directory"); + } + + struct dirent* dirent; + struct stat statInfo; + do { + if ((dirent = readdir(pkgDir))) { + std::string dirName = dirent->d_name; + std::string absFileName = path + "/" + dirName; + if (stat(absFileName.c_str(), &statInfo) != 0) { + ThrowMsg(Exceptions::InternalError, "Error occurs read file"); + } + + if (S_ISDIR(statInfo.st_mode)) { + if(strcmp(dirent->d_name, ".") == 0 || strcmp(dirent->d_name, + "..") == 0) { + continue; + } + EncryptDirectory(absFileName); + } else { + if (isSupportedForEncryption(absFileName)) { + EncryptFile(absFileName); + } + } + } + } + while(dirent); + if (closedir(pkgDir)) { + LogError("Fail to close directory : " << path); + } +} + +void TaskEncryptResource::EncryptFile(const std::string &fileName) +{ + Try + { + LogDebug("Need to ecnrypt file Name " << fileName); + std::string encFile = fileName + ".enc"; + + struct stat buf; + int ret = stat(fileName.c_str(), &buf); + if(ret == 0) { + size_t fileSize = buf.st_size; + + FILE* resFp = fopen(fileName.c_str(), "r"); + if ( NULL == resFp) { + LogDebug("Couldnot open file : " << fileName); + return; + } + + int blockSize = m_resEnc->GetBlockSize(fileSize); + LogDebug("Get block size : " << blockSize); + + unsigned char readBuf[fileSize]; + unsigned char outEncBuf[blockSize]; + memset(readBuf, 0, fileSize); + memset(outEncBuf, 0, blockSize); + + fread(readBuf, sizeof(unsigned char), fileSize, resFp); + + m_resEnc->EncryptChunk(readBuf, outEncBuf, fileSize); + + FILE* encFp = fopen(encFile.c_str(), "w"); + if (NULL == encFp) { + LogError("Failed to open ecryption file"); + return; + } + fwrite(outEncBuf, sizeof(unsigned char), blockSize, encFp); + + fclose(resFp); + fclose(encFp); + + LogDebug("Success to encrypt file"); + LogDebug("Remove unecrypted file : " << fileName); + + unlink(fileName.c_str()); + if ((rename(encFile.c_str(), fileName.c_str())) != 0) { + ThrowMsg(Exceptions::ExtractFileFailed, fileName); + } + + std::string realPath = fileName; + realPath.replace(0, tempInstalledPath.length(), + m_context.installPath); + + WrtDB::EncryptedFileInfo info; + info.fileName = DPL::FromUTF8String(realPath); + info.fileSize = fileSize; + + m_context.widgetConfig.encryptedFiles.insert(info); + } + } + Catch(ResourceEncryptor::Exception::Base) + { + ReThrowMsg(Exceptions::ExtractFileFailed, fileName); + } +} +} //namespace WidgetInstall +} //namespace Jobs diff --git a/src/jobs/widget_install/task_encrypt_resource.h b/src/jobs/widget_install/task_encrypt_resource.h new file mode 100644 index 0000000..de37640 --- /dev/null +++ b/src/jobs/widget_install/task_encrypt_resource.h @@ -0,0 +1,55 @@ +/* + * 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 task_encrypt_resource.h + * @author soyoung kim (sy037.kim@samsung.com) + * @version 1.0 + */ + +#ifndef SRC_JOBS_WIDGET_INSTALL_TASK_RESOURCE_ENCRYPT_H_ +#define SRC_JOBS_WIDGET_INSTALL_TASK_RESOURCE_ENCRYPT_H_ + +#include +#include + +#include + +class InstallerContext; + +namespace Jobs { +namespace WidgetInstall { + +class TaskEncryptResource : public DPL::TaskDecl +{ +private: + // Installation context + InstallerContext &m_context; + std::string tempInstalledPath; + + void StepEncryptResource(); + + void EncryptDirectory(std::string path); + void EncryptFile(const std::string &fileName); + + WRTEncryptor::ResourceEncryptor *m_resEnc; + + public: + explicit TaskEncryptResource(InstallerContext &installerContext); +}; + +} // namespace WidgetInstall +} // namespace Jobs +#endif /* SRC_JOBS_WIDGET_INSTALL_TASK_ENCRYPT_RESOURCE_H_ */ diff --git a/src/jobs/widget_install/task_unzip.cpp b/src/jobs/widget_install/task_unzip.cpp index 65282d8..dd9bdc8 100644 --- a/src/jobs/widget_install/task_unzip.cpp +++ b/src/jobs/widget_install/task_unzip.cpp @@ -29,6 +29,7 @@ #include #include #include +#include using namespace WrtDB; @@ -60,7 +61,6 @@ PathAndFilePair SplitFileAndPath(const std::string &filePath) position), filePath.substr(position + 1)); } - } namespace Jobs { @@ -102,15 +102,23 @@ void TaskUnzip::StepCreateTempPath() { // Step succedded, save temporary widget path m_installerContext.tempWidgetPath = createTempPath(); + std::ostringstream path; if (m_installerContext.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) { std::ostringstream tempRoot; tempRoot << m_installerContext.tempWidgetPath; tempRoot << "/" << GlobalConfig::GetWidgetSrcPath(); m_installerContext.tempWidgetRoot = tempRoot.str(); + + path << GlobalConfig::GetUserInstalledWidgetPath() << "/"; + path << m_installerContext.widgetConfig.pkgname; } else { m_installerContext.tempWidgetRoot = m_installerContext.tempWidgetPath; + path << GlobalConfig::GetUserInstalledWidgetPath() << "/"; + path << m_installerContext.widgetConfig.pkgname << "/"; + path << GlobalConfig::GetWidgetSrcPath(); } + m_installerContext.installPath = path.str(); m_installerContext.job->UpdateProgress( InstallerContext::INSTALL_CREATE_TEMPDIR, diff --git a/src/jobs/widget_install/task_unzip.h b/src/jobs/widget_install/task_unzip.h index 3b0de40..9cb8339 100644 --- a/src/jobs/widget_install/task_unzip.h +++ b/src/jobs/widget_install/task_unzip.h @@ -26,6 +26,7 @@ #include #include #include +#include class InstallerContext; @@ -42,9 +43,13 @@ class TaskUnzip : DPL::ScopedPtr m_zip; DPL::ZipInput::const_iterator m_zipIterator; + WRTEncryptor::ResourceEncryptor *m_resEnc; + void ExtractFile(DPL::ZipInput::File *input, const std::string &destFileName); + void EncryptionFile(const std::string &fileName); + // Steps void StepCreateTempPath(); diff --git a/src/jobs/widget_install/widget_install_context.h b/src/jobs/widget_install/widget_install_context.h index 086735c..3716488 100755 --- a/src/jobs/widget_install/widget_install_context.h +++ b/src/jobs/widget_install/widget_install_context.h @@ -84,13 +84,6 @@ struct InstallerContext INSTALL_END } InstallStep; - /* @@ - typedef enum PackageTypeEnum - { - WGT, WITH_OSP, INVALID - } PackageType; - */ - // Installation state variables std::string widgetSource; ///< Source widget zip file/widget url std::string tempWidgetPath; ///< Unpacked widget temporary path @@ -114,10 +107,9 @@ struct InstallerContext RequestedDevCapsMap staticPermittedDevCaps; std::string installInfo; /// bool m_quiet; - //PackageType pkgType; /* whether this widget is only wgt - // @@ or with osp service */ - // + std::string tempWidgetRoot; ///< temporary widget root path + std::string installPath; ///< widget install path }; #endif // INSTALLER_CONTEXT_H diff --git a/src/jobs/widget_uninstall/task_uninstall_ospsvc.cpp b/src/jobs/widget_uninstall/task_uninstall_ospsvc.cpp index 24909a8..403bce5 100644 --- a/src/jobs/widget_uninstall/task_uninstall_ospsvc.cpp +++ b/src/jobs/widget_uninstall/task_uninstall_ospsvc.cpp @@ -53,7 +53,7 @@ void TaskUninstallOspsvc::StepUninstallOspsvc() std::ostringstream commStr; commStr << OSP_INSTALL_STR << m_context.pkgname;; - LogDebug("@@osp uninstall command : " << commStr.str()); + LogDebug("osp uninstall command : " << commStr.str()); char readBuf[MAX_BUF_SIZE]; FILE *fd;