![]() |
Mads
Multi-Agent Distributed System
|
In-process ZAP (ZeroMQ Authentication Protocol, RFC 27) handler. More...
#include <zap_auth.hpp>
Public Member Functions | |
| ZapAuth (zmq::context_t &context) | |
| Construct a handler for the given context. Does not bind yet. | |
| ~ZapAuth () | |
| ZapAuth (const ZapAuth &)=delete | |
| ZapAuth & | operator= (const ZapAuth &)=delete |
| ZapAuth (ZapAuth &&)=delete | |
| ZapAuth & | operator= (ZapAuth &&)=delete |
| void | start () |
| Bind the ZAP endpoint and start servicing requests. | |
| void | stop () |
| Stop servicing requests and join the worker thread. | |
| void | set_verbose (bool verbose) |
| Log every authentication decision to stdout. | |
| void | configure_domain (const std::string &domain) |
| Restrict the handler to one ZAP domain. | |
| void | allow (const std::string &address) |
| Add an address to the whitelist. | |
| void | configure_curve (const std::string &z85_public_key) |
| Add a client public key to the CURVE allowlist. | |
| int | granted () const |
| Number of requests granted so far (test/diagnostic aid). | |
| int | denied () const |
| Number of requests denied so far (test/diagnostic aid). | |
Static Public Attributes | |
| static constexpr const char * | endpoint = "inproc://zeromq.zap.01" |
| The well-known ZAP endpoint mandated by RFC 27. | |
In-process ZAP (ZeroMQ Authentication Protocol, RFC 27) handler.
libzmq delegates every incoming connection on a socket that has a security mechanism enabled to a REP socket bound to inproc://zeromq.zap.01 inside the same context. This class owns that socket and the thread servicing it.
This replaces zmqpp::auth, which cppzmq has no equivalent for. It is deliberately limited to what MADS actually needs: an address whitelist and a CURVE client-key allowlist.
Ordering matters for security: libzmq only enforces authentication while a handler is bound, so start() completes the bind() before it returns and before any protected socket is bound or connected. Configuration calls are safe after start(); they are mutex-protected against the worker thread.
Only one handler may exist per zmq::context_t (the ZAP endpoint is a single well-known inproc address).
Definition at line 54 of file zap_auth.hpp.
|
inlineexplicit |
Construct a handler for the given context. Does not bind yet.
| context | The context whose sockets this handler will authenticate. |
Definition at line 61 of file zap_auth.hpp.
|
inline |
Definition at line 63 of file zap_auth.hpp.
References stop().
|
delete |
|
delete |
| void Mads::ZapAuth::allow | ( | const std::string & | address | ) |
Add an address to the whitelist.
While the whitelist is empty every peer address is acceptable. As soon as one address is added, any peer not on the list is rejected.
| address | The peer IP address to allow, e.g. "127.0.0.1". |
Referenced by Mads::CurveAuth::setup_auth().
| void Mads::ZapAuth::configure_curve | ( | const std::string & | z85_public_key | ) |
Add a client public key to the CURVE allowlist.
While the allowlist is empty every CURVE client is acceptable. As soon as one key is added, only those clients are accepted. The special value "*" accepts any CURVE client regardless of the rest of the list.
| z85_public_key | The client public key, Z85-encoded (40 characters). |
Referenced by Mads::CurveAuth::setup_curve_server().
| void Mads::ZapAuth::configure_domain | ( | const std::string & | domain | ) |
Restrict the handler to one ZAP domain.
| domain | The domain to serve; "*" (the default) serves every domain, matching how MADS configures it. |
Referenced by Mads::CurveAuth::setup_auth().
|
inline |
Number of requests denied so far (test/diagnostic aid).
Definition at line 127 of file zap_auth.hpp.
|
inline |
Number of requests granted so far (test/diagnostic aid).
Definition at line 124 of file zap_auth.hpp.
|
inline |
Log every authentication decision to stdout.
Definition at line 92 of file zap_auth.hpp.
Referenced by Mads::CurveAuth::setup_auth().
| void Mads::ZapAuth::start | ( | ) |
Bind the ZAP endpoint and start servicing requests.
Blocks until the endpoint is bound, so that no unauthenticated connection can slip through before the handler is listening. Calling it more than once is a no-op.
| zmq::error_t | if the ZAP endpoint cannot be bound (typically because another handler already owns it in this context). |
Referenced by Mads::CurveAuth::setup_auth().
| void Mads::ZapAuth::stop | ( | ) |
Stop servicing requests and join the worker thread.
Idempotent; also called by the destructor. Unlike zmqpp's actor-based authenticator, teardown is deterministic and leaves no process-lifetime state behind.
Referenced by ~ZapAuth().
|
staticconstexpr |
The well-known ZAP endpoint mandated by RFC 27.
Definition at line 130 of file zap_auth.hpp.