remove encryption api dependency from wrt-commons
authorSoyoung Kim <sy037.kim@samsung.com>
Mon, 11 Mar 2013 10:12:51 +0000 (19:12 +0900)
committerSoyoung Kim <sy037.kim@samsung.com>
Mon, 11 Mar 2013 10:34:12 +0000 (19:34 +0900)
[Issue#] N/A
[Problem] occur cyclic dependency
[Cause] N/A
[Solution] encryption api(using osp api) is called directly by installer
[SCMRequest] N/A

Change-Id: Ib547e5a5fd6054dbfef04c42504a53b4a74aaaae

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

index 06f8368..09311e3 100644 (file)
@@ -40,6 +40,9 @@ BuildRequires:  pkgconfig(drm-service-core-intel)
 BuildRequires:  pkgconfig(app2sd)
 BuildRequires:  pkgconfig(web-provider-svc)
 BuildRequires:  pkgconfig(libprivilege-control)
+BuildRequires:  pkgconfig(osp-appfw)
+BuildRequires:  osp-appfw-internal-devel
+Requires: osp-appfw
 Requires: xmlsec1
 
 %description
index 75cc5b2..67b1189 100644 (file)
@@ -120,11 +120,11 @@ PKG_CHECK_MODULES(INSTALLER_STATIC_DEP
     dpl-wrt-dao-rw
     wrt-commons-custom-handler-dao-rw
     wrt-commons-security-origin-dao
-    dpl-encryption
     wrt-plugins-types
     pkgmgr-installer
     pkgmgr-parser
     web-provider-svc
+    osp-appfw
     REQUIRED
 )
 
@@ -156,6 +156,7 @@ INCLUDE_DIRECTORIES(
     ${INSTALLER_DEP_INCLUDES}
     ${INSTALLER_INCLUDES}
     ${INSTALLER_STATIC_DEP_INCLUDE_DIRS}
+    ${OSP_APPFW_INCLUDES}
     )
 
 ADD_LIBRARY(${TARGET_INSTALLER_STATIC} STATIC
@@ -172,5 +173,8 @@ TARGET_LINK_LIBRARIES(${TARGET_INSTALLER_STATIC}
     ${SYS_INSTALLER_STATIC_DEP_LIBRARIES} "-ldl"
     )
 
+#for encryption
+TARGET_LINK_LIBRARIES(${TARGET_INSTALLER_STATIC} -L/usr/lib/osp -losp-appfw )
+
 ADD_SUBDIRECTORY(pkg-manager)
 ADD_SUBDIRECTORY(wrt-installer)
index 98faa16..3de2de7 100644 (file)
 #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 <widget_install/job_widget_install.h>
 #include <widget_install/widget_install_context.h>
 #include <widget_install/widget_install_errors.h>
 
 using namespace WrtDB;
-using namespace WRTEncryptor;
 
 namespace {
 const std::size_t ENCRYPTION_CHUNK_MAX_SIZE = 1008; // bytes
@@ -157,14 +158,36 @@ 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;
+
+    Tizen::Security::Crypto::_TrustZoneService* pInstance;
+    pInstance = Tizen::Security::Crypto::_TrustZoneService::GetInstance();
+
+    ByteBuffer pBuf;
+    pBuf.Construct(pBufSize);
+    const byte *pByte = reinterpret_cast<const byte*>(plainBuffer);
+    pBuf.SetArray(pByte, 0, pBufSize);
+    pBuf.Flip();
+
+    ByteBuffer* getBuffer = pInstance->_TrustZoneService::EncryptN(*appInfo, pBuf);
+    return getBuffer;
+}
 }
 
 namespace Jobs {
 namespace WidgetInstall {
 TaskEncryptResource::TaskEncryptResource(InstallerContext& context) :
     DPL::TaskDecl<TaskEncryptResource>(this),
-    m_context(context),
-    m_resEnc(NULL)
+    m_context(context)
 {
     AddStep(&TaskEncryptResource::StepEncryptResource);
 }
@@ -172,7 +195,6 @@ TaskEncryptResource::TaskEncryptResource(InstallerContext& context) :
 void TaskEncryptResource::StepEncryptResource()
 {
     LogDebug("Step Encrypt resource");
-    m_resEnc = new ResourceEncryptor;
 
     EncryptDirectory(m_context.locations->getTemporaryRootDir());
     m_context.job->UpdateProgress(
@@ -257,22 +279,35 @@ void TaskEncryptResource::EncryptFile(const std::string &fileName)
 
         const std::size_t chunkSize = (fileSize > ENCRYPTION_CHUNK_MAX_SIZE
                 ? ENCRYPTION_CHUNK_MAX_SIZE : fileSize);
-        const int maxBlockSize = m_resEnc->GetBlockSize(chunkSize);
 
         std::unique_ptr<unsigned char[]> inChunk(new unsigned char[chunkSize]);
         std::unique_ptr<unsigned char[]> outChunk;
 
         std::size_t bytesRead = 0;
-        int curBlockSize = 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());
+        appInfo.SetArray(b_pkgid, 0, pkgid.length());
+        appInfo.Flip();
+
         do
         {
             bytesRead = readBytes(inChunk.get(), chunkSize, inFile.Get());
             if (0 != bytesRead) {
-                int decBufSize = m_resEnc->EncryptChunkByTrustZone(DPL::ToUTF8String(
-                            m_context.widgetConfig.tzAppid),
+
+                ByteBuffer *getBuffer = EncryptChunkByTrustZone(
+                        &appInfo,
                         inChunk.get(), bytesRead);
+                int decBufSize = getBuffer->GetRemaining();
+
                 outChunk.reset(new unsigned char[decBufSize]);
-                m_resEnc->getEncStringByTrustZone(outChunk.get());
+                memcpy(outChunk.get(), getBuffer->GetPointer(), getBuffer->GetRemaining());
+                getBuffer->Reset();
 
                 writeBytes(outChunk.get(), decBufSize, outFile.Get());
             }
@@ -311,10 +346,6 @@ void TaskEncryptResource::EncryptFile(const std::string &fileName)
     {
         ReThrowMsg(Exceptions::ExtractFileFailed, fileName);
     }
-    Catch (ResourceEncryptor::Exception::Base)
-    {
-        ReThrowMsg(Exceptions::ExtractFileFailed, fileName);
-    }
 }
 
 } //namespace WidgetInstall
index 72dac56..9c95696 100644 (file)
@@ -25,8 +25,6 @@
 #include <dpl/task.h>
 #include <string>
 
-#include <dpl/encryption/resource_encryption.h>
-
 class InstallerContext;
 
 namespace Jobs {
@@ -43,8 +41,6 @@ class TaskEncryptResource : public DPL::TaskDecl<TaskEncryptResource>
     void EncryptDirectory(std::string path);
     void EncryptFile(const std::string &fileName);
 
-    WRTEncryptor::ResourceEncryptor *m_resEnc;
-
   public:
     explicit TaskEncryptResource(InstallerContext &installerContext);
 };