framework/service/file-system.cpp
framework/service/app-deleter.cpp
framework/service/cs-loader.cpp
+ framework/service/wp-loader.cpp
framework/ui/askuser.cpp
# question and response codes needed on both of
* limitations under the License
*/
/*
- * @file csl-oader.cpp
+ * @file cs-loader.cpp
* @author Sangsu Choi (sangsu.choi@samsung.com)
* @version 1.0
* @brief
namespace {
int getValueCstr(std::string &value,
- const std::function<int(const char *)> &getfunc)
+ const std::function<int(const char **)> &getfunc)
{
const char *cvalue = nullptr;
- auto retval = getfunc(cvalue);
-
+ auto retval = getfunc(&cvalue);
if (retval == CSRE_ERROR_NONE && cvalue != nullptr)
value = cvalue;
if (d == nullptr)
throw std::invalid_argument("cs loader get malware name");
- return getValueCstr(value, [&](const char *cvalue) {
- return m_pc.fpGetMalwareName(d, &cvalue);
+ return getValueCstr(value, [&](const char **cvalue) {
+ return m_pc.fpGetMalwareName(d, cvalue);
});
}
if (d == nullptr)
throw std::invalid_argument("cs loader get detailed url");
- return getValueCstr(value, [&](const char *cvalue) {
- return m_pc.fpGetDetailedUrl(d, &cvalue);
+ return getValueCstr(value, [&](const char **cvalue) {
+ return m_pc.fpGetDetailedUrl(d, cvalue);
});
}
int CsLoader::getErrorString(int ec, std::string &value)
{
- return getValueCstr(value, [&](const char *cvalue) {
- return m_pc.fpGetErrorString(ec, &cvalue);
+ return getValueCstr(value, [&](const char **cvalue) {
+ return m_pc.fpGetErrorString(ec, cvalue);
});
}
if (e == nullptr)
throw std::invalid_argument("cs loader get error string");
- return getValueCstr(value, [&](const char *cvalue) {
- return m_pc.fpGetEngineApiVersion(e, &cvalue);
+ return getValueCstr(value, [&](const char **cvalue) {
+ return m_pc.fpGetEngineApiVersion(e, cvalue);
});
}
if (e == nullptr)
throw std::invalid_argument("cs loader get engine vendor");
- return getValueCstr(value, [&](const char *cvalue) {
- return m_pc.fpGetEngineVendor(e, &cvalue);
+ return getValueCstr(value, [&](const char **cvalue) {
+ return m_pc.fpGetEngineVendor(e, cvalue);
});
}
if (e == nullptr)
throw std::invalid_argument("cs loader get engine name");
- return getValueCstr(value, [&](const char *cvalue) {
- return m_pc.fpGetEngineName(e, &cvalue);
+ return getValueCstr(value, [&](const char **cvalue) {
+ return m_pc.fpGetEngineName(e, cvalue);
});
}
if (e == nullptr)
throw std::invalid_argument("cs loader get engine version");
- return getValueCstr(value, [&](const char *cvalue) {
- return m_pc.fpGetEngineName(e, &cvalue);
+ return getValueCstr(value, [&](const char **cvalue) {
+ return m_pc.fpGetEngineName(e, cvalue);
});
}
if (e == nullptr)
throw std::invalid_argument("cs loader get engine version");
- return getValueCstr(value, [&](const char *cvalue) {
- return m_pc.fpGetEngineDataVersion(e, &cvalue);
+ return getValueCstr(value, [&](const char **cvalue) {
+ return m_pc.fpGetEngineDataVersion(e, cvalue);
});
}
return m_pc.fpGetEngineActivated(e, pactivated);
}
-int CsLoader::getEngineVendorLogo(csre_cs_engine_h e,
- std::vector<unsigned char> &value)
+int CsLoader::getEngineVendorLogo(csre_cs_engine_h e, std::vector<unsigned char> &value)
{
if (e == nullptr)
throw std::invalid_argument("cs loader get engine vendor logo");
void *handle = dlopen(enginePath.c_str(), RTLD_LAZY);
if (handle == nullptr)
- throw std::logic_error(FORMAT("engine dlopen error. path: " << enginePath <<
- " errno: " << errno));
+ throw std::logic_error(FORMAT("engine dlopen error. path: " << enginePath <<" errno: " << errno));
m_pc.dlhandle = handle;
- m_pc.fpGlobalInit = reinterpret_cast<FpGlobalInit>(dlsym(handle,
- "csre_cs_global_initialize"));
- m_pc.fpGlobalDeinit = reinterpret_cast<FpGlobalDeinit>(dlsym(handle,
- "csre_cs_global_deinitialize"));
- m_pc.fpContextCreate = reinterpret_cast<FpContextCreate>(dlsym(handle,
- "csre_cs_context_create"));
- m_pc.fpContextDestroy = reinterpret_cast<FpContextDestroy>(dlsym(handle,
- "csre_cs_context_destroy"));
- m_pc.fpScanData = reinterpret_cast<FpScanData>(dlsym(handle,
- "csre_cs_scan_data"));
- m_pc.fpScanFile = reinterpret_cast<FpScanFile>(dlsym(handle,
- "csre_cs_scan_file"));
- m_pc.fpScanAppOnCloud = reinterpret_cast<FpScanAppOnCloud>(dlsym(handle,
- "csre_cs_scan_app_on_cloud"));
- m_pc.fpGetSeverity = reinterpret_cast<FpGetSeverity>(dlsym(handle,
- "csre_cs_detected_get_severity"));
- m_pc.fpGetThreatType = reinterpret_cast<FpGetThreatType>(dlsym(handle,
- "csre_cs_detected_get_threat_type"));
- m_pc.fpGetMalwareName = reinterpret_cast<FpGetMalwareName>(dlsym(handle,
- "csre_cs_detected_get_malware_name"));
- m_pc.fpGetDetailedUrl = reinterpret_cast<FpGetDetailedUrl>(dlsym(handle,
- "csre_cs_detected_get_detailed_url"));
- m_pc.fpGetTimestamp = reinterpret_cast<FpGetTimestamp>(dlsym(handle,
- "csre_cs_detected_get_timestamp"));
- m_pc.fpGetErrorString = reinterpret_cast <FpGetErrorString>(dlsym(handle,
- "csre_cs_get_error_string"));
- m_pc.fpGetEngineInfo = reinterpret_cast<FpGetEngineInfo>(dlsym(handle,
- "csre_cs_engine_get_info"));
- m_pc.fpDestroyEngine = reinterpret_cast<FpDestroyEngine>(dlsym(handle,
- "csre_cs_engine_destroy"));
- m_pc.fpGetEngineApiVersion = reinterpret_cast<FpGetEngineApiVersion>(dlsym(
- handle, "csre_cs_engine_get_api_version"));
- m_pc.fpGetEngineVendor = reinterpret_cast<FpGetEngineVendor>(dlsym(handle,
- "csre_cs_engine_get_vendor"));
- m_pc.fpGetEngineName = reinterpret_cast<FpGetEngineName>(dlsym(handle,
- "csre_cs_engine_get_version"));
- m_pc.fpGetEngineVersion = reinterpret_cast<FpGetEngineVersion>(dlsym(handle,
- "csre_cs_engine_get_data_version"));
- m_pc.fpGetEngineDataVersion = reinterpret_cast<FpGetEngineDataVersion>(dlsym(
- handle, "csre_cs_engine_get_data_version"));
- m_pc.fpGetEngineLatestUpdateTime =
- reinterpret_cast<FpGetEngineLatestUpdateTime>(dlsym(handle,
- "csre_cs_engine_get_latest_update_time"));
- m_pc.fpGetEngineActivated = reinterpret_cast<FpGetEngineActivated>(dlsym(handle,
- "csre_cs_engine_get_activated"));
- m_pc.fpGetEngineVendorLogo = reinterpret_cast<FpGetEngineVendorLogo>(dlsym(
- handle, "csre_cs_engine_get_vendor_logo"));
+ m_pc.fpGlobalInit = reinterpret_cast<FpGlobalInit>(dlsym(handle, "csre_cs_global_initialize"));
+ m_pc.fpGlobalDeinit = reinterpret_cast<FpGlobalDeinit>(dlsym(handle, "csre_cs_global_deinitialize"));
+ m_pc.fpContextCreate = reinterpret_cast<FpContextCreate>(dlsym(handle, "csre_cs_context_create"));
+ m_pc.fpContextDestroy = reinterpret_cast<FpContextDestroy>(dlsym(handle, "csre_cs_context_destroy"));
+ m_pc.fpScanData = reinterpret_cast<FpScanData>(dlsym(handle, "csre_cs_scan_data"));
+ m_pc.fpScanFile = reinterpret_cast<FpScanFile>(dlsym(handle, "csre_cs_scan_file"));
+ m_pc.fpScanAppOnCloud = reinterpret_cast<FpScanAppOnCloud>(dlsym(handle, "csre_cs_scan_app_on_cloud"));
+ m_pc.fpGetSeverity = reinterpret_cast<FpGetSeverity>(dlsym(handle, "csre_cs_detected_get_severity"));
+ m_pc.fpGetThreatType = reinterpret_cast<FpGetThreatType>(dlsym(handle, "csre_cs_detected_get_threat_type"));
+ m_pc.fpGetMalwareName = reinterpret_cast<FpGetMalwareName>(dlsym(handle, "csre_cs_detected_get_malware_name"));
+ m_pc.fpGetDetailedUrl = reinterpret_cast<FpGetDetailedUrl>(dlsym(handle, "csre_cs_detected_get_detailed_url"));
+ m_pc.fpGetTimestamp = reinterpret_cast<FpGetTimestamp>(dlsym(handle, "csre_cs_detected_get_timestamp"));
+ m_pc.fpGetErrorString = reinterpret_cast <FpGetErrorString>(dlsym(handle, "csre_cs_get_error_string"));
+ m_pc.fpGetEngineInfo = reinterpret_cast<FpGetEngineInfo>(dlsym(handle, "csre_cs_engine_get_info"));
+ m_pc.fpDestroyEngine = reinterpret_cast<FpDestroyEngine>(dlsym(handle, "csre_cs_engine_destroy"));
+ m_pc.fpGetEngineApiVersion = reinterpret_cast<FpGetEngineApiVersion>(dlsym(handle, "csre_cs_engine_get_api_version"));
+ m_pc.fpGetEngineVendor = reinterpret_cast<FpGetEngineVendor>(dlsym(handle, "csre_cs_engine_get_vendor"));
+ m_pc.fpGetEngineName = reinterpret_cast<FpGetEngineName>(dlsym(handle, "csre_cs_engine_get_name"));
+ m_pc.fpGetEngineVersion = reinterpret_cast<FpGetEngineVersion>(dlsym(handle, "csre_cs_engine_get_version"));
+ m_pc.fpGetEngineDataVersion = reinterpret_cast<FpGetEngineDataVersion>(dlsym(handle, "csre_cs_engine_get_data_version"));
+ m_pc.fpGetEngineLatestUpdateTime = reinterpret_cast<FpGetEngineLatestUpdateTime>(dlsym(handle, "csre_cs_engine_get_latest_update_time"));
+ m_pc.fpGetEngineActivated = reinterpret_cast<FpGetEngineActivated>(dlsym(handle, "csre_cs_engine_get_activated"));
+ m_pc.fpGetEngineVendorLogo = reinterpret_cast<FpGetEngineVendorLogo>(dlsym(handle, "csre_cs_engine_get_vendor_logo"));
if (m_pc.fpGlobalInit == nullptr || m_pc.fpGlobalDeinit == nullptr ||
m_pc.fpContextCreate == nullptr || m_pc.fpContextDestroy == nullptr ||
using FpContextCreate = int(*)(csre_cs_context_h *);
using FpContextDestroy = int(*)(csre_cs_context_h);
using FpScanData = int(*)(csre_cs_context_h, const unsigned char *, size_t,
- csre_cs_detected_h *);
+ csre_cs_detected_h *);
using FpScanFile = int(*)(csre_cs_context_h, const char *,
- csre_cs_detected_h *);
+ csre_cs_detected_h *);
using FpScanAppOnCloud = int(*)(csre_cs_context_h, const char *,
csre_cs_detected_h *);
using FpGetSeverity = int(*)(csre_cs_detected_h, csre_cs_severity_level_e *);
using FpGetEngineLatestUpdateTime = int(*)(csre_cs_engine_h, time_t *);
using FpGetEngineActivated = int(*)(csre_cs_engine_h, csre_cs_activated_e *);
using FpGetEngineVendorLogo = int(*)(csre_cs_engine_h, unsigned char **,
- unsigned int *);
+ unsigned int *);
struct PluginContext {
void *dlhandle;
--- /dev/null
+/*
+ * 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 wp-loader.cpp
+ * @author Sangsu Choi (sangsu.choi@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+#include "service/wp-loader.h"
+
+#include <stdexcept>
+#include <dlfcn.h>
+
+#include "common/audit/logger.h"
+
+namespace Csr {
+
+namespace {
+
+int getValueCstr(std::string &value,
+ const std::function<int(const char **)> &getfunc)
+{
+ const char *cvalue = nullptr;
+ auto retval = getfunc(&cvalue);
+
+ if (retval == CSRE_ERROR_NONE && cvalue != nullptr)
+ value = cvalue;
+
+ return retval;
+}
+
+} // namespace anonymous
+
+int WpLoader::globalInit(const std::string &ro_res_dir,
+ const std::string &rw_working_dir)
+{
+ if (ro_res_dir.empty() || rw_working_dir.empty())
+ throw std::invalid_argument("wp loader global init");
+
+ return m_pc.fpGlobalInit(ro_res_dir.c_str(), rw_working_dir.c_str());
+}
+
+int WpLoader::globalDeinit()
+{
+ return m_pc.fpGlobalDeinit();
+}
+
+int WpLoader::contextCreate(csre_wp_context_h &c)
+{
+ return m_pc.fpContextCreate(&c);
+}
+
+int WpLoader::contextDestroy(csre_wp_context_h c)
+{
+ if (c == nullptr)
+ throw std::invalid_argument("wp loader context destroy");
+
+ return m_pc.fpContextDestroy(c);
+}
+
+int WpLoader::checkUrl(csre_wp_context_h c, const std::string &url, csre_wp_check_result_h *presult)
+{
+ if(c == nullptr || url.empty() || presult == nullptr)
+ throw std::invalid_argument("wp loader check url error");
+
+ return m_pc.fpCheckUrl(c,(const char*)url.c_str(),presult);
+}
+
+int WpLoader::getRiskLevel(csre_wp_check_result_h r, csre_wp_risk_level_e *plevel)
+{
+ if(r == nullptr || plevel == nullptr)
+ throw std::invalid_argument("wp loader Get Risk Level error");
+
+ return m_pc.fpGetRiskLevel(r,plevel);
+}
+
+int WpLoader::getDetailedUrl(csre_wp_check_result_h r, std::string &value)
+{
+ if (r == nullptr)
+ throw std::invalid_argument("wp loader get detailed url error");
+
+ return getValueCstr(value, [&](const char **cvalue) {
+ return m_pc.fpGetDetailedUrl(r, cvalue);
+ });
+}
+
+
+int WpLoader::getErrorString(int ec, std::string &value)
+{
+ return getValueCstr(value, [&](const char **cvalue) {
+ return m_pc.fpGetErrorString(ec, cvalue);
+ });
+}
+
+
+int WpLoader::getEngineInfo(csre_wp_engine_h &e)
+{
+ return m_pc.fpGetEngineInfo(&e);
+}
+
+int WpLoader::destroyEngine(csre_wp_engine_h e)
+{
+ return m_pc.fpDestroyEngine(e);
+}
+
+int WpLoader::getEngineApiVersion(csre_wp_engine_h e, std::string &value)
+{
+ if (e == nullptr)
+ throw std::invalid_argument("wp loader get error string");
+
+ return getValueCstr(value, [&](const char **cvalue) {
+ return m_pc.fpGetEngineApiVersion(e, cvalue);
+ });
+}
+
+int WpLoader::getEngineVendor(csre_wp_engine_h e, std::string &value)
+{
+ if (e == nullptr)
+ throw std::invalid_argument("wp loader get engine vendor");
+
+ return getValueCstr(value, [&](const char **cvalue) {
+ return m_pc.fpGetEngineVendor(e, cvalue);
+ });
+}
+
+int WpLoader::getEngineName(csre_wp_engine_h e, std::string &value)
+{
+ if (e == nullptr)
+ throw std::invalid_argument("wp loader get engine name");
+
+ return getValueCstr(value, [&](const char **cvalue) {
+ return m_pc.fpGetEngineName(e, cvalue);
+ });
+}
+
+int WpLoader::getEngineVersion(csre_wp_engine_h e, std::string &value)
+{
+ if (e == nullptr)
+ throw std::invalid_argument("wp loader get engine version");
+
+ return getValueCstr(value, [&](const char **cvalue) {
+ return m_pc.fpGetEngineName(e, cvalue);
+ });
+}
+
+int WpLoader::getEngineDataVersion(csre_wp_engine_h e, std::string &value)
+{
+ if (e == nullptr)
+ throw std::invalid_argument("wp loader get engine version");
+
+ return getValueCstr(value, [&](const char **cvalue) {
+ return m_pc.fpGetEngineDataVersion(e, cvalue);
+ });
+}
+
+int WpLoader::getEngineLatestUpdateTime(csre_wp_engine_h e, time_t *ptime)
+{
+ if (e == nullptr || ptime == nullptr)
+ throw std::invalid_argument("wp loader get latest update time");
+
+ return m_pc.fpGetEngineLatestUpdateTime(e, ptime);
+}
+
+int WpLoader::getEngineActivated(csre_wp_engine_h e,
+ csre_wp_activated_e *pactivated)
+{
+ if (e == nullptr || pactivated == nullptr)
+ throw std::invalid_argument("wp loader get engine activated");
+
+ return m_pc.fpGetEngineActivated(e, pactivated);
+}
+
+int WpLoader::getEngineVendorLogo(csre_wp_engine_h e,
+ std::vector<unsigned char> &value)
+{
+ if (e == nullptr)
+ throw std::invalid_argument("wp loader get engine vendor logo");
+
+ unsigned char *cvalue = nullptr;
+ unsigned int size = 0;
+ auto retval = m_pc.fpGetEngineVendorLogo(e, &cvalue, &size);
+
+ if (retval == CSRE_ERROR_NONE && cvalue != nullptr && size != 0)
+ value.assign(cvalue, cvalue + size);
+
+ return retval;
+}
+
+WpLoader::WpLoader(const std::string &enginePath)
+{
+ INFO("Load wp-Engine plugin start. engine path: " << enginePath);
+
+ void *handle = dlopen(enginePath.c_str(), RTLD_LAZY);
+
+ if (handle == nullptr)
+ throw std::logic_error(FORMAT("engine dlopen error. path: " << enginePath <<
+ " errno: " << errno));
+
+ m_pc.dlhandle = handle;
+
+ m_pc.fpGlobalInit = reinterpret_cast<FpGlobalInit>(dlsym(handle, "csre_wp_global_initialize"));
+ m_pc.fpGlobalDeinit = reinterpret_cast<FpGlobalDeinit>(dlsym(handle, "csre_wp_global_deinitialize"));
+ m_pc.fpContextCreate = reinterpret_cast<FpContextCreate>(dlsym(handle, "csre_wp_context_create"));
+ m_pc.fpContextDestroy = reinterpret_cast<FpContextDestroy>(dlsym(handle, "csre_wp_context_destroy"));
+ m_pc.fpCheckUrl = reinterpret_cast<FpCheckUrl>(dlsym(handle, "csre_wp_check_url"));
+ m_pc.fpGetRiskLevel = reinterpret_cast<FpGetRiskLevel>(dlsym(handle, "csre_wp_result_get_risk_level"));
+ m_pc.fpGetDetailedUrl = reinterpret_cast<FPGetDetailedUrl>(dlsym(handle, "csre_wp_result_get_detailed_url"));
+ m_pc.fpGetErrorString = reinterpret_cast <FpGetErrorString>(dlsym(handle, "csre_wp_get_error_string"));
+ m_pc.fpGetEngineInfo = reinterpret_cast<FpGetEngineInfo>(dlsym(handle, "csre_wp_engine_get_info"));
+ m_pc.fpDestroyEngine = reinterpret_cast<FpDestroyEngine>(dlsym(handle, "csre_wp_engine_destroy"));
+ m_pc.fpGetEngineApiVersion = reinterpret_cast<FpGetEngineApiVersion>(dlsym(handle, "csre_wp_engine_get_api_version"));
+ m_pc.fpGetEngineVendor = reinterpret_cast<FpGetEngineVendor>(dlsym(handle, "csre_wp_engine_get_vendor"));
+ m_pc.fpGetEngineName = reinterpret_cast<FpGetEngineName>(dlsym(handle, "csre_wp_engine_get_name"));
+ m_pc.fpGetEngineVersion = reinterpret_cast<FpGetEngineVersion>(dlsym(handle, "csre_wp_engine_get_version"));
+ m_pc.fpGetEngineDataVersion = reinterpret_cast<FpGetEngineDataVersion>(dlsym(handle, "csre_wp_engine_get_data_version"));
+ m_pc.fpGetEngineLatestUpdateTime = reinterpret_cast<FpGetEngineLatestUpdateTime>(dlsym(handle, "csre_wp_engine_get_latest_update_time"));
+ m_pc.fpGetEngineActivated = reinterpret_cast<FpGetEngineActivated>(dlsym(handle, "csre_wp_engine_get_activated"));
+ m_pc.fpGetEngineVendorLogo = reinterpret_cast<FpGetEngineVendorLogo>(dlsym(handle, "csre_wp_engine_get_vendor_logo"));
+
+ if (m_pc.fpGlobalInit == nullptr || m_pc.fpGlobalDeinit == nullptr ||
+ m_pc.fpContextCreate == nullptr || m_pc.fpContextDestroy == nullptr ||
+ m_pc.fpCheckUrl == nullptr || m_pc.fpGetRiskLevel == nullptr ||
+ m_pc.fpGetDetailedUrl == nullptr || m_pc.fpGetErrorString == nullptr ||
+ m_pc.fpGetEngineInfo == nullptr || m_pc.fpDestroyEngine == nullptr ||
+ m_pc.fpGetEngineApiVersion == nullptr || m_pc.fpGetEngineVendor == nullptr ||
+ m_pc.fpGetEngineName == nullptr || m_pc.fpGetEngineVersion == nullptr ||
+ m_pc.fpGetEngineDataVersion == nullptr ||
+ m_pc.fpGetEngineLatestUpdateTime == nullptr ||
+ m_pc.fpGetEngineActivated == nullptr || m_pc.fpGetEngineVendorLogo == nullptr) {
+ dlclose(handle);
+ throw std::runtime_error(FORMAT("Failed to load funcs from engine library. "
+ "engine path: " << enginePath << "errno: " <<
+ errno));
+ }
+}
+
+WpLoader::~WpLoader()
+{
+ dlclose(m_pc.dlhandle);
+}
+
+}
--- /dev/null
+/*
+ * 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 wp-loader.h
+ * @author Sangsu Choi (sangsu.choi@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+
+#pragma once
+
+#include <ctime>
+#include <cstddef>
+#include <vector>
+#include <string>
+
+
+#include "csre/web-protection-types.h"
+#include "csre/web-protection-engine-info.h"
+
+namespace Csr {
+
+class WpLoader {
+public:
+ WpLoader(const std::string &);
+ virtual ~WpLoader();
+ int globalInit(const std::string &, const std::string &);
+ int globalDeinit();
+ int contextCreate(csre_wp_context_h &);
+ int contextDestroy(csre_wp_context_h);
+ int checkUrl(csre_wp_context_h handle, const std::string &, csre_wp_check_result_h *);
+ int getRiskLevel(csre_wp_check_result_h, csre_wp_risk_level_e *);
+ int getDetailedUrl(csre_wp_check_result_h, std::string &);
+ int getErrorString(int, std::string &);
+ int getEngineInfo(csre_wp_engine_h &);
+ int destroyEngine(csre_wp_engine_h);
+ int getEngineApiVersion(csre_wp_engine_h, std::string &);
+ int getEngineVendor(csre_wp_engine_h, std::string &);
+ int getEngineName(csre_wp_engine_h, std::string &);
+ int getEngineVersion(csre_wp_engine_h, std::string &);
+ int getEngineDataVersion(csre_wp_engine_h, std::string &);
+ int getEngineLatestUpdateTime(csre_wp_engine_h, time_t *);
+ int getEngineActivated(csre_wp_engine_h, csre_wp_activated_e *);
+ int getEngineVendorLogo(csre_wp_engine_h, std::vector<unsigned char> &);
+
+private:
+ using FpGlobalInit = int(*)(const char *, const char *);
+ using FpGlobalDeinit = int(*)();
+ using FpContextCreate = int(*)(csre_wp_context_h *);
+ using FpContextDestroy = int(*)(csre_wp_context_h);
+ using FpCheckUrl = int(*)(csre_wp_context_h , const char *, csre_wp_check_result_h *);
+ using FpGetRiskLevel = int(*)(csre_wp_check_result_h, csre_wp_risk_level_e *);
+ using FPGetDetailedUrl = int(*)(csre_wp_check_result_h, const char **);
+ using FpGetErrorString = int(*)(int, const char **);
+ using FpGetEngineInfo = int(*)(csre_wp_engine_h *);
+ using FpDestroyEngine = int(*)(csre_wp_engine_h);
+ using FpGetEngineApiVersion = int(*)(csre_wp_engine_h, const char **);
+ using FpGetEngineVendor = int(*)(csre_wp_engine_h, const char **);
+ using FpGetEngineName = int(*)(csre_wp_engine_h, const char **);
+ using FpGetEngineVersion = int(*)(csre_wp_engine_h, const char **);
+ using FpGetEngineDataVersion = int(*)(csre_wp_engine_h, const char **);
+ using FpGetEngineLatestUpdateTime = int(*)(csre_wp_engine_h, time_t *);
+ using FpGetEngineActivated = int(*)(csre_wp_engine_h, csre_wp_activated_e *);
+ using FpGetEngineVendorLogo = int(*)(csre_wp_engine_h, unsigned char **, unsigned int *);
+
+ struct PluginContext {
+ void *dlhandle;
+
+ FpGlobalInit fpGlobalInit;
+ FpGlobalDeinit fpGlobalDeinit;
+ FpContextCreate fpContextCreate;
+ FpContextDestroy fpContextDestroy;
+ FpCheckUrl fpCheckUrl;
+ FpGetRiskLevel fpGetRiskLevel;
+ FPGetDetailedUrl fpGetDetailedUrl;
+ FpGetErrorString fpGetErrorString;
+ FpGetEngineInfo fpGetEngineInfo;
+ FpDestroyEngine fpDestroyEngine;
+ FpGetEngineApiVersion fpGetEngineApiVersion;
+ FpGetEngineVendor fpGetEngineVendor;
+ FpGetEngineName fpGetEngineName;
+ FpGetEngineVersion fpGetEngineVersion;
+ FpGetEngineDataVersion fpGetEngineDataVersion;
+ FpGetEngineLatestUpdateTime fpGetEngineLatestUpdateTime;
+ FpGetEngineActivated fpGetEngineActivated;
+ FpGetEngineVendorLogo fpGetEngineVendorLogo;
+ };
+
+ PluginContext m_pc;
+};
+
+}
${CSR_FW_SVC_SRC_PATH}/file-system.cpp
${CSR_FW_SVC_SRC_PATH}/app-deleter.cpp
${CSR_FW_SVC_SRC_PATH}/cs-loader.cpp
+ ${CSR_FW_SVC_SRC_PATH}/wp-loader.cpp
colour_log_formatter.cpp
test-api-content-screening.cpp
test-api-content-screening-async.cpp
test-main.cpp
test-common.cpp
test-cs-loader.cpp
+ test-wp-loader.cpp
)
INCLUDE_DIRECTORIES(
#define TEST_FILE_RISKY TEST_DIR "/test_risky_file"
#define TEST_APP_ROOT TEST_DIR "/test_app"
+
namespace {
inline void checkDetected(csre_cs_detected_h detected,
--- /dev/null
+/*
+ * 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 test-wp-loader.cpp
+ * @author Sangsu Choi (sangsu.choi@samsung.com)
+ * @version 1.0
+ * @brief web protection Engine loading test
+ */
+#include "service/wp-loader.h"
+
+#include <ctime>
+#include <cstring>
+#include <unordered_map>
+#include <cstdio>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <boost/test/unit_test.hpp>
+
+#include "test-common.h"
+
+
+
+
+namespace {
+
+struct Result {
+ csre_wp_risk_level_e risk_level;
+ std::string detailed_url;
+
+ 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://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(const std::string &url, csre_wp_check_result_h &result, const Result &expected)
+{
+ EXCEPTION_GUARD_START
+
+ CHECK_IS_NOT_NULL(result);
+
+ csre_wp_risk_level_e risk_level;
+ ASSERT_IF(csre_wp_result_get_risk_level(result, &risk_level), CSRE_ERROR_NONE);
+ BOOST_REQUIRE_MESSAGE(risk_level == expected.risk_level,
+ "url[" << url << "] risk level isn't expected value. "
+ "val: " << risk_level << " expected: " << expected.risk_level);
+
+ const char *detailed_url = nullptr;
+ ASSERT_IF(csre_wp_result_get_detailed_url(result, &detailed_url), CSRE_ERROR_NONE);
+ BOOST_REQUIRE_MESSAGE(expected.detailed_url.compare(detailed_url) == 0,
+ "url[" << url << "] detailed url isn't expected value. "
+ "val: " << detailed_url <<" expected: " << expected.detailed_url);
+
+
+ EXCEPTION_GUARD_END
+}
+
+template <typename T>
+struct Handle {
+ Handle()
+ {
+ BOOST_REQUIRE_MESSAGE(0, "Not specialized for handle template");
+ }
+
+ ~Handle()
+ {
+ BOOST_REQUIRE_MESSAGE(0, "Not specialized for handle template");
+ }
+
+ Csr::WpLoader loader;
+ T context;
+};
+
+template <>
+struct Handle<csre_wp_context_h> {
+ Handle() : loader(SAMPLE_ENGINE_DIR "/libcsr-wp-engine.so")
+ {
+ ASSERT_IF(
+ loader.globalInit(SAMPLE_ENGINE_RO_RES_DIR, SAMPLE_ENGINE_RW_WORKING_DIR),
+ CSRE_ERROR_NONE);
+ ASSERT_IF(loader.contextCreate(context), CSRE_ERROR_NONE);
+ }
+
+ ~Handle()
+ {
+ ASSERT_IF(loader.contextDestroy(context), CSRE_ERROR_NONE);
+ ASSERT_IF(loader.globalDeinit(), CSRE_ERROR_NONE);
+ }
+
+ Csr::WpLoader loader;
+ csre_wp_context_h context;
+};
+
+template <>
+struct Handle<csre_wp_engine_h> {
+ Handle() : loader(SAMPLE_ENGINE_DIR "/libcsr-wp-engine.so")
+ {
+ ASSERT_IF(
+ loader.globalInit(SAMPLE_ENGINE_RO_RES_DIR, SAMPLE_ENGINE_RW_WORKING_DIR),
+ CSRE_ERROR_NONE);
+ ASSERT_IF(loader.getEngineInfo(context), CSRE_ERROR_NONE);
+ }
+
+ ~Handle()
+ {
+ ASSERT_IF(loader.destroyEngine(context), CSRE_ERROR_NONE);
+ ASSERT_IF(loader.globalDeinit(), CSRE_ERROR_NONE);
+ }
+
+ Csr::WpLoader loader;
+ csre_wp_engine_h context;
+};
+
+} // namespace anonymous
+
+
+
+BOOST_AUTO_TEST_SUITE(WP_LOADER)
+
+BOOST_AUTO_TEST_CASE(context_create_destroy)
+{
+ EXCEPTION_GUARD_START
+
+ Handle<csre_wp_context_h> h;
+ (void) h;
+
+ EXCEPTION_GUARD_END
+}
+
+BOOST_AUTO_TEST_CASE(check_url)
+{
+ EXCEPTION_GUARD_START
+
+ Handle<csre_wp_context_h> h;
+
+ for (const auto &pair : ExpectedResult) {
+ csre_wp_check_result_h result;
+ ASSERT_IF(h.loader.checkUrl(h.context, pair.first.c_str(), &result), CSRE_ERROR_NONE);
+ checkResult(pair.first, result, pair.second);
+ }
+
+ EXCEPTION_GUARD_END
+}
+
+
+BOOST_AUTO_TEST_CASE(error_string)
+{
+ EXCEPTION_GUARD_START
+
+ Handle<csre_wp_engine_h> h;
+
+ std::string str;
+
+ ASSERT_IF(h.loader.getErrorString(CSRE_ERROR_UNKNOWN, str), CSRE_ERROR_NONE);
+ ASSERT_IF(str.empty(), false);
+
+ EXCEPTION_GUARD_END
+}
+
+
+BOOST_AUTO_TEST_CASE(get_engine_info)
+{
+ EXCEPTION_GUARD_START
+
+ Handle<csre_wp_engine_h> h;
+ (void) h;
+
+ EXCEPTION_GUARD_END
+}
+
+BOOST_AUTO_TEST_CASE(get_vendor)
+{
+ EXCEPTION_GUARD_START
+
+ Handle<csre_wp_engine_h> h;
+
+ std::string str;
+ ASSERT_IF(h.loader.getEngineVendor(h.context, str), CSRE_ERROR_NONE);
+ ASSERT_IF(str.empty(), false);
+
+ EXCEPTION_GUARD_END
+}
+
+BOOST_AUTO_TEST_CASE(get_vendor_logo)
+{
+ EXCEPTION_GUARD_START
+
+ Handle<csre_wp_engine_h> h;
+
+ std::vector<unsigned char> logo;
+ ASSERT_IF(h.loader.getEngineVendorLogo(h.context, logo), CSRE_ERROR_NONE);
+
+ EXCEPTION_GUARD_END
+}
+
+BOOST_AUTO_TEST_CASE(get_version)
+{
+ EXCEPTION_GUARD_START
+
+ Handle<csre_wp_engine_h> h;
+
+ std::string str;
+ ASSERT_IF(h.loader.getEngineVersion(h.context, str), CSRE_ERROR_NONE);
+ ASSERT_IF(str.empty(), false);
+
+ EXCEPTION_GUARD_END
+}
+
+BOOST_AUTO_TEST_CASE(get_data_version)
+{
+ EXCEPTION_GUARD_START
+
+ Handle<csre_wp_engine_h> h;
+
+ std::string str;
+ ASSERT_IF(h.loader.getEngineDataVersion(h.context, str), CSRE_ERROR_NONE);
+ ASSERT_IF(str.empty(), false);
+
+ EXCEPTION_GUARD_END
+}
+
+BOOST_AUTO_TEST_CASE(get_latest_update_time)
+{
+ EXCEPTION_GUARD_START
+
+ Handle<csre_wp_engine_h> h;
+
+ time_t time = 0;
+ ASSERT_IF(h.loader.getEngineLatestUpdateTime(h.context, &time),
+ CSRE_ERROR_NONE);
+
+ struct tm t;
+ BOOST_MESSAGE(asctime(gmtime_r(&time, &t)));
+
+ EXCEPTION_GUARD_END
+}
+
+BOOST_AUTO_TEST_CASE(get_engine_activated)
+{
+ EXCEPTION_GUARD_START
+
+ Handle<csre_wp_engine_h> h;
+
+ csre_wp_activated_e activated;
+ ASSERT_IF(h.loader.getEngineActivated(h.context, &activated), CSRE_ERROR_NONE);
+
+ EXCEPTION_GUARD_END
+}
+
+BOOST_AUTO_TEST_CASE(get_api_version)
+{
+ EXCEPTION_GUARD_START
+
+ Handle<csre_wp_engine_h> h;
+
+ std::string str;
+ ASSERT_IF(h.loader.getEngineApiVersion(h.context, str), CSRE_ERROR_NONE);
+ ASSERT_IF(str == CSRE_CS_API_VERSION, true);
+
+ EXCEPTION_GUARD_END
+}
+
+BOOST_AUTO_TEST_SUITE_END()
+