diff --git a/src/stream_engine.cpp b/src/stream_engine.cpp index 00a1bea9..4d252d89 100644 --- a/src/stream_engine.cpp +++ b/src/stream_engine.cpp @@ -530,20 +530,23 @@ bool zmq::stream_engine_t::handshake () in_batch_size, options.maxmsgsize); alloc_assert (decoder); - if (memcmp (greeting_recv + 12, "NULL\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 20) == 0) { + if (options.mechanism == ZMQ_NULL + && 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 (session, peer_address, options); alloc_assert (mechanism); } 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 (options.mechanism == ZMQ_PLAIN + && 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 (session, peer_address, options); alloc_assert (mechanism); } #ifdef HAVE_LIBSODIUM else - if (memcmp (greeting_recv + 12, "CURVE\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 20) == 0) { + if (options.mechanism == ZMQ_CURVE + && memcmp (greeting_recv + 12, "CURVE\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 20) == 0) { if (options.as_server) mechanism = new (std::nothrow) curve_server_t (session, peer_address, options); diff --git a/tests/test_security_curve.cpp b/tests/test_security_curve.cpp index 788fb2c1..04e2b0df 100644 --- a/tests/test_security_curve.cpp +++ b/tests/test_security_curve.cpp @@ -199,6 +199,26 @@ int main (void) expect_bounce_fail (server, client); close_zero_linger (client); + // Check CURVE security with NULL client credentials + // This must be caught by the curve_server class, not passed to ZAP + client = zmq_socket (ctx, ZMQ_DEALER); + assert (client); + rc = zmq_connect (client, "tcp://localhost:9998"); + assert (rc == 0); + expect_bounce_fail (server, client); + close_zero_linger (client); + + // Check CURVE security with PLAIN client credentials + // This must be caught by the curve_server class, not passed to ZAP + client = zmq_socket (ctx, ZMQ_DEALER); + assert (client); + rc = zmq_setsockopt (client, ZMQ_PLAIN_USERNAME, "admin", 5); + assert (rc == 0); + rc = zmq_setsockopt (client, ZMQ_PLAIN_PASSWORD, "password", 8); + assert (rc == 0); + expect_bounce_fail (server, client); + close_zero_linger (client); + // Shutdown rc = zmq_close (server); assert (rc == 0);