update encryption logic to capi.
authorSoyoung Kim <sy037.kim@samsung.com>
Thu, 9 May 2013 12:38:50 +0000 (21:38 +0900)
committerGerrit Code Review <gerrit2@kim11>
Wed, 22 May 2013 02:40:13 +0000 (11:40 +0900)
[Issue#] N/A
[Problem] N/A
[Cause] N/A
[Solution] update encryption logic to capi.
[SCMRequest] this commit have to release with wrt.

Change-Id: I5cf257135a8857647a4d77a7d031306df254b8b9

packaging/wrt-installer.spec
src/CMakeLists.txt
src/jobs/widget_install/task_encrypt_resource.cpp

index ed1c557..17f04cd 100644 (file)
@@ -41,10 +41,9 @@ BuildRequires:  pkgconfig(capi-appfw-app-manager)
 BuildRequires:  pkgconfig(app2sd)
 BuildRequires:  pkgconfig(web-provider)
 BuildRequires:  pkgconfig(libprivilege-control)
-BuildRequires:  pkgconfig(osp-appfw)
-BuildRequires:  osp-appfw-internal-devel
 BuildRequires:  pkgconfig(libsmack)
-Requires: osp-appfw
+BuildRequires:  libss-client-devel
+Requires: libss-client
 Requires: osp-installer
 Requires: xmlsec1
 
index 8832baf..584eda1 100644 (file)
@@ -125,7 +125,6 @@ PKG_CHECK_MODULES(INSTALLER_STATIC_DEP
     pkgmgr-parser
     pkgmgr-info
     web-provider
-    osp-appfw
     libsmack
     REQUIRED
 )
@@ -176,7 +175,7 @@ TARGET_LINK_LIBRARIES(${TARGET_INSTALLER_STATIC}
     )
 
 #for encryption
-TARGET_LINK_LIBRARIES(${TARGET_INSTALLER_STATIC} -L/usr/lib/osp -losp-appfw )
+TARGET_LINK_LIBRARIES(${TARGET_INSTALLER_STATIC} "-lss-client" )
 
 ADD_SUBDIRECTORY(pkg-manager)
 ADD_SUBDIRECTORY(wrt-installer)
index 0b47580..c96d1a2 100644 (file)
@@ -40,8 +40,7 @@
 #include <dpl/scoped_fclose.h>
 #include <dpl/wrt-dao-ro/global_config.h>
 #include <dpl/string.h>
-#include <FBaseByteBuffer.h>
-#include <security/FSecCrypto_TrustZoneService.h>
+#include <ss_manager.h>
 
 #include <widget_install/job_widget_install.h>
 #include <widget_install/widget_install_context.h>
 
 using namespace WrtDB;
 
-extern "C"
-{
-    void InitWebAppInfo(const char* appId, const char* rootPath);
-}
-
 namespace {
-const std::size_t ENCRYPTION_CHUNK_MAX_SIZE = 4096; // bytes
+const std::size_t ENCRYPTION_CHUNK_MAX_SIZE = 8192; // bytes
 const std::size_t ENCRYPTION_DEC_CHUNK_SIZE = 4; // bytes
 static bool initWebApp = false;
 
@@ -168,61 +162,6 @@ void writeBytes(unsigned char* buffer, std::size_t count, FILE* stream)
     } while ((bytesWritten != bytesToWrite) && (EINTR == errno));
 }
 
-/*
- * get encrypted string from trustzone
-*/
-Tizen::Base::ByteBuffer* EncryptChunkByTrustZone(
-        Tizen::Base::ByteBuffer* appInfo,
-        const unsigned char *plainBuffer,
-        int pBufSize)
-{
-    using namespace Tizen::Base;
-    if(!initWebApp)
-    {
-        char* pAppId = null;
-        pAppId = (char*)calloc(appInfo->GetRemaining()+1, 1);
-        memcpy(pAppId, appInfo->GetPointer(), appInfo->GetRemaining());
-        InitWebAppInfo(pAppId, "");
-        free (pAppId);
-        initWebApp = true;
-    }
-
-    Tizen::Security::Crypto::_TrustZoneService* pInstance;
-    pInstance = Tizen::Security::Crypto::_TrustZoneService::GetInstance();
-
-    ByteBuffer pBuf;
-    pBuf.Construct(pBufSize);
-    const byte *pByte = reinterpret_cast<const byte*>(plainBuffer);
-    if (pBuf.SetArray(pByte, 0, pBufSize) != E_SUCCESS) {
-        LogDebug("Couldnot set pBuf");
-        return NULL;
-    }
-    pBuf.Flip();
-
-    return pInstance->_TrustZoneService::EncryptN(*appInfo, pBuf);
-}
-
-Tizen::Base::ByteBuffer* TEST_dec(
-        Tizen::Base::ByteBuffer* appInfo,
-        const unsigned char *plainBuffer,
-        int pBufSize)
-{
-    using namespace Tizen::Base;
-
-    Tizen::Security::Crypto::_TrustZoneService* pInstance;
-    pInstance = Tizen::Security::Crypto::_TrustZoneService::GetInstance();
-
-    ByteBuffer pBuf;
-    pBuf.Construct(pBufSize);
-    const byte *pByte = reinterpret_cast<const byte*>(plainBuffer);
-    if (pBuf.SetArray(pByte, 0, pBufSize) != E_SUCCESS) {
-        LogDebug("Couldnot set pBuf");
-        return NULL;
-    }
-    pBuf.Flip();
-
-    return pInstance->_TrustZoneService::DecryptN(*appInfo, pBuf);
-}
 }
 
 namespace Jobs {
@@ -325,52 +264,31 @@ void TaskEncryptResource::EncryptFile(const std::string &fileName)
             ? ENCRYPTION_CHUNK_MAX_SIZE : fileSize);
 
     std::unique_ptr<unsigned char[]> inChunk(new unsigned char[chunkSize]);
-    std::unique_ptr<unsigned char[]> outChunk;
-
     std::size_t bytesRead = 0;
-    using namespace Tizen::Base;
-
-    std::string pkgid =
-        DPL::ToUTF8String(m_context.widgetConfig.tzAppid).c_str();
-    const byte *b_pkgid = reinterpret_cast<const byte*>(
-            pkgid.c_str());
-    ByteBuffer appInfo;
-    appInfo.Construct(pkgid.length());
-
-    if (appInfo.SetArray(b_pkgid, 0, pkgid.length()) != E_SUCCESS) {
-        LogDebug("Couldnot set appInfo");
-        return;
-    }
-
-    appInfo.Flip();
+    std::string appid = DPL::ToUTF8String(m_context.widgetConfig.tzAppid);
 
     do
     {
         bytesRead = readBytes(inChunk.get(), chunkSize, inFile.Get());
         if (0 != bytesRead) {
-            ByteBuffer *getBuffer = EncryptChunkByTrustZone(
-                    &appInfo,
-                    inChunk.get(), bytesRead);
-            if (getBuffer == NULL) {
+            int outDecSize = 0;
+            char *outChunk = NULL;
+            if (0 != ssm_encrypt(appid.c_str(), appid.length(),
+                        (char*)inChunk.get(), (int)bytesRead,
+                        &outChunk, &outDecSize)) {
                 ThrowMsg(Exceptions::EncryptionFailed,
                         "Encryption Failed using TrustZone");
             }
-            int decBufSize = getBuffer->GetRemaining();
-
-            outChunk.reset(new unsigned char[decBufSize]);
-            memcpy(outChunk.get(), getBuffer->GetPointer(), getBuffer->GetRemaining());
-            getBuffer->Reset();
 
-            char writeSize[ENCRYPTION_DEC_CHUNK_SIZE];
-            memset(writeSize, 0x00, ENCRYPTION_DEC_CHUNK_SIZE);
             std::stringstream toString;
-            toString << decBufSize;
-            strncpy(writeSize, toString.str().c_str(), toString.str().length());
+            toString << outDecSize;
 
-            writeBytes((unsigned char*)writeSize,
-                    ENCRYPTION_DEC_CHUNK_SIZE, outFile.Get());
-            writeBytes(outChunk.get(), decBufSize, outFile.Get());
+            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()));