#include <dpl/scoped_fclose.h>
#include <dpl/wrt-dao-ro/global_config.h>
#include <dpl/string.h>
-#include <FBaseByteBuffer.h>
-#include <security/FSecCrypto_TrustZoneService.h>
+#include <ss_manager.h>
#include <widget_install/job_widget_install.h>
#include <widget_install/widget_install_context.h>
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;
} 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<const byte*>(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<const byte*>(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 {
? ENCRYPTION_CHUNK_MAX_SIZE : fileSize);
std::unique_ptr<unsigned char[]> inChunk(new unsigned char[chunkSize]);
- std::unique_ptr<unsigned char[]> 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<const byte*>(
- 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()));