Add encryption for preload web app
authorSoyoung Kim <sy037.kim@samsung.com>
Tue, 21 May 2013 12:30:54 +0000 (21:30 +0900)
committerSoyoung Kim <sy037.kim@samsung.com>
Thu, 23 May 2013 07:36:58 +0000 (16:36 +0900)
[Issue#] N/A
[Problem] Can't install web app is required encryption during preload.
[Cause] there is no encryption api for preload web app.
[Solution] Add encryption api using master key.
[SCMRequest] this package have to release with ss-client and ss-server.

Change-Id: Id05cd77cf3657526ee0f13286ef6bc179b2f6840

src/jobs/widget_install/task_encrypt_resource.cpp

index c96d1a2..4e8a49b 100644 (file)
@@ -51,7 +51,6 @@ using namespace WrtDB;
 namespace {
 const std::size_t ENCRYPTION_CHUNK_MAX_SIZE = 8192; // bytes
 const std::size_t ENCRYPTION_DEC_CHUNK_SIZE = 4; // bytes
-static bool initWebApp = false;
 
 std::set<std::string>& getSupportedForEncryption()
 {
@@ -162,6 +161,18 @@ void writeBytes(unsigned char* buffer, std::size_t count, FILE* stream)
     } while ((bytesWritten != bytesToWrite) && (EINTR == errno));
 }
 
+int ssmEncrypt(InstallMode::RootPath rootPath, std::string pkgId, const char*
+        inChunk, int inBytes, char** outChunk, int *outBytes)
+{
+    if (rootPath == InstallMode::RootPath::RO) {
+        return ssm_encrypt_preloaded_application(inChunk, inBytes,
+                outChunk, outBytes);
+    } else {
+        return ssm_encrypt(pkgId.c_str(), pkgId.length(),
+                inChunk, inBytes,
+                outChunk, outBytes);
+    }
+}
 }
 
 namespace Jobs {
@@ -265,7 +276,8 @@ void TaskEncryptResource::EncryptFile(const std::string &fileName)
 
     std::unique_ptr<unsigned char[]> inChunk(new unsigned char[chunkSize]);
     std::size_t bytesRead = 0;
-    std::string appid = DPL::ToUTF8String(m_context.widgetConfig.tzAppid);
+    /* TODO : pkgId should change to appId after wrt-client label changed. */
+    std::string pkgId = DPL::ToUTF8String(m_context.widgetConfig.tzPkgid);
 
     do
     {
@@ -273,7 +285,7 @@ void TaskEncryptResource::EncryptFile(const std::string &fileName)
         if (0 != bytesRead) {
             int outDecSize = 0;
             char *outChunk = NULL;
-            if (0 != ssm_encrypt(appid.c_str(), appid.length(),
+            if (0 != ssmEncrypt(m_context.mode.rootPath, pkgId,
                         (char*)inChunk.get(), (int)bytesRead,
                         &outChunk, &outDecSize)) {
                 ThrowMsg(Exceptions::EncryptionFailed,