36d484eb8207a8b8feb23510ab9743249e9997c5
[platform/core/security/suspicious-activity-monitor.git] / device-agent / samonitor / report_stub.cpp
1 /**
2  * Samsung Ukraine R&D Center (SRK under a contract between)
3  * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
4  * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
5  */
6 /**
7  * @file   report_stub.cpp
8  * @brief  Report creation stub. Used as temporary solutution for test perposes.
9  *         Migrate to normal report service when possible.
10  * @date   Created Jul 14, 2017
11  * @author Mail to: <A HREF="mailto:d.lomtev@samsung.com">Dmytro Lomtev, d.lomtev@samsung.com</A>
12  */
13
14 #include <cstdlib>
15 #include <sstream>
16 #include <ctime>
17 #include "report_stub.h"
18
19 namespace
20 {
21
22 /**
23  * @brief The TestReport struct used for mocking DPM reports
24  */
25 struct TestReport {
26     std::string name;
27     std::string data;
28     int result;
29 };
30
31 const TestReport test_reports[] = {
32     {
33         "sim",
34         R"({"Content":{"deviceInfo":{"model":"UKS9000","tizenVersion":"2.3","tizenName":"Tizen","platform":"Tizen","manufacturer":"Samsung","cpuArch":"armv7","cpuFreq":"1.5GHz","buildStr":"tztv-2.4-main2016-jazz-m_20160930.1","buildDate":"2016-09-30","buildTime":"04:52:44","duid":"BUYD7RXBSUXKICGD"},"timestamp":"2017-02-22 UTC 11:15:20","appid":"0","nonce":"LocalAttestationNonce","AttReport":{"status":"1","report":{"SIMReport":{"version":"2.0","status":"1","protector":{"EVT":{"symbol":{},"status":"0"},"File":{"symbol":{"/usr/lib/systemd/system":{"attackCount":"1"}},"status":"1"},"PageTable":{"symbol":{},"status":"0"},"StaticMemory":{"symbol":{},"status":"0"},"LSM":{"symbol":{},"status":"0"},"LKM":{"symbol":{},"status":"0"},"VFS":{"symbol":{},"status":"0"},"Netfilter":{"symbol":{},"status":"0"}}}}}},"Integrity":{"Sign":"0"}})",
35         0
36     },
37     {
38         "smart-security",
39         "{\"status\":\"secured\",\"health\": 100}",
40         11
41     }
42 };
43
44 } // namespace
45
46 namespace NMD
47 {
48
49 static std::string currentDateTime();
50
51 std::string makeReport(const std::string& id, const std::string& name, int result, const std::string& data)
52 {
53     std::ostringstream oss;
54     std::string current_time = currentDateTime();
55     oss << "{\"did\": \"" << id << "\",";
56     oss << "\"date\": \"" << current_time << "\",";
57     oss << "\"name\": \"" << name << "\",";
58     oss << "\"result\": " << result << ",";
59     oss << "\"data\": {\"log\": \"" << data << "\"}}";
60     return oss.str();
61 }
62
63 std::string currentDateTime()
64 {
65     time_t rawtime;
66     struct tm* timeinfo;
67     char buffer[128];
68     time(&rawtime);
69     timeinfo = localtime(&rawtime);
70     strftime(buffer, sizeof(buffer), "%d-%m-%Y %I:%M:%S", timeinfo);
71     return std::string(buffer);
72 }
73
74 } // namespace NMD