Commit 182a224b authored by Martin Hurton's avatar Martin Hurton

Use socket options to select security mechanism

parent fbcbb06b
...@@ -121,11 +121,10 @@ bool zmq::plain_mechanism_t::is_handshake_complete () const ...@@ -121,11 +121,10 @@ bool zmq::plain_mechanism_t::is_handshake_complete () const
int zmq::plain_mechanism_t::hello_command (msg_t *msg_) const int zmq::plain_mechanism_t::hello_command (msg_t *msg_) const
{ {
// TODO: fetch these from options const std::string username = options.plain_username;
const std::string username = "username";
const std::string password = "password";
zmq_assert (username.length () < 256); zmq_assert (username.length () < 256);
const std::string password = options.plain_password;
zmq_assert (password.length () < 256); zmq_assert (password.length () < 256);
const size_t command_size = 8 + 1 + username.length () + const size_t command_size = 8 + 1 + username.length () +
...@@ -145,8 +144,6 @@ int zmq::plain_mechanism_t::hello_command (msg_t *msg_) const ...@@ -145,8 +144,6 @@ int zmq::plain_mechanism_t::hello_command (msg_t *msg_) const
memcpy (ptr, password.c_str (), password.length ()); memcpy (ptr, password.c_str (), password.length ());
ptr += password.length (); ptr += password.length ();
// TODO: check username and password
return 0; return 0;
} }
...@@ -202,6 +199,8 @@ int zmq::plain_mechanism_t::process_hello_command (msg_t *msg_) ...@@ -202,6 +199,8 @@ int zmq::plain_mechanism_t::process_hello_command (msg_t *msg_)
return -1; return -1;
} }
// TODO: Add user authentication
return 0; return 0;
} }
......
...@@ -455,7 +455,10 @@ bool zmq::stream_engine_t::handshake () ...@@ -455,7 +455,10 @@ bool zmq::stream_engine_t::handshake ()
else { else {
outpos [outsize++] = 0; // Minor version number outpos [outsize++] = 0; // Minor version number
memset (outpos + outsize, 0, 20); memset (outpos + outsize, 0, 20);
if (options.mechanism == ZMQ_NULL)
memcpy (outpos + outsize, "NULL", 4); memcpy (outpos + outsize, "NULL", 4);
else
memcpy (outpos + outsize, "PLAIN", 5);
outsize += 20; outsize += 20;
memset (outpos + outsize, 0, 32); memset (outpos + outsize, 0, 32);
outsize += 32; outsize += 32;
...@@ -529,7 +532,8 @@ bool zmq::stream_engine_t::handshake () ...@@ -529,7 +532,8 @@ bool zmq::stream_engine_t::handshake ()
} }
else else
if (memcmp (greeting_recv + 12, "PLAIN\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 20) == 0) { 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); mechanism = new (std::nothrow)
plain_mechanism_t (options, options.plain_server);
alloc_assert (mechanism); alloc_assert (mechanism);
} }
else { else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment