#include <dpl/wrt-dao-ro/global_config.h>
#include <task_commons.h>
#include <sys/stat.h>
+#include <dlfcn.h>
using namespace WrtDB;
namespace {
+const char *const DRM_LIB_PATH = "/usr/lib/libdrm-service-core-tizen.so";
+
struct PathAndFilePair
{
std::string path;
}
}
-std::string WidgetUnzip::decryptDrmPackage(const std::string &source)
+bool WidgetUnzip::isDRMPackage(const std::string &source)
+{
+ LogDebug("Enter : isDRMPackage()");
+ int ret = 0;
+ void* pHandle = NULL;
+ char* pErrorMsg = NULL;
+ int (*drm_oem_sapps_is_drm_file)(const char* pDcfPath, int dcfPathLen);
+
+ pHandle = dlopen(DRM_LIB_PATH, RTLD_LAZY | RTLD_GLOBAL);
+ if (!pHandle) {
+ LogError("dlopen failed : " << source << " [" << dlerror() << "]");
+ return false;
+ }
+
+ drm_oem_sapps_is_drm_file = reinterpret_cast <int (*)(const char*, int)>
+ (dlsym(pHandle, "drm_oem_sapps_is_drm_file"));
+ pErrorMsg = dlerror();
+ if ((pErrorMsg != NULL) || (drm_oem_sapps_is_drm_file == NULL)) {
+ LogError("dlopen failed : " << source << " [" << dlerror() << "]");
+ dlclose(pHandle);
+ return false;
+ }
+
+ ret = drm_oem_sapps_is_drm_file(source.c_str(), source.length());
+ dlclose(pHandle);
+ if (1 == ret) {
+ LogInfo(source << " is DRM file");
+ return true;
+ }
+ LogInfo(source << " isn't DRM file");
+ return false;
+}
+
+bool WidgetUnzip::decryptDRMPackage(const std::string &source, const std::string
+ &decryptedSource)
+{
+ LogDebug("Enter : decryptDRMPackage()");
+ int ret = 0;
+ void* pHandle = NULL;
+ char* pErrorMsg = NULL;
+ int (*drm_oem_sapps_decrypt_package)(const char* pDcfPath, int dcfPathLen,
+ const char* pDecryptedFile, int decryptedFileLen);
+
+ pHandle = dlopen(DRM_LIB_PATH, RTLD_LAZY | RTLD_GLOBAL);
+ if (!pHandle) {
+ LogError("dlopen failed : " << source << " [" << dlerror() << "]");
+ return false;
+ }
+
+ drm_oem_sapps_decrypt_package = reinterpret_cast <int (*)(const char*, int,
+ const char*, int)>
+ (dlsym(pHandle, "drm_oem_sapps_decrypt_package"));
+ pErrorMsg = dlerror();
+ if ((pErrorMsg != NULL) || (drm_oem_sapps_decrypt_package == NULL)) {
+ LogError("dlopen failed : " << source << " [" << dlerror() << "]");
+ dlclose(pHandle);
+ return false;
+ }
+
+ ret = drm_oem_sapps_decrypt_package(source.c_str(), source.length(),
+ decryptedSource.c_str(), decryptedSource.length());
+ dlclose(pHandle);
+ if (1 == ret) {
+ LogInfo(source << " is decrypted : " << decryptedSource);
+ return true;
+ }
+ return false;
+}
+
+std::string WidgetUnzip::getDecryptedPackage(const std::string &source)
{
LogInfo("Check DRM...");
- // TODO : check drm
+ if (isDRMPackage(source)) {
+ 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 (decryptDRMPackage(source, decryptedFile)) {
+ LogError("Failed decrypt drm file");
+ ThrowMsg(Exceptions::DrmDecryptFailed, source);
+ }
+ return decryptedFile;
+ }
return source;
}
std::string wgtFile;
Try
{
- wgtFile = decryptDrmPackage(source);
+ wgtFile = getDecryptedPackage(source);
LogDebug("wgtFile : " << wgtFile);
m_zip.reset(new DPL::ZipInput(wgtFile));