From: Soyoung Kim Date: Mon, 15 Oct 2012 07:28:10 +0000 (+0900) Subject: [Installer] Add installation drm file X-Git-Tag: accepted/tizen_2.1/20130425.023916~20^2~37 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2a527859481ea538e4ebf1a70270404acdab2cb4;p=framework%2Fweb%2Fwrt-installer.git [Installer] Add installation drm file [Issue#] N/A [Problem] N/A [Cause] N/A [Solution] Add installation drm file - installation task fixed because drm file. - Parsing config.xml task hold off unzip widget file. [SCMRequest] This commit should be released with wrt-commons --- diff --git a/etc/CMakeLists.txt b/etc/CMakeLists.txt index 370d4af..adccb68 100644 --- a/etc/CMakeLists.txt +++ b/etc/CMakeLists.txt @@ -1,3 +1,10 @@ SET(ETC_DIR ${PROJECT_SOURCE_DIR}/etc) INSTALL(PROGRAMS ${ETC_DIR}/wrt_preinstall_widgets.sh DESTINATION /etc/rc.d/init.d) + +# Below Code is temporary. When DRM engine is provided it will be removed. +IF("${ARCH}" MATCHES "arm") + INSTALL(FILES ${ETC_DIR}/drm/armv7l/libdrm-service-core-intel.so.0.0.0 DESTINATION lib) +ELSE("${ARCH}" MATCHES "arm") + INSTALL(FILES ${ETC_DIR}/drm/ix86/libdrm-service-core-intel.so.0.0.0 DESTINATION lib) +ENDIF("${ARCH}" MATCHES "arm") diff --git a/etc/drm/armv7l/libdrm-service-core-intel.so b/etc/drm/armv7l/libdrm-service-core-intel.so new file mode 120000 index 0000000..df92fda --- /dev/null +++ b/etc/drm/armv7l/libdrm-service-core-intel.so @@ -0,0 +1 @@ +libdrm-service-core-intel.so.0 \ No newline at end of file diff --git a/etc/drm/armv7l/libdrm-service-core-intel.so.0 b/etc/drm/armv7l/libdrm-service-core-intel.so.0 new file mode 120000 index 0000000..4af898f --- /dev/null +++ b/etc/drm/armv7l/libdrm-service-core-intel.so.0 @@ -0,0 +1 @@ +libdrm-service-core-intel.so.0.0.0 \ No newline at end of file diff --git a/etc/drm/armv7l/libdrm-service-core-intel.so.0.0.0 b/etc/drm/armv7l/libdrm-service-core-intel.so.0.0.0 new file mode 100755 index 0000000..68b76cf Binary files /dev/null and b/etc/drm/armv7l/libdrm-service-core-intel.so.0.0.0 differ diff --git a/etc/drm/ix86/libdrm-service-core-intel.so b/etc/drm/ix86/libdrm-service-core-intel.so new file mode 120000 index 0000000..df92fda --- /dev/null +++ b/etc/drm/ix86/libdrm-service-core-intel.so @@ -0,0 +1 @@ +libdrm-service-core-intel.so.0 \ No newline at end of file diff --git a/etc/drm/ix86/libdrm-service-core-intel.so.0 b/etc/drm/ix86/libdrm-service-core-intel.so.0 new file mode 120000 index 0000000..4af898f --- /dev/null +++ b/etc/drm/ix86/libdrm-service-core-intel.so.0 @@ -0,0 +1 @@ +libdrm-service-core-intel.so.0.0.0 \ No newline at end of file diff --git a/etc/drm/ix86/libdrm-service-core-intel.so.0.0.0 b/etc/drm/ix86/libdrm-service-core-intel.so.0.0.0 new file mode 100755 index 0000000..d21a059 Binary files /dev/null and b/etc/drm/ix86/libdrm-service-core-intel.so.0.0.0 differ diff --git a/packaging/wrt-installer.spec b/packaging/wrt-installer.spec index 068d546..46743bc 100644 --- a/packaging/wrt-installer.spec +++ b/packaging/wrt-installer.spec @@ -35,8 +35,12 @@ BuildRequires: pkgconfig(tapi) BuildRequires: pkgconfig(shortcut) BuildRequires: pkgconfig(dpl-encryption) BuildRequires: pkgconfig(capi-appfw-app-manager) +BuildRequires: pkgconfig(drm-client) +BuildRequires: pkgconfig(drm-trusted) Requires: xmlsec1 +Provides: libdrm-service-core-intel.so.0 + %description Description: Wrt Installer for Tizen apps and Wac apps @@ -44,12 +48,20 @@ Description: Wrt Installer for Tizen apps and Wac apps %setup -q %build +# for drm temporary code +%ifarch %{ix86} +BUILD_ARCH_=x86 +%else +BUILD_ARCH_=arm +%endif + export LDFLAGS+="-Wl,--rpath=/usr/lib -Wl,--hash-style=both -Wl,--as-needed" LDFLAGS="$LDFLAGS" cmake . -DCMAKE_INSTALL_PREFIX=/usr \ -DDPL_LOG=ON \ -DCMAKE_PACKAGE_VERSION=%{version} \ + -DARCH="$BUILD_ARCH_" \ -DCMAKE_BUILD_TYPE=%{?build_type:%build_type} make %{?jobs:-j%jobs} @@ -75,6 +87,14 @@ mkdir -p /opt/share/widget/temp_info ln -s /etc/rc.d/init.d/wrt_preinstall_widgets.sh /etc/rc.d/rc3.d/S46lwrt_preinstall_widgets.sh ln -s /etc/rc.d/init.d/wrt_preinstall_widgets.sh /etc/rc.d/rc5.d/S46lwrt_preinstall_widgets.sh +# for drm temporary code +mkdir -p /opt/var/drm/inteldrm +mkdir -p own 0:5000 /opt/var/drm/inteldrm +chmod 755 /opt/var/drm/inteldrm + +ln -s /usr/lib/libdrm-service-core-intel.so.0.0.0 /usr/lib/libdrm-service-core-intel.so.0 +ln -s /usr/lib/libdrm-service-core-intel.so.0 /usr/lib/libdrm-service-core-intel.so + %files %manifest wrt-installer.manifest %attr(755,root,root) %{_bindir}/wrt-installer @@ -82,3 +102,5 @@ ln -s /etc/rc.d/init.d/wrt_preinstall_widgets.sh /etc/rc.d/rc5.d/S46lwrt_preinst %attr(644,root,root) %{_datadir}/edje/wrt/* /usr/etc/package-manager/backendlib/libwgt.so %{_datadir}/license/%{name} +# for drm temporary code +/usr/lib/*.so* diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 929571e..b77d47e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -45,6 +45,7 @@ SET(INSTALLER_INCLUDES ${INSTALLER_SRC_DIR}/configuration_parser ${INSTALLER_SRC_DIR}/wrt-installer ${INSTALLER_SRC_DIR}/commons + ${INSTALLER_SRC_DIR}/commons/drm #this is temporary code for drm ${INSTALLER_SRC_DIR}/pkg-manager ) @@ -127,6 +128,8 @@ PKG_CHECK_MODULES(INSTALLER_STATIC_DEP tapi shortcut capi-appfw-app-manager + drm-client + drm-trusted REQUIRED ) @@ -147,6 +150,17 @@ TARGET_LINK_LIBRARIES(${TARGET_INSTALLER_STATIC} ${INSTALLER_STATIC_DEP_LIBRARIES} ) + +# Below Code is temporary. When DRM engine is provided it will be removed. +MESSAGE("ARCH ${ARCH}") +IF("${ARCH}" MATCHES "arm") + TARGET_LINK_LIBRARIES(${TARGET_INSTALLER_STATIC} + "-L${PROJECT_SOURCE_DIR}/etc/drm/armv7l -ldrm-service-core-intel" -Wl,--allow-shlib-undefine) +ELSE("${ARCH}" MATCHES "arm") + TARGET_LINK_LIBRARIES(${TARGET_INSTALLER_STATIC} + "-L${PROJECT_SOURCE_DIR}/etc/drm/ix86 -ldrm-service-core-intel" -Wl,--allow-shlib-undefine) +ENDIF("${ARCH}" MATCHES "arm") + SET_TARGET_PROPERTIES(${TARGET_INSTALLER_STATIC} PROPERTIES COMPILE_FLAGS -fPIC) diff --git a/src/commons/drm/CPointerArray.h b/src/commons/drm/CPointerArray.h new file mode 100755 index 0000000..3e30e79 --- /dev/null +++ b/src/commons/drm/CPointerArray.h @@ -0,0 +1,52 @@ + +/******************************************************************************** +* Copyright ? 2004-2009 by INKA Entworks, Inc (www.inka.co.kr). * +* All rights reserved. * +* * +* No parts of this source code may be in any way copied, reproduced, modified * +* or distributed without the prior written consent of INKA Entworks, Inc. * +* CPointerArray.h: interface for the CPointerArray class. * +*********************************************************************************/ + +#ifndef __CPOINTERARRAY_H__ +#define __CPOINTERARRAY_H__ + + +#if !defined(AFX_CPOINTERARRAY_H__AB67E4BE_A233_4E3E_B257_9830D90326EE__INCLUDED_) +#define AFX_CPOINTERARRAY_H__AB67E4BE_A233_4E3E_B257_9830D90326EE__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +//#include "Shp.h" +#include "InkaTypes.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +class CPointerArray +{ +protected: + LPVOID* m_ppData; + int m_nMaxSize; + int m_nNumOfData; + +public: + CPointerArray(); + virtual ~CPointerArray(); + + int Add( LPVOID pData ); + int Remove( int nIndex ); + LPVOID Get( int nIndex ); + inline int GetCount() { return m_nNumOfData; } + inline void RemoveAll() { m_nNumOfData = 0; } +}; + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif // !defined(AFX_CPOINTERARRAY_H__AB67E4BE_A233_4E3E_B257_9830D90326EE__INCLUDED_) +#endif /* __CPOINTERARRAY_H__ */ diff --git a/src/commons/drm/CXMLAttribute.h b/src/commons/drm/CXMLAttribute.h new file mode 100755 index 0000000..dda8fe3 --- /dev/null +++ b/src/commons/drm/CXMLAttribute.h @@ -0,0 +1,37 @@ + +/******************************************************************************** +* Copyright ? 2004-2009 by INKA Entworks, Inc (www.inka.co.kr). * +* All rights reserved. * +* * +* No parts of this source code may be in any way copied, reproduced, modified * +* or distributed without the prior written consent of INKA Entworks, Inc. * +* CXMLAttribute.h: interface for the CXMLAttribute class. * +*********************************************************************************/ +//#include "Shp.h" +#include "InkaTypes.h" + +#if !defined(AFX_CXMLATTRIBUTE_H__2B925786_3613_47B0_B85D_CAF2053F46DB__INCLUDED_) +#define AFX_CXMLATTRIBUTE_H__2B925786_3613_47B0_B85D_CAF2053F46DB__INCLUDED_ + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +class CXMLAttribute +{ +protected: + LPTSTR m_pszName; + LPTSTR m_pszValue; + +public: + CXMLAttribute(); + virtual ~CXMLAttribute(); + + int SetName( LPCTSTR pszName ); + int SetValue( LPCTSTR pszValue ); + + inline LPCTSTR GetName() { return m_pszName; } + inline LPCTSTR GetValue() { return m_pszValue; } +}; + +#endif // !defined(AFX_CXMLATTRIBUTE_H__2B925786_3613_47B0_B85D_CAF2053F46DB__INCLUDED_) diff --git a/src/commons/drm/CXMLElement.h b/src/commons/drm/CXMLElement.h new file mode 100755 index 0000000..eb74a0c --- /dev/null +++ b/src/commons/drm/CXMLElement.h @@ -0,0 +1,57 @@ + +/******************************************************************************** +* Copyright ? 2004-2009 by INKA Entworks, Inc (www.inka.co.kr). * +* All rights reserved. * +* * +* No parts of this source code may be in any way copied, reproduced, modified * +* or distributed without the prior written consent of INKA Entworks, Inc. * +* CXMLElement.h: interface for the CXMLElement class. * +*********************************************************************************/ + +#if !defined(AFX_CXMLELEMENT_H__B6A6A39B_1980_4A4F_B68B_E87B53A3EE9B__INCLUDED_) +#define AFX_CXMLELEMENT_H__B6A6A39B_1980_4A4F_B68B_E87B53A3EE9B__INCLUDED_ + +//#include "Shp.h" +#include "InkaTypes.h" +#include "CXMLAttribute.h" +#include "CPointerArray.h" + + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +class CXMLElement +{ +protected: + LPTSTR m_pszName; + LPTSTR m_pszValue; + + CPointerArray m_pChilds; + CPointerArray m_pAttributes; + + int _SearchNodes( CPointerArray* ppaChildNodes, CXMLElement* pCurrent, LPCTSTR pszTagName, va_list args ); + +public: + CXMLElement(); + virtual ~CXMLElement(); + + int SetName( LPCTSTR pszName ); + int SetValue( LPCTSTR pszValue ); + int AddAttribute( LPCTSTR pszName, LPCTSTR pszValue ); + + inline LPCTSTR GetName() { return m_pszName; } + inline LPCTSTR GetValue() { return m_pszValue; } + + int AddChild( CXMLElement* pChild ); + LPCTSTR GetAttribute( LPCTSTR pszName ); + + inline int GetChildCount() { return m_pChilds.GetCount(); } + inline int GetAttributeCount() { return m_pAttributes.GetCount(); } + inline CXMLElement* GetChild( int nIndex ) { return (CXMLElement*)m_pChilds.Get( nIndex ); } + inline CXMLAttribute* GetAttribute( int nIndex ) { return (CXMLAttribute*)m_pAttributes.Get( nIndex ); } + + int Find( CPointerArray* pSearchedChild, LPCTSTR pszChildName, ... ); +}; + +#endif // !defined(AFX_CXMLELEMENT_H__B6A6A39B_1980_4A4F_B68B_E87B53A3EE9B__INCLUDED_) diff --git a/src/commons/drm/CXMLFile.h b/src/commons/drm/CXMLFile.h new file mode 100755 index 0000000..0a3a2e2 --- /dev/null +++ b/src/commons/drm/CXMLFile.h @@ -0,0 +1,54 @@ + +/******************************************************************************** +* Copyright ? 2004-2009 by INKA Entworks, Inc (www.inka.co.kr). * +* All rights reserved. * +* * +* No parts of this source code may be in any way copied, reproduced, modified * +* or distributed without the prior written consent of INKA Entworks, Inc. * +* CXMLFile.h: interface for the CXMLFile class. * +*********************************************************************************/ + +#if !defined(AFX_CXMLFILE_H__21F76587_B9C8_4407_9C16_186F3D47ADE1__INCLUDED_) +#define AFX_CXMLFILE_H__21F76587_B9C8_4407_9C16_186F3D47ADE1__INCLUDED_ + +//#include "Shp.h" +#include "InkaTypes.h" +#include "CXMLElement.h" + +#if _MSC_VER > 1000 +#pragma once +#endif // _MSC_VER > 1000 + +#ifndef IN + #define IN +#endif + +#ifndef OUT + #define OUT +#endif + +#define ELEMENT_QUEUE_MAX 2048 +class CXMLFile +{ +protected: + LPCTSTR m_pszXML; + CXMLElement* m_paElementQueue[ ELEMENT_QUEUE_MAX ]; + int m_nQueueIndex; + CXMLElement* m_pRoot; + + int _Parse(); + int _GetElementName( LPTSTR pszElementName ); + CXMLElement* _Pop(); + int _Push( CXMLElement* p ); + int _GetAttributeNameAndValue( LPTSTR pszName, LPTSTR pszValue ); + +public: + CXMLFile(); + virtual ~CXMLFile(); + + int LoadFromStream( LPCTSTR pszXML ); + int LoadFromFile( LPCTSTR pszFileName ); + inline CXMLElement* GetRoot() { return m_pRoot; } +}; + +#endif // !defined(AFX_CXMLFILE_H__21F76587_B9C8_4407_9C16_186F3D47ADE1__INCLUDED_) diff --git a/src/commons/drm/InkaTypes.h b/src/commons/drm/InkaTypes.h new file mode 100755 index 0000000..d7a9291 --- /dev/null +++ b/src/commons/drm/InkaTypes.h @@ -0,0 +1,76 @@ +/* + * SHP + * Copyright (c) 2000-2007 UMTS Software Lab, Mobile Communication Division, + * Telecommunication Network Business, Samsung Electronics, Inc. + * All rights reserved. + * + * This software is the confidential and proprietary information + * of Samsung Electronics, Inc. ("Confidential Information"). You + * shall not disclose such Confidential Information and shall use + * it only in accordance with the terms of the license agreement + * you entered into with Samsung Electronics. + */ + +/** + * @file InkaTypes.h + * @brief This file includes definitions of constants, + * enumerations, and datastructures for the Inka DRM service. +# @author Jihyun Lee(ezhyun.lee@samsung.com) +# @author Donghyun Yoo(marku.yoo@samsung.com) + * @version 1.0 + */ + +#ifndef INKA_DRM_TYPES_H +#define INKA_DRM_TYPES_H + +//#include "shp.h" +//#include "FileMgr.h" +#include +#include + +#define _T +#define IF_ERROR_GOTO( error ) if( FAILED( HRESULT_FROM_WIN32( error ) ) ) { nResult = ERRORMSG( error, NULL ); goto finish; } +#define IF_TRUE_GOTO( cond, error ) if( cond ) { nResult = -1; goto finish; } + +#if defined(_WIN32) || defined(_WIN64) + #define snprintf _snprintf + #define vsnprintf _vsnprintf + #define strcasecmp _stricmp + #define strncasecmp _strnicmp +#endif + +#ifndef _SHP_SIMUL +typedef void* LPVOID; +typedef const char* LPCTSTR; +typedef unsigned char* LPBYTE; +typedef char TCHAR; +typedef char* LPTSTR; +typedef LPTSTR LPSTR; +typedef LPCTSTR LPCTSTR; +typedef LPCTSTR LPCSTR; + +#define DWORD unsigned long +#define LPBYTE unsigned char* +#define BYTE unsigned char +#define UINT unsigned int +#define ULONG unsigned long +#define INT32 long +#define INT64 long long +#define TRUE 1 +#define FALSE 0 + + +typedef char CHAR; +typedef bool BOOL; + + +//typedef HFile HANDLE; +#define ERROR_INVALID_DATA 13L +#define ERROR_INSUFFICIENT_BUFFER 122L // dderror +//#define CopyMemory AcMemcpy +#define INVALID_HOBJ NULL + +#endif + + +#endif //INKA_DRM_TYPES_H diff --git a/src/commons/drm/IntelDrm_Core.h b/src/commons/drm/IntelDrm_Core.h new file mode 100755 index 0000000..b8b4b48 --- /dev/null +++ b/src/commons/drm/IntelDrm_Core.h @@ -0,0 +1,46 @@ +//typedef char CHAR; +//typedef bool BOOL; + +typedef struct t_cek +{ + char *CID; // Content ID ¹öÆÛ Æ÷ÀÎÅÍ + char *CEK; // Content Encryption Key ¹öÆÛ Æ÷ÀÎÅÍ + char *EncryptionMethod; // CEK ¾Ë°í¸®Áò +}T_CEK; + +typedef struct t_dro +{ + char *CID; // Content ID ¹öÆÛ Æ÷ÀÎÅÍ + char *deviceId; // »ç¿ëÀÚ ½Äº° ¹ÙÀεù. IMEI, MIN °ª ¹ÙÀεù Á¦¾î + char *digestValue; // »ç¿ëÀÚ ½Äº° ¹ÙÀεù. IMEI, MIN °ª ¹ÙÀεù Á¦¾î + char *signedValue; // »ç¿ëÀÚ ½Äº° ¹ÙÀεù. IMEI, MIN °ª ¹ÙÀεù Á¦¾î + char *cert; // »ç¿ëÀÚ ½Äº° ¹ÙÀεù. IMEI, MIN °ª ¹ÙÀεù Á¦¾î + int Count; // »ç¿ë ȸ¼ö + char *CreatedTimestamp; // »ç¿ë °¡´É ½ÃÀÛ ÀϽà ¹öÆÛ Æ÷ÀÎÅÍ. GMT Ç¥±â + char *ExpiredTimeStamp; // »ç¿ë °¡´É ¸¸±â ÀϽà ¹öÆÛ Æ÷ÀÎÅÍ. GMT Ç¥±â + char *ExpirationDate; // ÃÖÃÊ »ç¿ë ÀÌÈÄ »ç¿ë °¡´É ½Ã°£. ½Ã°£ ´ÜÀ§ +}T_DRO; + +typedef struct t_dcf_file_header +{ + unsigned char Version; + unsigned char ContentTypeLen; + unsigned char ContentURILen; + char *ContentType; + char *ContentURI; + unsigned int HeadersLen; + unsigned int DataLen; + char *Headers; + unsigned int DataOffset; +}T_DCF_FILE_HEADER; + +// DRO Value size +#define APPID_SIZE 16 +#define CEK_SIZE 512 +#define ENCRYPTION_METHOD_SIZE 512 +#define DEVICEID_SIZE 256 +#define TIMESTAMP_SIZE 256 +#define DIGESTVALUE_SIZE 256 +#define SIGNATUREVALUE_SIZE 1024 +#define CERT_SIZE 1024 * 4 +#define AES_BLOCK_SIZE 16 diff --git a/src/commons/drm/drm-intel-crypto-util.h b/src/commons/drm/drm-intel-crypto-util.h new file mode 100755 index 0000000..eacb1e5 --- /dev/null +++ b/src/commons/drm/drm-intel-crypto-util.h @@ -0,0 +1,13 @@ +#include "InkaTypes.h" +//#include "IntelDrm_Core.h" + +#include "stdlib.h" +#include "string.h" +#include "stdio.h" + +#define AES_BLOCK_SIZE 16 + +LPSTR Base64Encode(LPBYTE pbData, int nLength); +LPBYTE Base64Decode(LPCSTR pszString, int* pnLength); + +int decrypt_block(unsigned char *iv, unsigned char *cipherText, int cipherTextLen, unsigned char *cek, int cekLen, unsigned char *plainText); diff --git a/src/commons/drm/drm-intel-util.h b/src/commons/drm/drm-intel-util.h new file mode 100755 index 0000000..08bb2cd --- /dev/null +++ b/src/commons/drm/drm-intel-util.h @@ -0,0 +1,69 @@ +#include "CPointerArray.h" +#include "CXMLAttribute.h" +#include "CXMLElement.h" +#include "CXMLFile.h" +#include "InkaTypes.h" +#include "IntelDrm_Core.h" +#include "drm-intel-crypto-util.h" + +#include "stdlib.h" +#include "string.h" +#include "stdio.h" + +/** + * An application can parse CEK XML Foramt. + * + * @param[in] pszXML Data String of the CEK information + * @param[out] t_cek parsing result to be saved + * @return This function returns 1 on success or 0 on failure. + * @remarks + * @see + * @since + */ +int parse_intel_cek(const char* pszXML, T_CEK* t_cek); + +/** + * An application can parse DRO XML Foramt. + * + * @param[in] pszXML Data String of the DRO information + * @param[out] t_cek parsing result to be saved + * @return This function returns 1 on success or 0 on failure. + * @remarks + * @see + * @since + */ +int parse_intel_dro(const char* pszXML, T_DRO* t_RO); + +int parse_intel_dro2(const char* pszXML, T_DRO* t_RO); + +/** + * An application can parse stored dro. + * + * @param[in] pFilepath file path of the internal dro + * @param[out] t_ro parsing result to be saved + * @return This function returns 1 on success or 0 on failure. + * @remarks + * @see + * @since + */ +int get_internal_dro(char *pFilepath, T_DRO* t_ro); + +/** + * An application can parse stored cek. + * + * @param[in] pFilepath file path of the internal cek + * @param[out] t_cek parsing result to be saved + * @return This function returns 1 on success or 0 on failure. + * @remarks + * @see + * @since + */ +int get_internal_cek(char *pFilepath, T_CEK* t_cek); + +int delete_internal_cek(char *pAppId); + +int get_dcf_header_info(char *pFilePath, T_DCF_FILE_HEADER *pTdcfHeader); + +bool get_Uintvar(unsigned int *nValue, FILE *pFile); + +int decrypt_package(char *pDcfPath, char *pDecryptedFilePath, unsigned char *pCEK, int cekLen, T_DCF_FILE_HEADER *t_dcf_header); diff --git a/src/commons/drm/drm-oem-intel.h b/src/commons/drm/drm-oem-intel.h new file mode 100755 index 0000000..80a9bb2 --- /dev/null +++ b/src/commons/drm/drm-oem-intel.h @@ -0,0 +1,172 @@ +/* + * drm-intel + * + * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Sunggun Jung + * + * This library is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation; either version 2.1 of the License, or (at your option) + * any later version. + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +/** +* @internal +* @defgroup DRM-INTEL drm-intel +* @{ +*/ +#include "drm-intel-util.h" +//#include "drm-intel-crypto-util.h" + +#include +#include +#include + +/** + * An application can install Intel DRM license(DRO). + * + * @param[in] pDroXML Data String of the Rights Request + * @param[in] droBufLen pDroXML Length + * @return This function returns 1 on success or 0 on failure. + * @remarks + * @see + * @since + */ +int drm_oem_intel_install_license(char *pDroXML, int droBufLen); + +/** + * An application can uninstall Intel DRM license(DRO). + * + * @param[in] pAppId App-id of the rigths which want to un-install + * @return This function returns 1 on success or 0 on failure. + * @remarks + * @see + * @since + */ +int drm_oem_intel_uninstall_license(char *pAppId); + +/** + * An application can install CEK(Contents Encryption Key). + * + * @param[in] pCekXML Data String of the Rights Request + * @param[in] cekBufLen pDroXML Length + * @return This function returns 1 on success or 0 on failure. + * @remarks + * @see + * @since + */ +int drm_oem_intel_install_cek(char *pCekXML, int cekBufLen); + +/** + * An application can get decrypted contents(Apps) which is encrypted + * + * @param[in] pDcfPath Intel DRM Package File Path + * @param[in] pDecryptedFile Decrypted File Path + * @return This function returns 1 on success or 0 on failure. + * @remarks + * @see + * @since + */ +int drm_oem_intel_decrypt_package(char *pDcfPath, char *pDecryptedFile); + +/** + * An application can get informations of rights (DRO). + * + * @param[in] pAppId App-id of the rights which want to know + * @param[out] pDro The rights information about the app-id + * @return This function can return any of the following codes + * DRM_INTEL_SUCCESS = 0 #include #include +#include +#include #include "root_parser.h" #include "widget_parser.h" #include "parser_runner.h" #include -#include #include #include #include @@ -51,6 +52,8 @@ #include #include #include +#include +#include #include #include @@ -68,6 +71,9 @@ #include #include #include +#include +#include +#include //temporary code using namespace WrtDB; @@ -132,35 +138,13 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath, JobContextBase(installerStruct), m_exceptionCaught(Exceptions::Success) { - // Check installation type (config.xml or widget.wgt) - bool browserRequest = hasExtension(widgetPath, XML_EXTENSION); - - LogInfo("Hosted app installation: " << browserRequest); - struct timeval tv; gettimeofday(&tv, NULL); srand(time(NULL) + tv.tv_usec); m_installerContext.m_quiet = m_jobStruct.m_quiet; - if(!browserRequest) - { - m_installerContext.widgetConfig.pType = checkPackageType(widgetPath); - } - else - { - m_installerContext.widgetConfig.pType = WrtDB::PKG_TYPE_TIZEN_WEBAPP; - } - LogDebug("widgetPath:" << widgetPath); - - ConfigParserData configData = getWidgetDataFromXML(widgetPath, browserRequest, - m_installerContext.widgetConfig.pType); - WidgetUpdateInfo update = detectWidgetUpdate(configData); - bool needEncryption = detectResourceEncryption(configData); - - // Configure installation - ConfigureResult result = ConfigureInstallation(widgetPath, configData, - update, browserRequest); + ConfigureResult result = PrePareInstallation(widgetPath); if (result == ConfigureResult::Ok) { LogInfo("Configure installation succeeded"); @@ -168,15 +152,18 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath, AddTask(new TaskRecovery(m_installerContext)); // Create installation tasks - if (!m_installerContext.locations->browserRequest()) { + if (m_installerContext.widgetConfig.packagingType != + WrtDB::PKG_TYPE_HOSTED_WEB_APP || !m_isDRM) { AddTask(new TaskUnzip(m_installerContext)); } + AddTask(new TaskWidgetConfig(m_installerContext)); - if (m_installerContext.locations->browserRequest()) { + if (m_installerContext.widgetConfig.packagingType == + WrtDB::PKG_TYPE_HOSTED_WEB_APP ) { AddTask(new TaskPrepareFiles(m_installerContext)); } AddTask(new TaskCertify(m_installerContext)); - if (needEncryption) { + if (m_needEncryption) { AddTask(new TaskEncryptResource(m_installerContext)); } AddTask(new TaskFileManipulation(m_installerContext)); @@ -191,8 +178,8 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath, AddTask(new TaskManifestFile(m_installerContext)); AddTask(new TaskCertificates(m_installerContext)); - if (m_installerContext.widgetConfig.pType == - PKG_TYPE_TIZEN_WITHSVCAPP) { + if (m_installerContext.widgetConfig.packagingType == + PKG_TYPE_HYBRID_WEB_APP) { AddTask(new TaskInstallOspsvc(m_installerContext)); } AddTask(new TaskPluginsCopy(m_installerContext)); @@ -201,12 +188,15 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath, } else if (result == ConfigureResult::Updated) { LogInfo("Configure installation updated"); LogInfo("Widget Update"); - - if (!m_installerContext.locations->browserRequest()) { + if (m_installerContext.widgetConfig.packagingType != + WrtDB::PKG_TYPE_HOSTED_WEB_APP || !m_isDRM) { AddTask(new TaskUnzip(m_installerContext)); } + AddTask(new TaskWidgetConfig(m_installerContext)); - if (m_installerContext.locations->browserRequest()) { + + if (m_installerContext.widgetConfig.packagingType == + WrtDB::PKG_TYPE_HOSTED_WEB_APP ) { AddTask(new TaskPrepareFiles(m_installerContext)); } @@ -217,8 +207,8 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath, AddTask(new TaskSmack(m_installerContext)); AddTask(new TaskManifestFile(m_installerContext)); - if (m_installerContext.widgetConfig.pType == - PKG_TYPE_TIZEN_WITHSVCAPP) { + if (m_installerContext.widgetConfig.packagingType == + PKG_TYPE_HYBRID_WEB_APP) { AddTask(new TaskInstallOspsvc(m_installerContext)); } AddTask(new TaskRemoveBackupFiles(m_installerContext)); @@ -244,6 +234,48 @@ JobWidgetInstall::JobWidgetInstall(std::string const &widgetPath, } } +JobWidgetInstall::ConfigureResult JobWidgetInstall::PrePareInstallation( + const std::string &widgetPath) +{ + ConfigureResult result; + m_needEncryption = false; + + Try + { + std::string tempDir = Jobs::WidgetInstall::createTempPath(); + + bool m_isDRM = isDRMWidget(widgetPath); + if (true == m_isDRM) { + LogDebug("decrypt DRM widget"); + if(DecryptDRMWidget(widgetPath, tempDir)) { + LogDebug("Failed decrypt DRM widget"); + return ConfigureResult::Failed; + } + } + + LogDebug("widgetPath:" << widgetPath); + + m_installerContext.widgetConfig.packagingType = + checkPackageType(widgetPath, tempDir); + ConfigParserData configData = getWidgetDataFromXML(widgetPath, tempDir, + m_installerContext.widgetConfig.packagingType, m_isDRM); + LogDebug("widget packaging type : " << + m_installerContext.widgetConfig.packagingType.pkgType); + WidgetUpdateInfo update = detectWidgetUpdate(configData); + m_needEncryption = detectResourceEncryption(configData); + + // Configure installation + result = ConfigureInstallation(widgetPath, configData, update, tempDir); + } + Catch(Exceptions::ExtractFileFailed) + { + LogError("Failed to create temporary path for widget"); + result = ConfigureResult::Failed; + } + + return result; +} + std::string JobWidgetInstall::generateTizenId() { std::string allowed("0123456789" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -318,10 +350,13 @@ DPL::OptionalString JobWidgetInstall::getNewTizenId() const return m_installerContext.widgetConfig.pkgname; } -void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath, bool browserRequest) +void JobWidgetInstall::configureWidgetLocation(const std::string & widgetPath, + const std::string& tempPath) { - m_installerContext.locations = WidgetLocation(DPL::ToUTF8String(*m_installerContext.widgetConfig.pkgname), - widgetPath, browserRequest, m_installerContext.widgetConfig.pType); + m_installerContext.locations = + WidgetLocation(DPL::ToUTF8String(*m_installerContext.widgetConfig.pkgname), + widgetPath, tempPath, + m_installerContext.widgetConfig.packagingType); LogInfo("widgetSource " << widgetPath); } @@ -330,7 +365,7 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation( const std::string &widgetSource, const WrtDB::ConfigParserData &configData, const WidgetUpdateInfo &update, - bool browserRequest) + const std::string &tempPath) { LogInfo( "Widget install/update: incoming guid = '" << @@ -406,7 +441,7 @@ JobWidgetInstall::ConfigureResult JobWidgetInstall::ConfigureInstallation( using namespace PackageManager; LogInfo("Tizen Id: " << m_installerContext.widgetConfig.pkgname); - configureWidgetLocation(widgetSource, browserRequest); + configureWidgetLocation(widgetSource, tempPath); // send start signal of pkgmgr PkgmgrSignalSingleton::Instance().setPkgname( @@ -462,48 +497,62 @@ WidgetUpdateMode::Type JobWidgetInstall::CalcWidgetUpdatePolicy( ConfigParserData JobWidgetInstall::getWidgetDataFromXML( const std::string &widgetSource, - bool fromBrowser, WrtDB::PkgType isOspsvc) + const std::string &tempPath, + WrtDB::PackagingType pkgType, + bool isDRM) { + // Parse config + ParserRunner parser; + ConfigParserData configInfo; + Try { - // Parse config - ParserRunner parser; - ConfigParserData configInfo; - - if (fromBrowser) { + if (pkgType == PKG_TYPE_HOSTED_WEB_APP) { parser.Parse(widgetSource, - ElementParserPtr( - new RootParser(configInfo, - DPL::FromUTF32String( - L"widget")))); - } - else { - // Open zip file - std::unique_ptr zipFile( - new DPL::ZipInput(widgetSource)); + ElementParserPtr( + new RootParser(configInfo, + DPL::FromUTF32String( + L"widget")))); + } else { + if (!isDRM) { + std::unique_ptr zipFile( + new DPL::ZipInput(widgetSource)); - std::unique_ptr configFile; + std::unique_ptr configFile; - // Open config.xml file - if (isOspsvc == PKG_TYPE_TIZEN_WITHSVCAPP) { - configFile.reset(zipFile->OpenFile(WITH_OSP_XML)); + // Open config.xml file + if (pkgType == PKG_TYPE_HYBRID_WEB_APP) { + configFile.reset(zipFile->OpenFile(WITH_OSP_XML)); + } else { + configFile.reset(zipFile->OpenFile(CONFIG_XML)); + } + + // Extract config + DPL::BinaryQueue buffer; + DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get()); + DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer); + DPL::Copy(&inputAdapter, &outputAdapter); + parser.Parse(&buffer, + ElementParserPtr( + new RootParser(configInfo, + DPL::FromUTF32String( + L"widget")))); } else { - configFile.reset(zipFile->OpenFile(CONFIG_XML)); - } + // DRM widget + std::string configFile; + if (pkgType == PKG_TYPE_HYBRID_WEB_APP) { + configFile = tempPath + "/" + WITH_OSP_XML; + } else { + configFile = tempPath + "/" + CONFIG_XML; + } - // Extract config - DPL::BinaryQueue buffer; - DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get()); - DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer); - DPL::Copy(&inputAdapter, &outputAdapter); - parser.Parse(&buffer, - ElementParserPtr( - new RootParser(configInfo, - DPL::FromUTF32String( - L"widget")))); + parser.Parse(configFile, + ElementParserPtr( + new RootParser(configInfo, + DPL::FromUTF32String( + L"widget")))); + } } - - return configInfo; } Catch(DPL::ZipInput::Exception::OpenFailed) { @@ -520,11 +569,17 @@ ConfigParserData JobWidgetInstall::getWidgetDataFromXML( LogError("Failed to extract config.xml file"); return ConfigParserData(); } + Catch(DPL::FileInput::Exception::OpenFailed) + { + LogError("Failed to open config.xml file"); + return ConfigParserData(); + } Catch(ElementParser::Exception::ParseError) { LogError("Failed to parse config.xml file"); return ConfigParserData(); } + return configInfo; } WidgetUpdateInfo JobWidgetInstall::detectWidgetUpdate( @@ -709,58 +764,68 @@ void JobWidgetInstall::displayWidgetInfo() } WrtDB::PackagingType JobWidgetInstall::checkPackageType( - const std::string &widgetSource) + const std::string &widgetSource, + const std::string &tempPath) { - using namespace WrtDB; - - PackagingType pType = PKG_TYPE_UNKNOWN; - std::unique_ptr zipFile; + // Check installation type (config.xml or widget.wgt) + if (hasExtension(widgetSource, XML_EXTENSION)) { + LogInfo("Hosted app installation"); + return PKG_TYPE_HOSTED_WEB_APP; + } - Try - { - // Open zip file - zipFile.reset(new DPL::ZipInput(widgetSource)); + if (m_isDRM) { + std::string configFile = tempPath + "/" + CONFIG_XML; + if (WrtUtilFileExists(configFile)) { + return PKG_TYPE_NOMAL_WEB_APP; + } - } - Catch(DPL::ZipInput::Exception::OpenFailed) - { - LogError("Failed to open widget package"); - return PKG_TYPE_UNKNOWN; - } + configFile = tempPath + "/" + WITH_OSP_XML; + if (WrtUtilFileExists(configFile)) { + return PKG_TYPE_HYBRID_WEB_APP; + } + } else { + std::unique_ptr zipFile; - Try - { - // Open config.xml file in package root - std::unique_ptr configFile( - zipFile->OpenFile(CONFIG_XML)); - pType = PKG_TYPE_TIZEN_WEBAPP; - } - Catch(DPL::ZipInput::Exception::OpenFileFailed) - { - LogWarning("Could not find ./config.xml"); - } + Try + { + // Open zip file + zipFile.reset(new DPL::ZipInput(widgetSource)); - Try - { - // Open config.xml file in package root - std::unique_ptr configFile( - zipFile->OpenFile(WITH_OSP_XML)); - if (pType == PKG_TYPE_TIZEN_WEBAPP) { - LogWarning("Two config.xml's found. Application type is unknown."); + } + Catch(DPL::ZipInput::Exception::OpenFailed) + { + LogDebug("Failed to open widget package"); return PKG_TYPE_UNKNOWN; } - pType = PKG_TYPE_TIZEN_WITHSVCAPP; - } - Catch(DPL::ZipInput::Exception::OpenFileFailed) - { - LogWarning("Could not find ./res/wgt/config.xml"); - } + Try + { + // Open config.xml file in package root + std::unique_ptr configFile( + zipFile->OpenFile(CONFIG_XML)); + return PKG_TYPE_NOMAL_WEB_APP; + } + Catch(DPL::ZipInput::Exception::OpenFileFailed) + { + LogDebug("Could not find config.xml"); + } + + Try + { + // Open config.xml file in package root + std::unique_ptr configFile( + zipFile->OpenFile(WITH_OSP_XML)); - if (pType == PKG_TYPE_UNKNOWN) { - LogWarning("config.xml not found. Application type is unknown."); + return PKG_TYPE_HYBRID_WEB_APP; + } + Catch(DPL::ZipInput::Exception::OpenFileFailed) + { + LogDebug("Could not find wgt/config.xml"); + return PKG_TYPE_UNKNOWN; + } } - return pType; + + return PKG_TYPE_UNKNOWN; } bool JobWidgetInstall::detectResourceEncryption(const WrtDB::ConfigParserData &configData) @@ -776,5 +841,54 @@ bool JobWidgetInstall::detectResourceEncryption(const WrtDB::ConfigParserData &c return false; } +bool JobWidgetInstall::isDRMWidget(std::string widgetPath) +{ + drm_bool_type_e is_drm_file = DRM_UNKNOWN; + int ret = -1; + + /* TODO : + ret = drm_is_drm_file(widgetPath.c_str(), &is_drm_file); + if(DRM_RETURN_SUCCESS == ret && DRM_TRUE == is_drm_file) { + */ + + /* blow code temporary code for drm. */ + ret = drm_oem_intel_isDrmFile(const_cast(widgetPath.c_str())); + if ( 1 == ret) { + return true; + } else { + return false; + } +} + +bool JobWidgetInstall::DecryptDRMWidget(std::string widgetPath, + std::string destPath) +{ + /* TODO : + drm_trusted_sapps_decrypt_package_info_s package_info; + + strncpy(package_info.sadcf_filepath, widgetPath.c_str(), + sizeof(package_info.sadcf_filepath)); + strncpy(package_info.decrypt_filepath, destPath.c_str(), + sizeof(package_info.decrypt_filepath)); + + drm_trusted_request_type_e requestType = + DRM_TRUSTED_REQ_TYPE_SAPPS_DECRYPT_PACKAGE; + + int ret = drm_trusted_handle_request(requestType, + (void *)&package_info, NULL); + if (DRM_TRUSTED_RETURN_SUCCESS == ret) { + return true; + } else { + return false; + } + */ + if (drm_oem_intel_decrypt_package(const_cast(widgetPath.c_str()), + const_cast(destPath.c_str())) != 0) { + return true; + } else { + return false; + } +} + } //namespace WidgetInstall } //namespace Jobs diff --git a/src/jobs/widget_install/job_widget_install.h b/src/jobs/widget_install/job_widget_install.h index 6e4281b..fa39392 100644 --- a/src/jobs/widget_install/job_widget_install.h +++ b/src/jobs/widget_install/job_widget_install.h @@ -48,6 +48,8 @@ class JobWidgetInstall : Exceptions::Type m_exceptionCaught; std::string m_exceptionMessage; WidgetUpdateInfo m_widgetUpdateInfo; + bool m_needEncryption; + bool m_isDRM; enum class ConfigureResult { @@ -58,10 +60,12 @@ class JobWidgetInstall : const WrtDB::ConfigParserData &configData, const WidgetUpdateInfo &update, - bool browserRequest); + const std::string &tempPath); static WrtDB::ConfigParserData getWidgetDataFromXML( const std::string &widgetSource, - bool fromBrowser, WrtDB::PkgType isOspsvc); + const std::string &tempPath, + WrtDB::PackagingType pkgType, + bool isDRM); static WidgetUpdateInfo detectWidgetUpdate( const WrtDB::ConfigParserData &configInfo); WidgetUpdateMode::Type CalcWidgetUpdatePolicy( @@ -70,12 +74,17 @@ class JobWidgetInstall : bool setTizenId(const WrtDB::ConfigParserData &configInfo, ConfigureResult result); void displayWidgetInfo(); - void configureWidgetLocation(const std::string & widgetPath, bool browserRequest); + void configureWidgetLocation(const std::string & widgetPath, + const std::string &tempPath); WrtDB::PackagingType checkPackageType( - const std::string &widgetSorce); + const std::string &widgetSource, + const std::string &tempPath); bool detectResourceEncryption(const WrtDB::ConfigParserData &configData); std::string generateTizenId(); + bool isDRMWidget(std::string widgetPath); + bool DecryptDRMWidget(std::string widgetPath, std::string destPath); + ConfigureResult PrePareInstallation(const std::string &widgetPath); public: /** diff --git a/src/jobs/widget_install/task_ace_check.cpp b/src/jobs/widget_install/task_ace_check.cpp index 616a1bd..c1b0a98 100644 --- a/src/jobs/widget_install/task_ace_check.cpp +++ b/src/jobs/widget_install/task_ace_check.cpp @@ -95,7 +95,8 @@ void TaskAceCheck::StepAceCheck() void TaskAceCheck::StepProcessAceResponse() { WrtDB::WidgetDAO dao(m_context.locations->getPkgname()); - if (m_context.locations->browserRequest()) { + if (m_context.widgetConfig.packagingType == + WrtDB::PKG_TYPE_HOSTED_WEB_APP) { return; } diff --git a/src/jobs/widget_install/task_certify.cpp b/src/jobs/widget_install/task_certify.cpp index f060447..532c206 100755 --- a/src/jobs/widget_install/task_certify.cpp +++ b/src/jobs/widget_install/task_certify.cpp @@ -437,7 +437,7 @@ void TaskCertify::stepAuthorInfoPopupAnswer() bool TaskCertify::isTizenWebApp() const { bool ret = FALSE; - if (m_installContext.widgetConfig.type.appType + if (m_installContext.widgetConfig.webAppType.appType == WrtDB::AppType::APP_TYPE_TIZENWEBAPP) ret = TRUE; diff --git a/src/jobs/widget_install/task_encrypt_resource.cpp b/src/jobs/widget_install/task_encrypt_resource.cpp index cbcf554..d133d83 100644 --- a/src/jobs/widget_install/task_encrypt_resource.cpp +++ b/src/jobs/widget_install/task_encrypt_resource.cpp @@ -21,6 +21,8 @@ */ #include "task_encrypt_resource.h" +#undef __USE_FILE_OFFSET64 + #include #include #include diff --git a/src/jobs/widget_install/task_file_manipulation.cpp b/src/jobs/widget_install/task_file_manipulation.cpp index 48abe91..ae02d73 100644 --- a/src/jobs/widget_install/task_file_manipulation.cpp +++ b/src/jobs/widget_install/task_file_manipulation.cpp @@ -61,7 +61,7 @@ void TaskFileManipulation::StepCreateDirs() // If package type is widget with osp service, we don't need to make bin // and src directory - if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) { + if (m_context.widgetConfig.packagingType == PKG_TYPE_HYBRID_WEB_APP) { LogDebug("Doesn't need to create resource directory"); } else { LogDebug("Create resource directory"); @@ -82,7 +82,7 @@ void TaskFileManipulation::StepRenamePath() ThrowMsg(Exceptions::InternalError, "No Package name exists."); } - if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) { + if (m_context.widgetConfig.packagingType == PKG_TYPE_HYBRID_WEB_APP) { instDir = m_context.locations->getPackageInstallationDir(); } else { instDir = m_context.locations->getSourceDir(); @@ -108,7 +108,7 @@ void TaskFileManipulation::StepAbortRenamePath() { LogDebug("[Rename Widget Path] Aborting.... (Rename path)"); std::string widgetPath; - if (m_context.widgetConfig.pType == PKG_TYPE_TIZEN_WITHSVCAPP) { + if (m_context.widgetConfig.packagingType == PKG_TYPE_HYBRID_WEB_APP) { widgetPath = m_context.locations->getPackageInstallationDir(); } else { widgetPath = m_context.locations->getSourceDir(); diff --git a/src/jobs/widget_install/task_manifest_file.cpp b/src/jobs/widget_install/task_manifest_file.cpp index 0c97454..3acb023 100644 --- a/src/jobs/widget_install/task_manifest_file.cpp +++ b/src/jobs/widget_install/task_manifest_file.cpp @@ -182,8 +182,9 @@ void TaskManifestFile::stepCopyIconFiles() targetFile << GlobalConfig::GetUserWidgetDesktopIconPath() << "/"; targetFile << getIconTargetFilename(*locale); - if (m_context.locations->browserRequest()) - { + + if (m_context.widgetConfig.packagingType == + WrtDB::PKG_TYPE_HOSTED_WEB_APP) { m_context.locations->setIconTargetFilenameForLocale(targetFile.str()); } diff --git a/src/jobs/widget_install/task_widget_config.cpp b/src/jobs/widget_install/task_widget_config.cpp index c1f0706..420c0dd 100644 --- a/src/jobs/widget_install/task_widget_config.cpp +++ b/src/jobs/widget_install/task_widget_config.cpp @@ -257,7 +257,7 @@ void TaskWidgetConfig::ProcessStartFile(const DPL::OptionalString& path, } else { // set property data for hosted start url // Hosted start url only support TIZEN WebApp - if (m_installContext.widgetConfig.type == + if (m_installContext.widgetConfig.webAppType == APP_TYPE_TIZENWEBAPP) { const char *startPath = @@ -423,7 +423,7 @@ void TaskWidgetConfig::StepShowWidgetInfo() void TaskWidgetConfig::StepCheckMinVersionInfo() { if (!isMinVersionCompatible( - m_installContext.widgetConfig.type.appType, + m_installContext.widgetConfig.webAppType.appType, m_installContext.widgetConfig.minVersion)) { std::string label = WIDGET_NOT_COMPATIBLE + QUESTION; createInstallPopup(PopupType::WIDGET_MIN_VERSION, label); @@ -448,14 +448,14 @@ void TaskWidgetConfig::StepVerifyFeatures() // check feature vender for permission // WAC, TIZEN WebApp cannot use other feature - if (!isFeatureAllowed(m_installContext.widgetConfig.type.appType, + if (!isFeatureAllowed(m_installContext.widgetConfig.webAppType.appType, it->name)) { LogInfo("This application type not allowed to use this feature"); ThrowMsg( Exceptions::WidgetConfigFileInvalid, "This app type [" << - m_installContext.widgetConfig.type.getApptypeToString() << + m_installContext.widgetConfig.webAppType.getApptypeToString() << "] cannot be allowed to use [" << DPL::ToUTF8String(it->name) + "] feature"); } @@ -522,9 +522,9 @@ void TaskWidgetConfig::setApplicationType() currentAppType = APP_TYPE_TIZENWEBAPP; } - if (widgetInfo->type == APP_TYPE_UNKNOWN) { - widgetInfo->type = currentAppType; - } else if (widgetInfo->type == currentAppType) { + if (widgetInfo->webAppType == APP_TYPE_UNKNOWN) { + widgetInfo->webAppType = currentAppType; + } else if (widgetInfo->webAppType == currentAppType) { continue; } else { ThrowMsg(Exceptions::WidgetConfigFileInvalid, @@ -533,11 +533,11 @@ void TaskWidgetConfig::setApplicationType() } // If there is no define, type set to WAC 2.0 - if (widgetInfo->type == APP_TYPE_UNKNOWN) { - widgetInfo->type = APP_TYPE_WAC20; + if (widgetInfo->webAppType == APP_TYPE_UNKNOWN) { + widgetInfo->webAppType = APP_TYPE_WAC20; } - LogInfo("type = [" << widgetInfo->type.getApptypeToString() << "]"); + LogInfo("type = [" << widgetInfo->webAppType.getApptypeToString() << "]"); } bool TaskWidgetConfig::isFeatureAllowed(WrtDB::AppType appType, @@ -644,7 +644,7 @@ bool TaskWidgetConfig::isMinVersionCompatible(WrtDB::AppType appType, bool TaskWidgetConfig::isTizenWebApp() const { bool ret = FALSE; - if (m_installContext.widgetConfig.type.appType + if (m_installContext.widgetConfig.webAppType.appType == WrtDB::AppType::APP_TYPE_TIZENWEBAPP) ret = TRUE; diff --git a/src/jobs/widget_install/widget_unzip.cpp b/src/jobs/widget_install/widget_unzip.cpp new file mode 100644 index 0000000..b8d0b98 --- /dev/null +++ b/src/jobs/widget_install/widget_unzip.cpp @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * @file widget_unzip.cpp + * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com) + * @version 1.0 + * @brief Implementation file for installer task unzip + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace WrtDB; + +namespace { +struct PathAndFilePair +{ + std::string path; + std::string file; + + PathAndFilePair(const std::string &p, + const std::string &f) : + path(p), + file(f) + { + } +}; + +PathAndFilePair SplitFileAndPath(const std::string &filePath) +{ + std::string::size_type position = filePath.rfind('/'); + + // Is this only a file without a path ? + if (position == std::string::npos) { + return PathAndFilePair(std::string(), filePath); + } + + // This is full file-path pair + return PathAndFilePair(filePath.substr(0, + position), + filePath.substr(position + 1)); +} +} + +namespace Jobs { +namespace WidgetInstall { +WidgetUnzip::WidgetUnzip(std::string source, std::string path) : + m_source(source), + m_destPath(path) +{ + LogDebug("WidgetUnzip"); +} + +void WidgetUnzip::ExtractFile(DPL::ZipInput::File *input, + const std::string &destFileName) +{ + Try + { + DPL::AbstractWaitableInputAdapter inputAdapter(input); + DPL::FileOutput output(destFileName); + + DPL::Copy(&inputAdapter, &output); + } + Catch(DPL::FileOutput::Exception::OpenFailed) + { + ReThrowMsg(Exceptions::ExtractFileFailed, destFileName); + } + Catch(DPL::CopyFailed) + { + ReThrowMsg(Exceptions::ExtractFileFailed, destFileName); + } +} + +void WidgetUnzip::UnzipWidget() +{ + UnzipPrepare(); + UnzipProgress(); +} + +void WidgetUnzip::UnzipPrepare() +{ + LogInfo("Prepare to unzip..."); + + Try + { + m_zip.reset(new DPL::ZipInput(m_source)); + LogInfo("Widget package comment: " << m_zip->GetGlobalComment()); + + // Widget package must not be empty + if (m_zip->empty()) { + ThrowMsg(Exceptions::ZipEmpty, m_source); + } + + // Set iterator to first file + m_zipIterator = m_zip->begin(); + } + Catch(DPL::ZipInput::Exception::OpenFailed) + { + ReThrowMsg(Exceptions::OpenZipFailed, m_source); + } +} + +void WidgetUnzip::UnzipProgress() +{ + + // Show file info + LogInfo("Unzipping: '" << m_zipIterator->name << + "', Comment: '" << m_zipIterator->comment << + "', Compressed size: " << m_zipIterator->compressedSize << + ", Uncompressed size: " << m_zipIterator->uncompressedSize); + + + // Normalize file paths + // FIXME: Implement checking for invalid characters + + // Extract file or path + std::string fileName = m_zipIterator->name; + + if (fileName[fileName.size() - 1] == '/') { + // This is path + std::string newPath = m_destPath + "/" + + fileName.substr(0, fileName.size() - 1); + LogPedantic("Path to extract: " << newPath); + + // Create path in case of it is empty + createTempPath(newPath); + } else { + // This is regular file + std::string fileExtractPath = m_destPath + "/" + fileName; + + LogPedantic("File to extract: " << fileExtractPath); + + // Split into pat & file pair + PathAndFilePair pathAndFile = SplitFileAndPath(fileExtractPath); + + LogPedantic("Path and file: " << + pathAndFile.path << + " : " << pathAndFile.file); + + // First, ensure that path exists + createTempPath(pathAndFile.path); + + Try + { + // Open file + std::unique_ptr file( + m_zip->OpenFile(fileName)); + + // Extract single file + ExtractFile(file.get(), fileExtractPath); + } + Catch(DPL::ZipInput::Exception::OpenFileFailed) + { + ThrowMsg(Exceptions::ExtractFileFailed, fileName); + } + } + + // Check whether there are more files to extract + if (++m_zipIterator == m_zip->end()) { + LogInfo("Unzip progress finished successfuly"); + m_zip.reset(); + } else { + UnzipProgress(); + } +} + +void WidgetUnzip::UnzipDRMWidget() +{ + LogDebug("Decrypt drm widget"); + drm_trusted_sapps_decrypt_package_info_s package_info; + + strncpy(package_info.sadcf_filepath, m_source.c_str(), + sizeof(package_info.sadcf_filepath)); + strncpy(package_info.decrypt_filepath, m_destPath.c_str(), + sizeof(package_info.decrypt_filepath)); + + drm_trusted_request_type_e requestType = + DRM_TRUSTED_REQ_TYPE_SAPPS_DECRYPT_PACKAGE; + + int ret = drm_trusted_handle_request(requestType, + (void *)&package_info, NULL); + if (DRM_TRUSTED_RETURN_SUCCESS != ret) { + LogDebug("Failed unzip drm widget"); + ThrowMsg(Exceptions::ExtractFileFailed, m_destPath); + } +} +} //namespace WidgetInstall +} //namespace Jobs diff --git a/src/jobs/widget_install/widget_unzip.h b/src/jobs/widget_install/widget_unzip.h new file mode 100644 index 0000000..7c7b4ca --- /dev/null +++ b/src/jobs/widget_install/widget_unzip.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * @file widget_unzip.cpp + * @author Przemyslaw Dobrowolski (p.dobrowolsk@samsung.com) + * @version 1.0 + * @brief Implementation file for installer task unzip + */ +#ifndef INSTALLER_CORE_JOS_WIDGET_INSTALL_WIDGET_UNZIP_H +#define INSTALLER_CORE_JOS_WIDGET_INSTALL_WIDGET_UNZIP_H + +#include +#include + +#include + +class InstallerContext; + +namespace Jobs { +namespace WidgetInstall { +class WidgetUnzip +{ + private: + // Installation context + std::string m_source; + std::string m_destPath; + + // Unzip state + std::unique_ptr m_zip; + DPL::ZipInput::const_iterator m_zipIterator; + + void ExtractFile(DPL::ZipInput::File *input, + const std::string &destFileName); + + void UnzipPrepare(); + void UnzipProgress(); + + public: + WidgetUnzip(std::string m_source, std::string m_destPath); + void UnzipWidget(); + void UnzipDRMWidget(); +}; +} //namespace WidgetInstall +} //namespace Jobs + +#endif // INSTALLER_CORE_JOS_WIDGET_INSTALL_WIDGET_UNZIP_H diff --git a/src/jobs/widget_uninstall/job_widget_uninstall.cpp b/src/jobs/widget_uninstall/job_widget_uninstall.cpp index 0bfc879..392106f 100644 --- a/src/jobs/widget_uninstall/job_widget_uninstall.cpp +++ b/src/jobs/widget_uninstall/job_widget_uninstall.cpp @@ -77,7 +77,7 @@ JobWidgetUninstall::JobWidgetUninstall(const std::string & widgetPkgName, AddTask(new TaskSmack(m_context)); AddTask(new TaskCheck(m_context)); - if (dao.getPkgType() == PKG_TYPE_TIZEN_WITHSVCAPP) { + if (dao.getPackagingType() == PKG_TYPE_HYBRID_WEB_APP) { AddTask(new TaskUninstallOspsvc(m_context)); } AddTask(new TaskRemoveFiles(m_context)); diff --git a/src/misc/widget_location.cpp b/src/misc/widget_location.cpp index 712f344..b899bec 100644 --- a/src/misc/widget_location.cpp +++ b/src/misc/widget_location.cpp @@ -34,6 +34,11 @@ WidgetLocation::DirectoryDeletor::DirectoryDeletor() m_dirpath = Jobs::WidgetInstall::createTempPath(); } +WidgetLocation::DirectoryDeletor::DirectoryDeletor(std::string tempPath) +{ + m_dirpath = tempPath; +} + WidgetLocation::DirectoryDeletor::~DirectoryDeletor() { LogDebug("Removing widget installation temporary directory: " << m_dirpath.c_str()); @@ -45,11 +50,12 @@ std::string WidgetLocation::DirectoryDeletor::getTempPath() const return m_dirpath; } -WidgetLocation::WidgetLocation() : m_browser(false) +WidgetLocation::WidgetLocation() { } -WidgetLocation::WidgetLocation(const std::string & widgetname) : m_pkgname(widgetname), m_browser(false) +WidgetLocation::WidgetLocation(const std::string & widgetname) : + m_pkgname(widgetname) { } @@ -59,16 +65,26 @@ WidgetLocation::~WidgetLocation() WidgetLocation::WidgetLocation(const std::string & widgetname, std::string sourcePath, - bool browserRequest, - WrtDB::PkgType t): + WrtDB::PackagingType t): m_pkgname(widgetname), m_widgetSource(sourcePath), - m_browser(browserRequest), m_type(t), m_temp(new WidgetLocation::DirectoryDeletor()) { } +WidgetLocation::WidgetLocation(const std::string & widgetname, + std::string sourcePath, + std::string dirPath, + WrtDB::PackagingType t): + m_pkgname(widgetname), + m_widgetSource(sourcePath), + m_type(t), + m_temp(new + WidgetLocation::DirectoryDeletor(dirPath)) +{ +} + // TODO cache all these paths std::string WidgetLocation::getInstallationDir() const { @@ -123,14 +139,9 @@ std::string WidgetLocation::getTemporaryPackageDir() const return m_temp->getTempPath(); } -bool WidgetLocation::browserRequest() const -{ - return m_browser; -} - std::string WidgetLocation::getTemporaryRootDir() const { - if(m_type == WrtDB::PKG_TYPE_TIZEN_WITHSVCAPP) + if(m_type == WrtDB::PKG_TYPE_HYBRID_WEB_APP) { return getTemporaryPackageDir() + WrtDB::GlobalConfig::GetWidgetSrcPath(); } @@ -142,7 +153,7 @@ std::string WidgetLocation::getTemporaryRootDir() const std::string WidgetLocation::getConfigurationDir() const { - if(m_browser) + if(m_type == WrtDB::PKG_TYPE_HOSTED_WEB_APP) { std::string path = "."; int index = m_widgetSource.find_last_of("\\/"); diff --git a/src/misc/widget_location.h b/src/misc/widget_location.h index 84106e4..ab9fa29 100644 --- a/src/misc/widget_location.h +++ b/src/misc/widget_location.h @@ -57,6 +57,7 @@ class WidgetLocation { public: DirectoryDeletor(); + DirectoryDeletor(std::string tempPath); ~DirectoryDeletor(); std::string getTempPath() const; private: @@ -84,14 +85,17 @@ public: * @brief WidgetLocation Builds paths for widget location during installation * * @param widgetname name of widget - * @param browserRequest is browser Request * @param sourcePath given source path * @param t declaraced type of widget if type is needed * * In destruction removes temporary directory */ WidgetLocation(const std::string & widgetname, std::string sourcePath, - bool browserRequest = false, WrtDB::PkgType t = WrtDB::PKG_TYPE_TIZEN_WEBAPP); + WrtDB::PackagingType t = WrtDB::PKG_TYPE_NOMAL_WEB_APP); + + WidgetLocation(const std::string & widgetname, std::string sourcePath, + std::string dirPath, + WrtDB::PackagingType t = WrtDB::PKG_TYPE_NOMAL_WEB_APP); ~WidgetLocation(); // Installed paths @@ -105,8 +109,6 @@ public: std::string getBackupBinaryDir() const; // /opt/apps/[package]/backup/bin std::string getBackupExecFile() const; // /opt/apps/[package]/backup/bin/[package] - bool browserRequest() const; - // Temporary paths /** * @brief getTemporaryRootDir @@ -178,10 +180,9 @@ public: private: std::string m_widgetSource; // Source widget zip file/widget url - bool m_browser; // is browser request installation std::string m_pkgname; //name of package std::string m_iconPath; //installed icon path - WrtDB::PkgType m_type; + WrtDB::PackagingType m_type; std::shared_ptr m_temp; //directory WrtDB::ExternalLocationList m_externals; };