From 76197f5e019f735536f1e3013f800287cedccf8e Mon Sep 17 00:00:00 2001 From: Soyoung Kim Date: Fri, 15 Mar 2013 17:24:38 +0900 Subject: [PATCH] Fixed encryption logic [Issue#] N/A [Problem] occur crash during ecryption. [Cause] should initialize osp app framework for trustzone api. [Solution] call InitWebAppInfo() before using encryption. [SCMRequest] N/A --- src/jobs/widget_install/task_certify.cpp | 7 --- src/jobs/widget_install/task_encrypt_resource.cpp | 53 +++++++++++++++++++++-- 2 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/jobs/widget_install/task_certify.cpp b/src/jobs/widget_install/task_certify.cpp index cd38d74..c806945 100644 --- a/src/jobs/widget_install/task_certify.cpp +++ b/src/jobs/widget_install/task_certify.cpp @@ -522,14 +522,7 @@ void TaskCertify::stepVerifyUpdate() between old widget and installing widget"); } } else { - if (NULL == newCertificate.Get() ) - LogDebug("@@@@ new certificate nul"); - - if (NULL == oldCertificate.Get() ) - LogDebug("@@@@ old certificate nul"); - if (!(NULL == newCertificate.Get() && NULL == oldCertificate.Get())) { - LogDebug("@@@@"); ThrowMsg(Exceptions::InvalidPackage, "Author signer certificates doesn't match \ between old widget and installing widget"); diff --git a/src/jobs/widget_install/task_encrypt_resource.cpp b/src/jobs/widget_install/task_encrypt_resource.cpp index 3de2de7..b88c27f 100644 --- a/src/jobs/widget_install/task_encrypt_resource.cpp +++ b/src/jobs/widget_install/task_encrypt_resource.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include @@ -47,8 +49,15 @@ using namespace WrtDB; +extern "C" +{ + void InitWebAppInfo(const char* appId, const char* rootPath); +} + namespace { -const std::size_t ENCRYPTION_CHUNK_MAX_SIZE = 1008; // bytes +const std::size_t ENCRYPTION_CHUNK_MAX_SIZE = 4096; // bytes +const std::size_t ENCRYPTION_DEC_CHUNK_SIZE = 4; // bytes +static bool initWebApp = false; std::set& getSupportedForEncryption() { @@ -168,6 +177,15 @@ Tizen::Base::ByteBuffer* EncryptChunkByTrustZone( 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(); @@ -181,6 +199,27 @@ Tizen::Base::ByteBuffer* EncryptChunkByTrustZone( ByteBuffer* getBuffer = pInstance->_TrustZoneService::EncryptN(*appInfo, pBuf); return getBuffer; } + +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); + pBuf.SetArray(pByte, 0, pBufSize); + pBuf.Flip(); + + ByteBuffer* getBufferTEST = + pInstance->_TrustZoneService::DecryptN(*appInfo, pBuf); + return getBufferTEST; +} } namespace Jobs { @@ -299,7 +338,6 @@ void TaskEncryptResource::EncryptFile(const std::string &fileName) { bytesRead = readBytes(inChunk.get(), chunkSize, inFile.Get()); if (0 != bytesRead) { - ByteBuffer *getBuffer = EncryptChunkByTrustZone( &appInfo, inChunk.get(), bytesRead); @@ -309,16 +347,23 @@ void TaskEncryptResource::EncryptFile(const std::string &fileName) 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()); + + writeBytes((unsigned char*)writeSize, + ENCRYPTION_DEC_CHUNK_SIZE, outFile.Get()); writeBytes(outChunk.get(), decBufSize, outFile.Get()); } } while (0 == std::feof(inFile.Get())); - LogDebug("File encrypted successfully"); - outFile.Reset(); inFile.Reset(); + LogDebug("File encrypted successfully"); LogDebug("Remove plain-text file: " << fileName); if (0 != unlink(fileName.c_str())) { -- 2.7.4