const char * const PHP_MIME = "application/x-php";
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
}
Bundle::Bundle(WKBundleRef bundle) :
WrtDB::WidgetDAOReadOnly(m_widgetTizenId).
getEncryptedFileList(m_encryptedFiles);
}
- size_t bufSize = buf.st_size;
- unsigned char contents[bufSize];
- memset(contents, 0, bufSize);
+
+ 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[]> outChunk;
FILE* fp = fopen(filePath.c_str(), "rb");
if (NULL == fp) {
return std::string();
}
- size_t ret = fread(contents, sizeof(unsigned char), buf.st_size, fp);
- if (ret < static_cast<size_t>(buf.st_size) ) {
- LogDebug("Couldnot read file : " << filePath);
- fclose(fp);
- return std::string();
- }
+ std::unique_ptr<unsigned char[]> DecryptedString(new unsigned
+ char[fileSize]);
+ int count = 0;
+
+ do {
+ size_t readSize = fread(inChunk.get(), sizeof(unsigned char),
+ readBufSize, fp);
+
+ if (0 != readSize) {
+ LogDebug("resource is encrypted. decrypting....");
+ int decSize = m_resDec->DecryptChunkByTrustZone(
+ DPL::ToUTF8String(m_widgetTizenId), inChunk.get(),
+ readSize);
+ outChunk.reset(new unsigned char[decSize]);
+ m_resDec->getDecryptStringByTrustZone(outChunk.get());
+ memcpy(DecryptedString.get() + (PLAIN_CHUNK_SIZE * count++),
+ outChunk.get(),
+ (readSize < PLAIN_CHUNK_SIZE ? readSize : PLAIN_CHUNK_SIZE));
+ }
+ } while( 0 == std::feof(fp));
fclose(fp);
- LogDebug("resource is encrypted. decrypting....");
- unsigned char outDecBuf[bufSize];
- memset(outDecBuf, 0, bufSize);
- m_resDec->GetDecryptedChunk(contents, outDecBuf, bufSize);
- memset(outDecBuf + size, '\n', bufSize - size);
-
+ memset(DecryptedString.get() + size, '\n', fileSize - size);
LogDebug("resource need to encoding base64");
BIO *bmem, *b64;
BUF_MEM *bptr;
b64 = BIO_new(BIO_f_base64());
bmem = BIO_new(BIO_s_mem());
b64 = BIO_push(b64, bmem);
- BIO_write(b64, outDecBuf, bufSize);
+ BIO_write(b64, DecryptedString.get(), fileSize);
BIO_flush(b64);
BIO_get_mem_ptr(b64, &bptr);