Fixed skip encryption when downgrade preload webapp
authorSoyoung Kim <sy037.kim@samsung.com>
Mon, 27 May 2013 11:25:38 +0000 (20:25 +0900)
committerSoyoung Kim <sy037.kim@samsung.com>
Mon, 27 May 2013 11:37:03 +0000 (20:37 +0900)
[Issue#] N/A
[Problem] twice encrypt during downgrade to preload webapp.
[Cause] preload webapp is already encrypted.
[Solution] if downgrade to preload webapp, skip encryption.
[SCMRequest] N/A

Change-Id: Idcfe249b59e0429b9759ccc059e3ccece7968bd9

src/jobs/widget_install/task_encrypt_resource.cpp

index 4e8a49b..e6838e5 100644 (file)
@@ -268,56 +268,62 @@ void TaskEncryptResource::EncryptFile(const std::string &fileName)
         return;
     }
 
-    DPL::ScopedFClose inFile(openFile(fileName, "r"));
-    DPL::ScopedFClose outFile(openFile(encFile, "w"));
+    // If update installed preload web, should skip encryption.
+    if (!(m_context.mode.rootPath == InstallMode::RootPath::RO &&
+                m_context.mode.installTime == InstallMode::InstallTime::PRELOAD
+                && m_context.mode.extension == InstallMode::ExtensionType::DIR)) {
 
-    const std::size_t chunkSize = (fileSize > ENCRYPTION_CHUNK_MAX_SIZE
-            ? ENCRYPTION_CHUNK_MAX_SIZE : fileSize);
+        DPL::ScopedFClose inFile(openFile(fileName, "r"));
+        DPL::ScopedFClose outFile(openFile(encFile, "w"));
 
-    std::unique_ptr<unsigned char[]> inChunk(new unsigned char[chunkSize]);
-    std::size_t bytesRead = 0;
-    /* TODO : pkgId should change to appId after wrt-client label changed. */
-    std::string pkgId = DPL::ToUTF8String(m_context.widgetConfig.tzPkgid);
+        const std::size_t chunkSize = (fileSize > ENCRYPTION_CHUNK_MAX_SIZE
+                ? ENCRYPTION_CHUNK_MAX_SIZE : fileSize);
 
-    do
-    {
-        bytesRead = readBytes(inChunk.get(), chunkSize, inFile.Get());
-        if (0 != bytesRead) {
-            int outDecSize = 0;
-            char *outChunk = NULL;
-            if (0 != ssmEncrypt(m_context.mode.rootPath, pkgId,
-                        (char*)inChunk.get(), (int)bytesRead,
-                        &outChunk, &outDecSize)) {
-                ThrowMsg(Exceptions::EncryptionFailed,
-                        "Encryption Failed using TrustZone");
-            }
-
-            std::stringstream toString;
-            toString << outDecSize;
+        std::unique_ptr<unsigned char[]> inChunk(new unsigned char[chunkSize]);
+        std::size_t bytesRead = 0;
+        /* TODO : pkgId should change to appId after wrt-client label changed. */
+        std::string pkgId = DPL::ToUTF8String(m_context.widgetConfig.tzPkgid);
 
-            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]);
+        do
+        {
+            bytesRead = readBytes(inChunk.get(), chunkSize, inFile.Get());
+            if (0 != bytesRead) {
+                int outDecSize = 0;
+                char *outChunk = NULL;
+                if (0 != ssmEncrypt(m_context.mode.rootPath, pkgId,
+                            (char*)inChunk.get(), (int)bytesRead,
+                            &outChunk, &outDecSize)) {
+                    ThrowMsg(Exceptions::EncryptionFailed,
+                            "Encryption Failed using TrustZone");
+                }
+
+                std::stringstream toString;
+                toString << outDecSize;
+
+                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()));
+        } while (0 == std::feof(inFile.Get()));
 
-    outFile.Reset();
-    inFile.Reset();
+        outFile.Reset();
+        inFile.Reset();
 
-    LogDebug("File encrypted successfully");
-    LogDebug("Remove plain-text file: " << fileName);
-    if (0 != unlink(fileName.c_str()))
-    {
-        Throw(Exceptions::EncryptionFailed);
-    }
+        LogDebug("File encrypted successfully");
+        LogDebug("Remove plain-text file: " << fileName);
+        if (0 != unlink(fileName.c_str()))
+        {
+            Throw(Exceptions::EncryptionFailed);
+        }
 
-    LogDebug("Rename encrypted file");
-    if (0 != std::rename(encFile.c_str(), fileName.c_str()))
-    {
-        Throw(Exceptions::EncryptionFailed);
+        LogDebug("Rename encrypted file");
+        if (0 != std::rename(encFile.c_str(), fileName.c_str()))
+        {
+            Throw(Exceptions::EncryptionFailed);
+        }
     }
 
     std::string realPath = fileName;