Change encryption API.
authorSoyoung Kim <sy037.kim@samsung.com>
Wed, 6 Mar 2013 01:19:10 +0000 (10:19 +0900)
committerGerrit Code Review <gerrit2@kim11>
Thu, 7 Mar 2013 01:52:41 +0000 (10:52 +0900)
[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] encryption API changed to using trust zone.
So resource encryption task  should be changed.
[SCMRequest] this commit should be release with wrt-commons.

Change-Id: I4b547b44df70dd7af7525d1cd1c8d17c931d9629

src/jobs/widget_install/task_encrypt_resource.cpp

index ae9cebb..98faa16 100644 (file)
@@ -47,7 +47,7 @@ using namespace WrtDB;
 using namespace WRTEncryptor;
 
 namespace {
-const std::size_t ENCRYPTION_CHUNK_MAX_SIZE = 1024; // bytes
+const std::size_t ENCRYPTION_CHUNK_MAX_SIZE = 1008; // bytes
 
 std::set<std::string>& getSupportedForEncryption()
 {
@@ -173,8 +173,6 @@ void TaskEncryptResource::StepEncryptResource()
 {
     LogDebug("Step Encrypt resource");
     m_resEnc = new ResourceEncryptor;
-    m_resEnc->CreateEncryptionKey(DPL::ToUTF8String(m_context.
-                                                        widgetConfig.tzAppid));
 
     EncryptDirectory(m_context.locations->getTemporaryRootDir());
     m_context.job->UpdateProgress(
@@ -269,24 +267,16 @@ void TaskEncryptResource::EncryptFile(const std::string &fileName)
         do
         {
             bytesRead = readBytes(inChunk.get(), chunkSize, inFile.Get());
-            if (chunkSize != bytesRead)
-            {
-                curBlockSize = m_resEnc->GetBlockSize(bytesRead);
-                outChunk.reset(new unsigned char[curBlockSize]);
-            }
-            else
-            {
-                if (maxBlockSize != curBlockSize)
-                {
-                    curBlockSize = maxBlockSize;
-                    outChunk.reset(new unsigned char[curBlockSize]);
-                }
+            if (0 != bytesRead) {
+                int decBufSize = m_resEnc->EncryptChunkByTrustZone(DPL::ToUTF8String(
+                            m_context.widgetConfig.tzAppid),
+                        inChunk.get(), bytesRead);
+                outChunk.reset(new unsigned char[decBufSize]);
+                m_resEnc->getEncStringByTrustZone(outChunk.get());
+
+                writeBytes(outChunk.get(), decBufSize, outFile.Get());
             }
 
-            m_resEnc->EncryptChunk(inChunk.get(), outChunk.get(), bytesRead);
-
-            writeBytes(outChunk.get(), curBlockSize, outFile.Get());
-
         } while (0 == std::feof(inFile.Get()));
 
         LogDebug("File encrypted successfully");