Implement ZMTP/3.0 PLAIN mechanism

This implements protocol handshake.
We still need to design and implement 1) API changes so a user
can set username and password, and 2) a mechanism for engine
to authenticate users.
This commit is contained in:
Martin Hurton
2013-05-14 10:41:37 +02:00
parent d47295db70
commit 4eecda8af3
9 changed files with 460 additions and 8 deletions

View File

@@ -41,6 +41,7 @@
#include "v2_encoder.hpp"
#include "v2_decoder.hpp"
#include "null_mechanism.hpp"
#include "plain_mechanism.hpp"
#include "raw_decoder.hpp"
#include "raw_encoder.hpp"
#include "config.hpp"
@@ -49,8 +50,10 @@
#include "likely.hpp"
#include "wire.hpp"
zmq::stream_engine_t::stream_engine_t (fd_t fd_, const options_t &options_, const std::string &endpoint_) :
zmq::stream_engine_t::stream_engine_t (fd_t fd_, const options_t &options_,
bool as_server_, const std::string &endpoint_) :
s (fd_),
as_server (as_server_),
inpos (NULL),
insize (0),
decoder (NULL),
@@ -523,13 +526,19 @@ bool zmq::stream_engine_t::handshake ()
if (memcmp (greeting_recv + 12, "NULL\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 20) == 0) {
mechanism = new (std::nothrow) null_mechanism_t (options);
alloc_assert (mechanism);
read_msg = &stream_engine_t::next_handshake_message;
write_msg = &stream_engine_t::process_handshake_message;
}
else
if (memcmp (greeting_recv + 12, "PLAIN\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 20) == 0) {
mechanism = new (std::nothrow) plain_mechanism_t (options, as_server);
alloc_assert (mechanism);
}
else {
error ();
return false;
}
read_msg = &stream_engine_t::next_handshake_message;
write_msg = &stream_engine_t::process_handshake_message;
}
// Start polling for output if necessary.