#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 <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 {
const std::size_t ENCRYPTION_CHUNK_MAX_SIZE = 1008; // bytes
}
} 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<const byte*>(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<TaskEncryptResource>(this),
- m_context(context),
- m_resEnc(NULL)
+ m_context(context)
{
AddStep(&TaskEncryptResource::StepEncryptResource);
}
void TaskEncryptResource::StepEncryptResource()
{
LogDebug("Step Encrypt resource");
- m_resEnc = new ResourceEncryptor;
EncryptDirectory(m_context.locations->getTemporaryRootDir());
m_context.job->UpdateProgress(
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<unsigned char[]> inChunk(new unsigned char[chunkSize]);
std::unique_ptr<unsigned char[]> 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<const byte*>(
+ 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());
}
{
ReThrowMsg(Exceptions::ExtractFileFailed, fileName);
}
- Catch (ResourceEncryptor::Exception::Base)
- {
- ReThrowMsg(Exceptions::ExtractFileFailed, fileName);
- }
}
} //namespace WidgetInstall