From fb67e160a11db104f89043c702000b7c974d7537 Mon Sep 17 00:00:00 2001 From: Pieter Hintjens Date: Mon, 2 Sep 2013 18:21:36 +0200 Subject: [PATCH] Fixed ZAP authentication - if ZAP server returns anything except 200, connection is closed - all security tests now pass correctly - test_security_curve now does proper client key authentication using test key - test_security_plain now does proper password authentication --- src/curve_server.cpp | 4 +++ src/plain_mechanism.cpp | 4 +++ tests/test_security_curve.cpp | 46 ++++++++++++++++++++++------------- tests/test_security_plain.cpp | 27 ++++++++++---------- tests/testutil.hpp | 11 +++++---- 5 files changed, 56 insertions(+), 36 deletions(-) diff --git a/src/curve_server.cpp b/src/curve_server.cpp index 19aba7a8..56e4cdf0 100644 --- a/src/curve_server.cpp +++ b/src/curve_server.cpp @@ -588,24 +588,28 @@ int zmq::curve_server_t::receive_and_process_zap_reply () // Address delimiter frame if (msg [0].size () > 0) { + rc = -1; errno = EPROTO; goto error; } // Version frame if (msg [1].size () != 3 || memcmp (msg [1].data (), "1.0", 3)) { + rc = -1; errno = EPROTO; goto error; } // Request id frame if (msg [2].size () != 1 || memcmp (msg [2].data (), "1", 1)) { + rc = -1; errno = EPROTO; goto error; } // Status code frame if (msg [3].size () != 3 || memcmp (msg [3].data (), "200", 3)) { + rc = -1; errno = EACCES; goto error; } diff --git a/src/plain_mechanism.cpp b/src/plain_mechanism.cpp index 4ba58c40..002adc37 100644 --- a/src/plain_mechanism.cpp +++ b/src/plain_mechanism.cpp @@ -439,24 +439,28 @@ int zmq::plain_mechanism_t::receive_and_process_zap_reply () // Address delimiter frame if (msg [0].size () > 0) { + rc = -1; errno = EPROTO; goto error; } // Version frame if (msg [1].size () != 3 || memcmp (msg [1].data (), "1.0", 3)) { + rc = -1; errno = EPROTO; goto error; } // Request id frame if (msg [2].size () != 1 || memcmp (msg [2].data (), "1", 1)) { + rc = -1; errno = EPROTO; goto error; } // Status code frame if (msg [3].size () != 3 || memcmp (msg [3].data (), "200", 3)) { + rc = -1; errno = EACCES; goto error; } diff --git a/tests/test_security_curve.cpp b/tests/test_security_curve.cpp index 464f1267..752b3f1c 100644 --- a/tests/test_security_curve.cpp +++ b/tests/test_security_curve.cpp @@ -18,10 +18,17 @@ */ #include "platform.hpp" -#include "../include/zmq_utils.h" #include #include #include "testutil.hpp" +#include "../include/zmq_utils.h" +#include "../src/z85_codec.hpp" + +// Test keys from the zmq_curve man page +static char client_public [] = "Yne@$w-vo