Jan_31_2024-Dev

This commit is contained in:
Ned Wright
2024-01-31 17:34:53 +00:00
parent 752a5785f0
commit 6d67818a94
376 changed files with 8101 additions and 7064 deletions

0
core/include/services_sdk/interfaces/i_agent_details.h Executable file → Normal file
View File

0
core/include/services_sdk/interfaces/i_cpu.h Executable file → Normal file
View File

View File

@@ -80,6 +80,7 @@ public:
virtual std::string getCurrentTrace() const = 0;
virtual std::string getCurrentSpan() const = 0;
virtual std::string getCurrentHeaders() = 0;
virtual std::map<std::string, std::string> getCurrentHeadersMap() = 0;
virtual void startNewTrace(bool new_span = true, const std::string &_trace_id = std::string()) = 0;
virtual void startNewSpan(
Span::ContextType _type,

0
core/include/services_sdk/interfaces/i_failopen.h Executable file → Normal file
View File

View File

View File

@@ -131,20 +131,18 @@ private:
IntelligenceQuery<Data> &intelligence_query,
const std::string &query_uri,
I_Messaging *i_message,
Flags<MessageConnConfig> conn_flags,
Flags<MessageConnectionConfig> conn_flags,
const std::string &ip,
uint server_port
) {
if (ip == "" && server_port == 0) {
return i_message->sendObject(
intelligence_query,
I_Messaging::Method::POST,
auto req_status = i_message->sendSyncMessage(
HTTPMethod::POST,
query_uri,
"",
nullptr,
true,
MessageTypeTag::INTELLIGENCE
intelligence_query,
MessageCategory::INTELLIGENCE
);
return req_status.ok();
}
dbgTrace(D_INTELLIGENCE)
@@ -154,18 +152,15 @@ private:
<< server_port
<< " query_uri: "
<< query_uri;
return i_message->sendObject(
intelligence_query,
I_Messaging::Method::POST,
ip,
server_port,
conn_flags,
MessageMetadata req_md(ip, server_port, conn_flags);
auto req_status = i_message->sendSyncMessage(
HTTPMethod::POST,
query_uri,
"",
nullptr,
MessageTypeTag::INTELLIGENCE
intelligence_query,
MessageCategory::INTELLIGENCE,
req_md
);
return req_status.ok();
}
template<typename Data>
@@ -174,7 +169,7 @@ private:
IntelligenceQuery<Data> &intelligence_query,
const std::string &query_uri,
I_Messaging *i_message,
Flags<MessageConnConfig> conn_flags,
Flags<MessageConnectionConfig> conn_flags,
const std::string &ip = "",
uint server_port = 0
) {
@@ -233,7 +228,7 @@ private:
const std::string &query_uri,
int assets_limit,
I_Messaging *i_message,
Flags<MessageConnConfig> conn_flags,
Flags<MessageConnectionConfig> conn_flags,
const std::string &ip = "",
uint server_port = 0
) {
@@ -265,7 +260,7 @@ private:
bool is_primary_port,
int assets_limit,
I_Messaging *i_message,
Flags<MessageConnConfig> conn_flags
Flags<MessageConnectionConfig> conn_flags
) {
static const std::string primary_port_setting = "local intelligence server primary port";
static const std::string secondary_port_setting = "local intelligence server secondary port";
@@ -299,7 +294,7 @@ private:
sendQueryObject(IntelligenceQuery<Data> &intelligence_query, const std::string &query_uri, int assets_limit)
{
auto i_message = getMessaging();
Flags<MessageConnConfig> conn_flags;
Flags<MessageConnectionConfig> conn_flags;
bool crowdsec_enabled = std::getenv("CROWDSEC_ENABLED") ?
std::string(std::getenv("CROWDSEC_ENABLED")) == "true" :

0
core/include/services_sdk/interfaces/i_ioctl.h Executable file → Normal file
View File

220
core/include/services_sdk/interfaces/i_messaging.h Executable file → Normal file
View File

@@ -10,172 +10,98 @@
// 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.
#ifndef __I_FOG_MESSAGING_H__
#define __I_FOG_MESSAGING_H__
#ifndef __I_MESSAGING_H__
#define __I_MESSAGING_H__
#include <string>
#include <map>
#include <sstream>
#include <fstream>
#include <functional>
#include <ostream>
#include "cereal/archives/json.hpp"
#include "cereal/types/common.hpp"
#include "cereal/types/string.hpp"
#include "cereal/types/vector.hpp"
#include "maybe_res.h"
#include "debug.h"
#include "messaging/http_core.h"
#include "i_agent_details.h"
#include "i_proxy_configuration.h"
#include "flags.h"
#include "maybe_res.h"
#include "messaging/http_response.h"
#include "messaging/messaging_metadata.h"
USE_DEBUG_FLAG(D_COMMUNICATION);
enum class MessageTypeTag
{
GENERIC,
LOG,
DEBUG,
METRIC,
REPORT,
WAAP_LEARNING,
INTELLIGENCE,
BUFFERED_MESSAGES,
COUNT
};
enum class MessageConnConfig
{
SECURE_CONN,
ONE_TIME_CONN,
EXPECT_REPLY,
EXTERNAL,
IGNORE_SSL_VALIDATION,
COUNT
};
USE_DEBUG_FLAG(D_MESSAGING);
class I_Messaging
:
Singleton::Consume<I_AgentDetails>,
Singleton::Consume<I_ProxyConfiguration>
{
public:
using string = std::string;
using ErrorCB = std::function<void(HTTPStatusCode)>;
template <typename serializableObject>
Maybe<void, HTTPResponse> sendSyncMessage(
HTTPMethod method,
const std::string &uri,
serializableObject &req_obj,
MessageCategory category = MessageCategory::GENERIC,
MessageMetadata message_metadata = MessageMetadata());
enum class Method { GET, POST, PATCH, CONNECT, PUT };
template <typename serializableObject>
bool sendSyncMessageWithoutResponse(
const HTTPMethod method,
const std::string &uri,
serializableObject &req_obj,
const MessageCategory category = MessageCategory::GENERIC,
MessageMetadata message_metadata = MessageMetadata());
template <typename T, typename ...Args>
bool
sendObject(T &obj, Args ...args)
{
auto req = obj.genJson();
if (!req.ok()) {
dbgWarning(D_COMMUNICATION) << "Failed to create a request. Error: " << req.getErr();
return false;
}
template <typename serializableObject>
void sendAsyncMessage(
const HTTPMethod method,
const std::string &uri,
serializableObject &req_obj,
const MessageCategory category = MessageCategory::GENERIC,
MessageMetadata message_metadata = MessageMetadata());
dbgTrace(D_COMMUNICATION) << "Request generated from json. Request: " << req.unpack();
auto res = sendMessage(true, *req, args...);
if (!res.ok()) {
dbgWarning(D_COMMUNICATION) << "Failed to send request. Error: " << res.getErr();
return false;
}
dbgTrace(D_COMMUNICATION) << "Successfully got response: " << res.unpack();
virtual void sendAsyncMessage(
const HTTPMethod method,
const std::string &uri,
const std::string &body,
const MessageCategory category,
MessageMetadata message_metadata
) = 0;
virtual Maybe<HTTPResponse, HTTPResponse> sendSyncMessage(
const HTTPMethod method,
const std::string &uri,
const std::string &body,
const MessageCategory category = MessageCategory::GENERIC,
MessageMetadata message_metadata = MessageMetadata()
) = 0;
auto res_json = obj.loadJson(res.unpack());
if (!res_json) {
dbgWarning(D_COMMUNICATION) << "Failed to parse response body. Content: " << res.unpack();
} else {
dbgTrace(D_COMMUNICATION) << "Successfully parsed response body";
}
return res_json;
}
virtual Maybe<HTTPStatusCode, HTTPResponse> downloadFile(
const HTTPMethod method,
const std::string &uri,
const std::string &download_file_path,
const MessageCategory category = MessageCategory::GENERIC,
MessageMetadata message_metadata = MessageMetadata()
) = 0;
template <typename T, typename ...Args>
bool
sendNoReplyObject(T &obj, Args ...args)
{
auto req = obj.genJson();
if (!req.ok()) {
dbgWarning(D_COMMUNICATION) << "Failed to create a request. Error: " << req.getErr();;
return false;
}
virtual Maybe<HTTPStatusCode, HTTPResponse> uploadFile(
const std::string & uri,
const std::string & upload_file_path,
const MessageCategory category = MessageCategory::GENERIC,
MessageMetadata message_metadata = MessageMetadata()
) = 0;
auto res = sendMessage(false, *req, args...);
if (!res.ok()) {
dbgWarning(D_COMMUNICATION) << "Failed to send request. Error: " << res.getErr();
}
return res.ok();
}
template <typename T, typename ...Args>
void
sendObjectWithPersistence(T &obj, Args ...args)
{
auto req = obj.genJson();
if (!req.ok()) {
dbgWarning(D_COMMUNICATION) << "Failed to create a request. Error: " << req.getErr();;
return;
}
sendPersistentMessage(false, req.unpackMove(), args...);
}
template <typename T, typename ...Args>
Maybe<string>
downloadFile(T &obj, Args ...args)
{
auto req = obj.genJson();
if (!req.ok()) return genError("Invalid request");
auto response = sendMessage(true, *req, args...);
if (response.ok()) {
return response.unpack();
}
return genError("Failed to download file. Error: " + response.getErr());
}
virtual bool setActiveFog(MessageTypeTag tag) = 0;
virtual bool setActiveFog(const string &host, const uint16_t port, bool is_secure, MessageTypeTag tag) = 0;
protected:
~I_Messaging() {}
private:
virtual Maybe<string>
sendPersistentMessage(
bool get_reply,
const string &&body,
Method method,
const string &uri,
const string &headers = "",
bool should_yield = true,
MessageTypeTag tag = MessageTypeTag::GENERIC,
bool skip_sending = false) = 0;
virtual Maybe<string>
sendMessage(
bool get_reply,
const string &body,
Method method,
const string &uri,
const string &headers = "",
ErrorCB err_call_back = nullptr,
bool should_yield = true,
MessageTypeTag tag = MessageTypeTag::GENERIC) = 0;
virtual Maybe<string>
sendMessage(
bool get_reply,
const string &body,
Method method,
virtual bool setFogConnection(
const std::string &host,
uint16_t port,
Flags<MessageConnConfig> &conn_flags,
const string &uri,
const string &headers = "",
ErrorCB err_call_back = nullptr,
MessageTypeTag tag = MessageTypeTag::GENERIC) = 0;
bool is_secure,
MessageCategory category
) = 0;
virtual bool setFogConnection(MessageCategory category = MessageCategory::GENERIC) = 0;
protected:
virtual ~I_Messaging() {}
};
#endif // __I_FOG_MESSAGING_H__
#include "messaging/interface_impl.h"
#endif // __I_MESSAGING_H__

View File

@@ -1,33 +0,0 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (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.
#ifndef __I_MESSAGING_BUFFER_H__
#define __I_MESSAGING_BUFFER_H__
#include "messaging_buffer/http_request_event.h"
#include "maybe_res.h"
class I_MessagingBuffer
{
public:
virtual Maybe<HTTPRequestEvent> peekRequest() = 0;
virtual void popRequest() = 0;
virtual void bufferNewRequest(const HTTPRequestEvent &request, bool is_rejected = false) = 0;
virtual bool isPending(const HTTPRequestSignature &request) = 0;
virtual void cleanBuffer() = 0;
protected:
~I_MessagingBuffer() {}
};
#endif // __I_MESSAGING_BUFFER_H__

View File

@@ -27,12 +27,12 @@ enum class ProxyProtocol
class I_ProxyConfiguration
{
public:
virtual Maybe<std::string> getProxyDomain(ProxyProtocol protocol) const = 0;
virtual Maybe<std::string> getProxyCredentials(ProxyProtocol protocol) const = 0;
virtual Maybe<uint16_t> getProxyPort(ProxyProtocol protocol) const = 0;
virtual bool getProxyExists(ProxyProtocol protocol) const = 0;
virtual Maybe<std::string> getProxyAddress(ProxyProtocol protocol) const = 0;
virtual Maybe<void> loadProxy() = 0;
virtual Maybe<std::string> getProxyDomain(ProxyProtocol protocol) const = 0;
virtual Maybe<std::string> getProxyAuthentication(ProxyProtocol protocol) const = 0;
virtual Maybe<uint16_t> getProxyPort(ProxyProtocol protocol) const = 0;
virtual bool getProxyExists(ProxyProtocol protocol) const = 0;
virtual Maybe<std::string> getProxyAddress(ProxyProtocol protocol) const = 0;
virtual Maybe<void> loadProxy() = 0;
};
#endif // __I_PROXY_CONFIGURATION_H__

0
core/include/services_sdk/interfaces/i_shell_cmd.h Executable file → Normal file
View File

View File

0
core/include/services_sdk/interfaces/i_socket_is.h Executable file → Normal file
View File

0
core/include/services_sdk/interfaces/i_trap_handler.h Executable file → Normal file
View File

View File

@@ -45,7 +45,8 @@ enum class Condition
IN,
NOT_IN,
GREATER_THAN,
LESS_THAN
LESS_THAN,
RANGE
};
enum class CursorState {
@@ -60,7 +61,7 @@ enum class ResponseStatus
IN_PROGRESS
};
enum class ObjectType { ASSET, ZONE, CONFIGURATION, COUNT };
enum class ObjectType { ASSET, ZONE, CONFIGURATION, SHORTLIVED, COUNT};
const std::string & convertConditionTypeToString(const Condition &condition_type);
const std::string & convertOperationTypeToString(const Operator &operation_type);

View File

@@ -30,7 +30,7 @@ using namespace Intelligence_IS_V2;
class SerializableQueryCondition
{
public:
typedef boost::variant<int64_t, std::string> ValueVariant;
typedef boost::variant<int64_t, std::string, std::vector<std::string>> ValueVariant;
SerializableQueryCondition() {}
@@ -48,6 +48,13 @@ public:
value(_value)
{}
SerializableQueryCondition(Condition _condition_type, std::string _key, std::vector<std::string> _value)
:
condition_type(_condition_type),
key(_key),
value(_value)
{}
void save(cereal::JSONOutputArchive &ar) const;
Condition getConditionType() const { return condition_type; }
@@ -66,11 +73,13 @@ public:
SerializableQueryFilter() {}
SerializableQueryFilter(Condition condition_type, const std::string &key, const std::string &value);
SerializableQueryFilter(Condition condition_type, const std::string &key, const int64_t &value);
SerializableQueryFilter(Condition condition_type, const std::string &key, const std::vector<std::string> &value);
void save(cereal::JSONOutputArchive &ar) const;
void addCondition(Condition condition_type, const std::string &key, const std::string &value);
void addCondition(Condition condition_type, const std::string &key, const int64_t &value);
void addCondition(Condition condition_type, const std::string &key, const std::vector<std::string> &value);
Operator getOperator() const { return operator_type; }
const std::vector<SerializableQueryCondition> & getConditionOperands() const { return condition_operands; }

View File

@@ -45,6 +45,14 @@ public:
AttributeKeyType type = AttributeKeyType::MAIN
);
QueryRequest(
Condition condition_type,
const std::string &key,
const std::vector<std::string> &value,
bool full_response,
AttributeKeyType type = AttributeKeyType::MAIN
);
void saveToJson(cereal::JSONOutputArchive &ar) const;
void save(cereal::JSONOutputArchive &ar) const;
@@ -66,6 +74,13 @@ public:
AttributeKeyType attribute_type = AttributeKeyType::MAIN
);
void addCondition(
Condition condition_type,
const std::string &key,
const std::vector<std::string> &value,
AttributeKeyType attribute_type = AttributeKeyType::MAIN
);
void setRequestedAttr(
const std::string &attr,
AttributeKeyType attribute_type = AttributeKeyType::REGULAR

View File

@@ -0,0 +1,45 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (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.
#ifndef __HTTP_RESPONSE_H__
#define __HTTP_RESPONSE_H__
#include <string>
#include <map>
#include <cereal/archives/json.hpp>
#include "singleton.h"
#include "i_env_details.h"
#include "i_agent_details.h"
#include "i_encryptor.h"
#include "messaging/messaging_enums.h"
class HTTPResponse
{
public:
// LCOV_EXCL_START Reason: Not actually called but is required by the caching interface
HTTPResponse() = default;
// LCOV_EXCL_STOP
HTTPResponse(HTTPStatusCode _status_code, const std::string &_body) : status_code(_status_code), body(_body) {}
HTTPStatusCode getHTTPStatusCode() const;
const std::string & getBody() const;
std::string toString() const;
private:
HTTPStatusCode status_code;
std::string body;
};
#endif // __HTTP_RESPONSE_H__

View File

@@ -0,0 +1,148 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (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.
#ifndef __INTERFACE_IMPL_H__
#define __INTERFACE_IMPL_H__
#ifndef __I_MESSAGING_H__
#error "interface_impl.h should not be included directly"
#endif // __I_MESSAGING_H__
USE_DEBUG_FLAG(D_MESSAGING);
MessageMetadata::MessageMetadata()
{
if (!Singleton::exists<I_AgentDetails>() || !Singleton::exists<I_ProxyConfiguration>()) return;
auto i_agent_details = Singleton::Consume<I_AgentDetails>::by<I_Messaging>();
auto i_proxy_configuration = Singleton::Consume<I_ProxyConfiguration>::by<I_Messaging>();
is_to_fog = true;
host_name = i_agent_details->getFogDomain().ok() ? i_agent_details->getFogDomain().unpack() : "";
port_num = i_agent_details->getFogPort().ok() ? i_agent_details->getFogPort().unpack() : 0;
ProxyProtocol protocol = i_agent_details->getSSLFlag() ? ProxyProtocol::HTTPS : ProxyProtocol::HTTP;
auto maybe_proxy_domain = i_proxy_configuration->getProxyDomain(protocol);
std::string proxy_domain = maybe_proxy_domain.ok() ? *maybe_proxy_domain : "";
dbgTrace(D_MESSAGING) << "Created message metadata. Host name: " << host_name << ", Port num: " << port_num;
if (proxy_domain.empty()) return;
auto maybe_proxy_port = i_proxy_configuration->getProxyPort(protocol);
uint16_t proxy_port = maybe_proxy_port.ok() ? *maybe_proxy_port : 0;
auto maybe_proxy_auth = i_proxy_configuration->getProxyAuthentication(protocol);
std::string proxy_auth = maybe_proxy_auth.ok() ? *maybe_proxy_auth : "";
setProxySettings(MessageProxySettings(proxy_domain, proxy_auth, proxy_port));
dbgTrace(D_MESSAGING) << "Proxy : " << proxy_domain << ":" << proxy_port;
}
template <typename serializableObject>
Maybe<void, HTTPResponse>
I_Messaging::sendSyncMessage(
HTTPMethod method,
const std::string &uri,
serializableObject &req_obj,
MessageCategory category,
MessageMetadata message_metadata)
{
Maybe<std::string> req_body = req_obj.genJson();
if (!req_body.ok()) {
return genError(
HTTPResponse(
HTTPStatusCode::NO_HTTP_RESPONSE,
"Failed to create a request. Error: " + req_body.getErr()
)
);
}
Maybe<HTTPResponse, HTTPResponse> response_data = sendSyncMessage(
method,
uri,
req_body.unpack(),
category,
message_metadata
);
if (!response_data.ok()) return response_data.passErr();
auto res_obj = req_obj.loadJson(response_data.unpack().getBody());
if (!res_obj) {
return genError(
HTTPResponse(
HTTPStatusCode::NO_HTTP_RESPONSE,
"Failed to parse response body. Body: " + response_data.unpack().getBody()
)
);
}
return {};
}
template <typename serializableObject>
bool
I_Messaging::sendSyncMessageWithoutResponse(
const HTTPMethod method,
const std::string &uri,
serializableObject &req_obj,
const MessageCategory category,
MessageMetadata message_metadata)
{
Maybe<std::string> req_body = req_obj.genJson();
if (!req_body.ok()) {
dbgWarning(D_MESSAGING) << "Failed to create a request. Error: " << req_body.getErr();
return false;
}
Maybe<HTTPResponse, HTTPResponse> response_data = sendSyncMessage(
method,
uri,
req_body.unpack(),
category,
message_metadata
);
if (!response_data.ok()) {
dbgWarning(D_MESSAGING)
<< "Received error from server. Status code: "
<< int(response_data.getErr().getHTTPStatusCode())
<< ", error response: "
<< response_data.getErr().getBody();
return false;
}
return true;
}
template <typename serializableObject>
void
I_Messaging::sendAsyncMessage(
const HTTPMethod method,
const std::string &uri,
serializableObject &req_obj,
const MessageCategory category,
MessageMetadata message_metadata)
{
Maybe<std::string> req_body = req_obj.genJson();
if (!req_body.ok()) {
dbgWarning(D_MESSAGING) << "Failed to create a request. Error: " << req_body.getErr();
return;
}
sendAsyncMessage(
method,
uri,
req_body.unpack(),
category,
message_metadata
);
}
#endif // __INTERFACE_IMPL_H__

View File

@@ -11,20 +11,45 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __HTTP_CORE_H__
#define __HTTP_CORE_H__
#ifndef __MESSAGING_ENUMS_H__
#define __MESSAGING_ENUMS_H__
#include <string>
#include <unordered_map>
enum class MessageCategory
{
GENERIC,
LOG,
DEBUG,
METRIC,
INTELLIGENCE,
#include "maybe_res.h"
#include "cereal/archives/json.hpp"
#include "cereal/types/string.hpp"
COUNT
};
enum class MessageConnectionConfig
{
UNSECURE_CONN,
ONE_TIME_CONN,
IGNORE_SSL_VALIDATION,
COUNT
};
enum class HTTPMethod
{
GET,
POST,
PATCH,
CONNECT,
PUT,
COUNT
};
enum class HTTPStatusCode
{
// 10X - Information responses. Not supported yet.
// 20x - Successful responses.
NO_HTTP_RESPONSE = 0,
HTTP_OK = 200,
HTTP_NO_CONTENT = 204,
HTTP_MULTI_STATUS = 207,
@@ -51,53 +76,8 @@ enum class HTTPStatusCode
HTTP_NOT_EXTENDED = 510,
HTTP_NETWORK_AUTHENTICATION_REQUIRED = 511,
// Not supported status code.
HTTP_UNKNOWN
HTTP_UNKNOWN = -1,
HTTP_SUSPEND = -2
};
class HTTPResponse
{
public:
HTTPResponse(const HTTPStatusCode status_code, const std::string &&body);
Maybe<std::string> getResponse() const;
HTTPStatusCode getStatusCode() const { return status_code; }
std::string getBody() const { return body; }
class BadRequestResponse
{
public:
void serialize(cereal::JSONInputArchive &ar);
std::string getMsg() const { return message; }
std::string getID() const { return message_id; }
private:
std::string message;
std::string message_id;
};
private:
HTTPStatusCode status_code;
std::string body;
};
class HTTPHeaders
{
public:
HTTPHeaders() = default;
static Maybe<HTTPHeaders> createHTTPHeader(const std::string &http_data);
void insertHeader(const std::string &header_key, const std::string &header_val);
void insertHeader(const std::string &header);
void insertHeaders(const std::string &headers);
Maybe<std::string> getHeaderVal(const std::string &header_key);
std::string toString() const;
private:
HTTPHeaders(const std::string &http_data);
std::unordered_map<std::string, std::string> headers;
};
#endif // __HTTP_CORE_H__
#endif // __MESSAGING_ENUMS_H__

View File

@@ -0,0 +1,198 @@
#ifndef __MESSAGING_METADATA_H__
#define __MESSAGING_METADATA_H__
#include <map>
#include <string>
#include "flags.h"
#include "singleton.h"
#include "i_agent_details.h"
class MessageProxySettings
{
public:
MessageProxySettings() {}
MessageProxySettings(const std::string &_proxy_host, const std::string &_proxy_auth, uint16_t _proxy_port)
:
proxy_host(_proxy_host), proxy_authentication(_proxy_auth), proxy_port(_proxy_port)
{}
const std::string &
getProxyHost() const
{
return proxy_host;
}
const std::string &
getProxyAuth() const
{
return proxy_authentication;
}
uint16_t
getProxyPort() const
{
return proxy_port;
}
template <class Archive>
void
serialize(Archive &ar)
{
ar(
cereal::make_nvp("proxy_host", proxy_host),
cereal::make_nvp("proxy_authentication", proxy_authentication),
cereal::make_nvp("proxy_port", proxy_port)
);
}
private:
std::string proxy_host = "";
std::string proxy_authentication = "";
uint16_t proxy_port = 0;
};
class MessageMetadata
{
public:
inline MessageMetadata();
MessageMetadata(const std::string &_host_name, uint16_t _port_num, bool _buffer = false, bool _fog = false) :
host_name(_host_name), port_num(_port_num), should_buffer(_buffer), is_to_fog(_fog)
{}
MessageMetadata(
std::string _host_name,
uint16_t _port_num,
Flags<MessageConnectionConfig> _conn_flags,
bool _should_buffer = false,
bool _is_to_fog = false
) :
host_name(_host_name),
port_num(_port_num),
conn_flags(_conn_flags),
should_buffer(_should_buffer),
is_to_fog(_is_to_fog)
{}
const std::string &
getHostName() const
{
return host_name;
}
const uint16_t &
getPort() const
{
return port_num;
}
void
setConnectioFlag(MessageConnectionConfig flag)
{
conn_flags.setFlag(flag);
}
const Flags<MessageConnectionConfig> &
getConnectionFlags() const
{
return conn_flags;
}
const MessageProxySettings &
getProxySettings() const
{
return proxy_settings;
}
const std::string &
getExternalCertificate() const
{
return external_certificate;
}
const std::map<std::string, std::string> &
getHeaders() const
{
return headers;
}
void
insertHeader(const std::string &header_key, const std::string &header_val)
{
headers[header_key] = header_val;
}
void
insertHeaders(const std::map<std::string, std::string> &_headers)
{
headers.insert(_headers.begin(), _headers.end());
}
void
setProxySettings(const MessageProxySettings &_proxy_settings)
{
proxy_settings = _proxy_settings;
is_proxy_set = true;
}
void
setExternalCertificate(const std::string &_external_certificate)
{
external_certificate = _external_certificate;
}
void
setShouldBufferMessage(bool _should_buffer)
{
should_buffer = _should_buffer;
}
bool
shouldBufferMessage() const
{
return should_buffer;
}
bool
isProxySet() const
{
return is_proxy_set;
}
bool
isToFog() const
{
return is_to_fog;
}
template <class Archive>
void
serialize(Archive &ar)
{
ar(
cereal::make_nvp("host_name", host_name),
cereal::make_nvp("port_num", port_num),
cereal::make_nvp("is_proxy_set", is_proxy_set),
cereal::make_nvp("headers", headers),
cereal::make_nvp("conn_flags", conn_flags),
cereal::make_nvp("external_certificate", external_certificate),
cereal::make_nvp("should_buffer", should_buffer),
cereal::make_nvp("is_to_fog", is_to_fog)
);
}
private:
std::string host_name = "";
uint16_t port_num = 0;
bool is_proxy_set = false;
std::map<std::string, std::string> headers;
Flags<MessageConnectionConfig> conn_flags;
MessageProxySettings proxy_settings;
std::string external_certificate = "";
bool should_buffer = false;
bool is_to_fog = false;
};
#endif // __MESSAGING_METADATA_H__

View File

0
core/include/services_sdk/interfaces/mock/mock_cpu.h Executable file → Normal file
View File

View File

@@ -29,6 +29,7 @@ public:
MOCK_CONST_METHOD0(getCurrentTrace, std::string());
MOCK_CONST_METHOD0(getCurrentSpan, std::string());
MOCK_METHOD0(getCurrentHeaders, std::string());
MOCK_METHOD0(getCurrentHeadersMap, std::map<std::string, std::string>());
MOCK_METHOD2(startNewTrace, void(bool, const std::string &));
MOCK_METHOD3(startNewSpan, void(Span::ContextType, const std::string &, const std::string &));

View File

View File

@@ -2,67 +2,69 @@
#define __MOCK_MESSAGING_H__
#include "i_messaging.h"
#include "cptest.h"
class MockMessaging : public Singleton::Provide<I_Messaging>::From<MockProvider<I_Messaging>>
{
public:
using string = std::string;
MOCK_METHOD10(
sendMessage,
Maybe<string> (
bool,
const string &,
Method,
const string &,
uint16_t,
Flags<MessageConnConfig> &,
MOCK_METHOD5(
sendSyncMessage,
Maybe<HTTPResponse, HTTPResponse> (
HTTPMethod,
const string &,
const string &,
I_Messaging::ErrorCB,
MessageTypeTag
MessageCategory,
MessageMetadata
)
);
MOCK_METHOD5(
sendAsyncMessage,
void (
HTTPMethod,
const string &,
const string &,
MessageCategory,
MessageMetadata
)
);
MOCK_METHOD7(
mockSendPersistentMessage,
Maybe<string>(bool, const string &, Method, const string &, const string &, bool, MessageTypeTag)
);
Maybe<string>
sendPersistentMessage(
bool get_reply,
const string &&body,
Method method,
const string &url,
const string &headers,
bool should_yield,
MessageTypeTag tag,
bool)
{
return mockSendPersistentMessage(get_reply, body, method, url, headers, should_yield, tag);
}
MOCK_METHOD8(
sendMessage,
Maybe<string> (
bool,
const string &,
Method,
MOCK_METHOD5(
downloadFile,
Maybe<HTTPStatusCode, HTTPResponse> (
HTTPMethod,
const string &,
const string &,
I_Messaging::ErrorCB,
bool,
MessageTypeTag
MessageCategory,
MessageMetadata
)
);
MOCK_METHOD0(setActiveFog, bool());
MOCK_METHOD1(setActiveFog, bool(MessageTypeTag));
MOCK_METHOD0(unsetFogProxy, void());
MOCK_METHOD0(loadFogProxy, void());
MOCK_METHOD4(setActiveFog, bool(const string &, const uint16_t, const bool, MessageTypeTag));
MOCK_METHOD4(
uploadFile,
Maybe<HTTPStatusCode, HTTPResponse> (
const string &,
const string &,
MessageCategory,
MessageMetadata
)
);
MOCK_METHOD4(setFogConnection, bool(const string &, uint16_t, bool, MessageCategory));
MOCK_METHOD0(setFogConnection, bool());
MOCK_METHOD1(setFogConnection, bool(MessageCategory));
};
static std::ostream &
operator<<(std::ostream &os, const HTTPResponse &)
{
return os;
}
static std::ostream &
operator<<(std::ostream &os, const HTTPStatusCode &)
{
return os;
}
#endif // __MOCK_MESSAGING_H__

View File

@@ -0,0 +1,23 @@
#ifndef __MOCK_PROXY_CONFIGURATION_H__
#define __MOCK_PROXY_CONFIGURATION_H__
#include "i_proxy_configuration.h"
#include "cptest.h"
class MockProxyConfiguration
:
public Singleton::Provide<I_ProxyConfiguration>::From<MockProvider<I_ProxyConfiguration>>
{
public:
using string = std::string;
MOCK_CONST_METHOD1(getProxyDomain, Maybe<std::string>(ProxyProtocol protocol));
MOCK_CONST_METHOD1(getProxyAuthentication, Maybe<std::string>(ProxyProtocol protocol));
MOCK_CONST_METHOD1(getProxyPort, Maybe<uint16_t>(ProxyProtocol protocol));
MOCK_CONST_METHOD1(getProxyExists, bool(ProxyProtocol protocol));
MOCK_CONST_METHOD1(getProxyAddress, Maybe<std::string>(ProxyProtocol protocol));
MOCK_METHOD0(loadProxy, Maybe<void>());
};
#endif // __MOCK_PROXY_CONFIGURATION_H__

View File

View File

0
core/include/services_sdk/interfaces/mock/mock_table.h Executable file → Normal file
View File

View File

2
core/include/services_sdk/resources/agent_details.h Executable file → Normal file
View File

@@ -96,7 +96,7 @@ public:
void setClusterId(const std::string &_cluster_id);
Maybe<std::string> getProxyDomain(ProxyProtocol protocol) const;
Maybe<std::string> getProxyCredentials(ProxyProtocol protocol) const;
Maybe<std::string> getProxyAuthentication(ProxyProtocol protocol) const;
Maybe<uint16_t> getProxyPort(ProxyProtocol protocol) const;
bool getProxyExists(ProxyProtocol protocol) const;
Maybe<std::string> getProxyAddress(ProxyProtocol protocol) const;

0
core/include/services_sdk/resources/component.h Executable file → Normal file
View File

View File

@@ -31,7 +31,6 @@
#include "rest_server.h"
#include "logging_comp.h"
#include "log_generator.h"
#include "proto_message_comp.h"
#include "table.h"
#include "agent_details.h"
#include "encryptor.h"
@@ -42,12 +41,12 @@
#include "socket_is.h"
#include "generic_rulebase/generic_rulebase.h"
#include "generic_rulebase/generic_rulebase_context.h"
#include "messaging_buffer.h"
#include "shell_cmd.h"
#include "generic_metric.h"
#include "tenant_manager.h"
#include "buffer.h"
#include "intelligence_comp_v2.h"
#include "messaging.h"
USE_DEBUG_FLAG(D_COMP_IS);
@@ -209,6 +208,7 @@ class ComponentListCore
Buffer,
ShellCmd,
GenericMetric,
Messaging,
ConfigComponent,
InstanceAwareness,
IntelligenceComponentV2,
@@ -220,11 +220,9 @@ class ComponentListCore
RestServer,
Encryptor,
SocketIS,
ProtoMessageComp,
CPUCalculator,
CPUManager,
MemoryCalculator,
MessagingBuffer,
TenantManager,
GenericRulebase,
Components...

0
core/include/services_sdk/resources/components_list.h Executable file → Normal file
View File

View File

0
core/include/services_sdk/resources/cpu.h Executable file → Normal file
View File

0
core/include/services_sdk/resources/cpu/cpu_metric.h Executable file → Normal file
View File

View File

14
core/include/services_sdk/resources/debug_flags.h Executable file → Normal file
View File

@@ -44,8 +44,10 @@ DEFINE_FLAG(D_INFRA, D_ALL)
DEFINE_FLAG(D_SOCKET, D_COMMUNICATION)
DEFINE_FLAG(D_SYNC, D_COMMUNICATION)
DEFINE_FLAG(D_UPGRADE, D_SYNC)
DEFINE_FLAG(D_EVENT_BUFFER, D_COMMUNICATION)
DEFINE_FLAG(D_HTTP_REQUEST, D_COMMUNICATION)
DEFINE_FLAG(D_MESSAGING, D_COMMUNICATION)
DEFINE_FLAG(D_CONNECTION, D_MESSAGING)
DEFINE_FLAG(D_MESSAGING_BUFFER, D_MESSAGING)
DEFINE_FLAG(D_HTTP_REQUEST, D_MESSAGING)
DEFINE_FLAG(D_COMPONENT, D_ALL)
DEFINE_FLAG(D_PRELOAD, D_COMPONENT)
@@ -99,6 +101,7 @@ DEFINE_FLAG(D_COMPONENT, D_ALL)
DEFINE_FLAG(D_IPS, D_COMPONENT)
DEFINE_FLAG(D_FILE_UPLOAD, D_COMPONENT)
DEFINE_FLAG(D_RATE_LIMIT, D_COMPONENT)
DEFINE_FLAG(D_ROLLBACK_TESTING, D_COMPONENT)
DEFINE_FLAG(D_PARSER, D_COMPONENT)
DEFINE_FLAG(D_WS, D_COMPONENT)
@@ -131,7 +134,6 @@ DEFINE_FLAG(D_COMPONENT, D_ALL)
DEFINE_FLAG(D_NGINX_POLICY, D_ORCHESTRATOR)
DEFINE_FLAG(D_GRADUAL_DEPLOYMENT, D_COMPONENT)
DEFINE_FLAG(D_C8_CONTROLLER, D_COMPONENT)
DEFINE_FLAG(D_SDWAN, D_COMPONENT)
DEFINE_FLAG(D_SDWAN_POLICY, D_SDWAN)
DEFINE_FLAG(D_SDWAN_DATA, D_SDWAN)
@@ -144,7 +146,7 @@ DEFINE_FLAG(D_COMPONENT, D_ALL)
DEFINE_FLAG(D_UPSTREAM_KEEPALIVE, D_REVERSE_PROXY)
DEFINE_FLAG(D_FORWARD_PROXY, D_REVERSE_PROXY)
DEFINE_FLAG(D_IDA, D_COMPONENT)
DEFINE_FLAG(D_IDA_SAML, D_COMPONENT)
DEFINE_FLAG(D_IOT_NEXT, D_COMPONENT)
DEFINE_FLAG(D_IOT_AUXILIARY, D_IOT_NEXT)
@@ -171,7 +173,9 @@ DEFINE_FLAG(D_COMPONENT, D_ALL)
DEFINE_FLAG(D_GEO_DB, D_COMPONENT)
DEFINE_FLAG(D_CPVIEW_METRIC_PROVIDER, D_COMPONENT)
DEFINE_FLAG(D_GEO_FILTER, D_COMPONENT)
DEFINE_FLAG(D_URL_FILTERING, D_COMPONENT)
DEFINE_FLAG(D_EGRESS_PROTECTION, D_COMPONENT)
DEFINE_FLAG(D_URL_FILTERING, D_EGRESS_PROTECTION)
DEFINE_FLAG(D_ANTIBOT, D_EGRESS_PROTECTION)
DEFINE_FLAG(D_L7_ACCESS_CONTROL, D_COMPONENT)
DEFINE_FLAG(D_IOT_ACCESS_CONTROL, D_COMPONENT)
DEFINE_FLAG(D_HORIZON_TELEMETRY, D_COMPONENT)

0
core/include/services_sdk/resources/environment/span.h Executable file → Normal file
View File

View File

View File

0
core/include/services_sdk/resources/generic_metric.h Executable file → Normal file
View File

View File

View File

0
core/include/services_sdk/resources/log_generator.h Executable file → Normal file
View File

View File

View File

0
core/include/services_sdk/resources/metric/average.h Executable file → Normal file
View File

0
core/include/services_sdk/resources/metric/counter.h Executable file → Normal file
View File

View File

0
core/include/services_sdk/resources/metric/max.h Executable file → Normal file
View File

View File

View File

@@ -27,16 +27,30 @@ namespace MetricCalculations
template <typename PrintableKey, typename Metric>
class MetricMap : public MetricCalc
{
class InnerMap : public std::map<std::string, Metric>
class InnerMap
{
public:
void
save(cereal::JSONOutputArchive &ar) const
{
for (auto &metric : *this) {
for (auto &metric : inner_map) {
metric.second.save(ar);
}
}
std::pair<typename std::map<std::string, Metric>::iterator, bool>
emplace(const std::string &key, Metric &&metric)
{
return inner_map.emplace(key, std::move(metric));
}
void clear() { inner_map.clear(); }
typename std::map<std::string, Metric>::const_iterator begin() const { return inner_map.begin(); }
typename std::map<std::string, Metric>::const_iterator end() const { return inner_map.end(); }
private:
std::map<std::string, Metric> inner_map;
};
public:

0
core/include/services_sdk/resources/metric/min.h Executable file → Normal file
View File

View File

0
core/include/services_sdk/resources/read_attribute.h Executable file → Normal file
View File

View File

View File

0
core/include/services_sdk/resources/report/log_rest.h Executable file → Normal file
View File

0
core/include/services_sdk/resources/report/report.h Executable file → Normal file
View File

View File

View File

@@ -155,8 +155,8 @@ enum class IssuingEngine {
IOT_NEXT,
SDWAN,
FILE_UPLOAD,
IDA_NEXT_BLADE_REGISTRATION,
IDA_NEXT_CLIENT_IP_NOTIFY,
IDA_SAML_IDN_BLADE_REGISTRATION,
IDA_SAML_IDN_CLIENT_IP_NOTIFY,
HORIZON_TELEMETRY_METRICS,
API_DISCOVERY
};

View File

0
core/include/services_sdk/utilities/connkey.h Executable file → Normal file
View File

View File

View File

View File

@@ -18,7 +18,7 @@
#include "cereal/types/bitset.hpp"
template <typename EnumClass, uint NumberOfValues = static_cast<uint>(EnumClass::COUNT) + 1>
template <typename EnumClass, uint32_t NumberOfValues = static_cast<uint32_t>(EnumClass::COUNT) + 1>
class Flags
{
static_assert(NumberOfValues > 0, "Number of possible Flags must be positive");
@@ -39,7 +39,7 @@ public:
void serialize(Archive &ar, uint32_t) { ar(flags); }
private:
uint getIndex(const EnumClass &flag) const { return static_cast<uint>(flag); }
uint32_t getIndex(const EnumClass &flag) const { return static_cast<uint32_t>(flag); }
std::bitset<NumberOfValues> flags;
};

View File

@@ -1,28 +0,0 @@
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
// Licensed under the Apache License, Version 2.0 (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.
#ifndef __FW_INCLUDE_SASAL_H__
#define __FW_INCLUDE_SASAL_H__
// Comment this out if no SASAL is allowed.
#define SASAL_ALLOWED
#if defined(SASAL_ALLOWED)
#define SASAL_START
#define SASAL_END
#else // SASAL_ALLOWED
#define SASAL_START ERROR: SASAL NOT ALLOWED
#define SASAL_END ERROR: SASAL NOT ALLOWED
#endif // SASAL_ALLOWED
#endif // __FW_INCLUDE_SASAL_H__

0
core/include/services_sdk/utilities/socket_is.h Executable file → Normal file
View File