18#ifndef WIN32_LEAN_AND_MEAN
19#define WIN32_LEAN_AND_MEAN
61 explicit ZapAuth(zmq::context_t &context) : _context(context) {}
110 void allow(
const std::string &address);
124 int granted()
const {
return _granted.load(); }
127 int denied()
const {
return _denied.load(); }
130 static constexpr const char *
endpoint =
"inproc://zeromq.zap.01";
147 bool _authorise(
const std::string &domain,
const std::string &address,
148 const std::string &mechanism,
149 const std::string &credentials, std::string &reason)
const;
151 zmq::context_t &_context;
152 std::unique_ptr<zmq::socket_t> _socket;
154 std::atomic<bool> _stop{
false};
155 std::atomic<bool> _running{
false};
156 std::atomic<bool> _verbose{
false};
157 std::atomic<int> _granted{0};
158 std::atomic<int> _denied{0};
159 mutable std::mutex _config_mutex;
160 std::string _domain =
"*";
161 std::set<std::string> _allowed_addresses;
162 std::set<std::string> _allowed_curve_keys;
In-process ZAP (ZeroMQ Authentication Protocol, RFC 27) handler.
ZapAuth(ZapAuth &&)=delete
int denied() const
Number of requests denied so far (test/diagnostic aid).
void configure_curve(const std::string &z85_public_key)
Add a client public key to the CURVE allowlist.
ZapAuth & operator=(ZapAuth &&)=delete
void start()
Bind the ZAP endpoint and start servicing requests.
ZapAuth(zmq::context_t &context)
Construct a handler for the given context. Does not bind yet.
ZapAuth & operator=(const ZapAuth &)=delete
void stop()
Stop servicing requests and join the worker thread.
ZapAuth(const ZapAuth &)=delete
void set_verbose(bool verbose)
Log every authentication decision to stdout.
void allow(const std::string &address)
Add an address to the whitelist.
void configure_domain(const std::string &domain)
Restrict the handler to one ZAP domain.
static constexpr const char * endpoint
The well-known ZAP endpoint mandated by RFC 27.
int granted() const
Number of requests granted so far (test/diagnostic aid).
CurveKeypair generate_keypair()
Generate a fresh CURVE keypair.
std::string z85_encode(const std::string &data)
Z85-encode a binary buffer.
A CURVE keypair, both keys Z85-encoded (40 characters each).