+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 <jihoon.chung@samsung.com> 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
-#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
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
${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
dpl-utils-efl
dpl-wrt-dao-ro
dpl-wrt-dao-rw
+ dpl-encryption
ace-install
ecore-x
xmlsec1
#include <widget_install/task_update_files.h>
#include <widget_install/task_new_db_insert.h>
#include <widget_install/task_remove_backup.h>
+#include <widget_install/task_encrypt_resource.h>
#include <widget_install/widget_install_errors.h>
#include <widget_install/widget_install_context.h>
#include <string>
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<InstallerTaskFail>
{
m_installerContext.browserRequest,
m_installerContext.widgetConfig.pType);
WidgetUpdateInfo update = detectWidgetUpdate(configData);
-
+ bool needEncryption = detectResourceEncryption(configData);
// Configure installation
ConfigureResult result = ConfigureInstallation(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
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
WrtDB::PackagingType checkPackageType(
const std::string &widgetSorce);
+ bool detectResourceEncryption(const WrtDB::ConfigParserData &configData);
public:
/**
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");
}
--- /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 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 <unistd.h>
+#include <string>
+#include <sys/stat.h>
+#include <dirent.h>
+
+#include <dpl/log/log.h>
+#include <dpl/errno_string.h>
+#include <dpl/foreach.h>
+#include <dpl/wrt-dao-ro/global_config.h>
+
+#include <widget_install/job_widget_install.h>
+#include <widget_install/widget_install_context.h>
+#include <widget_install/widget_install_errors.h>
+
+using namespace WrtDB;
+using namespace WRTEncryptor;
+
+namespace {
+std::set<std::string>& getSupportedForEncryption()
+{
+ static std::set<std::string> 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<TaskEncryptResource>(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
--- /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 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 <dpl/task.h>
+#include <string>
+
+#include <dpl/encryption/resource_encryption.h>
+
+class InstallerContext;
+
+namespace Jobs {
+namespace WidgetInstall {
+
+class TaskEncryptResource : public DPL::TaskDecl<TaskEncryptResource>
+{
+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_ */
#include <dpl/abstract_waitable_input_adapter.h>
#include <dpl/wrt-dao-ro/global_config.h>
#include <task_commons.h>
+#include <sys/stat.h>
using namespace WrtDB;
position),
filePath.substr(position + 1));
}
-
}
namespace Jobs {
{
// 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,
#include <dpl/scoped_ptr.h>
#include <dpl/task.h>
#include <string>
+#include <dpl/encryption/resource_encryption.h>
class InstallerContext;
DPL::ScopedPtr<DPL::ZipInput> 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();
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
RequestedDevCapsMap staticPermittedDevCaps;
std::string installInfo; ///<For recovery>
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
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;