From: Soyoung Kim Date: Mon, 11 Mar 2013 10:12:51 +0000 (+0900) Subject: remove encryption api dependency from wrt-commons X-Git-Tag: accepted/tizen_2.1/20130425.023916~20^2~11^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=381318ebb2d35eed651f7f3ab0a3ff5248d7a015;p=framework%2Fweb%2Fwrt-installer.git remove encryption api dependency from wrt-commons [Issue#] N/A [Problem] occur cyclic dependency [Cause] N/A [Solution] encryption api(using osp api) is called directly by installer [SCMRequest] N/A Change-Id: Ib547e5a5fd6054dbfef04c42504a53b4a74aaaae --- diff --git a/packaging/wrt-installer.spec b/packaging/wrt-installer.spec index 06f8368..09311e3 100644 --- a/packaging/wrt-installer.spec +++ b/packaging/wrt-installer.spec @@ -40,6 +40,9 @@ BuildRequires: pkgconfig(drm-service-core-intel) BuildRequires: pkgconfig(app2sd) BuildRequires: pkgconfig(web-provider-svc) BuildRequires: pkgconfig(libprivilege-control) +BuildRequires: pkgconfig(osp-appfw) +BuildRequires: osp-appfw-internal-devel +Requires: osp-appfw Requires: xmlsec1 %description diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 75cc5b2..67b1189 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -120,11 +120,11 @@ PKG_CHECK_MODULES(INSTALLER_STATIC_DEP dpl-wrt-dao-rw wrt-commons-custom-handler-dao-rw wrt-commons-security-origin-dao - dpl-encryption wrt-plugins-types pkgmgr-installer pkgmgr-parser web-provider-svc + osp-appfw REQUIRED ) @@ -156,6 +156,7 @@ INCLUDE_DIRECTORIES( ${INSTALLER_DEP_INCLUDES} ${INSTALLER_INCLUDES} ${INSTALLER_STATIC_DEP_INCLUDE_DIRS} + ${OSP_APPFW_INCLUDES} ) ADD_LIBRARY(${TARGET_INSTALLER_STATIC} STATIC @@ -172,5 +173,8 @@ TARGET_LINK_LIBRARIES(${TARGET_INSTALLER_STATIC} ${SYS_INSTALLER_STATIC_DEP_LIBRARIES} "-ldl" ) +#for encryption +TARGET_LINK_LIBRARIES(${TARGET_INSTALLER_STATIC} -L/usr/lib/osp -losp-appfw ) + ADD_SUBDIRECTORY(pkg-manager) ADD_SUBDIRECTORY(wrt-installer) diff --git a/src/jobs/widget_install/task_encrypt_resource.cpp b/src/jobs/widget_install/task_encrypt_resource.cpp index 98faa16..3de2de7 100644 --- a/src/jobs/widget_install/task_encrypt_resource.cpp +++ b/src/jobs/widget_install/task_encrypt_resource.cpp @@ -38,13 +38,14 @@ #include #include #include +#include +#include #include #include #include using namespace WrtDB; -using namespace WRTEncryptor; namespace { const std::size_t ENCRYPTION_CHUNK_MAX_SIZE = 1008; // bytes @@ -157,14 +158,36 @@ void writeBytes(unsigned char* buffer, std::size_t count, FILE* stream) } } while ((bytesWritten != bytesToWrite) && (EINTR == errno)); } + +/* + * get encrypted string from trustzone +*/ +Tizen::Base::ByteBuffer* EncryptChunkByTrustZone( + Tizen::Base::ByteBuffer* appInfo, + const unsigned char *plainBuffer, + int pBufSize) +{ + using namespace Tizen::Base; + + Tizen::Security::Crypto::_TrustZoneService* pInstance; + pInstance = Tizen::Security::Crypto::_TrustZoneService::GetInstance(); + + ByteBuffer pBuf; + pBuf.Construct(pBufSize); + const byte *pByte = reinterpret_cast(plainBuffer); + pBuf.SetArray(pByte, 0, pBufSize); + pBuf.Flip(); + + ByteBuffer* getBuffer = pInstance->_TrustZoneService::EncryptN(*appInfo, pBuf); + return getBuffer; +} } namespace Jobs { namespace WidgetInstall { TaskEncryptResource::TaskEncryptResource(InstallerContext& context) : DPL::TaskDecl(this), - m_context(context), - m_resEnc(NULL) + m_context(context) { AddStep(&TaskEncryptResource::StepEncryptResource); } @@ -172,7 +195,6 @@ TaskEncryptResource::TaskEncryptResource(InstallerContext& context) : void TaskEncryptResource::StepEncryptResource() { LogDebug("Step Encrypt resource"); - m_resEnc = new ResourceEncryptor; EncryptDirectory(m_context.locations->getTemporaryRootDir()); m_context.job->UpdateProgress( @@ -257,22 +279,35 @@ void TaskEncryptResource::EncryptFile(const std::string &fileName) const std::size_t chunkSize = (fileSize > ENCRYPTION_CHUNK_MAX_SIZE ? ENCRYPTION_CHUNK_MAX_SIZE : fileSize); - const int maxBlockSize = m_resEnc->GetBlockSize(chunkSize); std::unique_ptr inChunk(new unsigned char[chunkSize]); std::unique_ptr outChunk; std::size_t bytesRead = 0; - int curBlockSize = 0; + using namespace Tizen::Base; + + std::string pkgid = + DPL::ToUTF8String(m_context.widgetConfig.tzAppid).c_str(); + const byte *b_pkgid = reinterpret_cast( + pkgid.c_str()); + ByteBuffer appInfo; + appInfo.Construct(pkgid.length()); + appInfo.SetArray(b_pkgid, 0, pkgid.length()); + appInfo.Flip(); + do { bytesRead = readBytes(inChunk.get(), chunkSize, inFile.Get()); if (0 != bytesRead) { - int decBufSize = m_resEnc->EncryptChunkByTrustZone(DPL::ToUTF8String( - m_context.widgetConfig.tzAppid), + + ByteBuffer *getBuffer = EncryptChunkByTrustZone( + &appInfo, inChunk.get(), bytesRead); + int decBufSize = getBuffer->GetRemaining(); + outChunk.reset(new unsigned char[decBufSize]); - m_resEnc->getEncStringByTrustZone(outChunk.get()); + memcpy(outChunk.get(), getBuffer->GetPointer(), getBuffer->GetRemaining()); + getBuffer->Reset(); writeBytes(outChunk.get(), decBufSize, outFile.Get()); } @@ -311,10 +346,6 @@ void TaskEncryptResource::EncryptFile(const std::string &fileName) { ReThrowMsg(Exceptions::ExtractFileFailed, fileName); } - Catch (ResourceEncryptor::Exception::Base) - { - ReThrowMsg(Exceptions::ExtractFileFailed, fileName); - } } } //namespace WidgetInstall diff --git a/src/jobs/widget_install/task_encrypt_resource.h b/src/jobs/widget_install/task_encrypt_resource.h index 72dac56..9c95696 100644 --- a/src/jobs/widget_install/task_encrypt_resource.h +++ b/src/jobs/widget_install/task_encrypt_resource.h @@ -25,8 +25,6 @@ #include #include -#include - class InstallerContext; namespace Jobs { @@ -43,8 +41,6 @@ class TaskEncryptResource : public DPL::TaskDecl void EncryptDirectory(std::string path); void EncryptFile(const std::string &fileName); - WRTEncryptor::ResourceEncryptor *m_resEnc; - public: explicit TaskEncryptResource(InstallerContext &installerContext); };