Fix build warning and add related gcc options 12/61712/5 submit/tizen/20160311.052312
authorKyungwook Tak <k.tak@samsung.com>
Thu, 10 Mar 2016 04:32:42 +0000 (13:32 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Fri, 11 Mar 2016 05:17:38 +0000 (14:17 +0900)
Werror, Wall, Wextra options added

Change-Id: Ia4a361babc4e50704641d27ee47066cb421fe5a0
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
19 files changed:
CMakeLists.txt
service/drm-tapps-initialize.cpp
service/drm-tapps.cpp
tadcore/DrmFileHandleMgr/DrmFileApi.cpp
tadcore/DrmFileHandleMgr/DrmFileMgr.cpp
tadcore/TADCCore/TADC_Core.cpp
tadcore/TADCCore/TADC_Util.cpp
tadcore/TADCInterface/TADC_IF.cpp
tadcore/include/DrmFileApi.h
tadcore/include/DrmFileMgr.h
tadcore/include/TADC_IF.h
tappsd/src/rights/DTapps2Rights.cpp
tappsd/src/util/DTapps2Time.cpp
test/CMakeLists.txt
test/drm_testapps.cpp
test/drm_testcore.cpp [new file with mode: 0644]
test/drm_testcore.h [new file with mode: 0644]
test/drm_testutil.cpp
test/drm_testutil.h

index 7cc97ff..efb9776 100644 (file)
@@ -32,6 +32,11 @@ SET(CMAKE_CXX_FLAGS_CCOV       "-g -std=c++0x -O2 --coverage")
 
 ADD_DEFINITIONS("-fPIC")
 
+# Set compiler warning flags
+ADD_DEFINITIONS("-Werror")                      # Make all warnings into errors.
+ADD_DEFINITIONS("-Wall")                        # Generate all warnings
+ADD_DEFINITIONS("-Wextra")                      # Generate even more extra warnings
+
 INCLUDE_DIRECTORIES(
     SYSTEM
     ${CMAKE_CURRENT_SOURCE_DIR}/tadcore/include
index 2d0952e..e8910e1 100644 (file)
@@ -107,7 +107,7 @@ ErrorExit:
        return -1;
 }
 
-int main(int argc, char* argv[])
+int main(int, char *[])
 {
        DRM_TAPPS_FRQ_LOG("=============Start Create TAD DB file ================\n\n ");
 
index 2cc8c5e..cb7472d 100644 (file)
@@ -81,14 +81,13 @@ int _drm_tapps_register_license(const char *pRespBuf, unsigned int respBufLen);
 int _drm_tapps_decrypt_package(const char *pTADCFilepath, int stadFileLen, const char *pDecryptedFile, int decryptedFileLen);
 int _drm_tapps_is_drm_file(const char *pDcfPath, int dcfPathLen);
 
-EXPORT_API int drm_tizen_generate_license_request
-(
-       const char *pRespBuf,                   //Response Data String of the Purchase Request ( Null terminator string )
-       unsigned int respBufLen,                        //pResBuf Length
-       char *pReqBuf,                          //License Request Data
-       unsigned int *pReqBufLen,               //IN : pReqBuf Length, OUT : Rights Request Data String Size ( including null terminator )
-       char *pLicenseUrl,                      //License Acquisition URL Data
-       unsigned int *pLicenseUrlLen    //IN : pLicenseUrl Length, OUT : Rights Issuer Server URL Data String Size (  including null terminator )
+EXPORT_API int drm_tizen_generate_license_request(
+       const char *pRespBuf,        //Response Data String of the Purchase Request ( Null terminator string )
+       unsigned int respBufLen,     //pResBuf Length
+       char *pReqBuf,               //License Request Data
+       unsigned int *pReqBufLen,    //IN : pReqBuf Length, OUT : Rights Request Data String Size ( including null terminator )
+       char *pLicenseUrl,           //License Acquisition URL Data
+       unsigned int *pLicenseUrlLen //IN : pLicenseUrl Length, OUT : Rights Issuer Server URL Data String Size (  including null terminator )
 )
 {
        int ret = TADC_SUCCESS;
@@ -112,14 +111,13 @@ EXPORT_API int drm_tizen_generate_license_request
        return ret;
 }
 
-int _drm_tapps_generate_license_request
-(
-       const char *pRespBuf,           //Response Data String of the Purchase Request ( Null terminator string )
-       unsigned int respBufLen,        //pResBuf Length
-       char *pReqBuf,                          //License Request Data
-       unsigned int *pReqBufLen,       //IN : pReqBuf Length, OUT : Rights Request Data String Size ( including null terminator )
-       char *pLicenseUrl,                      //License Acquisition URL Data
-       unsigned int *pLicenseUrlLen//IN : pLicenseUrl Length, OUT : Rights Issuer Server URL Data String Size (  including null terminator )
+int _drm_tapps_generate_license_request(
+       const char *pRespBuf,        //Response Data String of the Purchase Request ( Null terminator string )
+       unsigned int respBufLen,     //pResBuf Length
+       char *pReqBuf,               //License Request Data
+       unsigned int *pReqBufLen,    //IN : pReqBuf Length, OUT : Rights Request Data String Size ( including null terminator )
+       char *pLicenseUrl,           //License Acquisition URL Data
+       unsigned int *pLicenseUrlLen //IN : pLicenseUrl Length, OUT : Rights Issuer Server URL Data String Size (  including null terminator )
 )
 {
        int ret = TADC_SUCCESS;
@@ -170,11 +168,7 @@ EXPORT_API int drm_tizen_register_license
        return ret;
 }
 
-int _drm_tapps_register_license
-(
-       const char *pRespBuf,                           //Response Data String of the Rights Request ( Null terminator string )
-       unsigned int respBufLen                         //pResBuf Length
-)
+int _drm_tapps_register_license(const char *pRespBuf, unsigned int respBufLen)
 {
        DRM_TAPPS_API_TIME()
 
@@ -310,10 +304,13 @@ int _drm_tapps_decrypt_package
        DRM_TAPPS_API_TIME()
 
        bool bRet = true;
-       int     ret = TADC_SUCCESS;
+       int ret = TADC_SUCCESS;
+
+       T_RO t_RO;
+       DrmTdcFileHeader fileHeader;
 
-       T_RO   t_RO = {0,};
-       DrmTdcFileHeader fileHeader = {{0}};
+       memset(&t_RO, 0x00, sizeof(t_RO));
+       memset(&fileHeader, 0x00, sizeof(fileHeader));
 
        DRM_TAPPS_LOG("%s starts", __func__);
        if (pTADCFilepath == NULL || pDecryptedFile == NULL)
index 0746450..1447364 100644 (file)
@@ -19,7 +19,7 @@
 #include "drm_intf_tapps.h"
 
 EXPORT_API
-int DrmTdcFileOpen(const char* filePath, int mode, int* handle)
+int DrmTdcFileOpen(const char* filePath, int* handle)
 {
        int nRet = TADC_SUCCESS;
        int key = 0;
@@ -39,7 +39,7 @@ int DrmTdcFileOpen(const char* filePath, int mode, int* handle)
                return TADC_GET_FILE_HANDLER_ERROR;
        }
 
-       nRet = pDrmFileMgr->OpenFileHandler(filePath, 1, &key);
+       nRet = pDrmFileMgr->OpenFileHandler(filePath, &key);
        if (nRet != TADC_SUCCESS)
        {
                DRM_TAPPS_EXCEPTION("DrmFileMgr::OpenFileHandler() error!");
index d1e1ae0..f50e6b0 100644 (file)
@@ -67,7 +67,7 @@ void DrmFileMgr::Construct(void)
        srand(time(NULL));
 }
 
-int DrmFileMgr::OpenFileHandler(const char *filePath, int mode, int *key)
+int DrmFileMgr::OpenFileHandler(const char *filePath, int *key)
 {
        //DRM_TAPPS_LOG("%s) started. key=%d", __func__, *key);
 
index e40bb58..0fe1ece 100644 (file)
@@ -15,8 +15,8 @@
  */
 
 /**
- * @file       TADC_Core.cpp
- * @brief      This file includes implementations of the Tizen Apps DRM Core APIs.
+ * @file    TADC_Core.cpp
+ * @brief   This file includes implementations of the Tizen Apps DRM Core APIs.
 */
 
 #include "drm-tizen-error.h"
 #include "TADC_IF.h"
 #include "TADC_ErrorCode.h"
 
-static BYTE g_baSignatureKey[ 32 ] =
-{
-       0x29, 0x2b, 0xf2, 0x29, 0x1f, 0x8b, 0x47, 0x81, 0x95, 0xa, 0x84, 0xf8, 0x91, 0xda, 0x7, 0xd0,
+static BYTE g_baSignatureKey[32] = {
+       0x29, 0x2b, 0xf2, 0x29, 0x1f, 0x8b, 0x47, 0x81, 0x95, 0x0a, 0x84, 0xf8, 0x91, 0xda, 0x07, 0xd0,
        0x9c, 0xde, 0x32, 0x3e, 0x9e, 0x46, 0x4a, 0xfc, 0xa4, 0xcc, 0x55, 0x6e, 0xf2, 0x81, 0x61, 0xdb
 };
 
-static BYTE    g_baAESKey[ 32 ] =
-{
-       -8, -121, 10, -59, -45, 109, 68, 73, 3, -97, -67, 30, -88, 47, -10,
-       -61, -33, 59, 2, 19, 88, 27, 18, 48, 28, -41, -83, -91, 31, 93, 1, 51
+static BYTE g_baAESKey[32] = {
+       0xf8, 0x87, 0x0a, 0xc5, 0xd3, 0x6d, 0x44, 0x49, 0x03, 0x9f, 0xbd, 0x1e, 0xa8, 0x2f, 0xf6, 0xc3,
+       0xdf, 0x3b, 0x02, 0x13, 0x58, 0x1b, 0x12, 0x30, 0x1c, 0xd7, 0xad, 0xa5, 0x1f, 0x5d, 0x01, 0x33
 };
 
 //Error Code
 static DWORD g_TADCErrorCode = 0;
 
-int    TADC_SetDeviceInfo(T_DEVICE_INFO *t_DeviceInfo)
+int TADC_SetDeviceInfo(T_DEVICE_INFO *t_DeviceInfo)
 {
        int nResult = 0;
 
@@ -53,11 +51,11 @@ int TADC_SetDeviceInfo(T_DEVICE_INFO *t_DeviceInfo)
        return nResult;
 }
 
-int    TADC_MakeRequestLicense( T_DEVICE_INFO *t_DeviceInfo,
-                                                        T_FILE_HEADER *t_FileHeader,
-                                                        T_DRM_HEADER *t_DRMHeader,
-                                                        unsigned char * outBuffer,
-                             size_t outBufferSize)
+int TADC_MakeRequestLicense(T_DEVICE_INFO *t_DeviceInfo,
+                                                       T_FILE_HEADER *t_FileHeader,
+                                                       T_DRM_HEADER *t_DRMHeader,
+                                                       unsigned char * outBuffer,
+                                                       size_t outBufferSize)
 {
        int nResult = 0;
        size_t length = 0;
@@ -79,7 +77,7 @@ int   TADC_MakeRequestLicense( T_DEVICE_INFO *t_DeviceInfo,
 
        snprintf(
                (char*)outBuffer + length,
-        outBufferSize - length,
+               outBufferSize - length,
                "<ContentInfo>\n<DRMType>%d</DRMType>\n<sid>%s</sid>\n<cid>%s</cid>\n</ContentInfo>\n</request>",
                        t_FileHeader->DRMType,
                        t_DRMHeader->SID,
@@ -92,12 +90,12 @@ int TADC_MakeRequestLicense( T_DEVICE_INFO *t_DeviceInfo,
        return nResult;
 }
 
-int    TADC_GetROAcqInfo(unsigned char * inBuffer, T_ROACQ_INFO *t_ROAcqInfo)
+int TADC_GetROAcqInfo(unsigned char * inBuffer, T_ROACQ_INFO *t_ROAcqInfo)
 {
-       int     nResult = -1;
-       int     i = 0, j = 0;
-       int     nSize = 0;
-       int     length = 0;
+       int nResult = -1;
+       int i = 0, j = 0;
+       int nSize = 0;
+       int length = 0;
 
        //Check Param buffer
        IF_TRUE_RETURN(inBuffer == NULL, TADC_PARAMETER_ERROR);
@@ -184,23 +182,23 @@ int       TADC_GetROAcqInfo(unsigned char * inBuffer, T_ROACQ_INFO *t_ROAcqInfo)
        return nResult;
 }
 
-int    TADC_MakeRequestRO(T_ROACQ_INFO *t_ROAcqInfo, unsigned char * outBuffer, size_t outBufferSize, unsigned char * ROVer)
+int TADC_MakeRequestRO(T_ROACQ_INFO *t_ROAcqInfo, unsigned char * outBuffer, size_t outBufferSize, unsigned char * ROVer)
 {
-       BYTE            sha1_tmp[20];
-       TADC_U8         *ReqTemp;
-       LPSTR           psz64Parameter = NULL;
+       BYTE sha1_tmp[20];
+       TADC_U8ReqTemp;
+       LPSTR psz64Parameter = NULL;
 
-       TADC_U8         key[16];
-       TADC_U8         iv[16];
+       TADC_U8 key[16];
+       TADC_U8 iv[16];
 
-       int                     outlen = 0;
-       int                     nResult = 0;
+       int outlen = 0;
+       int nResult = 0;
 
-       size_t          StrSize = 0;
-       size_t          len = 0;
-       size_t          i = 0;
-       size_t          k = 0;
-       size_t          reqdataset_size = 0;
+       size_t StrSize = 0;
+       size_t len = 0;
+       size_t i = 0;
+       long k = 0;
+       size_t reqdataset_size = 0;
 
        // Debug
        DRM_TAPPS_LOG("Debug Log == TADC_MakeRequestRO  : Start    \n");
@@ -296,7 +294,7 @@ int TADC_MakeRequestRO(T_ROACQ_INFO *t_ROAcqInfo, unsigned char * outBuffer, siz
 
        TADC_IF_MemCpy(key, &g_baAESKey[0], 16);
        TADC_IF_MemCpy(iv, &g_baAESKey[16], 16);
-       TADC_IF_AES_CTR(16, key, 16, iv, 20, (unsigned char*)sha1_tmp, &outlen, (unsigned char*)sha1_tmp);
+       TADC_IF_AES_CTR(key, 16, iv, 20, (unsigned char*)sha1_tmp, &outlen, (unsigned char*)sha1_tmp);
 
        // Debug
        DRM_TAPPS_LOG("Debug Log == TADC_MakeRequestRO  : After TADC_IF_AES_CTR  \n");
@@ -336,12 +334,12 @@ int       TADC_MakeRequestRO(T_ROACQ_INFO *t_ROAcqInfo, unsigned char * outBuffer, siz
        return len;
 }
 
-int    TADC_GetHashReqID(unsigned char * inBuffer, unsigned char *hashReqID)
+int TADC_GetHashReqID(unsigned char * inBuffer, unsigned char *hashReqID)
 {
-       int             i = 0, j = 0, nSize = 0;
-       char    tmpbuf[512];
-       int             length = 0;
-       int     nResult = 0;
+       int i = 0, j = 0, nSize = 0;
+       char tmpbuf[512];
+       int length = 0;
+       int nResult = 0;
 
        //Check Param Buffer
        IF_TRUE_RETURN(inBuffer == NULL, TADC_PARAMETER_ERROR);
@@ -414,42 +412,38 @@ int       TADC_GetHashReqID(unsigned char * inBuffer, unsigned char *hashReqID)
        return 0;
 }
 
-int    TADC_GetResponseRO(unsigned char * inBuffer, T_ROACQ_INFO *t_ROAcqInfo, T_RO *t_RO, unsigned char *outBuffer)
+int TADC_GetResponseRO(unsigned char * inBuffer, T_ROACQ_INFO *t_ROAcqInfo, T_RO *t_RO, unsigned char *outBuffer)
 {
-       int                     nHMacSize = 28; // Base64 Enc length of SHA1 20byte
-       TADC_U8         sha1_tmp[20] = {0, };
-       char            hmacBuf[512] = {0, };
-       BYTE            *ReqTemp = NULL;
-       LPBYTE          pbBuffer = NULL;
+       int nHMacSize = 28; // Base64 Enc length of SHA1 20byte
+       TADC_U8 sha1_tmp[20] = {0, };
+       char hmacBuf[512] = {0, };
+       BYTE *ReqTemp = NULL;
+       LPBYTE pbBuffer = NULL;
 
-       TADC_U8         key[16] = {0, };
-       TADC_U8         iv[16] = {0, };
+       TADC_U8 key[16] = {0, };
+       TADC_U8 iv[16] = {0, };
 
-       int                     outlen = 0;
+       int outlen = 0;
 
-       char            *License = NULL;
-       TCHAR           tmpDH_B[DHKey_SIZE * 2 + 1] = {0, };
+       char *License = NULL;
+       TCHAR tmpDH_B[DHKey_SIZE * 2 + 1] = {0, };
 
        // RO XML Parser
-       CXMLFile                        XMLParser;
-       CPointerArray           paChilds;
+       CXMLFile XMLParser;
+       CPointerArray paChilds;
 
        //2011.03.08
-       char                    *timeStamp = NULL;
-       int                             retLen = 0;
-       int                             i = 0, j = 0;
-       int                             nSize = 0;
-       int                             length = 0;
-       int                             req_length = 0;
-       int                             nResult = 0;
+       char *timeStamp = NULL;
+       int retLen = 0;
+       int i = 0, j = 0;
+       int nSize = 0;
+       int length = 0;
+       int req_length = 0;
+       int nResult = 0;
 
        char pRoHeader[36] = {'<', '?', 'x', 'm', 'l', ' ', 'v', 'e', 'r', 's', 'i', 'o', 'n', '=', '"', '1', '.', '0', '"', '?', '>', 0x0A,
                                                '<', 'T', 'i', 'z', 'e', 'n', 'L', 'i', 'c', 'e', 'n', 's', 'e', '>'};
 
-       // test code
-       FILE *fd = NULL;
-       char tmpPath[128] = {0, };
-
        //Check Param Buffer
        IF_TRUE_RETURN(inBuffer == NULL, TADC_PARAMETER_ERROR);
        IF_TRUE_RETURN(t_ROAcqInfo== NULL, TADC_PARAMETER_ERROR);
@@ -529,7 +523,7 @@ int TADC_GetResponseRO(unsigned char * inBuffer, T_ROACQ_INFO *t_ROAcqInfo, T_RO
 
        TADC_IF_MemCpy(key, &g_baAESKey[0], 16 );
        TADC_IF_MemCpy(iv, &g_baAESKey[16], 16 );
-       TADC_IF_AES_CTR(16, key, 16, iv, 20, (unsigned char*)pbBuffer, &outlen, (unsigned char*)pbBuffer);
+       TADC_IF_AES_CTR(key, 16, iv, 20, (unsigned char*)pbBuffer, &outlen, (unsigned char*)pbBuffer);
 
        TADC_IF_SHA1(ReqTemp, req_length, sha1_tmp);
        if (ReqTemp != NULL)
@@ -633,7 +627,7 @@ int TADC_GetResponseRO(unsigned char * inBuffer, T_ROACQ_INFO *t_ROAcqInfo, T_RO
        // Decrypt License
        TADC_IF_MemCpy(key, &t_ROAcqInfo->t_DHInfo.K[0], 16);
        TADC_IF_MemCpy(iv, &t_ROAcqInfo->t_DHInfo.K[16], 16);
-       TADC_IF_AES_CTR(16, key, 16, iv, length, (unsigned char*)pbBuffer, &outlen, (unsigned char*)pbBuffer);
+       TADC_IF_AES_CTR(key, 16, iv, length, (unsigned char*)pbBuffer, &outlen, (unsigned char*)pbBuffer);
 
        // Test Code for get the plaintext ro
        /*
@@ -721,7 +715,7 @@ int TADC_GetResponseRO(unsigned char * inBuffer, T_ROACQ_INFO *t_ROAcqInfo, T_RO
        // Decrypt timeStamp
        TADC_IF_MemCpy(key, &t_ROAcqInfo->t_DHInfo.K[0], 16);
        TADC_IF_MemCpy(iv, &t_ROAcqInfo->t_DHInfo.K[16], 16);
-       TADC_IF_AES_CTR(16, key, 16, iv, length, (unsigned char*)pbBuffer, &outlen, (unsigned char*)pbBuffer);
+       TADC_IF_AES_CTR(key, 16, iv, length, (unsigned char*)pbBuffer, &outlen, (unsigned char*)pbBuffer);
 
        if (length >= (int)sizeof(t_ROAcqInfo->sTimeStamp))
        {
@@ -743,8 +737,8 @@ int TADC_GetResponseRO(unsigned char * inBuffer, T_ROACQ_INFO *t_ROAcqInfo, T_RO
 
 int TADC_VerifyROSignature(IN LPBYTE pszXML)
 {
-       int                     nResult = 0;
-       int                     length = 0, i = 0, i2 = 0;
+       int nResult = 0;
+       int length = 0, i = 0, i2 = 0;
 
        unsigned char* pSigData = NULL;
        unsigned char* pRICert = NULL;
@@ -774,16 +768,16 @@ int TADC_VerifyROSignature(IN LPBYTE pszXML)
        i = FindString(pszXML, TADC_IF_StrLen((char*)pszXML), (LPBYTE)"<CertificateChain>", 18);
        IF_TRUE_RETURN(i < 0, TADC_RO_CERTIFICATE_ERROR);
 
-       p = pszXML + i;         // <certificateChain>
+       p = pszXML + i; // <certificateChain>
        length = TADC_IF_StrLen((char*)pszXML) - i;
 
        i = FindString(p, length, (LPBYTE)"<Certificate>", 13);
        IF_TRUE_RETURN(i < 0, TADC_RO_CERTIFICATE_ERROR);
-       i += 13;        // start position of RI Cert
+       i += 13; // start position of RI Cert
 
        i2 = FindString(p, length, (LPBYTE)"</Certificate>", 14);
        IF_TRUE_RETURN(i2 < (i + 13), TADC_RO_CERTIFICATE_ERROR);
-       certLen = i2 - i;       // size of RI Cert
+       certLen = i2 - i; // size of RI Cert
 
        TADC_IF_StrNCpy(TempBuf, (char*)p+i, certLen);
 
@@ -792,16 +786,16 @@ int TADC_VerifyROSignature(IN LPBYTE pszXML)
        TADC_IF_MemSet(TempBuf, 0x00, CERT_MAXSIZE);
 
        //Get Certificates ( RICA Cert )
-       p = p + (i2 + 14);      // first </certificate>
+       p = p + (i2 + 14); // first </certificate>
        length = length - (i2 + 14);
 
        i = FindString(p, length, (LPBYTE)"<Certificate>", 13);
        IF_TRUE_RETURN2(i < 0, TADC_IF_Free(pRICert),,,TADC_RO_CERTIFICATE_ERROR);
-       i += 13;        // start position of RICA Cert
+       i += 13; // start position of RICA Cert
 
        i2 = FindString(p, length, (LPBYTE)"</Certificate>", 14);
        IF_TRUE_RETURN2(i2 < (i + 13), TADC_IF_Free(pRICert),,,TADC_RO_CERTIFICATE_ERROR);
-       certLen2 = i2 - i;      // size of RICA Cert
+       certLen2 = i2 - i; // size of RICA Cert
 
        TADC_IF_StrNCpy(TempBuf, (char*)p + i, certLen2);
 
@@ -820,11 +814,11 @@ int TADC_VerifyROSignature(IN LPBYTE pszXML)
 
        i = FindString(p, length, (LPBYTE)"<SignatureValue>", 16);
        IF_TRUE_RETURN2(i < 0, TADC_IF_Free(pRICert),TADC_IF_Free(pRICACert),,TADC_RO_SIGNATURE_ERROR);
-       i += 16;        // start position of signature value
+       i += 16; // start position of signature value
 
        i2 = FindString(p, length, (LPBYTE)"</SignatureValue>", 17);
        IF_TRUE_RETURN2(i2 < (i + 16), TADC_IF_Free(pRICert),TADC_IF_Free(pRICACert),,TADC_RO_SIGNATURE_ERROR);
-       sigLen = i2 - i;        // size of signature value
+       sigLen = i2 - i; // size of signature value
 
        TADC_IF_StrNCpy(TempBuf, (char*)p + i, sigLen);
 
@@ -848,14 +842,14 @@ int TADC_VerifyROSignature(IN LPBYTE pszXML)
 
 int TADC_GetResponseROInfo(IN LPBYTE pszXML,  T_RO *t_RO)
 {
-       int                                     nResult = 0;
-       CXMLFile                        oXMLFile;
-       CXMLElement*            pRoot, *pElement;
-       CPointerArray           paChilds;
-       LPCTSTR                         pszValue;
-       LPBYTE                          pbBuffer = NULL;
-       int                                     length = 0;
-       TADC_U8                         TempVersion[3] = {0, };
+       int nResult = 0;
+       CXMLFile oXMLFile;
+       CXMLElement* pRoot, *pElement;
+       CPointerArray paChilds;
+       LPCTSTR pszValue;
+       LPBYTE pbBuffer = NULL;
+       int length = 0;
+       TADC_U8 TempVersion[3] = {0, };
 
        char pRoHeader[36] = {'<', '?', 'x', 'm', 'l', ' ', 'v', 'e', 'r', 's', 'i', 'o', 'n', '=', '"', '1', '.', '0', '"', '?', '>', 0x0A,
                                                '<', 'T', 'i', 'z', 'e', 'n', 'L', 'i', 'c', 'e', 'n', 's', 'e', '>'};
@@ -932,9 +926,9 @@ int TADC_GetResponseROInfo(IN LPBYTE pszXML,  T_RO *t_RO)
                goto finish;
        }
 
-       t_RO->t_Content.CID = (TADC_U8*)TADC_IF_Malloc(length + 1);     //2011.03.08 ( CID_SIZE -> length )
+       t_RO->t_Content.CID = (TADC_U8*)TADC_IF_Malloc(length + 1); //2011.03.08 ( CID_SIZE -> length )
        IF_TRUE_GOTO(t_RO->t_Content.CID == NULL, -2);
-       TADC_IF_MemSet(t_RO->t_Content.CID, 0, length + 1);                     //2011.03.08 ( CID_SIZE -> length )
+       TADC_IF_MemSet(t_RO->t_Content.CID, 0, length + 1); //2011.03.08 ( CID_SIZE -> length )
        TADC_IF_StrNCpy((CHAR*)t_RO->t_Content.CID, pszValue, length);
 
        // Get KeyValue (CEK)
@@ -966,9 +960,9 @@ int TADC_GetResponseROInfo(IN LPBYTE pszXML,  T_RO *t_RO)
                goto finish;
        }
 
-       t_RO->t_Content.CEK = (TADC_U8*)TADC_IF_Malloc(length + 1);     //2011.03.08 ( CEK_SIZE -> length )
+       t_RO->t_Content.CEK = (TADC_U8*)TADC_IF_Malloc(length + 1); //2011.03.08 ( CEK_SIZE -> length )
        IF_TRUE_GOTO(t_RO->t_Content.CEK == NULL, -2);
-       TADC_IF_MemSet(t_RO->t_Content.CEK, 0, length + 1);                     //2011.03.08 ( CEK_SIZE -> length )
+       TADC_IF_MemSet(t_RO->t_Content.CEK, 0, length + 1); //2011.03.08 ( CEK_SIZE -> length )
        TADC_IF_MemCpy(t_RO->t_Content.CEK, pbBuffer, length);
 
        TADC_IF_Free(pbBuffer);
@@ -1028,11 +1022,11 @@ finish:
        return nResult;
 }
 
-int    TADC_GetFileHeader(unsigned char * inBuffer,  T_FILE_HEADER *t_FileHeader)
+int TADC_GetFileHeader(unsigned char * inBuffer,  T_FILE_HEADER *t_FileHeader)
 {
-       int             i = 0;
-       BYTE    FixedFileType[8] = {0x00,0x00,0x00,0x14,0x66,0x74,0x79,0x70};
-       char    tmp[2];
+       int i = 0;
+       BYTE FixedFileType[8] = {0x00,0x00,0x00,0x14,0x66,0x74,0x79,0x70};
+       char tmp[2];
 
        //Check Param Bufffer
        IF_TRUE_RETURN(inBuffer == NULL, TADC_PARAMETER_ERROR);
@@ -1113,9 +1107,9 @@ int       TADC_GetFileHeader(unsigned char * inBuffer,  T_FILE_HEADER *t_FileHeader)
        return 0;
 }
 
-int    TADC_GetDRMHeader(unsigned char * inBuffer, T_DRM_HEADER *t_DRMHeader)
+int TADC_GetDRMHeader(unsigned char * inBuffer, T_DRM_HEADER *t_DRMHeader)
 {
-       int             i = 0;
+       int i = 0;
 
        //Check Param Bufffer
        IF_TRUE_RETURN(inBuffer == NULL, TADC_PARAMETER_ERROR);
@@ -1143,22 +1137,22 @@ int     TADC_GetDRMHeader(unsigned char * inBuffer, T_DRM_HEADER *t_DRMHeader)
        return 0;
 }
 
-int    TADC_GetDRMHeaderInfo(unsigned char * inBuffer, T_DRM_HEADER *t_DRMHeader)
+int TADC_GetDRMHeaderInfo(unsigned char * inBuffer, T_DRM_HEADER *t_DRMHeader)
 {
-       int                             nResult = 0;
-       CXMLFile                oXMLFile;
-       CXMLElement*    pRoot, *pNode;
-       CPointerArray   paChilds;
-       LPCTSTR                 pszValue;
+       int nResult = 0;
+       CXMLFile oXMLFile;
+       CXMLElement* pRoot, *pNode;
+       CPointerArray paChilds;
+       LPCTSTR pszValue;
 
-       BYTE                    sha1_tmp[20];
-       unsigned char   *ReqTemp=NULL;
+       BYTE sha1_tmp[20];
+       unsigned char *ReqTemp=NULL;
 
-       TADC_U8                 key[16];
-       TADC_U8                 iv[16];
+       TADC_U8 key[16];
+       TADC_U8 iv[16];
 
-       int                             outlen=0;
-       long                    Length=0;
+       int outlen=0;
+       long Length=0;
 
        //Check Param
        IF_TRUE_RETURN(inBuffer == NULL, TADC_PARAMETER_ERROR);
@@ -1184,7 +1178,7 @@ int       TADC_GetDRMHeaderInfo(unsigned char * inBuffer, T_DRM_HEADER *t_DRMHeader)
 
        TADC_IF_MemCpy(key, &g_baSignatureKey[0], 16);
        TADC_IF_MemCpy(iv, &g_baSignatureKey[16], 16);
-       TADC_IF_AES_CTR(16, key, 16, iv, 20, (unsigned char*)sha1_tmp, &outlen, (unsigned char*)sha1_tmp);
+       TADC_IF_AES_CTR(key, 16, iv, 20, (unsigned char*)sha1_tmp, &outlen, (unsigned char*)sha1_tmp);
 
        if (TADC_IF_MemCmp(sha1_tmp, inBuffer, sizeof(sha1_tmp)))
        {
@@ -1237,14 +1231,14 @@ int     TADC_GetDRMHeaderInfo(unsigned char * inBuffer, T_DRM_HEADER *t_DRMHeader)
                {
                        pNode = (CXMLElement*)paChilds.Get(0);
                        pszValue = pNode->GetValue();
-                       Length = TADC_IF_StrLen((char*)pszValue);                                               //2011.03.08
+                       Length = TADC_IF_StrLen((char*)pszValue); //2011.03.08
 
                        if (Length > 0)
                        {
-                               t_DRMHeader->CID = (TADC_U8*)TADC_IF_Malloc(Length + 1);                //2011.03.08 ( CID_SIZE -> Length )
+                               t_DRMHeader->CID = (TADC_U8*)TADC_IF_Malloc(Length + 1); //2011.03.08 ( CID_SIZE -> Length )
                                IF_TRUE_RETURN(t_DRMHeader->CID == NULL, TADC_MEMAlOC_ERROR);
-                               TADC_IF_MemSet(t_DRMHeader->CID, 0, Length + 1);                                //2011.03.08 ( CID_SIZE -> Length )
-                               TADC_IF_StrNCpy((CHAR*)t_DRMHeader->CID, pszValue, Length);     //2011.03.08 ( CID_SIZE -> Length )
+                               TADC_IF_MemSet(t_DRMHeader->CID, 0, Length + 1); //2011.03.08 ( CID_SIZE -> Length )
+                               TADC_IF_StrNCpy((CHAR*)t_DRMHeader->CID, pszValue, Length); //2011.03.08 ( CID_SIZE -> Length )
                        }
                }
        }
@@ -1395,9 +1389,9 @@ finish:
        return nResult;
 }
 
-int    TADC_GetCEK(T_DEVICE_INFO *t_DeviceInfo, T_RO *t_RODB, T_DRM_HEADER *t_DRMHeader)
+int TADC_GetCEK(T_DEVICE_INFO *t_DeviceInfo, T_RO *t_RODB, T_DRM_HEADER *t_DRMHeader)
 {
-       int     length1 = 0;
+       int length1 = 0;
 
        //Check Parameter Buffer
        IF_TRUE_RETURN(t_DeviceInfo == NULL, TADC_PARAMETER_ERROR);
@@ -1406,7 +1400,7 @@ int       TADC_GetCEK(T_DEVICE_INFO *t_DeviceInfo, T_RO *t_RODB, T_DRM_HEADER *t_DRMHe
        IF_TRUE_RETURN(t_RODB == NULL, TADC_PARAMETER_ERROR);
        IF_TRUE_RETURN(t_RODB->t_Content.CID == NULL, TADC_PARAMETER_ERROR);
 
-       if(!TADC_IF_StrCmp((char*)t_DRMHeader->CID, (char*)t_RODB->t_Content.CID))      //2011.03.08 ( TADC_IF_MemCmp -> TADC_IF_StrCmp )
+       if(!TADC_IF_StrCmp((char*)t_DRMHeader->CID, (char*)t_RODB->t_Content.CID)) //2011.03.08 ( TADC_IF_MemCmp -> TADC_IF_StrCmp )
        {
                if((t_RODB->PerFlag & DUID_RULE) && (t_RODB->t_Permission.t_Individual.BindingType & DUID_RULE))
                {
@@ -1436,18 +1430,18 @@ int     TADC_GetCEK(T_DEVICE_INFO *t_DeviceInfo, T_RO *t_RODB, T_DRM_HEADER *t_DRMHe
 
 int TADC_DecryptBlock( char* pbBuffer, int nSize, T_DRM_HEADER *t_DRMHeader)
 {
-       TADC_U8         key[16] = {0, };
-       TADC_U8         iv[16] = {0, };
-       int             i = 0, nBlocks = 0, nIndex = 0;
-       char            baToBeEncrypted[32] = {0, };
-       int             nRemainBytes = 0, nBlockBytes = 0;
+       TADC_U8 key[16] = {0, };
+       TADC_U8 iv[16] = {0, };
+       int i = 0, nBlocks = 0, nIndex = 0;
+       char baToBeEncrypted[32] = {0, };
+       int nRemainBytes = 0, nBlockBytes = 0;
 
-       int             nEncryptionLevel = 0;
-       int                     nEncryptionMethod = 0;
+       int nEncryptionLevel = 0;
+       int nEncryptionMethod = 0;
 
-       char            temp[512] = {0, };
-       int                     length = 0;
-       int                     totlength = 0;
+       char temp[512] = {0, };
+       int length = 0;
+       int totlength = 0;
 
        TADC_IF_MemSet(temp, 0, sizeof(temp));
 
@@ -1489,7 +1483,7 @@ int TADC_DecryptBlock( char* pbBuffer, int nSize, T_DRM_HEADER *t_DRMHeader)
        nRemainBytes = nSize;
        nBlockBytes = 16;
 
-       length    = 0;
+       length = 0;
        totlength = 0;
 
        for (i = 0 ; i < 32 ; i++)
@@ -1516,12 +1510,12 @@ int TADC_DecryptBlock( char* pbBuffer, int nSize, T_DRM_HEADER *t_DRMHeader)
 
        TADC_IF_MemCpy(key, &t_DRMHeader->CEK[0], 16);
        TADC_IF_MemCpy(iv, &t_DRMHeader->CEK[16], 16);
-       TADC_IF_AES_CTR(16, key, 16, iv, length, (unsigned char*)temp, &length, (unsigned char*)temp);
+       TADC_IF_AES_CTR(key, 16, iv, length, (unsigned char*)temp, &length, (unsigned char*)temp);
 
        nRemainBytes = nSize;
        nBlockBytes = 16;
 
-       length    = 0;
+       length = 0;
        totlength = 0;
 
        for (i = 0 ; i < 32 ; i++)
@@ -1548,16 +1542,16 @@ int TADC_DecryptBlock( char* pbBuffer, int nSize, T_DRM_HEADER *t_DRMHeader)
        return 0;
 }
 
-int    TADC_GetDRMHeaderFromFile(const char *pTADCFilepath, T_FILE_HEADER *t_FileHeader, T_DRM_HEADER *t_DRMHeader )
+int TADC_GetDRMHeaderFromFile(const char *pTADCFilepath, T_FILE_HEADER *t_FileHeader, T_DRM_HEADER *t_DRMHeader )
 {
 
        unsigned char tempbuf[512];
        unsigned char *pbuf = NULL;
 
-       int             ret=0;
-       ULONG   readsize=0, ReadLen=0;
+       int ret=0;
+       ULONG readsize=0, ReadLen=0;
 
-       FILE *  hFile =  0;             //Apps drm file
+       FILE *hFile =  0; //Apps drm file
 
        //null check
        if (pTADCFilepath == NULL || t_FileHeader == NULL || t_DRMHeader == NULL)
@@ -1640,8 +1634,8 @@ int       TADC_GetDRMHeaderFromFile(const char *pTADCFilepath, T_FILE_HEADER *t_FileHe
 
 DWORD TADC_GetLastError(void)
 {
-       DWORD   dwError = g_TADCErrorCode;
-       g_TADCErrorCode = 0;
+       DWORD dwError = g_TADCErrorCode;
+       g_TADCErrorCode = 0;
 
        return dwError;
 }
index 3bbd235..e198fc1 100644 (file)
 #include "TADC_ErrorCode.h"
 
 // -------------------------- Base64 --------------------------------
-static CHAR __base64_table[] = { 
-       'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 
-       'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 
-       'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 
-       'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0' 
-}; 
-static int __reverse_table[] = { 
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 
-       52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, 
-       -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 
-       15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, 
-       -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 
-       41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, 
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 
-       -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 
-}; 
-static CHAR __base64_pad = '='; 
-LPSTR Base64Encode( LPBYTE pbData,  int nLength ) 
-{ 
-       int                                     i = 0, result = 0; 
-       LPSTR                           pszResult = NULL; 
+static CHAR __base64_table[] = {
+       'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+       'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
+       'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
+       'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0'
+};
+
+static BYTE __reverse_table[256] = {
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f,
+       0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
+       0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
+       0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+};
+
+static CHAR __base64_pad = '=';
+
+LPSTR Base64Encode( LPBYTE pbData,  int nLength )
+{
+       int i = 0, result = 0;
+       LPSTR pszResult = NULL;
 
        if (nLength <= 0)
        {
-               return NULL;             
+               return NULL;
        }
-       result = ( ( nLength + 3 - nLength % 3 ) * 4 / 3 + 1 ); 
-       
+       result = ( ( nLength + 3 - nLength % 3 ) * 4 / 3 + 1 );
+
        pszResult = (LPSTR)TADC_IF_Malloc( result );
 
        if (pszResult == NULL)
        {
                return NULL;
        }
-       
+
        TADC_IF_MemSet(pszResult, 0x00, result);
-        
-       i = 0; 
-
-       while (nLength > 2) 
-       { 
-               /* keep going until we have less than 24 bits */ 
-               pszResult[ i++ ] = __base64_table[ pbData[ 0 ] >> 2 ]; 
-               pszResult[ i++ ] = __base64_table[ ( ( pbData[ 0 ] & 0x03 ) << 4 ) + ( pbData[ 1 ] >> 4 ) ]; 
-               pszResult[ i++ ] = __base64_table[ ( ( pbData[ 1 ] & 0x0f ) << 2 ) + ( pbData[ 2 ] >> 6 ) ]; 
-               pszResult[ i++ ] = __base64_table[ pbData[ 2 ] & 0x3f ]; 
-                
-               pbData += 3; 
-               nLength -= 3; /* we just handle 3 octets of data */ 
-       } 
-        
-       /* now deal with the tail end of things */ 
-       if (nLength != 0) 
-       { 
-               pszResult[ i++ ] = __base64_table[ pbData[ 0 ] >> 2 ]; 
-               if (nLength == 1) 
-               { 
-                       pszResult[ i++ ] = __base64_table[ ( pbData[ 0 ] & 0x03 ) << 4 ]; 
-                       pszResult[ i++ ] = __base64_pad; 
-                       pszResult[ i++ ] = __base64_pad; 
-               } 
-               else 
-               { 
-                       pszResult[ i++ ] = __base64_table[ ( ( pbData[ 0 ] & 0x03 ) << 4 ) + ( pbData[ 1 ] >> 4 ) ]; 
-                       pszResult[ i++ ] = __base64_table[ ( pbData[ 1 ] & 0x0f ) << 2 ]; 
-                       pszResult[ i++ ] = __base64_pad; 
-               } 
-       } 
-       pszResult[ i ] = 0; 
-       return pszResult; 
-} 
-LPBYTE Base64Decode(LPCSTR pszString, int* pnLength) 
-{ 
-       int                     result = 0; 
-       LPBYTE          pbResult = NULL; 
-       int                     nStrLength = 0, i = 0, nOutputLength = 0; 
-       BYTE            b1, b2, b3, b4; 
-       nStrLength = TADC_IF_StrLen(pszString);
-       if (nStrLength % 4 != 0) 
-       { 
-               result = -1; 
-               goto finish; 
-       } 
-       pbResult = (LPBYTE)TADC_IF_Malloc(nStrLength + 1);
-       if (pbResult == NULL)
+
+       i = 0;
+
+       while (nLength > 2)
        {
-                return NULL;
+               /* keep going until we have less than 24 bits */
+               pszResult[ i++ ] = __base64_table[ pbData[ 0 ] >> 2 ];
+               pszResult[ i++ ] = __base64_table[ ( ( pbData[ 0 ] & 0x03 ) << 4 ) + ( pbData[ 1 ] >> 4 ) ];
+               pszResult[ i++ ] = __base64_table[ ( ( pbData[ 1 ] & 0x0f ) << 2 ) + ( pbData[ 2 ] >> 6 ) ];
+               pszResult[ i++ ] = __base64_table[ pbData[ 2 ] & 0x3f ];
+
+               pbData += 3;
+               nLength -= 3; /* we just handle 3 octets of data */
        }
+
+       /* now deal with the tail end of things */
+       if (nLength != 0)
+       {
+               pszResult[ i++ ] = __base64_table[ pbData[ 0 ] >> 2 ];
+               if (nLength == 1)
+               {
+                       pszResult[ i++ ] = __base64_table[ ( pbData[ 0 ] & 0x03 ) << 4 ];
+                       pszResult[ i++ ] = __base64_pad;
+                       pszResult[ i++ ] = __base64_pad;
+               }
+               else
+               {
+                       pszResult[ i++ ] = __base64_table[ ( ( pbData[ 0 ] & 0x03 ) << 4 ) + ( pbData[ 1 ] >> 4 ) ];
+                       pszResult[ i++ ] = __base64_table[ ( pbData[ 1 ] & 0x0f ) << 2 ];
+                       pszResult[ i++ ] = __base64_pad;
+               }
+       }
+       pszResult[ i ] = 0;
+       return pszResult;
+}
+
+LPBYTE Base64Decode(LPCSTR pszString, int* pnLength)
+{
+       size_t nStrLength = TADC_IF_StrLen(pszString);
+       if (nStrLength % 4 != 0)
+               return NULL;
+
+       LPBYTE pbResult = (LPBYTE)TADC_IF_Malloc(nStrLength + 1);
+       if (pbResult == NULL)
+                return NULL;
+
        TADC_IF_MemSet(pbResult, 0x00, nStrLength + 1);
-        
-       nOutputLength = 0; 
-
-       for (i = 0 ; i < nStrLength ; i += 4) 
-       { 
-               b1 = (BYTE)__reverse_table[ pszString[ i ] ]; 
-               b2 = (BYTE)__reverse_table[ pszString[ i + 1 ] ]; 
-               b3 = (BYTE)__reverse_table[ pszString[ i + 2 ] ]; 
-               b4 = (BYTE)__reverse_table[ pszString[ i + 3 ] ]; 
-               pbResult[ nOutputLength++ ] = (BYTE)( ( b1 << 2 ) | ( b2 >> 4 ) ); 
-                
-               if (pszString[ i + 2 ] == '=') 
-               { 
-                       pbResult[ nOutputLength ] = (BYTE)( ( b2 & 0x0F ) << 4 ); 
-               } 
-               else 
-               { 
-                       pbResult[ nOutputLength++ ] = (BYTE)( ( ( b2 & 0x0F ) << 4 ) | ( b3 >> 2 ) ); 
-
-                       if (pszString[ i + 3 ] == '=') 
-                       { 
-                               pbResult[ nOutputLength ] = (BYTE)( ( b3 & 0x03 ) << 6 ); 
-                       } 
-                       else 
-                       { 
-                               pbResult[ nOutputLength++ ] = (BYTE)( ( ( b3 & 0x03 ) << 6 ) | b4 ); 
-                       } 
-               } 
-       } 
-       *pnLength = nOutputLength; 
-       result = 0; 
-finish: 
-       if (result != 0) 
-       { 
-               TADC_IF_Free( pbResult );
-       } 
-       return pbResult; 
-} 
+
+       int nOutputLength = 0;
+
+       for (size_t i = 0; i < nStrLength; i += 4) {
+               BYTE b1 = __reverse_table[static_cast<BYTE>(pszString[i])];
+               BYTE b2 = __reverse_table[static_cast<BYTE>(pszString[i + 1])];
+               BYTE b3 = __reverse_table[static_cast<BYTE>(pszString[i + 2])];
+               BYTE b4 = __reverse_table[static_cast<BYTE>(pszString[i + 3])];
+
+               pbResult[nOutputLength++] = (b1 << 2) | (b2 >> 4);
+
+               if (pszString[i + 2] == '=') {
+                       pbResult[nOutputLength] = (b2 & 0x0F) << 4;
+               } else {
+                       pbResult[nOutputLength++] = ((b2 & 0x0F) << 4) | (b3 >> 2);
+
+                       if (pszString[i + 3] == '=')
+                               pbResult[nOutputLength] = (b3 & 0x03) << 6;
+                       else
+                               pbResult[nOutputLength++] = ((b3 & 0x03) << 6) | b4;
+               }
+       }
+
+       *pnLength = nOutputLength;
+
+       return pbResult;
+}
 // -------------------------- Base64 --------------------------------]]]]
 
-int HEX2BIN(LPCSTR pszHex, LPBYTE baBin, int* pnLength ) 
-{ 
-       CHAR            szTemp[ 3 ]; 
-       CHAR            szHex[ 1024 ]; 
-       int                     i = 0, nLength = 0; 
-        
+int HEX2BIN(LPCSTR pszHex, LPBYTE baBin, int* pnLength )
+{
+       CHAR szTemp[ 3 ];
+       CHAR szHex[ 1024 ];
+       int i = 0, nLength = 0;
+
        nLength = TADC_IF_StrLen(pszHex);
-       
+
        if (nLength <= 0)
        {
-               return -1;               
+               return -1;
        }
-               
-       if ((nLength % 2) == 0) 
-       { 
+
+       if ((nLength % 2) == 0)
+       {
                TADC_IF_StrNCpy(szHex, pszHex, nLength);
-       } 
-       else 
-       { 
-               szHex[ 0 ] = '0'; 
+       }
+       else
+       {
+               szHex[ 0 ] = '0';
                TADC_IF_StrNCpy(&szHex[ 1 ], pszHex, nLength);
-               nLength += 1; 
-       } 
-       *pnLength = nLength / 2; 
-       szTemp[ 2 ] = 0; 
-
-       for (i = 0 ; i < *pnLength ; i++ ) 
-       { 
-               szTemp[ 0 ] = szHex[ i * 2 ]; 
-               szTemp[ 1 ] = szHex[ i * 2 + 1 ]; 
-               baBin[ i ] = (BYTE)strtoul( szTemp, NULL, 16 ); 
-       } 
+               nLength += 1;
+       }
+
+       *pnLength = nLength / 2;
+       szTemp[ 2 ] = 0;
+
+       for (i = 0 ; i < *pnLength ; i++ )
+       {
+               szTemp[ 0 ] = szHex[ i * 2 ];
+               szTemp[ 1 ] = szHex[ i * 2 + 1 ];
+               baBin[ i ] = (BYTE)strtoul( szTemp, NULL, 16 );
+       }
        return 0;
-} 
+}
 
 //Find String (2011.03.08)
 //return : start position of find string or error (-1)
index 122291e..8411132 100644 (file)
@@ -126,11 +126,11 @@ int TADC_IF_GetDHKey(T_DH_INFO *t_dhinfo)
 
 int TADC_IF_GetDHKey_K(T_DH_INFO *t_dhinfo)
 {
-       DH              *pDH = NULL;
-       BIGNUM  *pPubKey = NULL;
+       DH *pDH = NULL;
+       BIGNUM *pPubKey = NULL;
 
-       char    tempbuf[DHKey_SIZE + 1];
-       int             i = 0;
+       char tempbuf[DHKey_SIZE + 1];
+       int i = 0;
 
        unsigned char tempG[1];
 
@@ -173,12 +173,13 @@ int TADC_IF_GetDHKey_K(T_DH_INFO *t_dhinfo)
        return 0;
 }
 
-int TADC_IF_AES_CTR(int keyLen, unsigned char *pKey, int ivLen, unsigned char *pIV, int inLen, unsigned char *in, int *pOutLen, unsigned char *out)
+/* Only handles 128 bit aes key */
+int TADC_IF_AES_CTR(unsigned char *pKey, int ivLen, unsigned char *pIV, int inLen, unsigned char *in, int *pOutLen, unsigned char *out)
 {
-       AES_KEY         stKey;
-       UINT            num;
-       TADC_U8         ecount[16];
-       TADC_U8         chain[16];
+       AES_KEY stKey;
+       UINT num;
+       TADC_U8 ecount[16];
+       TADC_U8 chain[16];
 
        AES_set_encrypt_key(pKey, 128, &stKey);
 
@@ -197,7 +198,7 @@ int TADC_IF_AES_CTR(int keyLen, unsigned char *pKey, int ivLen, unsigned char *p
 
 int TADC_IF_SHA1(unsigned char *in, int inLen, unsigned char *out)
 {
-       SHA_CTX         AlgInfo;
+       SHA_CTX AlgInfo;
 
        SHA1_Init(&AlgInfo);
        SHA1_Update(&AlgInfo, in, inLen);
@@ -206,16 +207,16 @@ int TADC_IF_SHA1(unsigned char *in, int inLen, unsigned char *out)
        return 0;
 }
 
-int TADC_IF_VerifySignature( unsigned char* inData, int inLen,
-                                                        unsigned char* sigData, int sigLen,
-                                                        unsigned char* cert, int certLen )
+int TADC_IF_VerifySignature(unsigned char* inData, int inLen,
+                                                       unsigned char* sigData, int sigLen,
+                                                       unsigned char* cert, int certLen)
 {
-       unsigned char   hashValue[20];
-       int                             iRet = 0;
+       unsigned char hashValue[20];
+       int iRet = 0;
 
-       X509*                   pX509 = NULL;
-       EVP_PKEY*               pKey = NULL;
-       RSA*                    pRsa = NULL;
+       X509* pX509 = NULL;
+       EVP_PKEY* pKey = NULL;
+       RSA* pRsa = NULL;
 
        //Check parameters
        if (inData == NULL || sigData == NULL || cert == NULL || inLen < 1 || sigLen < 1 || certLen < 1)
@@ -237,7 +238,7 @@ int TADC_IF_VerifySignature( unsigned char* inData, int inLen,
                return -1;
        }
 
-    pKey = X509_get_pubkey(pX509);
+       pKey = X509_get_pubkey(pX509);
        if (pKey == NULL)
        {
                DRM_TAPPS_EXCEPTION("TADC_IF_VerifySignature Error : X509_get_pubkey!");
@@ -250,7 +251,7 @@ int TADC_IF_VerifySignature( unsigned char* inData, int inLen,
                DRM_TAPPS_EXCEPTION("TADC_IF_VerifySignature Error : EVP_PKEY_get1_RSA!");
                if (NULL != pKey)
                {
-                        EVP_PKEY_free(pKey);
+                       EVP_PKEY_free(pKey);
                }
                return -1;
        }
@@ -303,138 +304,138 @@ int AddCertUntrustedCerts(STACK_OF(X509)* untrustedCerts, unsigned char* cert, i
                return -1;
        }
 
-    sk_X509_push(untrustedCerts, pstX509);
+       sk_X509_push(untrustedCerts, pstX509);
 
        return 0;
 }
 
 int AddCertSTOREFromFile(X509_STORE* pstStore, const char* filePath)
 {
-    X509* pstX509 = NULL;
-    FILE* file = NULL;
-    int ret = 0;
-
-    file = fopen(filePath, "r");
-    if(!file)
-    {
-        DRM_TAPPS_EXCEPTION("AddCertSTOREFromFile Error : Parameter error! Fail to open a cert file.");
-        ret = -1;
-        goto error;
-    }
-
-    pstX509 = PEM_read_X509(file, NULL, NULL, NULL);
-    if (pstX509 == NULL)
-    {
-        DRM_TAPPS_EXCEPTION("AddCertSTORE Error : d2i_X509 error!");
-        ret = -1;
-        goto error;
-    }
-
-    X509_STORE_add_cert(pstStore, pstX509);
+       X509* pstX509 = NULL;
+       FILE* file = NULL;
+       int ret = 0;
+
+       file = fopen(filePath, "r");
+       if(!file)
+       {
+               DRM_TAPPS_EXCEPTION("AddCertSTOREFromFile Error : Parameter error! Fail to open a cert file.");
+               ret = -1;
+               goto error;
+       }
+
+       pstX509 = PEM_read_X509(file, NULL, NULL, NULL);
+       if (pstX509 == NULL)
+       {
+               DRM_TAPPS_EXCEPTION("AddCertSTORE Error : d2i_X509 error!");
+               ret = -1;
+               goto error;
+       }
+
+       X509_STORE_add_cert(pstStore, pstX509);
 
 error:
-    if(file!=NULL)
-        fclose(file);
-    return ret;
+       if(file!=NULL)
+               fclose(file);
+       return ret;
 }
 
 int AddCertSTOREFromDir(X509_STORE* pstStore, const char* dirPath)
 {
-    int ret = 0;
-
-    DIR *dir = NULL;
-    struct dirent entry;
-    struct dirent *result;
-    int error;
-    char file_path_buff[512];
-
-    if (pstStore == NULL || dirPath == NULL)
-    {
-        DRM_TAPPS_EXCEPTION("AddCertSTOREFromDir Error : Parameter error!");
-        ret = -1;
-        goto error;
-    }
-
-    dir = opendir(dirPath);
-    if(dir == NULL) {
-        DRM_TAPPS_EXCEPTION("AddCertSTOREFromDir Error : cannot open directory!");
-        ret = -1;
-        goto error;
-    }
-
-    for(;;) {
-        error = readdir_r(dir, &entry, &result);
-        if( error != 0 ) {
-            DRM_TAPPS_EXCEPTION("AddCertSTOREFromDir Error : fail to read entries from a directory!");
-            ret = -1;
-            goto error;
-        }
-        // readdir_r returns NULL in *result if the end 
-        // of the directory stream is reached
-        if(result == NULL) 
-            break;
-
-        if(entry.d_type == DT_REG) { // regular file
-            memset(file_path_buff, 0, sizeof(file_path_buff));
-            snprintf(file_path_buff, sizeof(file_path_buff), "%s/%s", dirPath, entry.d_name);
-            if(AddCertSTOREFromFile(pstStore, file_path_buff) == 0) {
-                DRM_TAPPS_LOG("Add root cert : file=%s", file_path_buff);
-            }else {
-                DRM_TAPPS_LOG("Fail to add root cert : file=%s", file_path_buff);
-            }
-        }
-    }
+       int ret = 0;
+
+       DIR *dir = NULL;
+       struct dirent entry;
+       struct dirent *result;
+       int error;
+       char file_path_buff[512];
+
+       if (pstStore == NULL || dirPath == NULL)
+       {
+               DRM_TAPPS_EXCEPTION("AddCertSTOREFromDir Error : Parameter error!");
+               ret = -1;
+               goto error;
+       }
+
+       dir = opendir(dirPath);
+       if(dir == NULL) {
+               DRM_TAPPS_EXCEPTION("AddCertSTOREFromDir Error : cannot open directory!");
+               ret = -1;
+               goto error;
+       }
+
+       for(;;) {
+               error = readdir_r(dir, &entry, &result);
+               if( error != 0 ) {
+                       DRM_TAPPS_EXCEPTION("AddCertSTOREFromDir Error : fail to read entries from a directory!");
+                       ret = -1;
+                       goto error;
+               }
+               // readdir_r returns NULL in *result if the end
+               // of the directory stream is reached
+               if(result == NULL)
+                       break;
+
+               if(entry.d_type == DT_REG) { // regular file
+                       memset(file_path_buff, 0, sizeof(file_path_buff));
+                       snprintf(file_path_buff, sizeof(file_path_buff), "%s/%s", dirPath, entry.d_name);
+                       if(AddCertSTOREFromFile(pstStore, file_path_buff) == 0) {
+                               DRM_TAPPS_LOG("Add root cert : file=%s", file_path_buff);
+                       }else {
+                               DRM_TAPPS_LOG("Fail to add root cert : file=%s", file_path_buff);
+                       }
+               }
+       }
 
 error:
-    if(dir!=NULL)
-        closedir(dir);
-    return ret;
+       if(dir!=NULL)
+               closedir(dir);
+       return ret;
 }
 
-int TADC_IF_VerifyCertChain( unsigned char* rica, int ricaLen,
-                                                        unsigned char* cert, int certLen )
+int TADC_IF_VerifyCertChain(unsigned char* rica, int ricaLen,
+                                                       unsigned char* cert, int certLen)
 {
-    X509_STORE_CTX*                    pstStoreCtx = NULL;
-    X509_STORE*                                pstStore = NULL;
-    STACK_OF(X509)*         untrustedCerts = NULL;
+       X509_STORE_CTX* pstStoreCtx = NULL;
+       X509_STORE* pstStore = NULL;
+       STACK_OF(X509)* untrustedCerts = NULL;
 
-    X509*                                      pstX509 = NULL;
+       X509* pstX509 = NULL;
 
-    int iRet = 0;
+       int iRet = 0;
        int iErrCode = 0;
 
        //must call this function.
        OpenSSL_add_all_algorithms();
 
-    pstStore = X509_STORE_new();
+       pstStore = X509_STORE_new();
        if(pstStore == NULL)
        {
-        iRet = -1;
-        goto error;
+               iRet = -1;
+               goto error;
        }
 
-    untrustedCerts = sk_X509_new_null();
+       untrustedCerts = sk_X509_new_null();
        if(untrustedCerts == NULL)
        {
-        iRet = -1;
-        goto error;
+               iRet = -1;
+               goto error;
        }
 
 
        //Add RICA Cert to certchain
-    if ((iRet = AddCertUntrustedCerts(untrustedCerts, rica, ricaLen)) != 0)
+       if ((iRet = AddCertUntrustedCerts(untrustedCerts, rica, ricaLen)) != 0)
        {
                DRM_TAPPS_EXCEPTION("TADC_IF_VerifyCertChain Error : Add RICA Cert to certchain!");
-        iRet = -1;
-        goto error;
+               iRet = -1;
+               goto error;
        }
 
        //Add Root CA Cert
-    if ((iRet = AddCertSTOREFromDir(pstStore, RO_ISSUER_ROOT_CERTS_DIR)) != 0)
+       if ((iRet = AddCertSTOREFromDir(pstStore, RO_ISSUER_ROOT_CERTS_DIR)) != 0)
        {
                DRM_TAPPS_EXCEPTION("TADC_IF_VerifyCertChain Error : Add Root CA Cert!");
-        iRet = -1;
-        goto error;
+               iRet = -1;
+               goto error;
        }
 
        //Get Cert
@@ -443,53 +444,53 @@ int TADC_IF_VerifyCertChain( unsigned char* rica, int ricaLen,
        if (pstX509 == NULL)
        {
                DRM_TAPPS_EXCEPTION("TADC_IF_VerifyCertChain Error : Get Cert d2i_X509 error!");
-        iRet = -1;
-        goto error;
+               iRet = -1;
+               goto error;
        }
 
-    X509_STORE_set_flags(pstStore, X509_V_FLAG_CB_ISSUER_CHECK);
-    pstStoreCtx = X509_STORE_CTX_new();
+       X509_STORE_set_flags(pstStore, X509_V_FLAG_CB_ISSUER_CHECK);
+       pstStoreCtx = X509_STORE_CTX_new();
        if (pstStoreCtx == NULL)
        {
                DRM_TAPPS_EXCEPTION("TADC_IF_VerifyCertChain Error : 509_STORE_CTX_new error!");
-        iRet = -1;
-        goto error;
+               iRet = -1;
+               goto error;
        }
 
        //init
-    X509_STORE_CTX_init(pstStoreCtx, pstStore, pstX509, untrustedCerts);
+       X509_STORE_CTX_init(pstStoreCtx, pstStore, pstX509, untrustedCerts);
 
        //Set Flag
-    X509_STORE_CTX_set_flags(pstStoreCtx, X509_V_FLAG_CB_ISSUER_CHECK);
+       X509_STORE_CTX_set_flags(pstStoreCtx, X509_V_FLAG_CB_ISSUER_CHECK);
 
        //verify
-    iRet = X509_verify_cert(pstStoreCtx);
+       iRet = X509_verify_cert(pstStoreCtx);
 
        //free
 error:
-    if (pstStore != NULL)
-           X509_STORE_free(pstStore);
-    if (pstStoreCtx != NULL)
-           X509_STORE_CTX_free(pstStoreCtx);
-    if (untrustedCerts != NULL)
-        sk_X509_free(untrustedCerts);
-
-    if (iRet == 1)
-    {
+       if (pstStore != NULL)
+               X509_STORE_free(pstStore);
+       if (pstStoreCtx != NULL)
+               X509_STORE_CTX_free(pstStoreCtx);
+       if (untrustedCerts != NULL)
+               sk_X509_free(untrustedCerts);
+
+       if (iRet == 1)
+       {
                DRM_TAPPS_LOG("TADC_IF_VerifyCertChain Success! \n");
-        return 0;
-    }
-    else if (iRet == 0)
-    {
-        iErrCode = X509_STORE_CTX_get_error(pstStoreCtx);
+               return 0;
+       }
+       else if (iRet == 0)
+       {
+               iErrCode = X509_STORE_CTX_get_error(pstStoreCtx);
                DRM_TAPPS_EXCEPTION("TADC_IF_VerifyCertChain Error : %s \n", X509_verify_cert_error_string(iErrCode));
-        return -1;
-    }
-    else
-    {
-        DRM_TAPPS_EXCEPTION("TADC_IF_VerifyCertChain Error : 509_verify_cert error! \n");
-        return -1;
-    }
+               return -1;
+       }
+       else
+       {
+               DRM_TAPPS_EXCEPTION("TADC_IF_VerifyCertChain Error : 509_verify_cert error! \n");
+               return -1;
+       }
 }
 
 size_t TADC_IF_StrLen(const char *string)
index 1d57060..1cf570c 100644 (file)
@@ -32,7 +32,7 @@ enum
 
 //typedef int DrmHandler;
 
-int DrmTdcFileOpen(const char* filePath, int mode, int* handle);
+int DrmTdcFileOpen(const char* filePath, int* handle);
 
 int DrmTdcFileClose(int* handle);
 
index d561efb..c4b7409 100644 (file)
@@ -24,7 +24,7 @@ public:
        static DrmFileMgr *GetInstance();
        static void FreeInstance(void);
 
-       int OpenFileHandler(const char *filePath, int mode, int *key);
+       int OpenFileHandler(const char *filePath, int *key);
        int CloseFileHandler(int key);
        int GetFileHandler(int key, DrmFileHandler **handler);
 
index f492f30..e868971 100644 (file)
@@ -32,7 +32,7 @@ int TADC_IF_GetDUID(char *DUID);
 int TADC_IF_GetDHKey(T_DH_INFO *t_dhinfo);
 int TADC_IF_GetDHKey_K(T_DH_INFO *t_dhinfo);
 
-int TADC_IF_AES_CTR(int keyLen, unsigned char *pKey, int ivLen, unsigned char *pIV, int inLen, unsigned char *in, int *pOutLen, unsigned char *out);
+int TADC_IF_AES_CTR(unsigned char *pKey, int ivLen, unsigned char *pIV, int inLen, unsigned char *in, int *pOutLen, unsigned char *out);
 int TADC_IF_SHA1(unsigned char *in, int inLen, unsigned char *out);
 
 size_t TADC_IF_StrLen(const char *string);
index 6efcc68..7b595f3 100644 (file)
@@ -99,16 +99,20 @@ int DTappsInstallLicense(const char* declicbuffer)
        unsigned char name[DTAPPS_NAME_SIZE] = {0, };
        unsigned char nullCek[CEK_SIZE] = {0, };
 
-       char sql_query[2048] = {0, };
        int len = 0;
        time_t now = 0;
        char time_buffer[21] = {0, };
-       T_RO t_RO = {0, };
+       T_RO t_RO;
+
+       memset(&t_RO, 0x00, sizeof(t_RO));
 
        DTAPPS_RIGHTS_ROW row;
 
 #ifdef DTAPPS_STORE_CEK_IN_DB
-       AES_KEY key = {{0}};
+       AES_KEY key;
+
+       memset(&key, 0x00, sizeof(key));
+
        unsigned char *encr_cek = NULL;
        unsigned int keylen = 0;
        unsigned int encr_cek_len = 0;
@@ -359,7 +363,7 @@ Error_Exit:
 
 int DTappsHasValidLicense(const char* szCid)
 {
-       int len = 0, const_buf_enclen = 0, hash_buf_enclen = 0, const_buf_declen = 0, hash_buf_declen = 0;
+       int const_buf_enclen = 0, hash_buf_enclen = 0, const_buf_declen = 0, hash_buf_declen = 0;
 
        unsigned char *pDevKey = NULL;
        unsigned int DevKeyLen = 0;
@@ -484,7 +488,6 @@ int DTappsGetROInfo(const char* pszXML, T_RO *t_RO, unsigned char* name)
        CPointerArray   paChilds;
        LPCTSTR                 pszValue;
        int                             length = 0;
-       TADC_U8                 TempVersion[3] = {0};
        unsigned char   *pbBuffer = NULL;
        int len_enc = 0, len_dec = 0;
 
@@ -731,7 +734,6 @@ finish:
 
 BOOL DTappsGetCEK(const char* szCid, T_RO* t_RO)
 {
-       char sql_query[2048] = {0, };
        int db_buf_enclen = 0, hash_buf_enclen = 0, db_buf_declen = 0, hash_buf_declen = 0;
        DTAPPS_RIGHTS_ROW row;
        BOOL check = FALSE;
@@ -749,7 +751,9 @@ BOOL DTappsGetCEK(const char* szCid, T_RO* t_RO)
        int check_valid = TADC_LICENSE_VALID;
        DTAPPS_CONSTRAINTS st_constaints = {0, };
 
-       AES_KEY key = {{0}};
+       AES_KEY key;
+
+       memset(&key, 0x00, sizeof(key));
 
        if (NULL == szCid || NULL == t_RO)
        {
index 6157e9e..74e8f9a 100644 (file)
 
 #include "DTapps2Time.h"
 
- BOOL DTappsDtTmStr2Sec(unsigned char *time_str,time_t *TotalSec)
- {
-        char           str[32] = {0};
-        char           short_str[5] = {0};
-        struct tm      time_fmt = {0,};
+BOOL DTappsDtTmStr2Sec(unsigned char *time_str,time_t *TotalSec)
+{
+       char str[32] = {0};
+       char short_str[5] = {0};
+       struct tm time_fmt;
 
-        (void)TAPPS_GSTRLCPY(str, (const char*)time_str, sizeof(str));
+       memset(&time_fmt, 0x00, sizeof(time_fmt));
 
-        DRM_TAPPS_LOG("str = %s",str);
+       TAPPS_GSTRLCPY(str, (const char*)time_str, sizeof(str));
 
-        if(str[4] != '-' || str[7] != '-' || str[10] != 'T' || str[13] != ':' || str[16] != ':')
-        {
-                DRM_TAPPS_EXCEPTION("Format is incorrect:str=%s", str);
+       DRM_TAPPS_LOG("str = %s",str);
 
-                return FALSE;
-        }
+       if(str[4] != '-' || str[7] != '-' || str[10] != 'T' || str[13] != ':' || str[16] != ':')
+       {
+               DRM_TAPPS_EXCEPTION("Format is incorrect:str=%s", str);
 
-        DTAPPS_MEMCPY(short_str, str, 4);
-        time_fmt.tm_year = DTAPPS_ATOI(short_str) - 1900;
-        DRM_TAPPS_FRQ_LOG("tm_year = %d", time_fmt.tm_year);
+               return FALSE;
+       }
 
-        DTAPPS_MEMSET(short_str, 0x0,5);
-        DTAPPS_MEMCPY(short_str, str + 5, 2);
-        time_fmt.tm_mon = DTAPPS_ATOI(short_str) - 1;
-        DRM_TAPPS_FRQ_LOG("tm_mon = %d", time_fmt.tm_mon);
+       DTAPPS_MEMCPY(short_str, str, 4);
+       time_fmt.tm_year = DTAPPS_ATOI(short_str) - 1900;
+       DRM_TAPPS_FRQ_LOG("tm_year = %d", time_fmt.tm_year);
 
-        DTAPPS_MEMCPY(short_str, str + 8, 2);
-        time_fmt.tm_mday = DTAPPS_ATOI(short_str);
-        DRM_TAPPS_FRQ_LOG("tm_mday = %d", time_fmt.tm_mday);
+       DTAPPS_MEMSET(short_str, 0x0,5);
+       DTAPPS_MEMCPY(short_str, str + 5, 2);
+       time_fmt.tm_mon = DTAPPS_ATOI(short_str) - 1;
+       DRM_TAPPS_FRQ_LOG("tm_mon = %d", time_fmt.tm_mon);
 
-        DTAPPS_MEMCPY(short_str, str + 11, 2);
-        time_fmt.tm_hour = DTAPPS_ATOI(short_str);
-        DRM_TAPPS_FRQ_LOG("tm_hour = %d", time_fmt.tm_hour);
+       DTAPPS_MEMCPY(short_str, str + 8, 2);
+       time_fmt.tm_mday = DTAPPS_ATOI(short_str);
+       DRM_TAPPS_FRQ_LOG("tm_mday = %d", time_fmt.tm_mday);
+       DTAPPS_MEMCPY(short_str, str + 11, 2);
+       time_fmt.tm_hour = DTAPPS_ATOI(short_str);
+       DRM_TAPPS_FRQ_LOG("tm_hour = %d", time_fmt.tm_hour);
 
-        DTAPPS_MEMCPY(short_str, str + 14, 2);
-        time_fmt.tm_min = DTAPPS_ATOI(short_str);
-        DRM_TAPPS_FRQ_LOG("tm_min = %d", time_fmt.tm_min);
+       DTAPPS_MEMCPY(short_str, str + 14, 2);
+       time_fmt.tm_min = DTAPPS_ATOI(short_str);
+       DRM_TAPPS_FRQ_LOG("tm_min = %d", time_fmt.tm_min);
 
-        DTAPPS_MEMCPY(short_str, str + 17, 2);
-        time_fmt.tm_sec = DTAPPS_ATOI(short_str);
-        DRM_TAPPS_FRQ_LOG("tm_sec = %d", time_fmt.tm_sec);
+       DTAPPS_MEMCPY(short_str, str + 17, 2);
+       time_fmt.tm_sec = DTAPPS_ATOI(short_str);
+       DRM_TAPPS_FRQ_LOG("tm_sec = %d", time_fmt.tm_sec);
 
-        /* Convert into Seconds */
-        *TotalSec = DTAPPS_MKTIME(&time_fmt);
-        DRM_TAPPS_LOG("TotalSec = %lu", *TotalSec);
+       /* Convert into Seconds */
+       *TotalSec = DTAPPS_MKTIME(&time_fmt);
+       DRM_TAPPS_LOG("TotalSec = %lu", *TotalSec);
 
-        return TRUE;
- }
+       return TRUE;
+}
 
 BOOL DTappsDtTmStr2StrucTm(unsigned char *time_str,struct tm *time_fmt)
- {
-        char           str[32] = {0};
-        char           short_str[5] = {0};
+{
+       char str[32] = {0};
+       char short_str[5] = {0};
 
-        (void)TAPPS_GSTRLCPY(str, (const char*)time_str, sizeof(str));
+       TAPPS_GSTRLCPY(str, (const char*)time_str, sizeof(str));
 
-        DRM_TAPPS_LOG("str = %s", str);
+       DRM_TAPPS_LOG("str = %s", str);
 
-        if(str[4]!='-' || str[7]!='-' || str[10]!='T' || str[13]!=':' || str[16]!=':')
-        {
-                DRM_TAPPS_EXCEPTION("Format is incorrect:str=%s", str);
+       if(str[4]!='-' || str[7]!='-' || str[10]!='T' || str[13]!=':' || str[16]!=':')
+       {
+               DRM_TAPPS_EXCEPTION("Format is incorrect:str=%s", str);
 
-                return FALSE;
-        }
+               return FALSE;
+       }
 
-        DTAPPS_MEMCPY(short_str, str, 4);
-        time_fmt->tm_year = DTAPPS_ATOI(short_str) - 1900;
-        DRM_TAPPS_FRQ_LOG("tm_year = %d", time_fmt->tm_year);
+       DTAPPS_MEMCPY(short_str, str, 4);
+       time_fmt->tm_year = DTAPPS_ATOI(short_str) - 1900;
+       DRM_TAPPS_FRQ_LOG("tm_year = %d", time_fmt->tm_year);
 
-        DTAPPS_MEMSET(short_str, 0x0, 5);
-        DTAPPS_MEMCPY(short_str, str + 5, 2);
-        time_fmt->tm_mon = DTAPPS_ATOI(short_str) - 1;
-        DRM_TAPPS_FRQ_LOG("tm_mon = %d", time_fmt->tm_mon);
+       DTAPPS_MEMSET(short_str, 0x0, 5);
+       DTAPPS_MEMCPY(short_str, str + 5, 2);
+       time_fmt->tm_mon = DTAPPS_ATOI(short_str) - 1;
+       DRM_TAPPS_FRQ_LOG("tm_mon = %d", time_fmt->tm_mon);
 
-        DTAPPS_MEMCPY(short_str, str + 8, 2);
-        time_fmt->tm_mday = DTAPPS_ATOI(short_str);
-        DRM_TAPPS_FRQ_LOG("tm_mday = %d", time_fmt->tm_mday);
+       DTAPPS_MEMCPY(short_str, str + 8, 2);
+       time_fmt->tm_mday = DTAPPS_ATOI(short_str);
+       DRM_TAPPS_FRQ_LOG("tm_mday = %d", time_fmt->tm_mday);
 
-        DTAPPS_MEMCPY(short_str, str + 11, 2);
-        time_fmt->tm_hour = DTAPPS_ATOI(short_str);
-        DRM_TAPPS_FRQ_LOG("tm_hour = %d", time_fmt->tm_hour);
+       DTAPPS_MEMCPY(short_str, str + 11, 2);
+       time_fmt->tm_hour = DTAPPS_ATOI(short_str);
+       DRM_TAPPS_FRQ_LOG("tm_hour = %d", time_fmt->tm_hour);
 
-        DTAPPS_MEMCPY(short_str, str + 14, 2);
-        time_fmt->tm_min = DTAPPS_ATOI(short_str);
-        DRM_TAPPS_FRQ_LOG("tm_min = %d", time_fmt->tm_min);
+       DTAPPS_MEMCPY(short_str, str + 14, 2);
+       time_fmt->tm_min = DTAPPS_ATOI(short_str);
+       DRM_TAPPS_FRQ_LOG("tm_min = %d", time_fmt->tm_min);
 
-        DTAPPS_MEMCPY(short_str, str + 17, 2);
-        time_fmt->tm_sec = DTAPPS_ATOI(short_str);
-        DRM_TAPPS_FRQ_LOG("tm_sec = %d", time_fmt->tm_sec);
+       DTAPPS_MEMCPY(short_str, str + 17, 2);
+       time_fmt->tm_sec = DTAPPS_ATOI(short_str);
+       DRM_TAPPS_FRQ_LOG("tm_sec = %d", time_fmt->tm_sec);
 
-        return TRUE;
- }
+       return TRUE;
+}
 
 BOOL DTappsGetSecureTime(time_t* seconds)
 {
@@ -120,6 +121,8 @@ BOOL DTappsGetSecureTime(time_t* seconds)
        int Delta = 0;
        struct tm gm_fmt;
 
+       memset(&gm_fmt, 0x00, sizeof(gm_fmt));
+
        now = DTAPPS_TIME(NULL);
 
        /* TODO: Read the Delta from VCONF */
index a15bd00..65a86bf 100644 (file)
@@ -9,6 +9,7 @@ pkg_check_modules(DRM_TEST_DEP
 
 SET(DRMTESTUTIL_SRCS
        ${PROJECT_SOURCE_DIR}/test/drm_testapps.cpp
+       ${PROJECT_SOURCE_DIR}/test/drm_testcore.cpp
        ${PROJECT_SOURCE_DIR}/test/drm_testutil.cpp
        ${PROJECT_SOURCE_DIR}/tadcore/TADCCore/TADC_Core.cpp
        ${PROJECT_SOURCE_DIR}/tadcore/TADCCore/TADC_Sub.cpp
index d81f32f..fbb3d3b 100644 (file)
  * limitations under the License.
  */
 
+#include <vector>
+#include <fstream>
+#include <iostream>
+
 #include "drm-tizen-apps.h"
 #include "drm-tizen-error.h"
 #include "TADC_Core.h"
@@ -22,6 +26,7 @@
 
 #include "DTapps2Rights.h"
 #include "drm_testutil.h"
+#include "drm_testcore.h"
 #include <tzplatform_config.h>
 
 #if 1
@@ -32,13 +37,13 @@ static int third_key = 0;
 bool _write_logfile(const char *filename, char *buf, unsigned int len)
 {
        FILE *fd = NULL;
-       
+
        if ((fd = fopen(filename,"w+b")) == NULL)
        {
                return false;
        }
 
-       fwrite(buf, 1, len,fd); 
+       fwrite(buf, 1, len,fd);
        fclose(fd);
 
        return true;
@@ -48,13 +53,13 @@ bool _read_logfile(const char *filename, char *buf, unsigned int *pLen)
 {
        FILE *fd = NULL;
        int  nReadLen = 0;
-       
+
        if ((fd = fopen(filename,"r+b")) == NULL)
        {
                return false;
        }
 
-       nReadLen = fread(buf, 1, *pLen,fd); 
+       nReadLen = fread(buf, 1, *pLen,fd);
        *pLen = nReadLen;
 
        fclose(fd);
@@ -64,587 +69,178 @@ bool _read_logfile(const char *filename, char *buf, unsigned int *pLen)
 
 bool tc01_VerifyRoSignature_Positive_01(void)
 {
-       char Buf[1024*10] = {0, };      
-       const char *pRo = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/38EIfBurLJ-1.0.2.ro");
-
-       FILE *fd = NULL;
-       int     nReadLen = 0;
-       long lSize = 0;
-       int nRet = 0;
-
        printf("tc01_VerifyRoSignature_Positive_01() -------- Started! \n");
 
-       fd = fopen(pRo, "rb");
-       if (fd == NULL)
-       {
-               printf("File is not exist! : %s\n", pRo);
-               goto CATCH;
-       }
-
-       fseek(fd, 0, SEEK_END);
-       lSize = ftell(fd);
-       if (lSize < 0)
-       {
-               printf("fseek() and ftell() failed.");
-               goto CATCH;
-       }
-       rewind(fd);
-
-       memset(Buf, 0x00, sizeof(Buf));
-       nReadLen = fread(Buf, 1, lSize, fd);
-       if (nReadLen >= sizeof(Buf))
-       {
-               printf("Buffer error! : %s\n", pRo);
-               goto CATCH;
-       }
+       const char *pRo = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/38EIfBurLJ-1.0.2.ro");
 
-       if (nReadLen != lSize)
-       {
-               printf("File read error! : %s\n", pRo);
-               goto CATCH;
-       }
+       auto buf = _read_ro_file(pRo);
 
-       nRet = TADC_VerifyROSignature((unsigned char*) Buf);
-       if (nRet != 0)
-       {
+       int nRet = TADC_VerifyROSignature(buf.data());
+       if (nRet != 0) {
                printf("VerifyROSignature Failed! : %s, %d\n", pRo, nRet);
-               goto CATCH;
-       }
-       if (fd != NULL)
-       {
-               fclose(fd);
+               return false;
        }
 
        printf("tc01_VerifyRoSignature_Positive_01() finished! -------- success \n");
-       return true;
 
-CATCH:
-       if (fd != NULL)
-       {
-               fclose(fd);
-       }
-       return false;
+       return true;
 }
 
 bool tc01_VerifyRoSignature_Positive_02(void)
 {
-       char Buf[1024*10] = {0, };      
-       const char *pRo = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/8SPXfqc6iL-1.0.0.ro");
-
-       FILE *fd = NULL;
-       int     nReadLen = 0;
-       long lSize = 0;
-       int nRet = 0;
-
        printf("tc01_VerifyRoSignature_Positive_02() -------- Started! \n");
+       const char *pRo = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/8SPXfqc6iL-1.0.0.ro");
 
-       fd = fopen(pRo, "rb");
-       if (fd == NULL)
-       {
-               printf("File is not exist! : %s\n", pRo);
-               goto CATCH;
-       }
-
-       fseek(fd, 0, SEEK_END);
-       lSize = ftell(fd);
-       if (lSize < 0)
-       {
-               printf("fseek() and ftell() failed.");
-               goto CATCH;
-       }
-       rewind(fd);
-
-       memset(Buf, 0x00, sizeof(Buf));
-       nReadLen = fread(Buf, 1, lSize, fd);
-       if (nReadLen >= sizeof(Buf))
-       {
-               printf("Buffer error! : %s\n", pRo);
-               goto CATCH;
-       }
-
-       if (nReadLen != lSize)
-       {
-               printf("File read error! : %s\n", pRo);
-               goto CATCH;
-       }
+       auto buf = _read_ro_file(pRo);
 
-       nRet = TADC_VerifyROSignature((unsigned char*) Buf);
-       if (nRet != 0)
-       {
+       int nRet = TADC_VerifyROSignature(buf.data());
+       if (nRet != 0) {
                printf("VerifyROSignature Failed! : %s, %d\n", pRo, nRet);
-               goto CATCH;
-       }
-       if (fd != NULL)
-       {
-               fclose(fd);
+               return false;
        }
 
        printf("tc01_VerifyRoSignature_Positive_02() finished! -------- success \n");
        return true;
-
-CATCH:
-       if (fd != NULL)
-       {
-               fclose(fd);
-       }
-       return false;
 }
 
 bool tc01_VerifyRoSignature_Positive_03(void)
 {
-       char Buf[1024*10] = {0, };      
-       const char *pRo = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/FightGuiIF-1.0.0.ro");
-
-       FILE *fd = NULL;
-       int     nReadLen = 0;
-       long lSize = 0;
-       int nRet = 0;
-
        printf("tc01_VerifyRoSignature_Positive_03() -------- Started! \n");
 
-       fd = fopen(pRo, "rb");
-       if (fd == NULL)
-       {
-               printf("File is not exist! : %s\n", pRo);
-               goto CATCH;
-       }
-
-       fseek(fd, 0, SEEK_END);
-       lSize = ftell(fd);
-       if (lSize < 0)
-       {
-               printf("fseek() and ftell() failed.");
-               goto CATCH;
-       }
-       rewind(fd);
+       const char *pRo = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/FightGuiIF-1.0.0.ro");
 
-       memset(Buf, 0x00, sizeof(Buf));
-       nReadLen = fread(Buf, 1, lSize, fd);
-       if (nReadLen >= sizeof(Buf))
-       {
-               printf("Buffer error! : %s\n", pRo);
-               goto CATCH;
-       }
+       auto buf = _read_ro_file(pRo);
 
-       if (nReadLen != lSize)
-       {
-               printf("File read error! : %s\n", pRo);
-               goto CATCH;
-       }
-
-       nRet = TADC_VerifyROSignature((unsigned char*) Buf);
+       int nRet = TADC_VerifyROSignature(buf.data());
        if (nRet != 0)
        {
                printf("VerifyROSignature Failed! : %s, %d\n", pRo, nRet);
-               goto CATCH;
-       }
-       if (fd != NULL)
-       {
-               fclose(fd);
+               return false;
        }
 
        printf("tc01_VerifyRoSignature_Positive_03() finished! -------- success \n");
        return true;
-
-CATCH:
-       if (fd != NULL)
-       {
-               fclose(fd);
-       }
-       return false;
 }
 
 bool tc02_VerifyRoSignature_Negative_Cert_01(void)
 {
-       char Buf[1024*10] = {0, };      
-       const char *pRo  = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/38EIfBurLJ-1.0.2.cert_only_selfsigned.ro");
-       FILE *fd = NULL;
-       int     nReadLen = 0;
-       long lSize = 0;
-       int nRet = 0;
-
        printf("tc02_VerifyRoSignature_Negative_Cert_01() -------- Started! \n");
 
-       fd = fopen(pRo, "rb");
-       if (fd == NULL)
-       {
-               printf("File is not exist! : %s\n", pRo);
-               goto CATCH;
-       }
-
-       fseek(fd, 0, SEEK_END);
-       lSize = ftell(fd);
-       if (lSize < 0)
-       {
-               printf("fseek() and ftell() failed.");
-               goto CATCH;
-       }
-       rewind(fd);
-
-       memset(Buf, 0x00, sizeof(Buf));
-       nReadLen = fread(Buf, 1, lSize, fd);
-       if (nReadLen >= sizeof(Buf))
-       {
-               printf("Buffer error! : %s\n", pRo);
-               goto CATCH;
-       }
+       const char *pRo  = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/38EIfBurLJ-1.0.2.cert_only_selfsigned.ro");
 
-       if (nReadLen != lSize)
-       {
-               printf("File read error! : %s\n", pRo);
-               goto CATCH;
-       }
+       auto buf = _read_ro_file(pRo);
 
-       nRet = TADC_VerifyROSignature((unsigned char*) Buf);
-       if (nRet >= 0)
-       {
+       int nRet = TADC_VerifyROSignature(buf.data());
+       if (nRet >= 0) {
                printf("VerifyROSignature have to be failed. But success! : %s, %d\n", pRo, nRet);
-               goto CATCH;
-       }
-       if (fd != NULL)
-       {
-               fclose(fd);
+               return false;
        }
 
        printf("tc02_VerifyRoSignature_Negative_Cert_01 finished! -------- success \n");
        return true;
-
-CATCH:
-       if (fd != NULL)
-       {
-               fclose(fd);
-       }
-       return false;
 }
 
 bool tc02_VerifyRoSignature_Negative_Cert_02(void)
 {
-       char Buf[1024*10] = {0, };      
-       const char *pRo = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/38EIfBurLJ-1.0.2.cert_chain_invalid.ro");
-       FILE *fd = NULL;
-       int     nReadLen = 0;
-       long lSize = 0;
-       int nRet = 0;
-
        printf("tc02_VerifyRoSignature_Negative_Cert_02() -------- Started! \n");
 
-       fd = fopen(pRo, "rb");
-       if (fd == NULL)
-       {
-               printf("File is not exist! : %s\n", pRo);
-               goto CATCH;
-       }
+       const char *pRo = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/38EIfBurLJ-1.0.2.cert_chain_invalid.ro");
 
-       fseek(fd, 0, SEEK_END);
-       lSize = ftell(fd);
-       if (lSize < 0)
-       {
-               printf("fseek() and ftell() failed.");
-               goto CATCH;
-       }
-       rewind(fd);
-
-       memset(Buf, 0x00, sizeof(Buf));
-       nReadLen = fread(Buf, 1, lSize, fd);
-       if (nReadLen >= sizeof(Buf))
-       {
-               printf("Buffer error! : %s\n", pRo);
-               goto CATCH;
-       }
-
-       if (nReadLen != lSize)
-       {
-               printf("File read error! : %s\n", pRo);
-               goto CATCH;
-       }
+       auto buf = _read_ro_file(pRo);
 
-       nRet = TADC_VerifyROSignature((unsigned char*) Buf);
-       if (nRet >= 0)
-       {
+       int nRet = TADC_VerifyROSignature(buf.data());
+       if (nRet >= 0) {
                printf("VerifyROSignature have to be failed. But success! : %s, %d\n", pRo, nRet);
-               goto CATCH;
-       }
-       if (fd != NULL)
-       {
-               fclose(fd);
+               return false;
        }
 
        printf("tc02_VerifyRoSignature_Negative_Cert_02 finished! -------- success \n");
        return true;
-
-CATCH:
-       if (fd != NULL)
-       {
-               fclose(fd);
-       }
-       return false;
 }
 
 bool tc02_VerifyRoSignature_Negative_Cert_03(void)
 {
-       char Buf[1024*10] = {0, };      
-       const char *pRo  = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/38EIfBurLJ-1.0.2.cert_invalid.ro");
-       FILE *fd = NULL;
-       int     nReadLen = 0;
-       long lSize = 0;
-       int nRet = 0;
-
        printf("tc02_VerifyRoSignature_Negative_Cert_03() -------- Started! \n");
 
-       fd = fopen(pRo, "rb");
-       if (fd == NULL)
-       {
-               printf("File is not exist! : %s\n", pRo);
-               goto CATCH;
-       }
-
-       fseek(fd, 0, SEEK_END);
-       lSize = ftell(fd);
-       if (lSize < 0)
-       {
-               printf("fseek() and ftell() failed.");
-               goto CATCH;
-       }
-       rewind(fd);
-
-       memset(Buf, 0x00, sizeof(Buf));
-       nReadLen = fread(Buf, 1, lSize, fd);
-       if (nReadLen >= sizeof(Buf))
-       {
-               printf("Buffer error! : %s\n", pRo);
-               goto CATCH;
-       }
+       const char *pRo  = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/38EIfBurLJ-1.0.2.cert_invalid.ro");
 
-       if (nReadLen != lSize)
-       {
-               printf("File read error! : %s\n", pRo);
-               goto CATCH;
-       }
+       auto buf = _read_ro_file(pRo);
 
-       nRet = TADC_VerifyROSignature((unsigned char*) Buf);
-       if (nRet >= 0)
-       {
+       int nRet = TADC_VerifyROSignature(buf.data());
+       if (nRet >= 0) {
                printf("VerifyROSignature have to be failed. But success! : %s, %d\n", pRo, nRet);
-               goto CATCH;
-       }
-       if (fd != NULL)
-       {
-               fclose(fd);
+               return false;
        }
 
        printf("tc02_VerifyRoSignature_Negative_Cert_03 finished! -------- success \n");
        return true;
-
-CATCH:
-       if (fd != NULL)
-       {
-               fclose(fd);
-       }
-       return false;
 }
 
 bool tc03_VerifyRoSignature_Negative_Signature_01(void)
 {
-       char Buf[1024*10] = {0, };      
-       const char *pRo   = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/FightGuiIF-1.0.0.signature_invalid.ro");
-       FILE *fd = NULL;
-       int     nReadLen = 0;
-       long lSize = 0;
-       int nRet = 0;
-
        printf("tc03_VerifyRoSignature_Negative_Signature_01() -------- Started! \n");
 
-       fd = fopen(pRo, "rb");
-       if (fd == NULL)
-       {
-               printf("File is not exist! : %s\n", pRo);
-               goto CATCH;
-       }
-
-       fseek(fd, 0, SEEK_END);
-       lSize = ftell(fd);
-       if (lSize < 0)
-       {
-               printf("fseek() and ftell() failed.");
-               goto CATCH;
-       }
-       rewind(fd);
-
-       memset(Buf, 0x00, sizeof(Buf));
-       nReadLen = fread(Buf, 1, lSize, fd);
-       if (nReadLen >= sizeof(Buf))
-       {
-               printf("Buffer error! : %s\n", pRo);
-               goto CATCH;
-       }
+       const char *pRo   = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/FightGuiIF-1.0.0.signature_invalid.ro");
 
-       if (nReadLen != lSize)
-       {
-               printf("File read error! : %s\n", pRo);
-               goto CATCH;
-       }
+       auto buf = _read_ro_file(pRo);
 
-       nRet = TADC_VerifyROSignature((unsigned char*) Buf);
-       if (nRet >= 0)
-       {
+       int nRet = TADC_VerifyROSignature(buf.data());
+       if (nRet >= 0) {
                printf("VerifyROSignature have to be failed. But success! : %s, %d\n", pRo, nRet);
-               goto CATCH;
-       }
-       if (fd != NULL)
-       {
-               fclose(fd);
+               return false;
        }
 
        printf("tc03_VerifyRoSignature_Negative_Signature_01() finished! -------- success \n");
 
        return true;
-
-CATCH:
-       if (fd != NULL)
-       {
-               fclose(fd);
-       }
-       return false;
 }
 
 bool tc03_VerifyRoSignature_Negative_Signature_02(void)
 {
-       char Buf[1024*10] = {0, };      
-       const char *pRo = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/38EIfBurLJ-1.0.2.signature_invalid.ro");
-       FILE *fd = NULL;
-       int     nReadLen = 0;
-       long lSize = 0;
-       int nRet = 0;
-
        printf("tc03_VerifyRoSignature_Negative_Signature_02() -------- Started! \n");
 
-       fd = fopen(pRo, "rb");
-       if (fd == NULL)
-       {
-               printf("File is not exist! : %s\n", pRo);
-               goto CATCH;
-       }
-
-       fseek(fd, 0, SEEK_END);
-       lSize = ftell(fd);
-       if (lSize < 0)
-       {
-               printf("fseek() and ftell() failed.");
-               goto CATCH;
-       }
-       rewind(fd);
-
-       memset(Buf, 0x00, sizeof(Buf));
-       nReadLen = fread(Buf, 1, lSize, fd);
-       if (nReadLen >= sizeof(Buf))
-       {
-               printf("Buffer error! : %s\n", pRo);
-               goto CATCH;
-       }
+       const char *pRo = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/38EIfBurLJ-1.0.2.signature_invalid.ro");
 
-       if (nReadLen != lSize)
-       {
-               printf("File read error! : %s\n", pRo);
-               goto CATCH;
-       }
+       auto buf = _read_ro_file(pRo);
 
-       nRet = TADC_VerifyROSignature((unsigned char*) Buf);
-       if (nRet >= 0)
-       {
+       int nRet = TADC_VerifyROSignature(buf.data());
+       if (nRet >= 0) {
                printf("VerifyROSignature have to be failed. But success! : %s, %d\n", pRo, nRet);
-               goto CATCH;
-       }
-       if (fd != NULL)
-       {
-               fclose(fd);
+               return false;
        }
 
        printf("tc03_VerifyRoSignature_Negative_Signature_01() finished! -------- success \n");
 
        return true;
-
-CATCH:
-       if (fd != NULL)
-       {
-               fclose(fd);
-       }
-       return false;
 }
 
 bool tc03_VerifyRoSignature_Negative_Signature_03(void)
 {
-       char Buf[1024*10] = {0, };      
-       const char *pRo  = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/8SPXfqc6iL-1.0.0.signature_invalid.ro");
-       FILE *fd = NULL;
-       int     nReadLen = 0;
-       long lSize = 0;
-       int nRet = 0;
-
        printf("tc03_VerifyRoSignature_Negative_Signature_03() -------- Started! \n");
 
-       fd = fopen(pRo, "rb");
-       if (fd == NULL)
-       {
-               printf("File is not exist! : %s\n", pRo);
-               goto CATCH;
-       }
-
-       fseek(fd, 0, SEEK_END);
-       lSize = ftell(fd);
-       if (lSize < 0)
-       {
-               printf("fseek() and ftell() failed.");
-               goto CATCH;
-       }
-       rewind(fd);
-
-       memset(Buf, 0x00, sizeof(Buf));
-       nReadLen = fread(Buf, 1, lSize, fd);
-       if (nReadLen >= sizeof(Buf))
-       {
-               printf("Buffer error! : %s\n", pRo);
-               goto CATCH;
-       }
+       const char *pRo  = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/8SPXfqc6iL-1.0.0.signature_invalid.ro");
 
-       if (nReadLen != lSize)
-       {
-               printf("File read error! : %s\n", pRo);
-               goto CATCH;
-       }
+       auto buf = _read_ro_file(pRo);
 
-       nRet = TADC_VerifyROSignature((unsigned char*) Buf);
-       if (nRet >= 0)
-       {
+       int nRet = TADC_VerifyROSignature(buf.data());
+       if (nRet >= 0) {
                printf("VerifyROSignature have to be failed. But success! : %s, %d\n", pRo, nRet);
-               goto CATCH;
-       }
-       if (fd != NULL)
-       {
-               fclose(fd);
+               return false;
        }
 
        printf("tc03_VerifyRoSignature_Negative_Signature_03() finished! -------- success \n");
 
        return true;
-
-CATCH:
-       if (fd != NULL)
-       {
-               fclose(fd);
-       }
-       return false;
 }
 
 bool tc04_isDrmFile_Positive_01(void)
 {
        const char *pDCF = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/DCF/38EIfBurLJ.tpk");
-       int nRet = 0;
 
        printf("tc04_isDrmFile_Positive_01() -------- Started!\n");
 
-       nRet = drm_tizen_is_drm_file(pDCF, strlen(pDCF));
-       if (nRet != TADC_SUCCESS)
-       {
+       int nRet = drm_tizen_is_drm_file(pDCF, strlen(pDCF));
+       if (nRet != TADC_SUCCESS) {
                printf("drm_tizen_is_drm_file failed. Path = %s, Ret = %d\n", pDCF,  nRet);
                printf("%s file is not TADC file!\n", pDCF);
                return false;
@@ -658,13 +254,11 @@ bool tc04_isDrmFile_Positive_01(void)
 bool tc04_isDrmFile_Positive_02(void)
 {
        const char *pDCF = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/DCF/8SPXfqc6iL.tpk");
-       int nRet = 0;
 
        printf("tc04_isDrmFile_Positive_02() -------- Started!\n");
 
-       nRet = drm_tizen_is_drm_file(pDCF, strlen(pDCF));
-       if (nRet != TADC_SUCCESS)
-       {
+       int nRet = drm_tizen_is_drm_file(pDCF, strlen(pDCF));
+       if (nRet != TADC_SUCCESS) {
                printf("drm_tizen_is_drm_file failed. Path = %s, Ret = %d\n", pDCF,  nRet);
                printf("%s file is not TADC file!\n", pDCF);
                return false;
@@ -678,13 +272,11 @@ bool tc04_isDrmFile_Positive_02(void)
 bool tc04_isDrmFile_Positive_03(void)
 {
        const char *pDCF = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/DCF/FightGuiIF.tpk");
-       int nRet = 0;
 
        printf("tc04_isDrmFile_Positive_03() -------- Started!\n");
 
-       nRet = drm_tizen_is_drm_file(pDCF, strlen(pDCF));
-       if (nRet != TADC_SUCCESS)
-       {
+       int nRet = drm_tizen_is_drm_file(pDCF, strlen(pDCF));
+       if (nRet != TADC_SUCCESS) {
                printf("drm_tizen_is_drm_file failed. Path = %s, Ret = %d\n", pDCF,  nRet);
                printf("%s file is not TADC file!\n", pDCF);
                return false;
@@ -698,13 +290,11 @@ bool tc04_isDrmFile_Positive_03(void)
 bool tc05_isDrmFile_Negative_01(void)
 {
        const char *pApp = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/DecryptedApp/38EIfBurLJ_dec.tpk");
-       int nRet = 0;
 
        printf("tc05_isDrmFile_Negative_01() -------- Started! \n");
 
-       nRet = drm_tizen_is_drm_file(pApp, strlen(pApp));
-       if(nRet == TADC_SUCCESS)
-       {
+       int nRet = drm_tizen_is_drm_file(pApp, strlen(pApp));
+       if(nRet == TADC_SUCCESS) {
                printf("drm_tizen_is_drm_file have to be failed. But Success!  Path = %s, Ret = %d\n", pApp,  nRet);
                return false;
        }
@@ -717,13 +307,11 @@ bool tc05_isDrmFile_Negative_01(void)
 bool tc05_isDrmFile_Negative_02(void)
 {
        const char *pApp = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/DecryptedApp/8SPXfqc6iL_dec.tpk");
-       int nRet = 0;
 
        printf("tc05_isDrmFile_Negative_02() -------- Started! \n");
 
-       nRet = drm_tizen_is_drm_file(pApp, strlen(pApp));
-       if(nRet == TADC_SUCCESS)
-       {
+       int nRet = drm_tizen_is_drm_file(pApp, strlen(pApp));
+       if(nRet == TADC_SUCCESS) {
                printf("drm_tizen_is_drm_file have to be failed. But Success!  Path = %s, Ret = %d\n", pApp,  nRet);
                return false;
        }
@@ -736,13 +324,11 @@ bool tc05_isDrmFile_Negative_02(void)
 bool tc05_isDrmFile_Negative_03(void)
 {
        const char *pApp = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/DecryptedApp/FightGuiIF_dec.tpk");
-       int nRet = 0;
 
        printf("tc05_isDrmFile_Negative_03() -------- Started! \n");
 
-       nRet = drm_tizen_is_drm_file(pApp, strlen(pApp));
-       if(nRet == TADC_SUCCESS)
-       {
+       int nRet = drm_tizen_is_drm_file(pApp, strlen(pApp));
+       if(nRet == TADC_SUCCESS) {
                printf("drm_tizen_is_drm_file have to be failed. But Success!  Path = %s, Ret = %d\n", pApp,  nRet);
                return false;
        }
@@ -1081,7 +667,7 @@ bool tc07_DrmFileMgrPositive_01(void)
 
        pDrmFileMgr = DrmFileMgr::GetInstance();
 
-       nRet = pDrmFileMgr->OpenFileHandler(pDCF, 1, &first_key);
+       nRet = pDrmFileMgr->OpenFileHandler(pDCF, &first_key);
        if (nRet != TADC_SUCCESS)
        {
                printf("tc07_DrmFileMgrPositive_01 - OpenFileHandler() failed : key = %d, file = %s, %x\n", first_key, pDCF, nRet);
@@ -1166,7 +752,7 @@ bool tc07_DrmFileMgrPositive_02(void)
 
        pDrmFileMgr = DrmFileMgr::GetInstance();
 
-       nRet = pDrmFileMgr->OpenFileHandler(pDCF, 1, &second_key);
+       nRet = pDrmFileMgr->OpenFileHandler(pDCF, &second_key);
        if (nRet != TADC_SUCCESS)
        {
                printf("tc07_DrmFileMgrPositive_02 - OpenFileHandler() failed : key = %d, file = %s, %x\n", second_key, pDCF, nRet);
@@ -1252,7 +838,7 @@ bool tc07_DrmFileMgrPositive_03(void)
 
        pDrmFileMgr = DrmFileMgr::GetInstance();
 
-       nRet = pDrmFileMgr->OpenFileHandler(pDCF, 1, &third_key);
+       nRet = pDrmFileMgr->OpenFileHandler(pDCF, &third_key);
        if (nRet != TADC_SUCCESS)
        {
                printf("tc07_DrmFileMgrPositive_03 - OpenFileHandler() failed : key = %d, file = %s, %x\n", third_key, pDCF, nRet);
@@ -1646,7 +1232,7 @@ bool tc09_DrmFileMgrPositive_FileAPI_01(void)
                DrmCurOffset = pDcfHandler->DrmTell();
                if (DrmCurOffset != pDcfHandler->m_DrmCurOffset)
                {
-                       printf("tc09_DrmFileMgrPositive_FileAPI_01 - DrmCurOffset Comparison failed (SEEK_END, forward) : origin = %lld, result = %lld, i = %%lld\n", DrmCurOffset, pDcfHandler->m_DrmCurOffset, i);
+                       printf("tc09_DrmFileMgrPositive_FileAPI_01 - DrmCurOffset Comparison failed (SEEK_END, forward) : origin = %lld, result = %lld, i = %lld\n", DrmCurOffset, pDcfHandler->m_DrmCurOffset, i);
                        goto CATCH;
                }
        }
@@ -2237,200 +1823,62 @@ bool tc12_TADC_SetDeviceInfo_01(void)
        }
        printf("DUID=%s\n", (char*)t_DeviceInfo.DUID);
        printf("tc12_TADC_SetDeviceInfo_01() finished! -------- success \n");
-       
+
        return true;
 }
 
-bool
-tc13_DTappsInstallLicense_01(void)
+bool tc13_DTappsInstallLicense_01(void)
 {
-       int nRet = TADC_SUCCESS;
-       char Buf[1024*10] = {0, };      
-       const char *pFirstRo = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/38EIfBurLJ-1.0.2.ro");
-       FILE* fd = NULL;
-       int     nReadLen = 0;
-       long lSize = 0;
-       bool res = true;
-
        printf("tc13_DTappsInstallLicense_01() -------- Started! \n");
 
-       fd = fopen(pFirstRo, "rb");
-       if (fd == NULL)
-       {
-               printf("File is not exist! : %s\n", pFirstRo);
-               res = false;
-               goto CATCH;
-       }
-
-       fseek(fd, 0, SEEK_END);
-       lSize = ftell(fd);
-       if (lSize < 0)
-       {
-               printf("fseek() and ftell() failed.");
-               res = false;
-               goto CATCH;
-       }
-       rewind(fd);
-
-       memset(Buf, 0x00, sizeof(Buf));
-       nReadLen = fread(Buf, 1, lSize, fd);
-       if (nReadLen >= sizeof(Buf))
-       {
-               printf("Buffer error! : %s\n", pFirstRo);
-               goto CATCH;
-       }
+       const char *pFirstRo = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/38EIfBurLJ-1.0.2.ro");
 
-       if (nReadLen != lSize)
-       {
-               printf("File read error! : %s\n", pFirstRo);
-               res = false;
-               goto CATCH;
-       }
+       auto buf = _read_ro_file(pFirstRo);
 
-       nRet = DTappsInstallLicense(Buf);
-       if (nRet != TADC_SUCCESS)
-       {
+       int nRet = DTappsInstallLicense(reinterpret_cast<char *>(buf.data()));
+       if (nRet != TADC_SUCCESS) {
                printf("tc13_DTappsInstallLicense_01() failed. nRet=%d\n", nRet);
-               res = false;
-               goto CATCH;
+               return false;
        }
 
        printf("tc13_DTappsInstallLicense_01() finished! -------- success \n");
-
-CATCH:
-       if (fd != NULL)
-       {
-               fclose(fd);
-       }
-       return res;
+       return true;
 }
 
-bool
-tc13_DTappsInstallLicense_02(void)
+bool tc13_DTappsInstallLicense_02(void)
 {
-       int     nRet = TADC_SUCCESS;
-       char Buf[1024*10] = {0, };      
-       const char *pFirstRo = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/8SPXfqc6iL-1.0.0.ro");
-       FILE* fd = NULL;
-       int     nReadLen = 0;
-       long lSize = 0;
-       bool res = true;
-
        printf("tc13_DTappsInstallLicense_02() -------- Started! \n");
 
-       fd = fopen(pFirstRo, "rb");
-       if (fd == NULL)
-       {
-               printf("File is not exist! : %s\n", pFirstRo);
-               res = false;
-               goto CATCH;
-       }
-
-       fseek(fd, 0, SEEK_END);
-       lSize = ftell(fd);
-       if (lSize < 0)
-       {
-               printf("fseek() and ftell() failed.");
-               res = false;
-               goto CATCH;
-       }
-       rewind(fd);
+       const char *pFirstRo = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/8SPXfqc6iL-1.0.0.ro");
 
-       memset(Buf, 0x00, sizeof(Buf));
-       nReadLen = fread(Buf, 1, lSize, fd);
-       if (nReadLen >= sizeof(Buf))
-       {
-               printf("Buffer error! : %s\n", pFirstRo);
-               goto CATCH;
-       }
+       auto buf = _read_ro_file(pFirstRo);
 
-       if (nReadLen != lSize)
-       {
-               printf("File read error! : %s\n", pFirstRo);
-               res = false;
-               goto CATCH;
-       }
-
-       nRet = DTappsInstallLicense(Buf);
-       if (nRet != TADC_SUCCESS)
-       {
+       int nRet = DTappsInstallLicense(reinterpret_cast<char *>(buf.data()));
+       if (nRet != TADC_SUCCESS) {
                printf("tc13_DTappsInstallLicense_02() failed. nRet=%d\n", nRet);
-               res = false;
-               goto CATCH;
+               return false;
        }
 
        printf("tc13_DTappsInstallLicense_02() finished! -------- success \n");
-
-CATCH:
-       if (fd != NULL)
-       {
-               fclose(fd);
-       }
-       return res;
+       return true;
 }
 
-bool
-tc13_DTappsInstallLicense_03(void)
+bool tc13_DTappsInstallLicense_03(void)
 {
-       int     nRet = TADC_SUCCESS;
-       char Buf[1024*10] = {0, };      
-       const char *pFirstRo = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/FightGuiIF-1.0.0.ro");
-       FILE* fd = NULL;
-       int     nReadLen = 0;
-       long lSize = 0;
-       bool res = true;
-
        printf("tc13_DTappsInstallLicense_03() -------- Started! \n");
 
-       fd = fopen(pFirstRo, "rb");
-       if (fd == NULL)
-       {
-               printf("File is not exist! : %s\n", pFirstRo);
-               res = false;
-               goto CATCH;
-       }
-
-       fseek(fd, 0, SEEK_END);
-       lSize = ftell(fd);
-       if (lSize < 0)
-       {
-               printf("fseek() and ftell() failed.");
-               res = false;
-               goto CATCH;
-       }
-       rewind(fd);
+       const char *pFirstRo = tzplatform_mkpath(TZ_SYS_DATA,"drm_test/RO/FightGuiIF-1.0.0.ro");
 
-       memset(Buf, 0x00, sizeof(Buf));
-       nReadLen = fread(Buf, 1, lSize, fd);
-       if (nReadLen >= sizeof(Buf))
-       {
-               printf("Buffer error! : %s\n", pFirstRo);
-               goto CATCH;
-       }
+       auto buf = _read_ro_file(pFirstRo);
 
-       if (nReadLen != lSize)
-       {
-               printf("File read error! : %s\n", pFirstRo);
-               res = false;
-               goto CATCH;
-       }
-
-       nRet = DTappsInstallLicense(Buf);
-       if (nRet != TADC_SUCCESS)
-       {
+       int nRet = DTappsInstallLicense(reinterpret_cast<char *>(buf.data()));
+       if (nRet != TADC_SUCCESS) {
                printf("tc13_DTappsInstallLicense_03() failed. nRet=%d\n", nRet);
-               res = false;
-               goto CATCH;
+               return false;
        }
 
        printf("tc13_DTappsInstallLicense_03() finished! -------- success \n");
-
-CATCH:
-       if (fd != NULL)
-       {
-               fclose(fd);
-       }
-       return res;
+       return true;
 }
 
 bool
@@ -2602,35 +2050,38 @@ bool tc15_DrmTdcDecryptPackge_01(void)
 */
 #endif
 
-int main(int argc, char* argv[])
+int main(int, char *[])
 {
-//     return 0;
+       printf(" ---------- Test Tizen DRM core --- Start ....\n");
+       test_drm_core();
+       printf(" ---------- Test Tizen DRM core ---  End  ....\n");
+
 #if 1
        printf(" ---------- Test Tizen DRM v2.0.1 APIs   ---  Start ....    \n");
 
-       int                             bRet = TADC_SUCCESS;
-       
-       char                    ReqBuf[1024*5] = {0, };
-       unsigned int    ReqBufLen = 0;
-       
-       char                    RespBuf[1024*10] = {0, };       
-       unsigned int    RespBufLen = 0;
-       
-//     char                    DecLicenseBuf[1024*10] = {0, }; 
-//     unsigned int    DecLicenseBufLen = 0;
-       
-       char                    LicenseUrl[1024] = {0, };
-       unsigned int    LicenseUrlLen = 0;
-       
+       int bRet = TADC_SUCCESS;
+
+       char ReqBuf[1024*5] = {0, };
+       unsigned int ReqBufLen = 0;
+
+       char RespBuf[1024*10] = {0, };
+       unsigned int RespBufLen = 0;
+
+//     char DecLicenseBuf[1024*10] = {0, };
+//     unsigned int DecLicenseBufLen = 0;
+
+       char LicenseUrl[1024] = {0, };
+       unsigned int LicenseUrlLen = 0;
+
        //2011.03.08
-       //DrmTdcFileHeader      TDCFileHeader;
-//     char    cid[1024] = {0, };
-//     char    riurl[1024] = {0, };
-       
-       char    testFileName[256] = {0, };
-       char    tempBuf[256] = {0, };
+       //DrmTdcFileHeader TDCFileHeader;
+//     char cid[1024] = {0, };
+//     char riurl[1024] = {0, };
+
+       char testFileName[256] = {0, };
+       char tempBuf[256] = {0, };
 
-       bool    isOk = false;
+       bool isOk = false;
 
        //----------------------------------------------------------------------------------------------------
        // 0. Static TC running
@@ -2867,7 +2318,7 @@ int main(int argc, char* argv[])
        printf("===============================================================================\n");
        printf ("Enter test file name  -->  ");
 
-       isOk = scanf("%s", testFileName); 
+       isOk = scanf("%s", testFileName);
        if (isOk < 1)
        {
                printf ("Input value wrong! scanf() failed!!");
@@ -2884,15 +2335,15 @@ int main(int argc, char* argv[])
        printf("%s file is TADC file!\n", testFileName);
 
        //----------------------------------------------------------------------------------------------------
-       // 2. Make PurchaseRequest Data 
+       // 2. Make PurchaseRequest Data
        //----------------------------------------------------------------------------------------------------
        printf("\n2. Make PurchaseRequest Data  Start  ----------------------------------------\n");
-       
+
        memset(ReqBuf, 0x00, sizeof(ReqBuf));
        memset(LicenseUrl, 0x00, sizeof(LicenseUrl));
        ReqBufLen = sizeof(ReqBuf);
        LicenseUrlLen = sizeof(LicenseUrl);
-       
+
        bRet = drm_tizen_generate_purchase_request(testFileName, ReqBuf, &ReqBufLen, LicenseUrl, &LicenseUrlLen);
        if (bRet == false)
        {
@@ -2900,7 +2351,7 @@ int main(int argc, char* argv[])
                return 0;
        }
 
-       printf("drm_tizen_generate_purchase_request - ReqBufLen : %d,  License Url : %s   \n", ReqBufLen, LicenseUrl);  
+       printf("drm_tizen_generate_purchase_request - ReqBufLen : %d,  License Url : %s   \n", ReqBufLen, LicenseUrl);
        if ((bRet = _write_logfile("Request_1.dat", ReqBuf, ReqBufLen-1)) == false)
        {
                printf(" drm_tizen_generate_purchase_request _write_logfile Error!  \n");
@@ -2909,9 +2360,9 @@ int main(int argc, char* argv[])
 
        //break.... HTTP Request & Reaponse Processing...
        printf ("Enter any key after create Response_1.dat file. -->  ");
-       scanf ("%s", tempBuf); 
+       std::cin >> tempBuf;
 
-       memset(RespBuf, 0x00, sizeof(RespBuf)); 
+       memset(RespBuf, 0x00, sizeof(RespBuf));
        RespBufLen = sizeof(RespBuf);
        if ((bRet = _read_logfile("Response_1.dat", RespBuf, &RespBufLen)) == false)
        {
@@ -2920,15 +2371,15 @@ int main(int argc, char* argv[])
        }
 
        //----------------------------------------------------------------------------------------------------
-       // 3. Make License Request Data  
+       // 3. Make License Request Data
        //----------------------------------------------------------------------------------------------------
        printf("\n3. Make License Request Data  Start  ----------------------------------------\n");
-       
+
        memset(ReqBuf, 0x00, sizeof(ReqBuf));
        memset(LicenseUrl, 0x00, sizeof(LicenseUrl));
        ReqBufLen = sizeof(ReqBuf);
-       LicenseUrlLen = sizeof(LicenseUrl);     
-       
+       LicenseUrlLen = sizeof(LicenseUrl);
+
        bRet = drm_tizen_generate_license_request(RespBuf,  RespBufLen, ReqBuf, &ReqBufLen, LicenseUrl, &LicenseUrlLen);
        if (bRet != TADC_SUCCESS)
        {
@@ -2945,9 +2396,9 @@ int main(int argc, char* argv[])
 
        //break.... HTTP Request & Reaponse Processing...
        printf ("Enter any key after create Response_2.dat file. -->  ");
-       scanf ("%s", tempBuf); 
+       std::cin >> tempBuf;
 
-       memset(RespBuf, 0x00, sizeof(RespBuf)); 
+       memset(RespBuf, 0x00, sizeof(RespBuf));
        RespBufLen = sizeof(RespBuf);
        if ((bRet = _read_logfile("Response_2.dat", RespBuf, &RespBufLen)) == false)
        {
diff --git a/test/drm_testcore.cpp b/test/drm_testcore.cpp
new file mode 100644 (file)
index 0000000..8fc2182
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ *  Copyright (c) 2016 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        drm_testcore.cpp
+ * @author      Kyungwook Tak(k.tak@samsung.com)
+ * @version     1.0
+ * @brief       Test drm library internal core codes
+ */
+#include "TADC_Util.h"
+
+#include <iostream>
+#include <cstring>
+
+bool tc_base64(void)
+{
+       unsigned char in[16] = {
+               0x12, 0x93, 0xe8, 0xf1, 0x28, 0xb3, 0xff, 0x85,
+               0x83, 0xab, 0x8c, 0x1f, 0x7f, 0x9e, 0x15, 0x22
+       };
+
+       char *encoded = Base64Encode(in, sizeof(in));
+       std::cout << "encoded: " << encoded << std::endl;
+
+       int len = 0;
+       unsigned char *decoded = Base64Decode(encoded, &len);
+       if (len <= 0
+                       || static_cast<size_t>(len) != sizeof(in)
+                       || memcmp(in, decoded, sizeof(in)) != 0) {
+               std::cerr << "input and decoded base64 is different!!" << std::endl;
+               return false;
+       }
+
+       return true;
+}
+
+void test_drm_core(void)
+{
+       tc_base64();
+}
diff --git a/test/drm_testcore.h b/test/drm_testcore.h
new file mode 100644 (file)
index 0000000..0915f9f
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ *  Copyright (c) 2016 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        drm_testcore.h
+ * @author      Kyungwook Tak(k.tak@samsung.com)
+ * @version     1.0
+ * @brief       Test drm library internal core codes
+ */
+
+void test_drm_core(void);
index 5fd6b88..75ba0b5 100644 (file)
@@ -18,6 +18,9 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <time.h>
+#include <vector>
+#include <fstream>
+#include <iostream>
 
 #include <openssl/bio.h>
 #include <openssl/evp.h>
 #define _INITIALIZED 0
 #define _UNINITIALIZED -1
 
-static unsigned char g_baSignatureKey[ 32 ] =
-{
-    0x29, 0x2b, 0xf2, 0x29, 0x1f, 0x8b, 0x47, 0x81, 0x95, 0xa, 0x84, 0xf8, 0x91, 0xda, 0x7, 0xd0,
-    0x9c, 0xde, 0x32, 0x3e, 0x9e, 0x46, 0x4a, 0xfc, 0xa4, 0xcc, 0x55, 0x6e, 0xf2, 0x81, 0x61, 0xdb
-};
+using Binary = std::vector<unsigned char>;
 
-static unsigned char g_baAESKey[ 32 ] =
+static unsigned char g_baAESKey[32] =
 {
-    -8, -121, 10, -59, -45, 109, 68, 73, 3, -97, -67, 30, -88, 47, -10,
-    -61, -33, 59, 2, 19, 88, 27, 18, 48, 28, -41, -83, -91, 31, 93, 1, 51
+    0xf8, 0x87, 0x0a, 0xc5, 0xd3, 0x6d, 0x44, 0x49, 0x03, 0x9f, 0xbd, 0x1e, 0xa8, 0x2f, 0xf6, 0xc3,
+    0xdf, 0x3b, 0x02, 0x13, 0x58, 0x1b, 0x12, 0x30, 0x1c, 0xd7, 0xad, 0xa5, 0x1f, 0x5d, 0x01, 0x33
 };
 
 
@@ -65,10 +64,14 @@ void __init_crypto()
 
 int __get_random_bytes(char* output, int random_len)
 {
-    FILE *fp;
-    fp = fopen("/dev/urandom", "r");
-    fread(output, 1, random_len, fp);
-    fclose(fp);
+    FILE *fp = fopen("/dev/urandom", "r");
+    auto size = fread(output, 1, random_len, fp);
+
+       fclose(fp);
+
+       if (size != static_cast<size_t>(random_len))
+               return DRMTEST_ERR_IO;
+
     return DRMTEST_SUCCESS;
 }
 
@@ -78,7 +81,7 @@ int __file_copy(const char* target_path, const char* source_path)
     FILE *source = NULL;
     FILE *target = NULL;
     size_t l1,l2;
-    unsigned char buffer[8192]; 
+    unsigned char buffer[8192];
 
     source = fopen(source_path, "r");
     if(source == NULL) {
@@ -112,7 +115,7 @@ error:
 
 void _base64_encode(const unsigned char* input, int length, char** output)
 {
-    *output = Base64Encode((unsigned char*)input, length);    
+    *output = Base64Encode((unsigned char*)input, length);
 }
 
 void _base64_decode(const char* input, unsigned char** output, int* out_len)
@@ -150,44 +153,28 @@ char* _replace_all(char *s, const char *olds, const char *news)
     return result;
 }
 
-int _read_text_file(const char* path, char** output)
+Binary _read_ro_file(const char *filename)
 {
-    int ret = DRMTEST_SUCCESS;
-    FILE *file = NULL;
-    char *buffer = NULL;
-    unsigned long fileLen;
-    
-    //Open file
-    file = fopen(path, "rb");
-    if (file == NULL) {
-        ret = DRMTEST_ERR_IO;
-        goto error;
-    }
-    
-    //Get file length
-    fseek(file, 0, SEEK_END);
-    fileLen=ftell(file);
-    fseek(file, 0, SEEK_SET);
-    
-    //Allocate memory
-    buffer=(char *)malloc(fileLen+1);
-    if (buffer == NULL) {
-        ret = DRMTEST_ERR_MEMORY;
-        goto error;
-    }
-    memset(buffer, 0, fileLen+1);
+    try {
+        std::ifstream is(filename, std::ifstream::binary);
+        if (!is || !is.is_open())
+            return Binary();
 
-    //Read file contents into buffer
-    fread(buffer, fileLen, 1, file);
-    
-    *output = buffer;
-error:
-    if(file != NULL)
-        fclose(file);
-    if(ret != DRMTEST_SUCCESS && buffer != NULL)
-        free(buffer);
+        is.seekg(0, is.end);
+        int length = is.tellg();
+        is.seekg(0, is.beg);
 
-    return ret;
+        Binary buffer(length + 1); /* for null-terminated */
+
+        is.read(reinterpret_cast<char *>(buffer.data()), length);
+        if (!is)
+            return Binary();
+
+        return buffer;
+    } catch (...) {
+        std::cerr << "Failed to read ro file: " << filename << std::endl;
+        return Binary();
+    }
 }
 
 int _create_dh_key(const char* dh_key_p_hex, const char* dh_key_g_hex, DH** ppkey)
@@ -216,9 +203,9 @@ int _create_dh_key(const char* dh_key_p_hex, const char* dh_key_g_hex, DH** ppke
 
     *ppkey = pDH;
 error:
-    if(ret != DRMTEST_SUCCESS && pDH != NULL) 
+    if(ret != DRMTEST_SUCCESS && pDH != NULL)
         DH_free(pDH);
-    
+
     return ret;
 }
 
@@ -236,7 +223,7 @@ int _get_dh_hex_pubkey(const DH* pkey, char** dh_pubkey)
     return DRMTEST_SUCCESS;
 }
 
-int _get_dh_shared_secret_key(const char* dh_hex_pubkey, DH *pkey, 
+int _get_dh_shared_secret_key(const char* dh_hex_pubkey, DH *pkey,
                               unsigned char** dh_shared_secret_key, int *dh_sec_key_len)
 {
     int ret = DRMTEST_SUCCESS;
@@ -244,7 +231,6 @@ int _get_dh_shared_secret_key(const char* dh_hex_pubkey, DH *pkey,
     BIGNUM  *pPubKey = NULL;
     unsigned char *secret_key_buff = NULL;
     unsigned char tmp_buff[DH_size(pkey)] = {0,};
-    
 
     BN_hex2bn(&pPubKey, dh_hex_pubkey);
 
@@ -260,12 +246,12 @@ int _get_dh_shared_secret_key(const char* dh_hex_pubkey, DH *pkey,
     }
     memset(secret_key_buff, 0, DH_size(pkey)/2);
 
-printf("APP_DRM TEST: shared secret : ");
+    printf("APP_DRM TEST: shared secret : ");
     for(int i=0; i<(DH_size(pkey)/2); i++) {
-        secret_key_buff[i] = tmp_buff[i * 2] ^ tmp_buff[(i * 2) + 1];        
+        secret_key_buff[i] = tmp_buff[i * 2] ^ tmp_buff[(i * 2) + 1];
         printf("%02x", secret_key_buff[i]);
     }
-printf("\n");
+    printf("\n");
 
     *dh_shared_secret_key = secret_key_buff;
     *dh_sec_key_len = DH_size(pkey)/2;
@@ -283,25 +269,20 @@ int _create_right_object_without_signature(const char* ro_template_path, const c
                                 char** ro_buff)
 {
     int ret = DRMTEST_SUCCESS;
-    char *file_buff = NULL;
     char *cid_filled = NULL;
     char *duid_filled = NULL;
 
-    ret = _read_text_file(ro_template_path, &file_buff);
-    if(ret != DRMTEST_SUCCESS) {
-        goto error;
-    }
+    auto buf = _read_ro_file(ro_template_path);
 
-    cid_filled = _replace_all(file_buff, STR_PLACE_HOLDER_CID, cid);
+    cid_filled = _replace_all(reinterpret_cast<char *>(buf.data()), STR_PLACE_HOLDER_CID, cid);
     duid_filled = _replace_all(cid_filled, STR_PLACE_HOLDER_DUID, duid);
 
     *ro_buff = duid_filled;
-error:
-    if(file_buff != NULL)
-        free(file_buff);
-    if(cid_filled != NULL)
+
+    if (cid_filled != NULL)
         free(cid_filled);
-    if(ret != DRMTEST_SUCCESS && duid_filled != NULL)
+
+    if (ret != DRMTEST_SUCCESS && duid_filled != NULL)
         free(duid_filled);
 
     return ret;
@@ -363,8 +344,8 @@ int _create_ro_signature(const char* ro_buff, const char* signer_prikey_path, ch
 
     *signature = b64_sig_value;
 error:
-       if(file != NULL)
-               fclose(file);
+    if(file != NULL)
+        fclose(file);
     if(pkey != NULL)
         EVP_PKEY_free(pkey);
     if(ret != DRMTEST_SUCCESS && b64_sig_value != NULL)
@@ -396,7 +377,7 @@ int _encrypt_ro_with_dh_sec_key(const char* ro_with_signature,
 
     TADC_IF_MemCpy(key, dh_secret_key, 16);
     TADC_IF_MemCpy(iv, (dh_secret_key+16), 16);
-    ret = TADC_IF_AES_CTR(16, key, 16, iv, strlen(ro_with_signature), (unsigned char*)ro_with_signature, 
+    ret = TADC_IF_AES_CTR(key, 16, iv, strlen(ro_with_signature), (unsigned char*)ro_with_signature,
                                     &encrypted_len, (unsigned char*)encrypted_buff);
     if(ret != 0) {
         ret = DRMTEST_ERR_CRYPTO;
@@ -414,23 +395,23 @@ int _create_response_data_in_ro_response(const char* reqid, const char* encrypte
 {
     int ret = DRMTEST_SUCCESS;
     char tmp_buff[MAX_CERT_SIZE] = {0,};
-    unsigned char hashed_reqid[20]={0,}; 
+    unsigned char hashed_reqid[20]={0,};
     char hex_hashed_reqid[256] = {0, };
-    unsigned char hash_value[20]={0,}; 
+    unsigned char hash_value[20]={0,};
     int hmac_len = 0;
     unsigned char hmac[1024*10] = {0,};
     char* hmac_base64 = NULL;
     char* resp_data = NULL;
 
     // get hashed req_id
-    SHA_CTX     alginfoForReqId;
+    SHA_CTX alginfoForReqId;
     SHA1_Init(&alginfoForReqId);
     SHA1_Update(&alginfoForReqId, reqid, strlen(reqid));
     SHA1_Final(hashed_reqid, &alginfoForReqId);
 
-    for(int i=0; i<sizeof(hashed_reqid); i++) {
-        sprintf(hex_hashed_reqid + i*2, "%02x", hashed_reqid[i]);
-    }
+    for (size_t i = 0; i < sizeof(hashed_reqid); i++)
+        sprintf(hex_hashed_reqid + i * 2, "%02x", hashed_reqid[i]);
+
     sprintf(tmp_buff, "reqid=%s;B=%s;license=%s", hex_hashed_reqid, dh_pubkey, encrypted_ro);
 
     // get hash value
@@ -445,12 +426,12 @@ int _create_response_data_in_ro_response(const char* reqid, const char* encrypte
 
     TADC_IF_MemCpy(key, g_baAESKey, 16);
     TADC_IF_MemCpy(iv, (g_baAESKey+16), 16);
-    ret = TADC_IF_AES_CTR(16, key, 16, iv, 20, hash_value, &hmac_len, hmac);
+    ret = TADC_IF_AES_CTR(key, 16, iv, 20, hash_value, &hmac_len, hmac);
     if(ret != 0) {
         ret = DRMTEST_ERR_CRYPTO;
         goto error;
     }
-    
+
     // base64 encode
     _base64_encode(hmac, 20, &hmac_base64);
 
@@ -458,7 +439,7 @@ int _create_response_data_in_ro_response(const char* reqid, const char* encrypte
     strncat(tmp_buff, ";hmac=", strlen(";hmac="));
     strncat(tmp_buff, hmac_base64, strlen(hmac_base64));
 
-    // make return value    
+    // make return value
     resp_data = (char*) malloc(strlen(tmp_buff)+1);
     if(resp_data == NULL) {
         ret = DRMTEST_ERR_MEMORY;
@@ -485,11 +466,11 @@ int _create_time_stamp(const unsigned char* dh_secret_key, char** time_stamp)
     unsigned char enc_time_buff[512] = {0,};
     char *time_base64 = NULL;
     int enc_time_buff_len = 0;
-    time_t now = time(NULL); 
+    time_t now = time(NULL);
     const struct tm* gt = gmtime(&now);
 
-    sprintf(tmp_time_buff, "%d-%d-%dT%d:%d:00:Z", 
-                           gt->tm_year+1900, gt->tm_mon+1, gt->tm_mday, 
+    sprintf(tmp_time_buff, "%d-%d-%dT%d:%d:00:Z",
+                           gt->tm_year+1900, gt->tm_mon+1, gt->tm_mday,
                            gt->tm_hour+1, gt->tm_min+1);
 
     // encrypt time_stamp
@@ -498,7 +479,7 @@ int _create_time_stamp(const unsigned char* dh_secret_key, char** time_stamp)
 
     TADC_IF_MemCpy(key, dh_secret_key, 16);
     TADC_IF_MemCpy(iv, (dh_secret_key+16), 16);
-    ret = TADC_IF_AES_CTR(16, key, 16, iv, strlen(tmp_time_buff), (unsigned char*)tmp_time_buff, 
+    ret = TADC_IF_AES_CTR(key, 16, iv, strlen(tmp_time_buff), (unsigned char*)tmp_time_buff,
                           &enc_time_buff_len, enc_time_buff);
     if(ret != 0) {
         ret = DRMTEST_ERR_CRYPTO;
@@ -507,7 +488,7 @@ int _create_time_stamp(const unsigned char* dh_secret_key, char** time_stamp)
 
     // convert to base64
     _base64_encode(enc_time_buff, enc_time_buff_len, &time_base64);
-    
+
     *time_stamp = time_base64;
 error:
     if(ret != DRMTEST_SUCCESS && time_base64 != NULL)
@@ -516,8 +497,6 @@ error:
 
 }
 
-static int req_id_seq = 0;
-
 int generate_purchase_response(char** purchase_response_buff, char** req_id)
 {
     int ret = DRMTEST_SUCCESS;
@@ -547,10 +526,9 @@ int generate_purchase_response(char** purchase_response_buff, char** req_id)
         goto error;
     }
     memset(rid, 0, 1024);
-   
-    for(int i=0; i<sizeof(random); i++) {
-        sprintf(rid + i*2, "%02x", random[i]);
-    }
+
+    for (size_t i = 0; i < sizeof(random); i++)
+        sprintf(rid + i * 2, "%02x", random[i]);
 
     strncat(resp_buff, format1, strlen(format1));
     strncat(resp_buff, format2, strlen(format2));
@@ -573,8 +551,7 @@ error:
     return ret;
 }
 
-int generate_right_object_request(const char* license_response_buff,
-                              char** ro_request_buff)
+int generate_right_object_request(const char* license_response_buff)
 {
     int ret = DRMTEST_SUCCESS;
     unsigned int  req_buff_len = 1024*5;
@@ -634,7 +611,7 @@ int get_dh_key_from_ro_request(const char* ro_request_buff,
     memset(buff_p, 0, len_p + 1);
     strncpy(buff_p, idx_p + strlen(PFX_P), len_p);
     *dh_key_p = buff_p;
+
     buff_g = (char *)malloc(len_g + 1);
     if(buff_g == NULL) {
         ret = DRMTEST_ERR_MEMORY;
@@ -643,7 +620,7 @@ int get_dh_key_from_ro_request(const char* ro_request_buff,
     memset(buff_g, 0, len_g + 1);
     strncpy(buff_g, idx_g + strlen(PFX_G), len_g);
     *dh_key_g = buff_g;
+
     buff_a = (char *)malloc(len_a + 1);
     if(buff_a == NULL) {
         ret = DRMTEST_ERR_MEMORY;
@@ -652,7 +629,7 @@ int get_dh_key_from_ro_request(const char* ro_request_buff,
     memset(buff_a, 0, len_a + 1);
     strncpy(buff_a, idx_a + strlen(PFX_A), len_a);
     *dh_key_a = buff_a;
+
 error:
     if(ret != DRMTEST_SUCCESS && buff_p != NULL)
         free(buff_p);
@@ -743,8 +720,8 @@ int generate_right_object_response(const char* dh_key_p, const char* dh_key_g, c
         goto error;
     }
     memset(ro_resp_buff, 0, ro_resp_buff_len);
-    sprintf(ro_resp_buff, format, response_data, time_stamp); 
-    
+    sprintf(ro_resp_buff, format, response_data, time_stamp);
+
     *ro_response_buff = ro_resp_buff;
 
 error:
@@ -777,7 +754,7 @@ int is_identical_files(const char* file1, const char* file2, int* identical)
 {
     int ret = DRMTEST_SUCCESS;
 
-       FILE *fp1 = NULL, *fp2 = NULL;
+    FILE *fp1 = NULL, *fp2 = NULL;
     int ch1, ch2;
 
     fp1 = fopen(file1, "r");
index 2eb8739..6f2a70e 100644 (file)
  * limitations under the License.
  */
 
+#include <vector>
 #include <openssl/dh.h>
 #include <tzplatform_config.h>
 
-
 #define RIURL "http://appdrm.test.com/"
 
 #define RO_ISSUER_SIGNER_KEY_FILE tzplatform_mkpath(TZ_SYS_DATA, "drm_test/Key/ro_test_signer.key")
@@ -45,8 +45,7 @@
 
 int generate_purchase_response(char** purchase_response_buff, char** req_id);
 
-int generate_right_object_request(const char* license_response_buff,
-                              char** ro_request_buff);
+int generate_right_object_request(const char* license_response_buff);
 
 int get_dh_key_from_ro_request(const char* ro_request_buff,
                               char** dh_key_p, char** dh_key_g, char** dh_key_a);
@@ -74,13 +73,15 @@ int _create_right_object_without_signature(const char* ro_template_path, const c
                                char** ro_buff);
 int _create_ro_signature(const char* ro_buff, const char* signer_prikey_path, char** signature);
 int _add_signature_to_ro(const char* ro_buff, const char* signature, char** ro_with_signature);
-int _encrypt_ro_with_dh_sec_key(const char* ro_with_signature, 
-                                const unsigned char* dh_secret_key, const int dh_sec_key_len, 
+int _encrypt_ro_with_dh_sec_key(const char* ro_with_signature,
+                                const unsigned char* dh_secret_key, const int dh_sec_key_len,
                                 char **encrypted_ro);
 
 int _create_response_data_in_ro_response(const char* reqid, const char* encrypted_ro, const char* dh_pubkey,
-                                char **response_data); 
+                                char **response_data);
 
 int _create_time_stamp(const unsigned char* dh_secret_key, char** time_stamp);
 
 
+using Binary = std::vector<unsigned char>;
+Binary _read_ro_file(const char *filename);