# MALWARE/RISKY/GENERIC
threat_type=MALWARE
# detailed_url can be null
-detailed_url=http://detailedinfo.malware.com
+detailed_url=http://high.malware.com
signature=X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
name=test_risk
severity=MEDIUM
threat_type=RISKY
-detailed_url=
+detailed_url=http://medium.malware.com
signature=RISKY_MALWARE
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <limits.h>
#include <unistd.h>
#include <fcntl.h>
#define PRIVATE_DB_NAME "csret_cs_virus_signatures"
#define PRIVATE_LOGO_FILE "vendor_logo.bmp"
-#define MAX_FILE_PATH_LEN 256
+#define MAX_FILE_PATH_LEN PATH_MAX
#define MAX_NAME_LEN 64
#define MAX_VERSION_LEN 32
#define MAX_URL_LEN 256
#define ENGINE_NAME "TEST_LOCAL_TCS_ENGINE"
#define ENGINE_VERSION "0.0.1"
-typedef enum __csret_cs_scan_on_cloud {
- TCSE_SCAN_ON_CLOUD_OFF = 0,
- TCSE_SCAN_ON_CLOUD_ON = 1
-} csret_cs_scan_on_cloud_e;
-
typedef struct __csret_cs_malware {
csre_cs_severity_level_e severity;
csre_cs_threat_type_e threat_type;
unsigned int image_size;
char engine_version[MAX_VERSION_LEN];
char data_version[MAX_VERSION_LEN];
+ time_t latest_update;
} csret_cs_engine_s;
typedef enum __csret_cs_internal_error {
return nullptr;
auto found = strstr(line, key);
- if (found == nullptr)
+ if (found != line)
return nullptr;
auto value = found + strlen(key);
// name=test_malware // this starts a description of a new malware
// severity=HIGH // LOW/MEDIUM/HIGH
// threat_type=MALWARE // MALWARE/RISKY/GENERIC
- // detailed_url= // It can be null
+ // detailed_url=http://high.malware.com
// signature=X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
//
// name=test_risk
// severity=MEDIUM
// threat_type=RISKY
- // detailed_url=
+ // detailed_url=http://medium.malware.com
// signature=RISKY_MALWARE
csret_cs_malware_list_s *curr_sig = nullptr;
int csret_cs_init_engine(const char *root_dir)
{
int ret = CSRE_ERROR_NONE;
+ char db_file_name[MAX_FILE_PATH_LEN] = {0, };
char logo_file_name[MAX_FILE_PATH_LEN] = {0, };
+ struct stat attrib;
engine_info = (csret_cs_engine_s *) calloc(sizeof(csret_cs_engine_s), 1);
if (engine_info == nullptr)
snprintf(engine_info->vendor_name, MAX_NAME_LEN, "%s", VENDOR_NAME);
snprintf(engine_info->engine_name, MAX_NAME_LEN, "%s", ENGINE_NAME);
snprintf(engine_info->engine_version, MAX_VERSION_LEN, "%s", ENGINE_VERSION);
+ snprintf(db_file_name, MAX_FILE_PATH_LEN, "%s/%s", root_dir, PRIVATE_DB_NAME);
snprintf(logo_file_name, MAX_FILE_PATH_LEN, "%s/%s", root_dir, PRIVATE_LOGO_FILE);
ret = csret_cs_read_binary(logo_file_name, &(engine_info->vendor_logo_image),
&(engine_info->image_size));
ret = CSRE_ERROR_NONE;
}
+ stat(db_file_name, &attrib);
+ engine_info->latest_update = attrib.st_mtime;
+
return ret;
}
}
API
-int csre_cs_set_scan_on_cloud(csre_cs_context_h handle)
-{
- if (handle == nullptr)
- return CSRE_ERROR_INVALID_HANDLE;
-
- csret_cs_context_s *context = (csret_cs_context_s *)handle;
- context->scan_on_data = TCSE_SCAN_ON_CLOUD_ON;
- return CSRE_ERROR_NONE;
-}
-
-API
int csre_cs_scan_data(csre_cs_context_h handle,
const unsigned char *data,
size_t length,
csret_cs_context_s *context = (csret_cs_context_s *)handle;
- if (context->scan_on_data == TCSE_SCAN_ON_CLOUD_ON) {
- //ignored in this engine implementation.
- }
-
ret = csret_cs_detect_malware(context, data, length, &detected);
if (ret != CSRE_ERROR_NONE)
const char *file_path,
csre_cs_detected_h *pdetected)
{
- int fd = open(file_path, O_RDONLY);
-
- if (fd < 0)
- return CSRE_ERROR_FILE_NOT_FOUND;
-
- return csre_cs_scan_file_by_fd(handle, fd, pdetected);
-}
-
-API
-int csre_cs_scan_file_by_fd(csre_cs_context_h handle,
- int file_descriptor,
- csre_cs_detected_h *pdetected)
-{
csret_cs_detected_s *detected = nullptr;
unsigned char *data;
unsigned int data_len;
int ret = CSRE_ERROR_NONE;
+ if (file_path == nullptr)
+ return CSRE_ERROR_INVALID_PARAMETER;
+
+ int fd = open(file_path, O_RDONLY);
+ if (fd < 0)
+ return CSRE_ERROR_FILE_NOT_FOUND;
+
if (handle == nullptr)
return CSRE_ERROR_INVALID_HANDLE;
- if (file_descriptor < 0)
- return CSRE_ERROR_INVALID_PARAMETER;
-
csret_cs_context_s *context = (csret_cs_context_s *)handle;
- if (context->scan_on_data == TCSE_SCAN_ON_CLOUD_ON) {
- //ignored in this engine implementation.
- }
-
- ret = csret_cs_read_binary_by_fd(file_descriptor, &data, &data_len);
+ ret = csret_cs_read_binary(file_path, &data, &data_len);
if (ret != CSRE_ERROR_NONE)
return ret;
return CSRE_ERROR_NONE;
}
+API
+int csre_cs_scan_app_on_cloud(csre_cs_context_h handle,
+ const char *app_root_dir,
+ csre_cs_detected_h *pdetected)
+{
+ int ret;
+ DIR *dir;
+ struct dirent entry;
+ struct dirent *result;
+ csret_cs_detected_s *detected = nullptr;
+ csret_cs_detected_s *most_severe= nullptr;
+ int path_length;
+ char path[MAX_FILE_PATH_LEN] = {0 };
+
+ dir = opendir(app_root_dir);
+ if(!dir)
+ return CSRE_ERROR_FILE_NOT_FOUND;
+
+ while ((!readdir_r(dir, &entry, &result))) {
+ if(result == nullptr) // when the end of the directory stread is reached
+ break;
+
+ path_length = snprintf(path, MAX_FILE_PATH_LEN, "%s/%s", app_root_dir, entry.d_name);
+ if(path_length >= MAX_FILE_PATH_LEN) {
+ ret = CSRE_ERROR_UNKNOWN;
+ goto error;
+ }
+
+ if( (entry.d_type & DT_REG) || (entry.d_type & DT_LNK) ) {
+ ret = csre_cs_scan_file(handle, path, (csre_cs_detected_h *)(&detected) );
+ } else if( (entry.d_type & DT_DIR)
+ && (strcmp(entry.d_name,"..") != 0)
+ && (strcmp(entry.d_name,".") != 0) ) {
+ ret = csre_cs_scan_app_on_cloud(handle, path, (csre_cs_detected_h *)(&detected) );
+ } else {
+ continue;
+ }
+
+ if(ret != CSRE_ERROR_NONE)
+ goto error;
+ if(detected != nullptr) { // detected
+ if(most_severe == nullptr || detected->malware.severity > most_severe->malware.severity)
+ most_severe = detected;
+ else
+ detected = nullptr;
+ }
+ }
+
+error:
+ if(dir != nullptr)
+ closedir(dir);
+
+ *pdetected = (csre_cs_detected_h) detected;
+
+ return ret;
+}
+
//==============================================================================
// Result related
//==============================================================================
}
API
+int csre_cs_engine_get_latest_update_time(csre_cs_engine_h engine, time_t *time)
+{
+ csret_cs_engine_s *eng = (csret_cs_engine_s *) engine;
+
+ if (eng == nullptr)
+ return CSRE_ERROR_INVALID_HANDLE;
+
+ if (time == nullptr)
+ return CSRE_ERROR_INVALID_PARAMETER;
+
+ *time = eng->latest_update;
+ return CSRE_ERROR_NONE;
+}
+
+API
int csre_cs_engine_get_activated(csre_cs_engine_h engine, csre_cs_activated_e *pactivated)
{
csret_cs_engine_s *eng = (csret_cs_engine_s *) engine;
url=highrisky.test.com
# LOW/MEDIUM/HIGH
risk_level=HIGH
+detailed_url=http://high.risky.com
url=mediumrisky.test.com
risk_level=MEDIUM
+detailed_url=http://medium.risky.com
url=lowrisky.test.com
risk_level=LOW
#include <cstdlib>
#include <cstdio>
#include <cstring>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#define API __attribute__((visibility("default")))
typedef struct __csret_wp_risky_url {
char url[MAX_URL_LEN];
csre_wp_risk_level_e risk_level;
+ char detailed_url[MAX_URL_LEN];
} csret_wp_risky_url_s;
typedef struct __csret_wp_risky_url_list {
unsigned int image_size;
char engine_version[MAX_VERSION_LEN];
char data_version[MAX_VERSION_LEN];
+ time_t latest_update;
} csret_wp_engine_s;
typedef enum __csret_wp_internal_error {
return nullptr;
auto found = strstr(line, key);
- if (found == nullptr)
+ if (found != line)
return nullptr;
auto value = found + strlen(key);
//
// url=highrisky.test.com // this starts a description of a new risky url
// risk_level=HIGH // LOW/MEDIUM/HIGH
+ // detailed_url=http://high.risky.com
//
// url=midiumrisky.test.com
// risk_level=MEDIUM
+ // detailed_url=http://medium.risky.com
FILE *fp;
char *line = nullptr;
size_t len = 0;
else
curr_url->risky_url->risk_level = CSRE_WP_RISK_UNVERIFIED;
}
+
+ value = csret_wp_extract_value(line, "detailed_url=");
+
+ if (value != nullptr)
+ strncpy(curr_url->risky_url->detailed_url, value, sizeof(curr_url->risky_url->detailed_url) - 1);
}
free(line);
int csret_wp_init_engine(const char *root_dir)
{
int ret = CSRE_ERROR_NONE;
+ char db_file_name[MAX_FILE_PATH_LEN] = {0, };
char logo_file_name[MAX_FILE_PATH_LEN] = {0, };
+ struct stat attrib;
engine_info = (csret_wp_engine_s *) calloc(sizeof(csret_wp_engine_s), 1);
if (engine_info == nullptr)
snprintf(engine_info->vendor_name, MAX_NAME_LEN, "%s", VENDOR_NAME);
snprintf(engine_info->engine_name, MAX_NAME_LEN, "%s", ENGINE_NAME);
snprintf(engine_info->engine_version, MAX_VERSION_LEN, "%s", ENGINE_VERSION);
+ snprintf(db_file_name, MAX_FILE_PATH_LEN, "%s/%s", root_dir, PRIVATE_DB_NAME);
snprintf(logo_file_name, MAX_FILE_PATH_LEN, "%s/%s", root_dir, PRIVATE_LOGO_FILE);
ret = csret_wp_read_binary(logo_file_name, &(engine_info->vendor_logo_image),
&(engine_info->image_size));
ret = CSRE_ERROR_NONE;
}
+ stat(db_file_name, &attrib);
+ engine_info->latest_update = attrib.st_mtime;
+
return ret;
}
if (strstr(url, risky_url) != nullptr) { // found
detected->risk_level = curr_url->risky_url->risk_level;
+ snprintf(detected->detailed_url, MAX_URL_LEN, "%s", curr_url->risky_url->detailed_url);
break; // return the first risky url info in test engine
}
return CSRE_ERROR_NONE;
}
+API
+int csre_wp_result_get_detailed_url(csre_wp_check_result_h result, const char** detailed_url)
+{
+ csret_wp_risky_url_s *detected = nullptr;
+
+ if (result == nullptr)
+ return CSRE_ERROR_INVALID_HANDLE;
+
+ if (detailed_url == nullptr)
+ return CSRE_ERROR_INVALID_PARAMETER;
+
+ detected = (csret_wp_risky_url_s *) result;
+ *detailed_url = detected->detailed_url;
+ return CSRE_ERROR_NONE;
+}
+
//==============================================================================
// Engine information related
//==============================================================================
return CSRE_ERROR_NONE;
}
+
+API
+int csre_wp_engine_get_latest_update_time(csre_wp_engine_h engine, time_t *time)
+{
+ csret_wp_engine_s *eng = (csret_wp_engine_s *) engine;
+
+ if (eng == nullptr)
+ return CSRE_ERROR_INVALID_HANDLE;
+
+ if (time == nullptr)
+ return CSRE_ERROR_INVALID_PARAMETER;
+
+ *time = eng->latest_update;
+ return CSRE_ERROR_NONE;
+}
+
+
API
int csre_wp_engine_get_activated(csre_wp_engine_h engine, csre_wp_activated_e *pactivated)
{
#define API __attribute__((visibility("default")))
API
-int csr_get_selected_engine(csr_engine_id_e id, csr_engine_h *engine)
+int csr_get_current_engine(csr_engine_id_e id, csr_engine_h *engine)
{
(void) id;
(void) engine;
DEBUG("start");
return CSR_ERROR_NONE;
}
+
+API
+int csr_engine_destroy(csr_engine_h engine)
+{
+ (void) engine;
+ DEBUG("start");
+ return CSR_ERROR_NONE;
+}
/**
* @brief Releases all system resources associated with a Malware Screening API handle.
*
- * @details The handle is one returned by the csr_cs_context_create() function.
- *
* @param[in] handle CSR CS context handle returned by csr_cs_context_create().
*
* @return #CSR_ERROR_NONE on success, otherwise a negative error value
* @retval #CSR_ERROR_INVALID_PARAMETER data or presult is invalid
* @retval #CSR_ERROR_SOCKET Socket error between client and server
* @retval #CSR_ERROR_SERVER Server has been failed for some reason
- * @retval #CSR_ERROR_ENGINE_NOT_SELECTED No engine selected
+ * @retval #CSR_ERROR_ENGINE_NOT_EXIST No engine exists
* @retval #CSR_ERROR_ENGINE_NOT_ACTIVATED Engine is not activated
* @retval #CSR_ERROR_ENGINE_INTERNAL Engine Internal error
* @retval #CSR_ERROR_UNKNOWN Error with unknown reason
* @retval #CSR_ERROR_FILE_NOT_FOUND File not found
* @retval #CSR_ERROR_SOCKET Socket error between client and server
* @retval #CSR_ERROR_SERVER Server has been failed for some reason
- * @retval #CSR_ERROR_ENGINE_NOT_SELECTED No engine selected
+ * @retval #CSR_ERROR_ENGINE_NOT_EXIST No engine exists
* @retval #CSR_ERROR_ENGINE_NOT_ACTIVATED Engine is not activated
* @retval #CSR_ERROR_ENGINE_INTERNAL Engine Internal error
* @retval #CSR_ERROR_UNKNOWN Error with unknown reason
* @retval #CSR_ERROR_FILE_NOT_FOUND File not found
* @retval #CSR_ERROR_SOCKET Socket error between client and server
* @retval #CSR_ERROR_SERVER Server has been failed for some reason
- * @retval #CSR_ERROR_ENGINE_NOT_SELECTED No engine selected
+ * @retval #CSR_ERROR_ENGINE_NOT_EXIST No engine exists
* @retval #CSR_ERROR_ENGINE_NOT_ACTIVATED Engine is not activated
* @retval #CSR_ERROR_ENGINE_INTERNAL Engine Internal error
* @retval #CSR_ERROR_UNKNOWN Error with unknown reason
* @retval #CSR_ERROR_FILE_NOT_FOUND File not found
* @retval #CSR_ERROR_SOCKET Socket error between client and server
* @retval #CSR_ERROR_SERVER Server has been failed for some reason
- * @retval #CSR_ERROR_ENGINE_NOT_SELECTED No engine selected
+ * @retval #CSR_ERROR_ENGINE_NOT_EXIST No engine exists
* @retval #CSR_ERROR_ENGINE_NOT_ACTIVATED Engine is not activated
* @retval #CSR_ERROR_ENGINE_INTERNAL Engine Internal error
* @retval #CSR_ERROR_UNKNOWN Error with unknown reason
* @retval #CSR_ERROR_FILE_NOT_FOUND File not found
* @retval #CSR_ERROR_SOCKET Socket error between client and server
* @retval #CSR_ERROR_SERVER Server has been failed for some reason
- * @retval #CSR_ERROR_ENGINE_NOT_SELECTED No engine selected
+ * @retval #CSR_ERROR_ENGINE_NOT_EXIST No engine exists
* @retval #CSR_ERROR_ENGINE_NOT_ACTIVATED Engine is not activated
* @retval #CSR_ERROR_ENGINE_INTERNAL Engine Internal error
* @retval #CSR_ERROR_UNKNOWN Error with unknown reason
#ifndef __CSR_ENGINE_MANAGER_H_
#define __CSR_ENGINE_MANAGER_H_
+#include <time.h>
#include "csr/content-screening-types.h"
#include "csr/web-protection-types.h"
#include "csr/error.h"
} csr_activated_e;
/**
- * @brief Gets the handle of a selected engine information.
+ * @brief Gets the handle of a current engine information.
*
* @param[in] id Engine identifier to get handle.
* @param[out] pengine A pointer of the engine information handle.
* @return #CSR_ERROR_NONE on success, otherwise a negative error value
*
* @retval #CSR_ERROR_NONE Successful
- * @retval #CSR_ERROR_INVALID_HANDLE Invalid handle
* @retval #CSR_ERROR_INVALID_PARAMETER pengine is invalid
- * @retval #CSR_ERROR_ENGINE_NOT_SELECTED No engine selected
+ * @retval #CSR_ERROR_ENGINE_NOT_EXIST No engine exists
* @retval #CSR_ERROR_ENGINE_NOT_ACTIVATED Engine is not activated
* @retval #CSR_ERROR_ENGINE_INTERNAL Engine Internal error
* @retval #CSR_ERROR_UNKNOWN Error with unknown reason
*/
-int csr_get_selected_engine(csr_engine_id_e id, csr_engine_h *engine);
+int csr_get_current_engine(csr_engine_id_e id, csr_engine_h *pengine);
/**
* @brief Extracts an vendor name from the engine information handle.
* @retval #CSR_ERROR_ENGINE_INTERNAL Engine Internal error
* @retval #CSR_ERROR_UNKNOWN Error with unknown reason
*
- * @see csr_get_selected_engine()
+ * @see csr_get_current_engine()
*/
int csr_engine_get_vendor(csr_engine_h engine, char **vendor);
* @retval #CSR_ERROR_ENGINE_INTERNAL Engine Internal error
* @retval #CSR_ERROR_UNKNOWN Error with unknown reason
*
- * @see csr_get_selected_engine()
+ * @see csr_get_current_engine()
*/
int csr_engine_get_name(csr_engine_h engine, char **name);
* @retval #CSR_ERROR_NONE Successful
* @retval #CSR_ERROR_INVALID_HANDLE Invalid engine information handle
* @retval #CSR_ERROR_INVALID_PARAMETER engine_version is invalid
- * @retval #CSR_ERROR_UNKNOWN Error with unknown reason
* @retval #CSR_ERROR_ENGINE_INTERNAL Engine Internal error
* @retval #CSR_ERROR_UNKNOWN Error with unknown reason
*
- * @see csr_get_selected_engine()
+ * @see csr_get_current_engine()
*/
int csr_engine_get_version(csr_engine_h engine, char **version);
* @retval #CSR_ERROR_NONE Successful
* @retval #CSR_ERROR_INVALID_HANDLE Invalid engine information handle
* @retval #CSR_ERROR_INVALID_PARAMETER engine_version is invalid
- * @retval #CSR_ERROR_UNKNOWN Error with unknown reason
* @retval #CSR_ERROR_ENGINE_INTERNAL Engine Internal error
* @retval #CSR_ERROR_UNKNOWN Error with unknown reason
*
- * @see csr_get_selected_engine()
+ * @see csr_get_current_engine()
*/
int csr_engine_get_data_version(csr_engine_h engine, char **version);
/**
+ * @brief Extracts the latest update time of an engine from the engine information handle.
+ *
+ * @param[in] engine The engine information handle.
+ * @param[out] time A pointer of lasted update time.
+ *
+ * @return #CSR_ERROR_NONE on success, otherwise a negative error value
+ *
+ * @retval #CSR_ERROR_NONE Successful
+ * @retval #CSR_ERROR_INVALID_HANDLE Invalid engine information handle
+ * @retval #CSR_ERROR_INVALID_PARAMETER time is invalid
+ * @retval #CSR_ERROR_ENGINE_INTERNAL Engine Internal error
+ * @retval #CSR_ERROR_UNKNOWN Error with unknown reason
+ *
+ * @see csr_get_current_engine()
+ */
+int csr_engine_get_latest_update_time(csr_engine_h engine, time_t *time);
+
+/**
* @brief Extracts the state of engine activation from the engine information handle.
*
* @param[in] engine The engine information handle.
* @retval #CSR_ERROR_ENGINE_INTERNAL Engine Internal error
* @retval #CSR_ERROR_UNKNOWN Error with unknown reason
*
- * @see csr_get_selected_engine()
+ * @see csr_get_current_engine()
*/
int csr_engine_get_activated(csr_engine_h engine, csr_activated_e *pactivated);
+/**
+ * @brief Releases all system resources associated with a engine information handle.
+ *
+ * @param[in] engine The engine information handle.
+ *
+ * @return #CSR_ERROR_NONE on success, otherwise a negative error value
+ *
+ * @retval #CSR_ERROR_NONE Successful
+ * @retval #CSR_ERROR_INVALID_HANDLE Invalid handle
+ * @retval #CSR_ERROR_SOCKET Socket error between client and server
+ * @retval #CSR_ERROR_SERVER Server has been failed for some reason
+ * @retval #CSR_ERROR_ENGINE_INTERNAL Engine Internal error
+ * @retval #CSR_ERROR_UNKNOWN Error with unknown reason
+ */
+int csr_engine_destroy(csr_engine_h engine);
+
#ifdef __cplusplus
}
#endif
CSR_ERROR_SERVER = TIZEN_ERROR_CSR | 0x03, /**< Server has been failed for some reason */
CSR_ERROR_NO_TASK = TIZEN_ERROR_CSR | 0x04, /**< No Task exists*/
CSR_ERROR_ENGINE_PERMISSION = TIZEN_ERROR_CSR | 0x11, /**< Insufficient permission of engine */
- CSR_ERROR_ENGINE_NOT_SELECTED = TIZEN_ERROR_CSR | 0x12, /**< No engine is selected*/
+ CSR_ERROR_ENGINE_NOT_EXIST = TIZEN_ERROR_CSR | 0x12, /**< No engine exists*/
CSR_ERROR_ENGINE_NOT_ACTIVATED = TIZEN_ERROR_CSR | 0x13, /**< Engine is not activated*/
CSR_ERROR_ENGINE_INTERNAL = TIZEN_ERROR_CSR | 0x19, /**< Engine Internal error*/
CSR_ERROR_UNKNOWN = TIZEN_ERROR_CSR | 0xFF, /**< The error with unknown reason */
/**
* @brief Releases all system resources associated with a CSR Web Protection API handle.
*
- * @details The handle is one returned by the csr_wp_context_create().
- *
* @param[in] handle CSR WP context handle returned by csr_wp_context_create().
*
* @return #CSR_ERROR_NONE on success, otherwise a negative error value
* @retval #CSR_ERROR_INVALID_PARAMETER URL or presult is invalid
* @retval #CSR_ERROR_SOCKET Socket error between client and server
* @retval #CSR_ERROR_SERVER Server has been failed for some reason
- * @retval #CSR_ERROR_ENGINE_NOT_SELECTED No engine selected
+ * @retval #CSR_ERROR_ENGINE_NOT_EXIST No engine exists
* @retval #CSR_ERROR_ENGINE_NOT_ACTIVATED Engine is not activated
* @retval #CSR_ERROR_ENGINE_INTERNAL Engine Internal error
* @retval #CSR_ERROR_UNKNOWN Error with unknown reason
int csr_wp_result_get_risk_level(csr_wp_check_result_h result, csr_wp_risk_level_e* plevel);
/**
+ * @brief Extracts an url of vendor's web site that contains detailed information about the risk
+ * from the result handle.
+ *
+ * @param[in] result A result handle returned by csr_wp_check_url().
+ * @param[out] detailed_url A pointer of an url that contains detailed information about the risk.
+ * If the risk level is CSR_WP_RISK_MEDIUM or CSR_WP_RISK_HIGH,
+ * this url should be provided by the engine.
+ * A caller should not free this string.
+ *
+ * @return #CSR_ERROR_NONE on success, otherwise a negative error value
+ *
+ * @retval #CSR_ERROR_NONE Successful
+ * @retval #CSR_ERROR_INVALID_HANDLE Invalid result handle
+ * @retval #CSR_ERROR_INVALID_PARAMETER detailed_url is invalid
+ * @retval #CSR_ERROR_UNKNOWN Error with unknown reason
+ *
+ * @see csr_wp_check_url()
+ */
+int csr_wp_result_get_detailed_url(csr_wp_check_result_h result, const char** detailed_url);
+
+/**
* @brief Extracts a user reponse of a popup from the result handle.
*
* @param[in] result A result handle returned by csr_wp_check_url().
#ifndef __CSRE_CS_ENGINE_INFO_H_
#define __CSRE_CS_ENGINE_INFO_H_
+#include <time.h>
#include "csre/error.h"
#ifdef __cplusplus
int csre_cs_engine_get_data_version(csre_cs_engine_h engine, const char **version);
/**
+ * @brief Extracts the latest update time of an engine from the engine information handle.
+ *
+ * @param[in] engine The engine information handle.
+ * @param[out] time A pointer of lasted update time.
+ *
+ * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
+ *
+ * @retval #CSRE_ERROR_NONE Successful
+ * @retval #CSRE_ERROR_INVALID_HANDLE Invalid engine information handle
+ * @retval #CSRE_ERROR_INVALID_PARAMETER time is invalid
+ * @retval #CSRE_ERROR_UNKNOWN Error with unknown reason
+ * @retval #CSRE_ERROR_ENGINE_INTERNAL Engine Internal error
+ * @retval #CSRE_ERROR_UNKNOWN Error with unknown reason
+ *
+ * @see csre_cs_get_engine_info()
+ */
+int csre_cs_engine_get_latest_update_time(csre_cs_engine_h engine, time_t *time);
+
+/**
* @brief Extracts the state of engine activation from the engine information handle.
*
* @param[in] engine The engine information handle.
int csre_cs_context_destroy(csre_cs_context_h handle);
/**
- * @brief Sets a database which is used in scanning.
- *
- * @details If a database is not set or an engine does not support "scanning on cloud",
- * the scanning will be done in a local device.
- *
- * @param[in] handle CSR CS context handle returned by csre_cs_context_create().
- *
- * @return #CSRE_CS_ERROR_NONE on success, otherwise a negative error value
- *
- * @retval #CSRE_CS_ERROR_NONE Successful
- * @retval #CSRE_CS_ERROR_INVALID_HANDLE Invalid handle
- * @retval #CSRE_CS_ERROR_UNKNOWN Error with unknown reason
- */
-int csre_cs_set_scan_on_cloud(csre_cs_context_h handle);
-
-/**
* @brief Main function for caller to scan a data buffer for malware.
*
* @param[in] handle CSR CS Engine context handle returned by
*
* @see csre_cs_context_create()
* @see csre_cs_scan_file()
- * @see csre_cs_scan_file_by_fd()
*/
int csre_cs_scan_data(csre_cs_context_h handle,
const unsigned char *data,
*
* @see csre_cs_context_create()
* @see csre_cs_scan_data()
- * @see csre_cs_scan_file_by_fd()
*/
int csre_cs_scan_file(csre_cs_context_h handle,
const char *file_path,
csre_cs_detected_h *pdetected);
/**
- * @brief Main function for caller to scan a file specified by file descriptor for malware.
+ * @brief Main function for caller to scan an application specified
+ * by an application's root directory for malware.
+ * The detection of a malware is done on the vendor's clould server.
*
- * @details The file is opened in readonly by another processe and its file descriptor
- * is delivered to the engine. This is useful in case of an insufficient
- * permission of a server process with scanning function. The client with
- * permission to a file opens the file and deliver its descriptor to a server
- * with an insufficient permission.
- *
- * @param[in] handle CSR CS Engine context handle returned by
- * csre_cs_context_create().
- * @param[in] file_descriptor A file descriptor of scan target file.
- * @param[out] pdetected A pointer of the detected malware handle. It can be null
- * when no malware detected.
+ * @param[in] handle CSR CS Engine context handle returned by
+ * csre_cs_context_create().
+ * @param[in] app_root_dir A absolute root path of scan target application.
+ * @param[out] pdetected A pointer of the detected malware handle. It can be null when
+ * no malware detected.
*
* @return #CSRE_CS_ERROR_NONE on success, otherwise a negative error value
*
* @retval #CSRE_CS_ERROR_NONE Successful
* @retval #CSRE_CS_ERROR_INVALID_HANDLE Invalid handle
* @retval #CSRE_CS_ERROR_OUT_OF_MEMORY Not enough memory
- * @retval #CSRE_CS_ERROR_INVALID_PARAMETER presult is invalid
+ * @retval #CSRE_CS_ERROR_INVALID_PARAMETER app_root_dir or presult is invalid
* @retval #CSRE_CS_ERROR_ENGINE_NOT_ACTIVATED Engine is not activated
* @retval #CSRE_CS_ERROR_PERMISSION_DENIED Access denied
* @retval #CSRE_CS_ERROR_FILE_NOT_FOUND File not found
*
* @see csre_cs_context_create()
* @see csre_cs_scan_data()
- * @see csre_cs_scan_file()
*/
-int csre_cs_scan_file_by_fd(csre_cs_context_h handle,
- int file_descriptor,
+int csre_cs_scan_app_on_cloud(csre_cs_context_h handle, const char* app_root_dir,
csre_cs_detected_h *pdetected);
//==============================================================================
int csre_cs_detected_get_malware_name(csre_cs_detected_h detected, const char** name);
/**
- * @brief Extracts an url that contains detailed information on vendor's web site from the
- * detected malware handle.
+ * @brief Extracts an url of the vendor's web site that contains detailed information
+ * about the detected malware from the detected malware handle.
*
* @param[in] detected A detected malware handle.
* @param[out] detailed_url A pointer of an url that contains detailed information on
- * vendor's web site. It can be null if a vendor doesn't provide
- * this information. A caller should not free this string.
+ * vendor's web site. A caller should not free this string.
*
* @return #CSRE_CS_ERROR_NONE on success, otherwise a negative error value
*
#ifndef __CSRE_WEB_PROTECTION_ENGINE_INFO_H_
#define __CSRE_WEB_PROTECTION_ENGINE_INFO_H_
+#include <time.h>
#include "csre/error.h"
#ifdef __cplusplus
int csre_wp_engine_get_data_version(csre_wp_engine_h engine, const char **version);
/**
+ * @brief Extracts the latest update time of an engine from the engine information handle.
+ *
+ * @param[in] engine The engine information handle.
+ * @param[out] time A pointer of lasted update time.
+ *
+ * @return #CSRE_ERROR_NONE on success, otherwise a negative error value
+ *
+ * @retval #CSRE_ERROR_NONE Successful
+ * @retval #CSRE_ERROR_INVALID_HANDLE Invalid engine information handle
+ * @retval #CSRE_ERROR_INVALID_PARAMETER time is invalid
+ * @retval #CSRE_ERROR_UNKNOWN Error with unknown reason
+ * @retval #CSRE_ERROR_ENGINE_INTERNAL Engine Internal error
+ * @retval #CSRE_ERROR_UNKNOWN Error with unknown reason
+ *
+ * @see csre_wp_get_engine_info()
+ */
+int csre_wp_engine_get_latest_update_time(csre_wp_engine_h engine, time_t *time);
+
+/**
* @brief Extracts the state of engine activation from the engine information handle.
*
* @param[in] engine The engine information handle.
int csre_wp_result_get_risk_level(csre_wp_check_result_h result, csre_wp_risk_level_e* plevel);
/**
+ * @brief Extracts an url of vendor's web site that contains detailed information about the risk
+ * from the result handle.
+ *
+ * @param[in] result A result handle returned by csre_wp_check_url().
+ * @param[out] detailed_url A pointer of an url that contains detailed information about the risk.
+ * If the risk level is CSRE_WP_RISK_MEDIUM or CSRE_WP_RISK_HIGH,
+ * this url should be provided by the engine.
+ * A caller should not free this string.
+ *
+ * @return #CSRE_CS_ERROR_NONE on success, otherwise a negative error value
+ *
+ * @retval #CSRE_CS_ERROR_NONE Successful
+ * @retval #CSRE_ERROR_INVALID_HANDLE Invalid result handle
+ * @retval #CSRE_ERROR_INVALID_PARAMETER detailed_url is invalid
+ * @retval #CSRE_ERROR_UNKNOWN Error with unknown reason
+ * @retval -0x0100~-0xFF00 Engine defined error
+ */
+int csre_wp_result_get_detailed_url(csre_wp_check_result_h result, const char** detailed_url);
+
+/**
* @brief Get the error string for a given engine-defined error code.
*
* @details The error strings are managed by the engine, therefore a caller should not
--- /dev/null
+aabbccX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*112233
#define TEST_FILE_NORMAL TEST_DIR "/test_normal_file"
#define TEST_FILE_MALWARE TEST_DIR "/test_malware_file"
#define TEST_FILE_RISKY TEST_DIR "/test_risky_file"
+#define TEST_APP_ROOT TEST_DIR "/test_app"
namespace {
CSRE_CS_SEVERITY_HIGH,
CSRE_CS_THREAT_MALWARE,
"test_malware",
- "http://detailedinfo.malware.com",
+ "http://high.malware.com",
0);
}
CHECK_IS_NULL(detected);
}
-BOOST_AUTO_TEST_CASE(scan_file_normal_on_cloud)
-{
- int ret = CSRE_ERROR_UNKNOWN;
- auto contextPtr = getContextHandle();
- auto context = contextPtr->get();
-
- BOOST_REQUIRE_NO_THROW(ret = csre_cs_set_scan_on_cloud(context));
- BOOST_REQUIRE(ret == CSRE_ERROR_NONE);
-
- csre_cs_detected_h detected;
- BOOST_REQUIRE_NO_THROW(ret = csre_cs_scan_file(context, TEST_FILE_NORMAL, &detected));
-
- BOOST_REQUIRE(ret == CSRE_ERROR_NONE);
- CHECK_IS_NULL(detected);
-}
-
BOOST_AUTO_TEST_CASE(scan_file_malware)
{
int ret = CSRE_ERROR_UNKNOWN;
CSRE_CS_SEVERITY_HIGH,
CSRE_CS_THREAT_MALWARE,
"test_malware",
- "http://detailedinfo.malware.com",
+ "http://high.malware.com",
0);
}
CSRE_CS_SEVERITY_MEDIUM,
CSRE_CS_THREAT_RISKY,
"test_risk",
- nullptr,
+ "http://medium.malware.com",
0);
}
-BOOST_AUTO_TEST_CASE(scan_file_by_fd_normal)
+BOOST_AUTO_TEST_CASE(scan_app_on_cloud)
{
int ret = CSRE_ERROR_UNKNOWN;
auto contextPtr = getContextHandle();
auto context = contextPtr->get();
- ScopedFile f(TEST_FILE_NORMAL);
-
csre_cs_detected_h detected;
- BOOST_REQUIRE_NO_THROW(ret = csre_cs_scan_file_by_fd(context, f.getFd(), &detected));
-
- BOOST_REQUIRE(ret == CSRE_ERROR_NONE);
- CHECK_IS_NULL(detected);
-}
-
-BOOST_AUTO_TEST_CASE(scan_file_by_fd_malware)
-{
- int ret = CSRE_ERROR_UNKNOWN;
- auto contextPtr = getContextHandle();
- auto context = contextPtr->get();
-
- ScopedFile f(TEST_FILE_MALWARE);
-
- csre_cs_detected_h detected;
- BOOST_REQUIRE_NO_THROW(ret = csre_cs_scan_file_by_fd(context, f.getFd(), &detected));
+ BOOST_REQUIRE_NO_THROW(ret = csre_cs_scan_app_on_cloud(context, TEST_APP_ROOT,&detected));
BOOST_REQUIRE(ret == CSRE_ERROR_NONE);
CHECK_IS_NOT_NULL(detected);
CSRE_CS_SEVERITY_HIGH,
CSRE_CS_THREAT_MALWARE,
"test_malware",
- "http://detailedinfo.malware.com",
+ "http://high.malware.com",
0);
}
-BOOST_AUTO_TEST_CASE(scan_file_by_fd_risky)
-{
- int ret = CSRE_ERROR_UNKNOWN;
- auto contextPtr = getContextHandle();
- auto context = contextPtr->get();
-
- ScopedFile f(TEST_FILE_RISKY);
-
- csre_cs_detected_h detected;
- BOOST_REQUIRE_NO_THROW(ret = csre_cs_scan_file_by_fd(context, f.getFd(), &detected));
-
- BOOST_REQUIRE(ret == CSRE_ERROR_NONE);
- CHECK_IS_NOT_NULL(detected);
-
- checkDetected(detected,
- CSRE_CS_SEVERITY_MEDIUM,
- CSRE_CS_THREAT_RISKY,
- "test_risk",
- nullptr,
- 0);
-}
BOOST_AUTO_TEST_SUITE_END()
CHECK_IS_NOT_NULL(version);
}
+BOOST_AUTO_TEST_CASE(get_latest_update_time)
+{
+ int ret = CSRE_ERROR_UNKNOWN;
+ auto handle = getEngineHandle();
+
+ time_t time = 0;
+ BOOST_REQUIRE_NO_THROW(ret = csre_cs_engine_get_latest_update_time(handle, &time));
+ BOOST_REQUIRE(ret == CSRE_ERROR_NONE);
+ BOOST_REQUIRE(time > 0);
+}
+
BOOST_AUTO_TEST_CASE(get_engine_activated)
{
int ret = CSRE_ERROR_UNKNOWN;
BOOST_AUTO_TEST_SUITE(API_ENGINE_MANAGER)
-BOOST_AUTO_TEST_CASE(get_selected_engine)
+BOOST_AUTO_TEST_CASE(get_current_engine)
{
int ret = CSR_ERROR_UNKNOWN;
csr_engine_h handle;
- BOOST_REQUIRE_NO_THROW(ret = csr_get_selected_engine(CSR_ENGINE_CS, &handle));
+ BOOST_REQUIRE_NO_THROW(ret = csr_get_current_engine(CSR_ENGINE_CS, &handle));
+ BOOST_REQUIRE(ret == CSR_ERROR_NONE);
+
+ BOOST_REQUIRE_NO_THROW(ret = csr_engine_destroy(handle));
BOOST_REQUIRE(ret == CSR_ERROR_NONE);
}
int ret = CSR_ERROR_UNKNOWN;
csr_engine_h handle;
- BOOST_REQUIRE_NO_THROW(ret = csr_get_selected_engine(CSR_ENGINE_CS, &handle));
+ BOOST_REQUIRE_NO_THROW(ret = csr_get_current_engine(CSR_ENGINE_CS, &handle));
BOOST_REQUIRE(ret == CSR_ERROR_NONE);
char *name = nullptr;
BOOST_REQUIRE_NO_THROW(ret = csr_engine_get_name(handle, &name));
BOOST_REQUIRE(ret == CSR_ERROR_NONE);
+
+ BOOST_REQUIRE_NO_THROW(ret = csr_engine_destroy(handle));
+ BOOST_REQUIRE(ret == CSR_ERROR_NONE);
}
BOOST_AUTO_TEST_SUITE_END()
struct Result {
csre_wp_risk_level_e risk_level;
+ std::string detailed_url;
- Result(csre_wp_risk_level_e r) : risk_level(r) {}
+ Result(csre_wp_risk_level_e r, const char* durl) : risk_level(r), detailed_url(durl) {}
};
std::unordered_map<std::string, Result> ExpectedResult = {
- {"http://normal.test.com", Result(CSRE_WP_RISK_UNVERIFIED)},
- {"http://highrisky.test.com", Result(CSRE_WP_RISK_HIGH)},
- {"http://mediumrisky.test.com", Result(CSRE_WP_RISK_MEDIUM)},
- {"http://lowrisky.test.com", Result(CSRE_WP_RISK_LOW)}
+ {"http://normal.test.com", Result(CSRE_WP_RISK_UNVERIFIED, "")},
+ {"http://highrisky.test.com", Result(CSRE_WP_RISK_HIGH, "http://high.risky.com")},
+ {"http://mediumrisky.test.com", Result(CSRE_WP_RISK_MEDIUM, "http://medium.risky.com")},
+ {"http://lowrisky.test.com", Result(CSRE_WP_RISK_LOW, "")}
};
inline void checkResult(csre_wp_check_result_h &result, const Result &expected)
BOOST_REQUIRE_MESSAGE(risk_level == expected.risk_level,
"risk level isn't expected value. "
"val: " << risk_level << " expected: " << expected.risk_level);
+
+ const char *detailed_url = nullptr;
+ BOOST_REQUIRE_NO_THROW(ret = csre_wp_result_get_detailed_url(result, &detailed_url));
+
+ BOOST_REQUIRE(ret == CSRE_ERROR_NONE);
+ BOOST_REQUIRE_MESSAGE(expected.detailed_url.compare(detailed_url) == 0,
+ "detailed url isn't expected value. "
+ "val: " << detailed_url <<" expected: " << expected.detailed_url);
}
class ContextPtr {
CHECK_IS_NOT_NULL(version);
}
+BOOST_AUTO_TEST_CASE(get_latest_update_time)
+{
+ int ret = CSRE_ERROR_UNKNOWN;
+ auto handle = getEngineHandle();
+
+ time_t time = 0;
+ BOOST_REQUIRE_NO_THROW(ret = csre_wp_engine_get_latest_update_time(handle, &time));
+ BOOST_REQUIRE(ret == CSRE_ERROR_NONE);
+ BOOST_REQUIRE(time > 0);
+}
+
BOOST_AUTO_TEST_CASE(get_engine_activated)
{
int ret = CSRE_ERROR_UNKNOWN;