// URI localization on WebProcess side
#include "bundle_uri_handling.h"
+extern "C" {
+void InitWebAppInfo(const char* appId, const char* rootPath);
+}
namespace {
const char * const uriChangedMessageName = "uri_changed_msg";
const char * const VIEWMODE_TYPE_FULLSCREEN = "fullscreen";
const char * const VIEWMODE_TYPE_MAXIMIZED = "maximized";
const std::size_t FILE_BUF_MAX_SIZE = 1024; // bytes
-const std::size_t PLAIN_CHUNK_SIZE = 1008; // bytes
+static bool m_initWebApp = false;
+
+Tizen::Base::ByteBuffer *DecryptChunkByTrustZone(
+ Tizen::Base::ByteBuffer *appInfo,
+ const unsigned char *inBuffer,
+ int inBufSize)
+{
+ using namespace Tizen::Base;
+
+ if (!m_initWebApp) {
+ char* pAppId = null;
+ pAppId = (char*)calloc(appInfo->GetRemaining()+1, 1);
+ memcpy(pAppId, appInfo->GetPointer(), appInfo->GetRemaining());
+
+ InitWebAppInfo(pAppId, "");
+ free (pAppId);
+ m_initWebApp = true;
+ }
+
+ Tizen::Security::Crypto::_TrustZoneService* pInstance;
+ pInstance = Tizen::Security::Crypto::_TrustZoneService::GetInstance();
+
+ ByteBuffer pBuf;
+ pBuf.Construct(inBufSize);
+ const byte *pByte = reinterpret_cast<const byte*>(inBuffer);
+ pBuf.SetArray(pByte, 0, inBufSize);
+ pBuf.Flip();
+
+ ByteBuffer *getBuffer = pInstance->_TrustZoneService::DecryptN(*appInfo, pBuf);
+ return getBuffer;
+}
}
Bundle::Bundle(WKBundleRef bundle) :
struct stat buf;
if (0 == stat(filePath.c_str(), &buf)) {
const std::size_t fileSize = buf.st_size;
- const std::size_t readBufSize = (fileSize > FILE_BUF_MAX_SIZE
- ? FILE_BUF_MAX_SIZE : fileSize);
-
- std::unique_ptr<unsigned char[]> inChunk(new unsigned char[readBufSize]);
+ std::unique_ptr<unsigned char[]> inChunk;
FILE* fp = fopen(filePath.c_str(), "rb");
if (NULL == fp) {
std::unique_ptr<unsigned char[]> DecryptedString(new unsigned
char[fileSize]);
- int count = 0;
+ std::string pkgid(DPL::ToUTF8String(m_widgetTizenId));
+
+ using namespace Tizen::Base;
+ 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();
+ int writeCount = 0;
do {
- size_t readSize = fread(inChunk.get(), sizeof(unsigned char),
- readBufSize, fp);
+ unsigned char getDecSize[4];
+ memset(getDecSize, 0x00, sizeof(getDecSize));
+ size_t readSize = fread(getDecSize, sizeof(unsigned char),
+ sizeof(getDecSize), fp);
if (0 != readSize) {
- LogDebug("resource is encrypted. decrypting....");
- using namespace Tizen::Base;
- ByteBuffer *getBuffer =
- reinterpret_cast<ByteBuffer*>(DecryptChunkByTrustZone(inChunk.get(),
- readSize));
- memcpy(DecryptedString.get() + (PLAIN_CHUNK_SIZE * count++),
- getBuffer->GetPointer(),
- (readSize < PLAIN_CHUNK_SIZE ? readSize : PLAIN_CHUNK_SIZE));
- getBuffer->Reset();
+ int readBufSize = 0;
+ std::istringstream(std::string((char*)getDecSize)) >> readBufSize;
+ inChunk.reset(new unsigned char[readBufSize]);
+
+ size_t decReadSize = fread(inChunk.get(), sizeof(unsigned char),
+ readBufSize, fp);
+ if (0 != decReadSize) {
+ ByteBuffer *getBuffer =
+ DecryptChunkByTrustZone(&appInfo, inChunk.get(),
+ decReadSize);
+ memcpy(DecryptedString.get() + writeCount,
+ getBuffer->GetPointer(), getBuffer->GetRemaining());
+ writeCount += getBuffer->GetRemaining();
+ getBuffer->Reset();
+ }
}
} while( 0 == std::feof(fp));
return std::string();
}
-void *Bundle::DecryptChunkByTrustZone(const unsigned char *inBuffer,
- int inBufSize)
-{
- using namespace Tizen::Base;
- std::string pkgid(DPL::ToUTF8String(m_widgetTizenId));
-
- 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();
-
- Tizen::Security::Crypto::_TrustZoneService* pInstance;
- pInstance = Tizen::Security::Crypto::_TrustZoneService::GetInstance();
-
- ByteBuffer pBuf;
- pBuf.Construct(inBufSize);
- const byte *pByte = reinterpret_cast<const byte*>(inBuffer);
- pBuf.SetArray(pByte, 0, inBufSize);
- pBuf.Flip();
-
- ByteBuffer *getBuffer = pInstance->_TrustZoneService::DecryptN(appInfo, pBuf);
- return reinterpret_cast<void*>(getBuffer);
-}
-
extern "C"
{
WK_EXPORT