add malware detector for mms 77/63677/1 accepted/tizen/common/20160325.135924 submit/tizen/20160325.075607
authorKyeonghun Lee <kh9090.lee@samsung.com>
Fri, 25 Mar 2016 07:24:11 +0000 (16:24 +0900)
committerKyeonghun Lee <kh9090.lee@samsung.com>
Fri, 25 Mar 2016 07:24:11 +0000 (16:24 +0900)
Change-Id: I7f08ab698ec6cca6ab079e27ed4f5bcf941e4f97

include/utils/MsgUtilFile.h
packaging/msg-service.spec
plugin/mms_plugin/MmsPluginAppBase.cpp
plugin/mms_plugin/MmsPluginStorage.cpp
utils/CMakeLists.txt
utils/MsgUtilFile.cpp

index 6b345ee..88596c5 100755 (executable)
@@ -65,6 +65,7 @@ int MsgCheckFilepathSmack(const char *app_smack_label, char *file_path);
 
 bool MsgScanFile(char *filePath);
 void MsgGetMimeType(char *filePath, char *mimeType, int size);
+int MsgTcsScanFile(const char *filepath, int *bLevel);
 bool MsgAclInit();
 #endif /* MSG_UTIL_FILE_H */
 
index 3c41330..e7ef5c1 100755 (executable)
@@ -37,6 +37,7 @@ BuildRequires: pkgconfig(capi-system-device)
 BuildRequires: pkgconfig(capi-system-info)
 BuildRequires: pkgconfig(capi-system-system-settings)
 BuildRequires: pkgconfig(capi-telephony)
+BuildRequires: pkgconfig(csr-framework)
 BuildRequires: pkgconfig(cynara-client)
 BuildRequires: pkgconfig(cynara-creds-commons)
 BuildRequires: pkgconfig(cynara-creds-socket)
index 7197b5c..2677ed9 100755 (executable)
@@ -131,7 +131,7 @@ msg_error_t MmsMakePreviewInfo(int msgId, MMS_MESSAGE_DATA_S *pMmsMsg, bool allo
 
        /* scan malware in raw file */
        if (raw_filepath && strlen(raw_filepath) > 0 && MsgAccessFile(raw_filepath, F_OK) == true) {
-               int tcs_ret = 0; /* MmsPluginTcsScanFile(raw_filepath, &bc_level); */
+               int tcs_ret = MsgTcsScanFile(raw_filepath, &bc_level);
                if (tcs_ret == 0) {
                        if (bc_level > -1) {
                                MSG_DEBUG("malware exist, level = %d", bc_level);
index b54bae5..408c8bf 100755 (executable)
@@ -857,7 +857,7 @@ msg_error_t MmsPluginStorage::insertMultipart(msg_message_id_t msgId, MMS_MULTIP
                /* CID 41991: pMultipart->szFilePath is an array, hence checking for null is not required */
                if (strlen(pMultipart->szFilePath) > 0 && MsgAccessFile(pMultipart->szFilePath, F_OK) == true) {
                        int bc_level = -1;
-                       int tcs_ret = 0; /* MsgTcsScanFile(pMultipart->szFilePath, &bc_level); */
+                       int tcs_ret = MsgTcsScanFile(pMultipart->szFilePath, &bc_level);
                        if (tcs_ret == 0) {
                                if (bc_level > -1) {
                                        MSG_DEBUG("This content is malware, level = %d", bc_level);
index 3b96a1b..8af74a5 100755 (executable)
@@ -46,7 +46,7 @@ INCLUDE_DIRECTORIES(
 
 INCLUDE(FindPkgConfig)
 
-SET(PKG_MODULES glib-2.0 vconf dlog libxml-2.0 storage json-glib-1.0 capi-system-info capi-media-thumbnail-util capi-media-image-util capi-content-media-content aul sqlite3 capi-media-metadata-extractor icu-uc libsystemd-login)
+SET(PKG_MODULES glib-2.0 vconf dlog libxml-2.0 storage json-glib-1.0 capi-system-info capi-media-thumbnail-util capi-media-image-util capi-content-media-content aul sqlite3 capi-media-metadata-extractor icu-uc libsystemd-login csr-framework)
 pkg_check_modules(utils_pkgs REQUIRED ${PKG_MODULES})
 
 FOREACH(flag ${utils_pkgs_CFLAGS})
index 3c9c9f8..0467c11 100755 (executable)
@@ -31,6 +31,8 @@
 #include <media_content.h>
 #include <thumbnail_util.h>
 #include <image_util.h>
+#include <TCSImpl.h>
+#include <TCSErrorCodes.h>
 
 #include "MsgStorageTypes.h"
 #include "MsgDebug.h"
@@ -1260,6 +1262,71 @@ void MsgGetMimeType(char *filePath, char *mimeType, int size)
 }
 
 
+int MsgTcsScanFile(const char *filepath, int *bLevel)
+{
+       MSG_BEGIN();
+       TCSLIB_HANDLE hLib;
+       TCSScanResult result;
+       TCSDetected* pDetected;
+       int rtn, i;
+       int ret_b_level = -1;
+
+       if (MsgAccessFile(filepath, R_OK) == false) {
+               MSG_SEC_DEBUG("not exist source file [%s]", filepath);
+               return -1;
+       }
+
+       MSG_SEC_DEBUG("Scanning file name : %s\n", filepath);
+
+       hLib = TCSLibraryOpen();
+       if(hLib == INVALID_TCSLIB_HANDLE) {
+               MSG_DEBUG("TCSLibraryOpen error\n");
+               return -1;
+       }
+
+       rtn = TCSScanFile(hLib, filepath, TCS_DTYPE_UNKNOWN, TCS_SA_SCANONLY, 1, &result);
+       if(rtn == 0)
+       {
+               MSG_DEBUG("Detected malware number: %d\n", result.iNumDetected);
+               i = result.iNumDetected;
+               pDetected = result.pDList;
+               while(i && pDetected)
+               {
+                       int temp_b_level;
+                       int temp_s_class;
+                       MSG_SEC_DEBUG(" +-- Malware [%d] Name: %s\n", i, pDetected->pszName);
+                       MSG_DEBUG(" +-- Malware [%d] uAction: %u : 0x%04x\n", i, pDetected->uAction, pDetected->uAction);
+
+                       temp_b_level  = (pDetected->uAction & 0xFF00) >> 8;
+                       MSG_DEBUG(" +-- Malware [%d] Behavior level: %u\n", i, temp_b_level);
+
+                       if (ret_b_level == -1 || ret_b_level < temp_b_level) {
+                               ret_b_level = temp_b_level;
+                       }
+
+                       temp_s_class  = (pDetected->uAction & 0x00FF);
+                       MSG_DEBUG(" +-- Malware [%d] Severity class: %u\n", i, temp_s_class);
+
+                       pDetected = pDetected->pNext;
+                       i --;
+               }
+
+               result.pfFreeResult(&result);
+       } else {
+               MSG_DEBUG("TCSScanFile fail: err = %d\n", rtn);
+       }
+
+       TCSLibraryClose(hLib);
+
+       if (bLevel)
+               *bLevel = ret_b_level;
+
+       MSG_END();
+
+       return 0;
+}
+
+
 bool MsgAclInit()
 {
        /* ACL */