Fixed decrypt drm
authorSoyoung Kim <sy037.kim@samsung.com>
Fri, 21 Jun 2013 07:10:27 +0000 (16:10 +0900)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Mon, 24 Jun 2013 05:04:01 +0000 (05:04 +0000)
[Issue#] N/A
[Problem] failed to decyprt drm wgt file
[Cause] there was a issue to decrypt.
[Solution] change paramater.
[SCMRequest] N/A

Change-Id: Ie7299603e3b1a2f1f3a27721bda529672bd4ff1a

src/jobs/widget_install/widget_unzip.cpp
src/jobs/widget_install/widget_unzip.h

index e78cdba..56d1dff 100644 (file)
@@ -182,18 +182,45 @@ void WidgetUnzip::unzipProgress(const std::string &destination)
     }
 }
 
+std::string WidgetUnzip::decryptDrmPackage(const std::string &source)
+{
+    LogInfo("Check DRM...");
+    if (1 == drm_oem_sapps_is_drm_file(source.c_str(), source.length())) {
+        std::string decryptedFile;
+        size_t found = source.find_last_of(".wgt");
+        if (found == std::string::npos) {
+            decryptedFile += source + "_tmp.wgt";
+        } else {
+            decryptedFile += source.substr(0, source.find_last_not_of(".wgt") +
+                    1) + "_tmp.wgt";
+        }
+
+        LogDebug("decrypted file name : " << decryptedFile);
+        if (1 != drm_oem_sapps_decrypt_package(source.c_str(), source.length(),
+                    decryptedFile.c_str(), decryptedFile.length())) {
+            LogError("Failed decrypt drm file");
+            ThrowMsg(Exceptions::DrmDecryptFailed, source);
+        }
+        return decryptedFile;
+    }
+    return source;
+}
+
 void WidgetUnzip::unzipWgtFile(const std::string &source, const std::string &destination)
 {
     LogInfo("Prepare to unzip...");
-
+    std::string wgtFile;
     Try
     {
-        m_zip.reset(new DPL::ZipInput(source));
+        wgtFile = decryptDrmPackage(source);
+        LogDebug("wgtFile : " << wgtFile);
+
+        m_zip.reset(new DPL::ZipInput(wgtFile));
         LogInfo("Widget package comment: " << m_zip->GetGlobalComment());
 
         // Widget package must not be empty
         if (m_zip->empty()) {
-            ThrowMsg(Exceptions::ZipEmpty, source);
+            ThrowMsg(Exceptions::ZipEmpty, wgtFile);
         }
 
         // Set iterator to first file
@@ -209,11 +236,15 @@ void WidgetUnzip::unzipWgtFile(const std::string &source, const std::string &des
     }
     Catch(DPL::ZipInput::Exception::OpenFailed)
     {
-        ReThrowMsg(Exceptions::OpenZipFailed, source);
+        ReThrowMsg(Exceptions::OpenZipFailed, wgtFile);
     }
     Catch(DPL::ZipInput::Exception::SeekFileFailed)
     {
-        ThrowMsg(Exceptions::ExtractFileFailed, source);
+        ThrowMsg(Exceptions::ExtractFileFailed, wgtFile);
+    }
+    Catch(Exceptions::DrmDecryptFailed)
+    {
+        ReThrowMsg(Exceptions::ExtractFileFailed, wgtFile);
     }
 }
 
index 4db5af7..77a0b57 100644 (file)
@@ -41,6 +41,7 @@ class WidgetUnzip
     void unzipProgress(const std::string &destination);
     void ExtractFile(DPL::ZipInput::File *input, const std::string
             &destFileName);
+    std::string decryptDrmPackage(const std::string &source);
 
 };