strawberry/include/strawberry/ioc_set.hpp
trvon fadc6363f9
Add policy, threat-intel feeds and OpenSnitch containment
PolicyStore (allowlist, protection settings, operator actions), the
rule/feed updater with HTTPS-only fetches and a systemd timer, IOC
hash/domain/network sets, OpenSnitch blocklist containment, the root
control socket (SCM_RIGHTS credentials, verb allowlist) and scanner
health snapshots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 18:17:05 -06:00

66 lines
2.1 KiB
C++

#ifndef STRAWBERRY_IOC_SET_HPP
#define STRAWBERRY_IOC_SET_HPP
// Threat-intel SHA-256 set loaded from installed hash feeds
// (<feeds_dir>/<id>/current/list.txt). Stored as a sorted array of raw
// 32-byte digests (~33 bytes per entry) for compact, fast lookups.
#include <array>
#include <cstddef>
#include <cstdint>
#include <optional>
#include <string>
#include <utility>
#include <vector>
namespace strawberry {
class IocHashSet {
public:
/// Replace contents from (feed id, list file) pairs. Invalid lines are skipped.
void load(const std::vector<std::pair<std::string, std::string>>& sources);
/// Feed id that lists this lowercase/uppercase hex digest, if any.
std::optional<std::string> find(const std::string& sha256_hex) const;
std::size_t size() const { return entries_.size(); }
private:
struct Entry {
std::array<uint8_t, 32> digest;
uint16_t feed;
bool operator<(const Entry& other) const { return digest < other.digest; }
};
std::vector<Entry> entries_;
std::vector<std::string> feeds_;
};
/// Broadest network prefixes accepted from "nets" feeds (by the updater and
/// when loading): anything wider is treated as a bad entry, never a block.
inline constexpr int kMinNetPrefixV4 = 8;
inline constexpr int kMinNetPrefixV6 = 16;
/// Threat-intel IPs and CIDR networks (from "ips" and "nets" feeds).
class IocNetSet {
public:
void load(const std::vector<std::pair<std::string, std::string>>& ip_lists,
const std::vector<std::pair<std::string, std::string>>& net_lists);
/// Feed id listing this IP (exact or inside a network), if any.
std::optional<std::string> find(const std::string& ip) const;
std::size_t size() const { return ips_.size() + nets_.size(); }
private:
struct Net {
std::array<uint8_t, 16> address;
int prefix;
bool v6;
uint16_t feed;
};
std::vector<std::pair<std::string, uint16_t>> ips_; // sorted
std::vector<Net> nets_;
std::vector<std::string> feeds_;
};
} // namespace strawberry
#endif // STRAWBERRY_IOC_SET_HPP