From: Soyoung Kim Date: Thu, 9 May 2013 12:38:50 +0000 (+0900) Subject: update encryption logic to capi. X-Git-Tag: submit/tizen_2.2/20130713.111652^2~123 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e22701ca3233da6f08910f4458f74f56e4095a4e;p=platform%2Fframework%2Fweb%2Fwrt-installer.git update encryption logic to capi. [Issue#] N/A [Problem] N/A [Cause] N/A [Solution] update encryption logic to capi. [SCMRequest] this commit have to release with wrt. Change-Id: I5cf257135a8857647a4d77a7d031306df254b8b9 --- diff --git a/packaging/wrt-installer.spec b/packaging/wrt-installer.spec index ed1c557..17f04cd 100644 --- a/packaging/wrt-installer.spec +++ b/packaging/wrt-installer.spec @@ -41,10 +41,9 @@ BuildRequires: pkgconfig(capi-appfw-app-manager) BuildRequires: pkgconfig(app2sd) BuildRequires: pkgconfig(web-provider) BuildRequires: pkgconfig(libprivilege-control) -BuildRequires: pkgconfig(osp-appfw) -BuildRequires: osp-appfw-internal-devel BuildRequires: pkgconfig(libsmack) -Requires: osp-appfw +BuildRequires: libss-client-devel +Requires: libss-client Requires: osp-installer Requires: xmlsec1 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8832baf..584eda1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -125,7 +125,6 @@ PKG_CHECK_MODULES(INSTALLER_STATIC_DEP pkgmgr-parser pkgmgr-info web-provider - osp-appfw libsmack REQUIRED ) @@ -176,7 +175,7 @@ TARGET_LINK_LIBRARIES(${TARGET_INSTALLER_STATIC} ) #for encryption -TARGET_LINK_LIBRARIES(${TARGET_INSTALLER_STATIC} -L/usr/lib/osp -losp-appfw ) +TARGET_LINK_LIBRARIES(${TARGET_INSTALLER_STATIC} "-lss-client" ) 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 0b47580..c96d1a2 100644 --- a/src/jobs/widget_install/task_encrypt_resource.cpp +++ b/src/jobs/widget_install/task_encrypt_resource.cpp @@ -40,8 +40,7 @@ #include #include #include -#include -#include +#include #include #include @@ -49,13 +48,8 @@ using namespace WrtDB; -extern "C" -{ - void InitWebAppInfo(const char* appId, const char* rootPath); -} - namespace { -const std::size_t ENCRYPTION_CHUNK_MAX_SIZE = 4096; // bytes +const std::size_t ENCRYPTION_CHUNK_MAX_SIZE = 8192; // bytes const std::size_t ENCRYPTION_DEC_CHUNK_SIZE = 4; // bytes static bool initWebApp = false; @@ -168,61 +162,6 @@ 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; - if(!initWebApp) - { - char* pAppId = null; - pAppId = (char*)calloc(appInfo->GetRemaining()+1, 1); - memcpy(pAppId, appInfo->GetPointer(), appInfo->GetRemaining()); - InitWebAppInfo(pAppId, ""); - free (pAppId); - initWebApp = true; - } - - Tizen::Security::Crypto::_TrustZoneService* pInstance; - pInstance = Tizen::Security::Crypto::_TrustZoneService::GetInstance(); - - ByteBuffer pBuf; - pBuf.Construct(pBufSize); - const byte *pByte = reinterpret_cast(plainBuffer); - if (pBuf.SetArray(pByte, 0, pBufSize) != E_SUCCESS) { - LogDebug("Couldnot set pBuf"); - return NULL; - } - pBuf.Flip(); - - return pInstance->_TrustZoneService::EncryptN(*appInfo, pBuf); -} - -Tizen::Base::ByteBuffer* TEST_dec( - 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); - if (pBuf.SetArray(pByte, 0, pBufSize) != E_SUCCESS) { - LogDebug("Couldnot set pBuf"); - return NULL; - } - pBuf.Flip(); - - return pInstance->_TrustZoneService::DecryptN(*appInfo, pBuf); -} } namespace Jobs { @@ -325,52 +264,31 @@ void TaskEncryptResource::EncryptFile(const std::string &fileName) ? ENCRYPTION_CHUNK_MAX_SIZE : fileSize); std::unique_ptr inChunk(new unsigned char[chunkSize]); - std::unique_ptr outChunk; - std::size_t bytesRead = 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()); - - if (appInfo.SetArray(b_pkgid, 0, pkgid.length()) != E_SUCCESS) { - LogDebug("Couldnot set appInfo"); - return; - } - - appInfo.Flip(); + std::string appid = DPL::ToUTF8String(m_context.widgetConfig.tzAppid); do { bytesRead = readBytes(inChunk.get(), chunkSize, inFile.Get()); if (0 != bytesRead) { - ByteBuffer *getBuffer = EncryptChunkByTrustZone( - &appInfo, - inChunk.get(), bytesRead); - if (getBuffer == NULL) { + int outDecSize = 0; + char *outChunk = NULL; + if (0 != ssm_encrypt(appid.c_str(), appid.length(), + (char*)inChunk.get(), (int)bytesRead, + &outChunk, &outDecSize)) { ThrowMsg(Exceptions::EncryptionFailed, "Encryption Failed using TrustZone"); } - int decBufSize = getBuffer->GetRemaining(); - - outChunk.reset(new unsigned char[decBufSize]); - memcpy(outChunk.get(), getBuffer->GetPointer(), getBuffer->GetRemaining()); - getBuffer->Reset(); - char writeSize[ENCRYPTION_DEC_CHUNK_SIZE]; - memset(writeSize, 0x00, ENCRYPTION_DEC_CHUNK_SIZE); std::stringstream toString; - toString << decBufSize; - strncpy(writeSize, toString.str().c_str(), toString.str().length()); + toString << outDecSize; - writeBytes((unsigned char*)writeSize, - ENCRYPTION_DEC_CHUNK_SIZE, outFile.Get()); - writeBytes(outChunk.get(), decBufSize, outFile.Get()); + writeBytes((unsigned char*)toString.str().c_str(), + sizeof(int), outFile.Get()); + writeBytes((unsigned char*)outChunk, outDecSize, outFile.Get()); + delete outChunk; } + inChunk.reset(new unsigned char[chunkSize]); } while (0 == std::feof(inFile.Get()));