2013-06-22 16:17:25 +01:00
|
|
|
/*
|
2017-05-01 12:11:11 +01:00
|
|
|
Copyright (c) 2007-2017 Contributors as noted in the AUTHORS file
|
2013-06-22 16:17:25 +01:00
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
This file is part of libzmq, the ZeroMQ core engine in C++.
|
2013-06-22 16:17:25 +01:00
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
libzmq is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License (LGPL) as published
|
|
|
|
by the Free Software Foundation; either version 3 of the License, or
|
2013-06-22 16:17:25 +01:00
|
|
|
(at your option) any later version.
|
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
As a special exception, the Contributors give you permission to link
|
|
|
|
this library with independent modules to produce an executable,
|
|
|
|
regardless of the license terms of these independent modules, and to
|
|
|
|
copy and distribute the resulting executable under terms of your choice,
|
|
|
|
provided that you also meet, for each linked independent module, the
|
|
|
|
terms and conditions of the license of that module. An independent
|
|
|
|
module is a module which is not derived from or based on this library.
|
|
|
|
If you modify this library, you must extend this exception to your
|
|
|
|
version of the library.
|
|
|
|
|
|
|
|
libzmq is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
2013-06-22 16:17:25 +01:00
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "testutil.hpp"
|
2014-12-03 10:34:34 -08:00
|
|
|
#if defined (ZMQ_HAVE_WINDOWS)
|
2017-08-03 15:15:56 +02:00
|
|
|
# include <winsock2.h>
|
|
|
|
# include <ws2tcpip.h>
|
|
|
|
# include <stdexcept>
|
|
|
|
# define close closesocket
|
2014-12-03 10:34:34 -08:00
|
|
|
#else
|
2017-08-03 15:15:56 +02:00
|
|
|
# include <sys/socket.h>
|
|
|
|
# include <netinet/in.h>
|
|
|
|
# include <arpa/inet.h>
|
|
|
|
# include <unistd.h>
|
2014-12-03 10:34:34 -08:00
|
|
|
#endif
|
2013-09-02 18:21:36 +02:00
|
|
|
|
2017-08-15 16:28:24 +02:00
|
|
|
#include "../src/tweetnacl.h"
|
|
|
|
#include "../src/curve_client_tools.hpp"
|
|
|
|
#include "../src/random.hpp"
|
|
|
|
|
2013-09-30 15:14:02 +02:00
|
|
|
// We'll generate random test keys at startup
|
2017-08-04 15:11:14 +02:00
|
|
|
static char valid_client_public [41];
|
|
|
|
static char valid_client_secret [41];
|
|
|
|
static char valid_server_public [41];
|
|
|
|
static char valid_server_secret [41];
|
|
|
|
|
|
|
|
void *zap_requests_handled;
|
2013-06-22 16:17:25 +01:00
|
|
|
|
2016-12-31 00:08:05 +01:00
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
|
|
|
// Read one event off the monitor socket; return value and address
|
|
|
|
// by reference, if not null, and event number by value. Returns -1
|
|
|
|
// in case of error.
|
|
|
|
|
|
|
|
static int
|
2017-08-07 18:07:37 +02:00
|
|
|
get_monitor_event_internal (void *monitor, int *value, char **address, int recv_flag)
|
2016-12-31 00:08:05 +01:00
|
|
|
{
|
|
|
|
// First frame in message contains event number and value
|
|
|
|
zmq_msg_t msg;
|
|
|
|
zmq_msg_init (&msg);
|
2017-08-03 15:15:56 +02:00
|
|
|
if (zmq_msg_recv (&msg, monitor, recv_flag) == -1) {
|
|
|
|
assert (errno == EAGAIN);
|
|
|
|
return -1; // timed out or no message available
|
|
|
|
}
|
2016-12-31 00:08:05 +01:00
|
|
|
assert (zmq_msg_more (&msg));
|
|
|
|
|
|
|
|
uint8_t *data = (uint8_t *) zmq_msg_data (&msg);
|
|
|
|
uint16_t event = *(uint16_t *) (data);
|
|
|
|
if (value)
|
|
|
|
*value = *(uint32_t *) (data + 2);
|
|
|
|
|
|
|
|
// Second frame in message contains event address
|
|
|
|
zmq_msg_init (&msg);
|
2017-08-03 15:15:56 +02:00
|
|
|
int res = zmq_msg_recv (&msg, monitor, recv_flag) == -1;
|
|
|
|
assert (res != -1);
|
2016-12-31 00:08:05 +01:00
|
|
|
assert (!zmq_msg_more (&msg));
|
|
|
|
|
|
|
|
if (address) {
|
|
|
|
uint8_t *data = (uint8_t *) zmq_msg_data (&msg);
|
|
|
|
size_t size = zmq_msg_size (&msg);
|
|
|
|
*address = (char *) malloc (size + 1);
|
|
|
|
memcpy (*address, data, size);
|
|
|
|
*address [size] = 0;
|
|
|
|
}
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2017-08-03 15:15:56 +02:00
|
|
|
int get_monitor_event_with_timeout (void *monitor,
|
|
|
|
int *value,
|
|
|
|
char **address,
|
|
|
|
int timeout)
|
|
|
|
{
|
2017-08-07 18:07:37 +02:00
|
|
|
int res;
|
|
|
|
if (timeout == -1) {
|
|
|
|
// process infinite timeout in small steps to allow the user
|
|
|
|
// to see some information on the console
|
|
|
|
|
|
|
|
int timeout_step = 250;
|
|
|
|
int wait_time = 0;
|
|
|
|
zmq_setsockopt (monitor, ZMQ_RCVTIMEO, &timeout_step,
|
|
|
|
sizeof (timeout_step));
|
|
|
|
while ((res = get_monitor_event_internal (monitor, value, address, 0))
|
|
|
|
== -1) {
|
|
|
|
wait_time += timeout_step;
|
|
|
|
fprintf (stderr, "Still waiting for monitor event after %i ms\n",
|
|
|
|
wait_time);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
zmq_setsockopt (monitor, ZMQ_RCVTIMEO, &timeout, sizeof (timeout));
|
|
|
|
res = get_monitor_event_internal (monitor, value, address, 0);
|
|
|
|
}
|
2017-08-03 15:15:56 +02:00
|
|
|
int timeout_infinite = -1;
|
|
|
|
zmq_setsockopt (monitor, ZMQ_RCVTIMEO, &timeout_infinite,
|
|
|
|
sizeof (timeout_infinite));
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
// assert_* are macros rather than functions, to allow assertion failures be
|
|
|
|
// attributed to the causing source code line
|
|
|
|
#define assert_no_more_monitor_events_with_timeout(monitor, timeout) \
|
|
|
|
{ \
|
|
|
|
int event_count = 0; \
|
|
|
|
int event, err; \
|
|
|
|
while ((event = get_monitor_event_with_timeout ((monitor), &err, NULL, \
|
|
|
|
(timeout))) \
|
|
|
|
!= -1) { \
|
|
|
|
++event_count; \
|
|
|
|
fprintf (stderr, "Unexpected event: %x (err = %i)\n", event, err); \
|
|
|
|
} \
|
|
|
|
assert (event_count == 0); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2016-12-31 00:08:05 +01:00
|
|
|
|
2013-09-15 17:30:18 +02:00
|
|
|
// --------------------------------------------------------------------------
|
2017-08-03 15:15:56 +02:00
|
|
|
// This methods receives and validates ZAP requests (allowing or denying
|
2014-03-16 11:53:40 +01:00
|
|
|
// each client connection).
|
2013-09-15 17:30:18 +02:00
|
|
|
|
2017-08-04 12:07:41 +02:00
|
|
|
enum zap_protocol_t
|
|
|
|
{
|
|
|
|
zap_ok,
|
|
|
|
// ZAP-compliant non-standard cases
|
2017-08-08 14:10:20 +02:00
|
|
|
zap_status_temporary_failure,
|
2017-08-04 12:07:41 +02:00
|
|
|
zap_status_internal_error,
|
|
|
|
// ZAP protocol errors
|
|
|
|
zap_wrong_version,
|
|
|
|
zap_wrong_request_id,
|
|
|
|
zap_status_invalid,
|
|
|
|
zap_too_many_parts
|
|
|
|
};
|
|
|
|
|
2017-08-06 23:56:10 +01:00
|
|
|
static void zap_handler_generic (void *ctx, zap_protocol_t zap_protocol)
|
2013-06-22 16:17:25 +01:00
|
|
|
{
|
2017-08-06 23:56:10 +01:00
|
|
|
void *control = zmq_socket (ctx, ZMQ_REQ);
|
|
|
|
assert (control);
|
|
|
|
int rc = zmq_connect (control, "inproc://handler-control");
|
|
|
|
assert (rc == 0);
|
|
|
|
|
|
|
|
void *handler = zmq_socket (ctx, ZMQ_REP);
|
|
|
|
assert (handler);
|
|
|
|
rc = zmq_bind (handler, "inproc://zeromq.zap.01");
|
|
|
|
assert (rc == 0);
|
|
|
|
|
|
|
|
// Signal main thread that we are ready
|
|
|
|
rc = s_send (control, "GO");
|
|
|
|
assert (rc == 2);
|
|
|
|
|
|
|
|
zmq_pollitem_t items [] = {
|
|
|
|
{ control, 0, ZMQ_POLLIN, 0 },
|
|
|
|
{ handler, 0, ZMQ_POLLIN, 0 },
|
|
|
|
};
|
|
|
|
|
2013-09-02 17:22:24 +02:00
|
|
|
// Process ZAP requests forever
|
2017-08-06 23:56:10 +01:00
|
|
|
while (zmq_poll (items, 2, -1) >= 0) {
|
|
|
|
if (items [0].revents & ZMQ_POLLIN) {
|
|
|
|
char *buf = s_recv (control);
|
|
|
|
assert (buf);
|
|
|
|
assert (streq (buf, "STOP"));
|
|
|
|
free (buf);
|
|
|
|
break; // Terminating - main thread signal
|
|
|
|
}
|
|
|
|
if (!(items [1].revents & ZMQ_POLLIN))
|
|
|
|
continue;
|
|
|
|
|
2013-09-16 10:56:49 +02:00
|
|
|
char *version = s_recv (handler);
|
2013-09-02 17:22:24 +02:00
|
|
|
if (!version)
|
2017-08-06 23:56:10 +01:00
|
|
|
break; // Terminating - peer's socket closed
|
2013-09-02 17:22:24 +02:00
|
|
|
|
2013-09-16 10:56:49 +02:00
|
|
|
char *sequence = s_recv (handler);
|
|
|
|
char *domain = s_recv (handler);
|
|
|
|
char *address = s_recv (handler);
|
|
|
|
char *identity = s_recv (handler);
|
|
|
|
char *mechanism = s_recv (handler);
|
2013-09-02 18:21:36 +02:00
|
|
|
uint8_t client_key [32];
|
2013-09-16 10:56:49 +02:00
|
|
|
int size = zmq_recv (handler, client_key, 32, 0);
|
2013-09-02 18:21:36 +02:00
|
|
|
assert (size == 32);
|
|
|
|
|
2013-09-05 15:18:42 +02:00
|
|
|
char client_key_text [41];
|
2013-09-16 00:06:24 +02:00
|
|
|
zmq_z85_encode (client_key_text, client_key, 32);
|
2013-09-02 18:21:36 +02:00
|
|
|
|
2013-09-02 17:22:24 +02:00
|
|
|
assert (streq (version, "1.0"));
|
|
|
|
assert (streq (mechanism, "CURVE"));
|
|
|
|
assert (streq (identity, "IDENT"));
|
|
|
|
|
2017-08-04 12:07:41 +02:00
|
|
|
s_sendmore (handler, zap_protocol == zap_wrong_version
|
|
|
|
? "invalid_version"
|
|
|
|
: version);
|
|
|
|
s_sendmore (handler, zap_protocol == zap_wrong_request_id
|
|
|
|
? "invalid_request_id"
|
|
|
|
: sequence);
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2017-08-04 15:11:14 +02:00
|
|
|
if (streq (client_key_text, valid_client_public)) {
|
2017-08-08 14:10:20 +02:00
|
|
|
const char *status_code;
|
|
|
|
switch (zap_protocol) {
|
|
|
|
case zap_status_internal_error:
|
|
|
|
status_code = "500";
|
|
|
|
break;
|
|
|
|
case zap_status_temporary_failure:
|
|
|
|
status_code = "300";
|
|
|
|
break;
|
|
|
|
case zap_status_invalid:
|
|
|
|
status_code = "invalid_status";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
status_code = "200";
|
|
|
|
}
|
|
|
|
s_sendmore (handler, status_code);
|
2013-09-16 10:56:49 +02:00
|
|
|
s_sendmore (handler, "OK");
|
|
|
|
s_sendmore (handler, "anonymous");
|
2017-08-04 12:07:41 +02:00
|
|
|
if (zap_protocol == zap_too_many_parts) {
|
|
|
|
s_sendmore (handler, "");
|
|
|
|
}
|
2017-08-03 15:15:56 +02:00
|
|
|
s_send (handler, "");
|
|
|
|
} else {
|
2013-09-16 10:56:49 +02:00
|
|
|
s_sendmore (handler, "400");
|
|
|
|
s_sendmore (handler, "Invalid client public key");
|
|
|
|
s_sendmore (handler, "");
|
2017-08-03 15:15:56 +02:00
|
|
|
s_send (handler, "");
|
2013-09-02 18:21:36 +02:00
|
|
|
}
|
2013-09-02 17:22:24 +02:00
|
|
|
free (version);
|
|
|
|
free (sequence);
|
|
|
|
free (domain);
|
|
|
|
free (address);
|
|
|
|
free (identity);
|
|
|
|
free (mechanism);
|
2017-08-04 15:11:14 +02:00
|
|
|
|
|
|
|
zmq_atomic_counter_inc (zap_requests_handled);
|
2013-08-30 17:56:59 -07:00
|
|
|
}
|
2017-08-06 23:56:10 +01:00
|
|
|
rc = zmq_unbind (handler, "inproc://zeromq.zap.01");
|
|
|
|
assert (rc == 0);
|
|
|
|
close_zero_linger (handler);
|
|
|
|
|
|
|
|
rc = s_send (control, "STOPPED");
|
|
|
|
assert (rc == 7);
|
|
|
|
close_zero_linger (control);
|
2013-06-22 16:17:25 +01:00
|
|
|
}
|
|
|
|
|
2017-08-06 23:56:10 +01:00
|
|
|
static void zap_handler (void *ctx)
|
2017-08-04 12:07:41 +02:00
|
|
|
{
|
2017-08-06 23:56:10 +01:00
|
|
|
zap_handler_generic (ctx, zap_ok);
|
2017-08-04 12:07:41 +02:00
|
|
|
}
|
|
|
|
|
2017-08-06 23:56:10 +01:00
|
|
|
static void zap_handler_wrong_version (void *ctx)
|
2017-08-04 12:07:41 +02:00
|
|
|
{
|
2017-08-06 23:56:10 +01:00
|
|
|
zap_handler_generic (ctx, zap_wrong_version);
|
2017-08-04 12:07:41 +02:00
|
|
|
}
|
|
|
|
|
2017-08-06 23:56:10 +01:00
|
|
|
static void zap_handler_wrong_request_id (void *ctx)
|
2017-08-04 12:07:41 +02:00
|
|
|
{
|
2017-08-06 23:56:10 +01:00
|
|
|
zap_handler_generic (ctx, zap_wrong_request_id);
|
2017-08-04 12:07:41 +02:00
|
|
|
}
|
|
|
|
|
2017-08-06 23:56:10 +01:00
|
|
|
static void zap_handler_wrong_status_invalid (void *ctx)
|
2017-08-04 12:07:41 +02:00
|
|
|
{
|
2017-08-06 23:56:10 +01:00
|
|
|
zap_handler_generic (ctx, zap_status_invalid);
|
2017-08-04 12:07:41 +02:00
|
|
|
}
|
|
|
|
|
2017-08-08 14:10:20 +02:00
|
|
|
static void zap_handler_wrong_status_temporary_failure (void *ctx)
|
|
|
|
{
|
|
|
|
zap_handler_generic (ctx, zap_status_temporary_failure);
|
|
|
|
}
|
|
|
|
|
2017-08-06 23:56:10 +01:00
|
|
|
static void zap_handler_wrong_status_internal_error (void *ctx)
|
2017-08-04 12:07:41 +02:00
|
|
|
{
|
2017-08-06 23:56:10 +01:00
|
|
|
zap_handler_generic (ctx, zap_status_internal_error);
|
2017-08-04 12:07:41 +02:00
|
|
|
}
|
|
|
|
|
2017-08-06 23:56:10 +01:00
|
|
|
static void zap_handler_too_many_parts (void *ctx)
|
2017-08-04 12:07:41 +02:00
|
|
|
{
|
2017-08-06 23:56:10 +01:00
|
|
|
zap_handler_generic (ctx, zap_too_many_parts);
|
2017-08-04 12:07:41 +02:00
|
|
|
}
|
|
|
|
|
2017-08-04 15:11:14 +02:00
|
|
|
void *create_and_connect_curve_client (void *ctx,
|
|
|
|
char *server_public,
|
|
|
|
char *client_public,
|
|
|
|
char *client_secret,
|
|
|
|
char *my_endpoint)
|
2013-06-22 16:17:25 +01:00
|
|
|
{
|
2017-08-03 15:15:56 +02:00
|
|
|
void *client = zmq_socket (ctx, ZMQ_DEALER);
|
|
|
|
assert (client);
|
|
|
|
int rc = zmq_setsockopt (client, ZMQ_CURVE_SERVERKEY, server_public, 41);
|
2013-09-30 15:14:02 +02:00
|
|
|
assert (rc == 0);
|
2017-08-03 15:15:56 +02:00
|
|
|
rc = zmq_setsockopt (client, ZMQ_CURVE_PUBLICKEY, client_public, 41);
|
|
|
|
assert (rc == 0);
|
|
|
|
rc = zmq_setsockopt (client, ZMQ_CURVE_SECRETKEY, client_secret, 41);
|
|
|
|
assert (rc == 0);
|
|
|
|
rc = zmq_connect (client, my_endpoint);
|
2013-09-30 15:14:02 +02:00
|
|
|
assert (rc == 0);
|
2017-08-04 15:11:14 +02:00
|
|
|
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
|
|
|
void expect_new_client_curve_bounce_fail (void *ctx,
|
|
|
|
char *server_public,
|
|
|
|
char *client_public,
|
|
|
|
char *client_secret,
|
|
|
|
char *my_endpoint,
|
|
|
|
void *server)
|
|
|
|
{
|
|
|
|
void *client = create_and_connect_curve_client (
|
|
|
|
ctx, server_public, client_public, client_secret, my_endpoint);
|
2017-08-03 15:15:56 +02:00
|
|
|
expect_bounce_fail (server, client);
|
|
|
|
close_zero_linger (client);
|
2017-08-04 15:11:14 +02:00
|
|
|
}
|
|
|
|
|
2017-08-04 16:05:20 +02:00
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
|
|
|
// expects that one or more occurrences of the expected event are received
|
|
|
|
// via the specified socket monitor
|
|
|
|
// returns the number of occurrences of the expected event
|
2017-08-07 09:26:38 +01:00
|
|
|
// interrupts, if a ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with EPIPE, ECONNRESET
|
|
|
|
// or ECONNABORTED occurs; in this case, 0 is returned
|
2017-08-04 16:05:20 +02:00
|
|
|
// this should be investigated further, see
|
|
|
|
// https://github.com/zeromq/libzmq/issues/2644
|
|
|
|
int expect_monitor_event_multiple (void *server_mon,
|
|
|
|
int expected_event,
|
|
|
|
int expected_err = -1)
|
|
|
|
{
|
|
|
|
int count_of_expected_events = 0;
|
|
|
|
int client_closed_connection = 0;
|
2017-08-08 14:10:20 +02:00
|
|
|
// infinite timeout at the start
|
2017-08-04 16:05:20 +02:00
|
|
|
int timeout = -1;
|
|
|
|
|
|
|
|
int event;
|
|
|
|
int err;
|
|
|
|
while (
|
|
|
|
(event = get_monitor_event_with_timeout (server_mon, &err, NULL, timeout))
|
|
|
|
!= -1) {
|
|
|
|
timeout = 250;
|
|
|
|
|
2017-08-07 09:26:38 +01:00
|
|
|
// ignore errors with EPIPE/ECONNRESET/ECONNABORTED, which can happen
|
2017-08-05 18:08:21 +01:00
|
|
|
// ECONNRESET can happen on very slow machines, when the engine writes
|
|
|
|
// to the peer and then tries to read the socket before the peer reads
|
2017-08-07 09:26:38 +01:00
|
|
|
// ECONNABORTED happens when a client aborts a connection via RST/timeout
|
2017-08-05 18:08:21 +01:00
|
|
|
if (event == ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL &&
|
2017-08-07 09:26:38 +01:00
|
|
|
(err == EPIPE || err == ECONNRESET || err == ECONNABORTED)) {
|
2017-08-07 18:07:37 +02:00
|
|
|
fprintf (
|
|
|
|
stderr,
|
|
|
|
"Ignored event (skipping any further events): %x (err = %i)\n",
|
|
|
|
event, err);
|
2017-08-04 16:05:20 +02:00
|
|
|
client_closed_connection = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (event != expected_event
|
|
|
|
|| (-1 != expected_err && err != expected_err)) {
|
|
|
|
fprintf (stderr, "Unexpected event: %x (err = %i)\n", event, err);
|
|
|
|
assert (false);
|
|
|
|
}
|
|
|
|
++count_of_expected_events;
|
|
|
|
}
|
|
|
|
assert (count_of_expected_events > 0 || client_closed_connection);
|
|
|
|
|
|
|
|
return count_of_expected_events;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-08-04 15:11:14 +02:00
|
|
|
void test_garbage_key(void *ctx,
|
|
|
|
void *server,
|
|
|
|
void *server_mon,
|
|
|
|
char *my_endpoint,
|
|
|
|
char *server_public,
|
|
|
|
char *client_public,
|
|
|
|
char *client_secret)
|
|
|
|
{
|
|
|
|
expect_new_client_curve_bounce_fail (ctx, server_public, client_public,
|
|
|
|
client_secret, my_endpoint, server);
|
2013-09-30 15:14:02 +02:00
|
|
|
|
2017-08-03 15:15:56 +02:00
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
2017-08-04 16:05:20 +02:00
|
|
|
int handshake_failed_encryption_event_count =
|
|
|
|
expect_monitor_event_multiple (server_mon,
|
|
|
|
ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION);
|
2017-08-03 15:15:56 +02:00
|
|
|
|
2017-08-04 16:05:20 +02:00
|
|
|
// handshake_failed_encryption_event_count should be at least two because
|
2017-08-03 15:15:56 +02:00
|
|
|
// expect_bounce_fail involves two exchanges
|
|
|
|
// however, with valgrind we see only one event (maybe the next one takes
|
|
|
|
// very long, or does not happen at all because something else takes very
|
|
|
|
// long)
|
2017-08-04 16:05:20 +02:00
|
|
|
|
|
|
|
fprintf (stderr,
|
|
|
|
"count of ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION events: %i\n",
|
|
|
|
handshake_failed_encryption_event_count);
|
2017-08-03 15:15:56 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup_context_and_server_side (void **ctx,
|
|
|
|
void **handler,
|
|
|
|
void **zap_thread,
|
|
|
|
void **server,
|
|
|
|
void **server_mon,
|
2017-08-04 12:07:41 +02:00
|
|
|
char *my_endpoint,
|
|
|
|
zmq_thread_fn zap_handler_ = &zap_handler)
|
2017-08-03 15:15:56 +02:00
|
|
|
{
|
|
|
|
*ctx = zmq_ctx_new ();
|
|
|
|
assert (*ctx);
|
2013-06-22 16:17:25 +01:00
|
|
|
|
2013-09-02 17:22:24 +02:00
|
|
|
// Spawn ZAP handler
|
2017-08-04 15:11:14 +02:00
|
|
|
zap_requests_handled = zmq_atomic_counter_new ();
|
|
|
|
assert (zap_requests_handled != NULL);
|
|
|
|
|
2017-08-03 15:15:56 +02:00
|
|
|
*handler = zmq_socket (*ctx, ZMQ_REP);
|
|
|
|
assert (*handler);
|
2017-08-06 23:56:10 +01:00
|
|
|
int rc = zmq_bind (*handler, "inproc://handler-control");
|
2013-09-16 10:56:49 +02:00
|
|
|
assert (rc == 0);
|
2017-08-06 23:56:10 +01:00
|
|
|
|
|
|
|
*zap_thread = zmq_threadstart (zap_handler_, *ctx);
|
|
|
|
|
|
|
|
char *buf = s_recv (*handler);
|
|
|
|
assert (buf);
|
|
|
|
assert (streq (buf, "GO"));
|
|
|
|
free (buf);
|
2013-06-22 16:17:25 +01:00
|
|
|
|
2013-09-02 17:22:24 +02:00
|
|
|
// Server socket will accept connections
|
2017-08-03 15:15:56 +02:00
|
|
|
*server = zmq_socket (*ctx, ZMQ_DEALER);
|
|
|
|
assert (*server);
|
|
|
|
|
2013-09-17 14:05:55 +02:00
|
|
|
int as_server = 1;
|
2017-08-03 15:15:56 +02:00
|
|
|
rc = zmq_setsockopt (*server, ZMQ_CURVE_SERVER, &as_server, sizeof (int));
|
Added Z85 support
The use of binary for CURVE keys is painful; you cannot easily copy
these in e.g. email, or use them directly in source code. There are
various encoding possibilities. Base16 and Base64 are not optimal.
Ascii85 is not safe for source (it generates quotes and escapes).
So, I've designed a new Base85 encoding, Z85, which is safe to use
in code and elsewhere, and I've modified libzmq to use this where
it also uses binary keys (in get/setsockopt).
Very simply, if you use a 32-byte value, it's Base256 (binary),
and if you use a 40-byte value, it's Base85 (Z85).
I've put the Z85 codec into z85_codec.hpp, it's not elegant C++
but it is minimal and it works. Feel free to rewrap as a real class
if this annoys you.
2013-06-28 22:10:22 +02:00
|
|
|
assert (rc == 0);
|
2017-08-03 15:15:56 +02:00
|
|
|
|
2017-08-04 15:11:14 +02:00
|
|
|
rc = zmq_setsockopt (*server, ZMQ_CURVE_SECRETKEY, valid_server_secret, 41);
|
Added Z85 support
The use of binary for CURVE keys is painful; you cannot easily copy
these in e.g. email, or use them directly in source code. There are
various encoding possibilities. Base16 and Base64 are not optimal.
Ascii85 is not safe for source (it generates quotes and escapes).
So, I've designed a new Base85 encoding, Z85, which is safe to use
in code and elsewhere, and I've modified libzmq to use this where
it also uses binary keys (in get/setsockopt).
Very simply, if you use a 32-byte value, it's Base256 (binary),
and if you use a 40-byte value, it's Base85 (Z85).
I've put the Z85 codec into z85_codec.hpp, it's not elegant C++
but it is minimal and it works. Feel free to rewrap as a real class
if this annoys you.
2013-06-28 22:10:22 +02:00
|
|
|
assert (rc == 0);
|
2017-08-03 15:15:56 +02:00
|
|
|
|
|
|
|
rc = zmq_setsockopt (*server, ZMQ_IDENTITY, "IDENT", 6);
|
2013-09-02 17:22:24 +02:00
|
|
|
assert (rc == 0);
|
2017-08-03 15:15:56 +02:00
|
|
|
|
|
|
|
rc = zmq_bind (*server, "tcp://127.0.0.1:*");
|
2017-05-01 12:11:11 +01:00
|
|
|
assert (rc == 0);
|
|
|
|
|
|
|
|
size_t len = MAX_SOCKET_STRING;
|
2017-08-03 15:15:56 +02:00
|
|
|
rc = zmq_getsockopt (*server, ZMQ_LAST_ENDPOINT, my_endpoint, &len);
|
2013-08-20 13:48:05 -04:00
|
|
|
assert (rc == 0);
|
2013-06-22 16:17:25 +01:00
|
|
|
|
2016-12-31 00:08:05 +01:00
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
2017-08-03 15:15:56 +02:00
|
|
|
char monitor_endpoint [] = "inproc://monitor-server";
|
|
|
|
|
2016-12-31 00:08:05 +01:00
|
|
|
// Monitor handshake events on the server
|
2017-08-03 15:15:56 +02:00
|
|
|
rc = zmq_socket_monitor (
|
|
|
|
*server, monitor_endpoint,
|
|
|
|
ZMQ_EVENT_HANDSHAKE_SUCCEEDED | ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL
|
|
|
|
| ZMQ_EVENT_HANDSHAKE_FAILED_ZAP | ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP
|
|
|
|
| ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION);
|
2016-12-31 00:08:05 +01:00
|
|
|
assert (rc == 0);
|
|
|
|
|
|
|
|
// Create socket for collecting monitor events
|
2017-08-03 15:15:56 +02:00
|
|
|
*server_mon = zmq_socket (*ctx, ZMQ_PAIR);
|
|
|
|
assert (*server_mon);
|
2016-12-31 00:08:05 +01:00
|
|
|
|
|
|
|
// Connect it to the inproc endpoints so they'll get events
|
2017-08-03 15:15:56 +02:00
|
|
|
rc = zmq_connect (*server_mon, monitor_endpoint);
|
2016-12-31 00:08:05 +01:00
|
|
|
assert (rc == 0);
|
|
|
|
#endif
|
2017-08-03 15:15:56 +02:00
|
|
|
}
|
2016-12-31 00:08:05 +01:00
|
|
|
|
2017-08-03 15:15:56 +02:00
|
|
|
void shutdown_context_and_server_side (void *ctx,
|
|
|
|
void *zap_thread,
|
|
|
|
void *server,
|
2017-08-06 23:56:10 +01:00
|
|
|
void *server_mon,
|
|
|
|
void *handler)
|
2017-08-03 15:15:56 +02:00
|
|
|
{
|
2017-08-06 23:56:10 +01:00
|
|
|
int rc = s_send (handler, "STOP");
|
|
|
|
assert (rc == 4);
|
|
|
|
char *buf = s_recv (handler);
|
|
|
|
assert (buf);
|
|
|
|
assert (streq (buf, "STOPPED"));
|
|
|
|
free (buf);
|
|
|
|
rc = zmq_unbind (handler, "inproc://handler-control");
|
|
|
|
assert (rc == 0);
|
|
|
|
close_zero_linger (handler);
|
|
|
|
|
2016-12-31 00:08:05 +01:00
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
2017-08-03 15:15:56 +02:00
|
|
|
close_zero_linger (server_mon);
|
2016-12-31 00:08:05 +01:00
|
|
|
#endif
|
2017-08-03 15:15:56 +02:00
|
|
|
close_zero_linger (server);
|
2016-12-31 00:08:05 +01:00
|
|
|
|
2017-08-03 15:15:56 +02:00
|
|
|
// Wait until ZAP handler terminates
|
|
|
|
zmq_threadclose (zap_thread);
|
2017-08-04 15:11:14 +02:00
|
|
|
|
2017-08-06 23:56:10 +01:00
|
|
|
rc = zmq_ctx_term (ctx);
|
|
|
|
assert (rc == 0);
|
|
|
|
|
2017-08-04 15:11:14 +02:00
|
|
|
zmq_atomic_counter_destroy (&zap_requests_handled);
|
2017-08-03 15:15:56 +02:00
|
|
|
}
|
2016-12-31 00:08:05 +01:00
|
|
|
|
2017-08-03 15:15:56 +02:00
|
|
|
void test_curve_security_with_valid_credentials (
|
|
|
|
void *ctx, char *my_endpoint, void *server, void *server_mon, int timeout)
|
|
|
|
{
|
2017-08-04 15:11:14 +02:00
|
|
|
void *client = create_and_connect_curve_client (
|
|
|
|
ctx, valid_server_public, valid_client_public, valid_client_secret, my_endpoint);
|
2017-08-03 15:15:56 +02:00
|
|
|
bounce (server, client);
|
2017-08-04 15:11:14 +02:00
|
|
|
int rc = zmq_close (client);
|
2013-08-30 17:56:59 -07:00
|
|
|
assert (rc == 0);
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2016-12-31 00:08:05 +01:00
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
2017-08-07 18:07:37 +02:00
|
|
|
int event = get_monitor_event_with_timeout (server_mon, NULL, NULL, -1);
|
2017-08-03 15:15:56 +02:00
|
|
|
assert (event == ZMQ_EVENT_HANDSHAKE_SUCCEEDED);
|
|
|
|
|
|
|
|
assert_no_more_monitor_events_with_timeout (server_mon, timeout);
|
2016-12-31 00:08:05 +01:00
|
|
|
#endif
|
2017-08-03 15:15:56 +02:00
|
|
|
}
|
2016-12-31 00:08:05 +01:00
|
|
|
|
2017-08-03 15:15:56 +02:00
|
|
|
void test_curve_security_with_bogus_client_credentials (
|
|
|
|
void *ctx, char *my_endpoint, void *server, void *server_mon, int timeout)
|
|
|
|
{
|
2013-09-02 17:22:24 +02:00
|
|
|
// This must be caught by the ZAP handler
|
2013-09-30 15:14:02 +02:00
|
|
|
char bogus_public [41];
|
|
|
|
char bogus_secret [41];
|
|
|
|
zmq_curve_keypair (bogus_public, bogus_secret);
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2017-08-04 15:11:14 +02:00
|
|
|
expect_new_client_curve_bounce_fail (ctx, valid_server_public, bogus_public,
|
|
|
|
bogus_secret, my_endpoint, server);
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2017-08-08 14:10:20 +02:00
|
|
|
int event_count = 0;
|
2016-12-31 00:08:05 +01:00
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
2017-08-03 15:15:56 +02:00
|
|
|
// TODO add another event type ZMQ_EVENT_HANDSHAKE_FAILED_AUTH for this case?
|
2017-08-08 14:10:20 +02:00
|
|
|
event_count = expect_monitor_event_multiple (
|
|
|
|
server_mon, ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, EACCES);
|
|
|
|
assert (event_count <= 1);
|
2016-12-31 00:08:05 +01:00
|
|
|
#endif
|
2017-08-04 15:11:14 +02:00
|
|
|
|
|
|
|
// there may be more than one ZAP request due to repeated attempts by the client
|
2017-08-08 14:10:20 +02:00
|
|
|
assert (0 == event_count
|
|
|
|
|| 1 <= zmq_atomic_counter_value (zap_requests_handled));
|
2017-08-03 15:15:56 +02:00
|
|
|
}
|
2016-12-31 00:08:05 +01:00
|
|
|
|
2017-08-04 15:11:14 +02:00
|
|
|
void expect_zmtp_failure (void *client, char *my_endpoint, void *server, void *server_mon)
|
2017-08-03 15:15:56 +02:00
|
|
|
{
|
2014-09-19 19:24:45 +02:00
|
|
|
// This must be caught by the curve_server class, not passed to ZAP
|
2017-08-03 15:15:56 +02:00
|
|
|
int rc = zmq_connect (client, my_endpoint);
|
2014-09-18 07:32:07 +02:00
|
|
|
assert (rc == 0);
|
|
|
|
expect_bounce_fail (server, client);
|
|
|
|
close_zero_linger (client);
|
|
|
|
|
2017-08-08 14:10:20 +02:00
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
|
|
|
expect_monitor_event_multiple (server_mon, ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP);
|
2016-12-31 00:08:05 +01:00
|
|
|
#endif
|
2017-08-04 15:11:14 +02:00
|
|
|
|
|
|
|
assert (0 == zmq_atomic_counter_value (zap_requests_handled));
|
2017-08-03 15:15:56 +02:00
|
|
|
}
|
2016-12-31 00:08:05 +01:00
|
|
|
|
2017-08-04 15:11:14 +02:00
|
|
|
void test_curve_security_with_null_client_credentials (void *ctx,
|
|
|
|
char *my_endpoint,
|
|
|
|
void *server,
|
|
|
|
void *server_mon)
|
|
|
|
{
|
|
|
|
void *client = zmq_socket (ctx, ZMQ_DEALER);
|
|
|
|
assert (client);
|
|
|
|
|
|
|
|
expect_zmtp_failure (client, my_endpoint, server, server_mon);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_curve_security_with_plain_client_credentials (void *ctx,
|
|
|
|
char *my_endpoint,
|
|
|
|
void *server,
|
|
|
|
void *server_mon)
|
2017-08-03 15:15:56 +02:00
|
|
|
{
|
|
|
|
void *client = zmq_socket (ctx, ZMQ_DEALER);
|
2014-09-18 07:32:07 +02:00
|
|
|
assert (client);
|
2017-08-03 15:15:56 +02:00
|
|
|
int rc = zmq_setsockopt (client, ZMQ_PLAIN_USERNAME, "admin", 5);
|
2014-09-18 07:32:07 +02:00
|
|
|
assert (rc == 0);
|
|
|
|
rc = zmq_setsockopt (client, ZMQ_PLAIN_PASSWORD, "password", 8);
|
|
|
|
assert (rc == 0);
|
2017-08-04 11:35:00 +02:00
|
|
|
|
2017-08-04 15:11:14 +02:00
|
|
|
expect_zmtp_failure (client, my_endpoint, server, server_mon);
|
2017-08-03 15:15:56 +02:00
|
|
|
}
|
2014-11-07 17:35:41 +01:00
|
|
|
|
2017-08-15 16:28:24 +02:00
|
|
|
int connect_vanilla_socket (char *my_endpoint)
|
2017-08-03 15:15:56 +02:00
|
|
|
{
|
2014-12-03 10:34:34 -08:00
|
|
|
int s;
|
2017-08-15 16:28:24 +02:00
|
|
|
struct sockaddr_in ip4addr;
|
2014-12-03 10:34:34 -08:00
|
|
|
|
2017-05-01 12:11:11 +01:00
|
|
|
unsigned short int port;
|
2017-08-03 15:15:56 +02:00
|
|
|
int rc = sscanf (my_endpoint, "tcp://127.0.0.1:%hu", &port);
|
2017-05-01 12:11:11 +01:00
|
|
|
assert (rc == 1);
|
|
|
|
|
2014-12-03 10:34:34 -08:00
|
|
|
ip4addr.sin_family = AF_INET;
|
2017-05-01 12:11:11 +01:00
|
|
|
ip4addr.sin_port = htons (port);
|
2017-08-03 15:15:56 +02:00
|
|
|
#if defined(ZMQ_HAVE_WINDOWS) && (_WIN32_WINNT < 0x0600)
|
2015-05-07 16:52:37 -04:00
|
|
|
ip4addr.sin_addr.s_addr = inet_addr ("127.0.0.1");
|
|
|
|
#else
|
2017-08-03 15:15:56 +02:00
|
|
|
inet_pton (AF_INET, "127.0.0.1", &ip4addr.sin_addr);
|
2015-05-07 16:52:37 -04:00
|
|
|
#endif
|
2014-12-03 10:34:34 -08:00
|
|
|
|
|
|
|
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
2017-08-03 15:15:56 +02:00
|
|
|
rc = connect (s, (struct sockaddr *) &ip4addr, sizeof (ip4addr));
|
2014-12-03 10:34:34 -08:00
|
|
|
assert (rc > -1);
|
2017-08-15 16:28:24 +02:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_curve_security_unauthenticated_message (char *my_endpoint,
|
|
|
|
void *server,
|
|
|
|
int timeout)
|
|
|
|
{
|
|
|
|
// Unauthenticated messages from a vanilla socket shouldn't be received
|
|
|
|
int s = connect_vanilla_socket(my_endpoint);
|
2014-12-03 14:51:57 -08:00
|
|
|
// send anonymous ZMTP/1.0 greeting
|
|
|
|
send (s, "\x01\x00", 2, 0);
|
|
|
|
// send sneaky message that shouldn't be received
|
|
|
|
send (s, "\x08\x00sneaky\0", 9, 0);
|
2017-08-03 15:15:56 +02:00
|
|
|
|
2014-12-03 10:34:34 -08:00
|
|
|
zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof (timeout));
|
|
|
|
char *buf = s_recv (server);
|
2014-12-03 14:51:57 -08:00
|
|
|
if (buf != NULL) {
|
|
|
|
printf ("Received unauthenticated message: %s\n", buf);
|
|
|
|
assert (buf == NULL);
|
|
|
|
}
|
2014-12-03 10:34:34 -08:00
|
|
|
close (s);
|
2017-08-03 15:15:56 +02:00
|
|
|
}
|
2014-12-03 10:34:34 -08:00
|
|
|
|
2017-08-15 16:28:24 +02:00
|
|
|
void send_all (int fd, const char *data, size_t size)
|
|
|
|
{
|
|
|
|
while (size > 0) {
|
|
|
|
int res = send (fd, data, size, 0);
|
|
|
|
assert (res > 0);
|
|
|
|
size -= res;
|
|
|
|
data += res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <size_t N> void send (int fd, const char (&data) [N])
|
|
|
|
{
|
|
|
|
send_all (fd, data, N - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void send_greeting(int s)
|
|
|
|
{
|
|
|
|
send (s, "\xff\0\0\0\0\0\0\0\0\x7f"); // signature
|
|
|
|
send (s, "\x03\x00"); // version 3.0
|
|
|
|
send (s, "CURVE\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"); // mechanism CURVE
|
|
|
|
send (s, "\0"); // as-server == false
|
|
|
|
send (s, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_curve_security_invalid_hello_wrong_length (char *my_endpoint,
|
|
|
|
void *server,
|
|
|
|
void *server_mon,
|
|
|
|
int timeout)
|
|
|
|
{
|
|
|
|
int s = connect_vanilla_socket (my_endpoint);
|
|
|
|
|
|
|
|
// send GREETING
|
|
|
|
send_greeting (s);
|
|
|
|
|
|
|
|
// send CURVE HELLO of wrong size
|
|
|
|
send(s, "\x04\x05HELLO");
|
|
|
|
|
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
|
|
|
expect_monitor_event_multiple (server_mon, ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP,
|
|
|
|
EPROTO);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
close (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
const size_t hello_length = 200;
|
|
|
|
const size_t welcome_length = 168;
|
|
|
|
|
|
|
|
zmq::curve_client_tools_t make_curve_client_tools ()
|
|
|
|
{
|
|
|
|
uint8_t valid_client_secret_decoded[32];
|
|
|
|
uint8_t valid_client_public_decoded[32];
|
|
|
|
|
|
|
|
zmq_z85_decode (valid_client_public_decoded, valid_client_public);
|
|
|
|
zmq_z85_decode (valid_client_secret_decoded, valid_client_secret);
|
|
|
|
|
|
|
|
uint8_t valid_server_public_decoded[32];
|
|
|
|
zmq_z85_decode (valid_server_public_decoded, valid_server_public);
|
|
|
|
|
|
|
|
return zmq::curve_client_tools_t (valid_client_public_decoded,
|
|
|
|
valid_client_secret_decoded,
|
|
|
|
valid_server_public_decoded);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef htonll
|
|
|
|
uint64_t htonll (uint64_t value)
|
|
|
|
{
|
|
|
|
// The answer is 42
|
|
|
|
static const int num = 42;
|
|
|
|
|
|
|
|
// Check the endianness
|
|
|
|
if (*reinterpret_cast<const char *> (&num) == num) {
|
|
|
|
const uint32_t high_part = htonl (static_cast<uint32_t> (value >> 32));
|
|
|
|
const uint32_t low_part =
|
|
|
|
htonl (static_cast<uint32_t> (value & 0xFFFFFFFFLL));
|
|
|
|
|
|
|
|
return (static_cast<uint64_t> (low_part) << 32) | high_part;
|
|
|
|
} else {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template <size_t N> void send_command (int s, char (&command)[N])
|
|
|
|
{
|
|
|
|
if (N < 256) {
|
|
|
|
send(s, "\x04");
|
|
|
|
char len = (char)N;
|
|
|
|
send_all(s, &len, 1);
|
|
|
|
} else {
|
|
|
|
send(s, "\x06");
|
|
|
|
uint64_t len = htonll (N);
|
|
|
|
send_all (s, (char*)&len, 8);
|
|
|
|
}
|
|
|
|
send_all (s, command, N);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_curve_security_invalid_hello_command_name (char *my_endpoint,
|
|
|
|
void *server,
|
|
|
|
void *server_mon,
|
|
|
|
int timeout)
|
|
|
|
{
|
|
|
|
int s = connect_vanilla_socket (my_endpoint);
|
|
|
|
|
|
|
|
send_greeting (s);
|
|
|
|
|
|
|
|
zmq::curve_client_tools_t tools = make_curve_client_tools ();
|
|
|
|
|
|
|
|
// send CURVE HELLO with a misspelled command name (but otherwise correct)
|
|
|
|
char hello[hello_length];
|
|
|
|
int rc = tools.produce_hello (hello, 0);
|
|
|
|
assert (rc == 0);
|
|
|
|
hello[5] = 'X';
|
|
|
|
|
|
|
|
send_command(s, hello);
|
|
|
|
|
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
|
|
|
expect_monitor_event_multiple (server_mon, ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP,
|
|
|
|
EPROTO);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
close (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_curve_security_invalid_hello_version (char *my_endpoint,
|
|
|
|
void *server,
|
|
|
|
void *server_mon,
|
|
|
|
int timeout)
|
|
|
|
{
|
|
|
|
int s = connect_vanilla_socket (my_endpoint);
|
|
|
|
|
|
|
|
send_greeting (s);
|
|
|
|
|
|
|
|
zmq::curve_client_tools_t tools = make_curve_client_tools ();
|
|
|
|
|
|
|
|
// send CURVE HELLO with a wrong version number (but otherwise correct)
|
|
|
|
char hello[hello_length];
|
|
|
|
int rc = tools.produce_hello (hello, 0);
|
|
|
|
assert (rc == 0);
|
|
|
|
hello[6] = 2;
|
|
|
|
|
|
|
|
send_command (s, hello);
|
|
|
|
|
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
|
|
|
expect_monitor_event_multiple (server_mon, ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP,
|
|
|
|
EPROTO);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
close (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void flush_read(int fd)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
while ((res = recv (fd, buf, 256, 0)) == 256) {
|
|
|
|
}
|
|
|
|
assert (res != -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void recv_all(int fd, uint8_t *data, size_t len)
|
|
|
|
{
|
|
|
|
size_t received = 0;
|
|
|
|
while (received < len)
|
|
|
|
{
|
|
|
|
int res = recv(fd, (char*)data, len, 0);
|
|
|
|
assert(res > 0);
|
|
|
|
|
|
|
|
data += res;
|
|
|
|
received += res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void recv_greeting (int fd)
|
|
|
|
{
|
|
|
|
uint8_t greeting[64];
|
|
|
|
recv_all (fd, greeting, 64);
|
|
|
|
// TODO assert anything about the greeting received from the server?
|
|
|
|
}
|
|
|
|
|
|
|
|
int connect_exchange_greeting_and_send_hello (char *my_endpoint,
|
|
|
|
zmq::curve_client_tools_t &tools)
|
|
|
|
{
|
|
|
|
int s = connect_vanilla_socket (my_endpoint);
|
|
|
|
|
|
|
|
send_greeting (s);
|
|
|
|
recv_greeting (s);
|
|
|
|
|
|
|
|
// send valid CURVE HELLO
|
|
|
|
char hello[hello_length];
|
|
|
|
int rc = tools.produce_hello (hello, 0);
|
|
|
|
assert (rc == 0);
|
|
|
|
|
|
|
|
send_command (s, hello);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_curve_security_invalid_initiate_length (char *my_endpoint,
|
|
|
|
void *server,
|
|
|
|
void *server_mon,
|
|
|
|
int timeout)
|
|
|
|
{
|
|
|
|
zmq::curve_client_tools_t tools = make_curve_client_tools ();
|
|
|
|
|
|
|
|
int s = connect_exchange_greeting_and_send_hello (my_endpoint, tools);
|
|
|
|
|
|
|
|
// receive but ignore WELCOME
|
|
|
|
flush_read (s);
|
|
|
|
|
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
|
|
|
int res = get_monitor_event_with_timeout (server_mon, NULL, NULL, timeout);
|
|
|
|
assert (res == -1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
send(s, "\x04\x08INITIATE");
|
|
|
|
|
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
|
|
|
expect_monitor_event_multiple (server_mon, ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP,
|
|
|
|
EPROTO);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
close (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
int connect_exchange_greeting_and_hello_welcome (
|
|
|
|
char *my_endpoint,
|
|
|
|
void *server_mon,
|
|
|
|
int timeout,
|
|
|
|
zmq::curve_client_tools_t &tools)
|
|
|
|
{
|
|
|
|
int s = connect_exchange_greeting_and_send_hello (
|
|
|
|
my_endpoint, tools);
|
|
|
|
|
|
|
|
// receive but ignore WELCOME
|
|
|
|
uint8_t welcome[welcome_length + 2];
|
|
|
|
recv_all (s, welcome, welcome_length + 2);
|
|
|
|
|
|
|
|
int res = tools.process_welcome (welcome + 2, welcome_length);
|
|
|
|
assert (res == 0);
|
|
|
|
|
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
|
|
|
res = get_monitor_event_with_timeout (server_mon, NULL, NULL, timeout);
|
|
|
|
assert (res == -1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_curve_security_invalid_initiate_command_name (char *my_endpoint,
|
|
|
|
void *server,
|
|
|
|
void *server_mon,
|
|
|
|
int timeout)
|
|
|
|
{
|
|
|
|
zmq::curve_client_tools_t tools = make_curve_client_tools ();
|
|
|
|
int s = connect_exchange_greeting_and_hello_welcome (
|
|
|
|
my_endpoint, server_mon, timeout, tools);
|
|
|
|
|
|
|
|
char initiate [257];
|
|
|
|
tools.produce_initiate (initiate, 257, 1, NULL, 0);
|
|
|
|
// modify command name
|
|
|
|
initiate[5] = 'X';
|
|
|
|
|
|
|
|
send_command (s, initiate);
|
|
|
|
|
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
|
|
|
expect_monitor_event_multiple (server_mon, ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP,
|
|
|
|
EPROTO);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
close (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_curve_security_invalid_initiate_command_encrypted_cookie (
|
|
|
|
char *my_endpoint, void *server, void *server_mon, int timeout)
|
|
|
|
{
|
|
|
|
zmq::curve_client_tools_t tools = make_curve_client_tools ();
|
|
|
|
int s = connect_exchange_greeting_and_hello_welcome (
|
|
|
|
my_endpoint, server_mon, timeout, tools);
|
|
|
|
|
|
|
|
char initiate [257];
|
|
|
|
tools.produce_initiate (initiate, 257, 1, NULL, 0);
|
|
|
|
// make garbage from encrypted cookie
|
|
|
|
initiate[30] = !initiate[30];
|
|
|
|
|
|
|
|
send_command (s, initiate);
|
|
|
|
|
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
|
|
|
expect_monitor_event_multiple (
|
|
|
|
server_mon, ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION, EPROTO);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
close (s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_curve_security_invalid_initiate_command_encrypted_content (
|
|
|
|
char *my_endpoint, void *server, void *server_mon, int timeout)
|
|
|
|
{
|
|
|
|
zmq::curve_client_tools_t tools = make_curve_client_tools ();
|
|
|
|
int s = connect_exchange_greeting_and_hello_welcome (
|
|
|
|
my_endpoint, server_mon, timeout, tools);
|
|
|
|
|
|
|
|
char initiate [257];
|
|
|
|
tools.produce_initiate (initiate, 257, 1, NULL, 0);
|
|
|
|
// make garbage from encrypted content
|
|
|
|
initiate[150] = !initiate[150];
|
|
|
|
|
|
|
|
send_command (s, initiate);
|
|
|
|
|
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
|
|
|
expect_monitor_event_multiple (
|
|
|
|
server_mon, ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION, EPROTO);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
close (s);
|
|
|
|
}
|
|
|
|
|
2017-08-04 12:07:41 +02:00
|
|
|
void test_curve_security_zap_unsuccessful (void *ctx,
|
|
|
|
char *my_endpoint,
|
|
|
|
void *server,
|
|
|
|
void *server_mon,
|
|
|
|
int expected_event,
|
|
|
|
int expected_err)
|
|
|
|
{
|
2017-08-04 15:11:14 +02:00
|
|
|
expect_new_client_curve_bounce_fail (
|
|
|
|
ctx, valid_server_public, valid_client_public, valid_client_secret,
|
|
|
|
my_endpoint, server);
|
2017-08-04 12:07:41 +02:00
|
|
|
|
2017-08-07 10:59:36 +02:00
|
|
|
int events_received = 0;
|
2017-08-04 12:07:41 +02:00
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
2017-08-07 10:59:36 +02:00
|
|
|
events_received =
|
2017-08-08 14:10:20 +02:00
|
|
|
expect_monitor_event_multiple (server_mon, expected_event, expected_err);
|
2017-08-04 12:07:41 +02:00
|
|
|
#endif
|
2017-08-04 15:11:14 +02:00
|
|
|
|
|
|
|
// there may be more than one ZAP request due to repeated attempts by the client
|
2017-08-07 10:59:36 +02:00
|
|
|
assert (events_received == 0
|
|
|
|
|| 1 <= zmq_atomic_counter_value (zap_requests_handled));
|
2017-08-04 12:07:41 +02:00
|
|
|
}
|
|
|
|
|
2017-08-04 16:05:20 +02:00
|
|
|
void test_curve_security_zap_protocol_error (void *ctx,
|
|
|
|
char *my_endpoint,
|
|
|
|
void *server,
|
|
|
|
void *server_mon)
|
2017-08-04 12:07:41 +02:00
|
|
|
{
|
2017-08-04 16:05:20 +02:00
|
|
|
test_curve_security_zap_unsuccessful (ctx, my_endpoint, server, server_mon,
|
2017-08-04 12:07:41 +02:00
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
2017-08-04 16:05:20 +02:00
|
|
|
ZMQ_EVENT_HANDSHAKE_FAILED_ZAP, EPROTO
|
2017-08-04 12:07:41 +02:00
|
|
|
#else
|
2017-08-04 16:05:20 +02:00
|
|
|
0, 0
|
2017-08-04 12:07:41 +02:00
|
|
|
#endif
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-08-03 15:15:56 +02:00
|
|
|
void test_curve_security_invalid_keysize (void *ctx)
|
|
|
|
{
|
2014-11-07 17:35:41 +01:00
|
|
|
// Check return codes for invalid buffer sizes
|
2017-08-03 15:15:56 +02:00
|
|
|
void *client = zmq_socket (ctx, ZMQ_DEALER);
|
2014-11-07 17:35:41 +01:00
|
|
|
assert (client);
|
|
|
|
errno = 0;
|
2017-08-04 15:11:14 +02:00
|
|
|
int rc = zmq_setsockopt (client, ZMQ_CURVE_SERVERKEY, valid_server_public, 123);
|
2014-11-07 17:35:41 +01:00
|
|
|
assert (rc == -1 && errno == EINVAL);
|
|
|
|
errno = 0;
|
2017-08-04 15:11:14 +02:00
|
|
|
rc = zmq_setsockopt (client, ZMQ_CURVE_PUBLICKEY, valid_client_public, 123);
|
2014-11-07 17:35:41 +01:00
|
|
|
assert (rc == -1 && errno == EINVAL);
|
|
|
|
errno = 0;
|
2017-08-04 15:11:14 +02:00
|
|
|
rc = zmq_setsockopt (client, ZMQ_CURVE_SECRETKEY, valid_client_secret, 123);
|
2014-11-07 17:35:41 +01:00
|
|
|
assert (rc == -1 && errno == EINVAL);
|
|
|
|
rc = zmq_close (client);
|
|
|
|
assert (rc == 0);
|
2017-08-03 15:15:56 +02:00
|
|
|
}
|
2014-11-07 17:35:41 +01:00
|
|
|
|
2017-08-03 15:15:56 +02:00
|
|
|
int main (void)
|
|
|
|
{
|
|
|
|
if (!zmq_has ("curve")) {
|
|
|
|
printf ("CURVE encryption not installed, skipping test\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-15 16:28:24 +02:00
|
|
|
zmq::random_open ();
|
|
|
|
|
2017-08-03 15:15:56 +02:00
|
|
|
// Generate new keypairs for these tests
|
2017-08-04 15:11:14 +02:00
|
|
|
int rc = zmq_curve_keypair (valid_client_public, valid_client_secret);
|
2013-09-02 17:22:24 +02:00
|
|
|
assert (rc == 0);
|
2017-08-04 15:11:14 +02:00
|
|
|
rc = zmq_curve_keypair (valid_server_public, valid_server_secret);
|
2013-06-22 16:17:25 +01:00
|
|
|
assert (rc == 0);
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2017-08-03 15:15:56 +02:00
|
|
|
int timeout = 250;
|
|
|
|
|
|
|
|
setup_test_environment ();
|
|
|
|
|
|
|
|
void *ctx;
|
|
|
|
void *handler;
|
|
|
|
void *zap_thread;
|
|
|
|
void *server;
|
|
|
|
void *server_mon;
|
|
|
|
char my_endpoint [MAX_SOCKET_STRING];
|
|
|
|
|
2017-08-07 18:07:37 +02:00
|
|
|
fprintf (stderr, "test_curve_security_with_valid_credentials\n");
|
2017-08-03 15:15:56 +02:00
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint);
|
|
|
|
test_curve_security_with_valid_credentials (ctx, my_endpoint, server,
|
|
|
|
server_mon, timeout);
|
2017-08-06 23:56:10 +01:00
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
2017-08-03 15:15:56 +02:00
|
|
|
|
|
|
|
char garbage_key [] = "0000000000000000000000000000000000000000";
|
|
|
|
|
|
|
|
// Check CURVE security with a garbage server key
|
|
|
|
// This will be caught by the curve_server class, not passed to ZAP
|
|
|
|
fprintf (stderr, "test_garbage_server_key\n");
|
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint);
|
|
|
|
test_garbage_key (ctx, server, server_mon, my_endpoint, garbage_key,
|
2017-08-04 15:11:14 +02:00
|
|
|
valid_client_public, valid_client_secret);
|
2017-08-06 23:56:10 +01:00
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
2017-08-03 15:15:56 +02:00
|
|
|
|
|
|
|
// Check CURVE security with a garbage client public key
|
|
|
|
// This will be caught by the curve_server class, not passed to ZAP
|
|
|
|
fprintf (stderr, "test_garbage_client_public_key\n");
|
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint);
|
2017-08-04 15:11:14 +02:00
|
|
|
test_garbage_key (ctx, server, server_mon, my_endpoint, valid_server_public,
|
|
|
|
garbage_key, valid_client_secret);
|
2017-08-06 23:56:10 +01:00
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
2017-08-03 15:15:56 +02:00
|
|
|
|
|
|
|
// Check CURVE security with a garbage client secret key
|
|
|
|
// This will be caught by the curve_server class, not passed to ZAP
|
|
|
|
fprintf (stderr, "test_garbage_client_secret_key\n");
|
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint);
|
2017-08-04 15:11:14 +02:00
|
|
|
test_garbage_key (ctx, server, server_mon, my_endpoint, valid_server_public,
|
|
|
|
valid_client_public, garbage_key);
|
2017-08-06 23:56:10 +01:00
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
2017-08-03 15:15:56 +02:00
|
|
|
|
2017-08-07 18:07:37 +02:00
|
|
|
fprintf (stderr, "test_curve_security_with_bogus_client_credentials\n");
|
2017-08-03 15:15:56 +02:00
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint);
|
|
|
|
test_curve_security_with_bogus_client_credentials (ctx, my_endpoint, server,
|
|
|
|
server_mon, timeout);
|
2017-08-06 23:56:10 +01:00
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
2017-08-03 15:15:56 +02:00
|
|
|
|
2017-08-07 18:07:37 +02:00
|
|
|
fprintf (stderr, "test_curve_security_with_null_client_credentials\n");
|
2017-08-03 15:15:56 +02:00
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint);
|
|
|
|
test_curve_security_with_null_client_credentials (ctx, my_endpoint, server,
|
|
|
|
server_mon);
|
2017-08-06 23:56:10 +01:00
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
2017-08-03 15:15:56 +02:00
|
|
|
|
2017-08-07 18:07:37 +02:00
|
|
|
fprintf (stderr, "test_curve_security_with_plain_client_credentials\n");
|
2017-08-03 15:15:56 +02:00
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint);
|
2017-08-04 15:11:14 +02:00
|
|
|
test_curve_security_with_plain_client_credentials (ctx, my_endpoint, server,
|
|
|
|
server_mon);
|
2017-08-06 23:56:10 +01:00
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
2017-08-03 15:15:56 +02:00
|
|
|
|
2017-08-07 18:07:37 +02:00
|
|
|
fprintf (stderr, "test_curve_security_unauthenticated_message\n");
|
2017-08-03 15:15:56 +02:00
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint);
|
|
|
|
test_curve_security_unauthenticated_message (my_endpoint, server, timeout);
|
2017-08-06 23:56:10 +01:00
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
2017-08-03 15:15:56 +02:00
|
|
|
|
2017-08-04 12:07:41 +02:00
|
|
|
// Invalid ZAP protocol tests
|
|
|
|
|
|
|
|
// wrong version
|
2017-08-07 18:07:37 +02:00
|
|
|
fprintf (stderr, "test_curve_security_zap_protocol_error wrong_version\n");
|
2017-08-04 12:07:41 +02:00
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint,
|
|
|
|
&zap_handler_wrong_version);
|
|
|
|
test_curve_security_zap_protocol_error (ctx, my_endpoint, server,
|
2017-08-04 16:05:20 +02:00
|
|
|
server_mon);
|
2017-08-06 23:56:10 +01:00
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
2017-08-04 12:07:41 +02:00
|
|
|
|
|
|
|
// wrong request id
|
2017-08-07 18:07:37 +02:00
|
|
|
fprintf (stderr, "test_curve_security_zap_protocol_error wrong_request_id\n");
|
2017-08-04 12:07:41 +02:00
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint,
|
|
|
|
&zap_handler_wrong_request_id);
|
|
|
|
test_curve_security_zap_protocol_error (ctx, my_endpoint, server,
|
2017-08-04 16:05:20 +02:00
|
|
|
server_mon);
|
2017-08-06 23:56:10 +01:00
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
2017-08-04 12:07:41 +02:00
|
|
|
|
|
|
|
// status invalid (not a 3-digit number)
|
2017-08-07 18:07:37 +02:00
|
|
|
fprintf (stderr, "test_curve_security_zap_protocol_error wrong_status_invalid\n");
|
2017-08-04 12:07:41 +02:00
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint,
|
|
|
|
&zap_handler_wrong_status_invalid);
|
|
|
|
test_curve_security_zap_protocol_error (ctx, my_endpoint, server,
|
2017-08-04 16:05:20 +02:00
|
|
|
server_mon);
|
2017-08-06 23:56:10 +01:00
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
2017-08-04 12:07:41 +02:00
|
|
|
|
|
|
|
// too many parts
|
2017-08-07 18:07:37 +02:00
|
|
|
fprintf (stderr, "test_curve_security_zap_protocol_error too_many_parts\n");
|
2017-08-04 12:07:41 +02:00
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint,
|
|
|
|
&zap_handler_too_many_parts);
|
|
|
|
test_curve_security_zap_protocol_error (ctx, my_endpoint, server,
|
2017-08-04 16:05:20 +02:00
|
|
|
server_mon);
|
2017-08-06 23:56:10 +01:00
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
2017-08-04 12:07:41 +02:00
|
|
|
|
|
|
|
// ZAP non-standard cases
|
|
|
|
|
2017-08-08 14:10:20 +02:00
|
|
|
// TODO make these observable on the client side as well (they are
|
|
|
|
// transmitted as an ERROR message)
|
|
|
|
|
|
|
|
// status 300 temporary failure
|
|
|
|
fprintf (stderr, "test_curve_security_zap_unsuccessful status 300\n");
|
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint,
|
|
|
|
&zap_handler_wrong_status_temporary_failure);
|
|
|
|
test_curve_security_zap_unsuccessful (ctx, my_endpoint, server, server_mon,
|
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
|
|
|
ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL,
|
|
|
|
EAGAIN
|
|
|
|
#else
|
|
|
|
0, 0
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
|
|
|
|
2017-08-04 12:07:41 +02:00
|
|
|
// status 500 internal error
|
2017-08-08 14:10:20 +02:00
|
|
|
fprintf (stderr, "test_curve_security_zap_unsuccessful status 500\n");
|
2017-08-04 12:07:41 +02:00
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint,
|
|
|
|
&zap_handler_wrong_status_internal_error);
|
2017-08-04 16:05:20 +02:00
|
|
|
test_curve_security_zap_unsuccessful (ctx, my_endpoint, server, server_mon,
|
2017-08-04 12:07:41 +02:00
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
2017-08-04 16:05:20 +02:00
|
|
|
ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL,
|
2017-08-08 14:10:20 +02:00
|
|
|
EFAULT
|
2017-08-04 12:07:41 +02:00
|
|
|
#else
|
2017-08-04 16:05:20 +02:00
|
|
|
0, 0
|
2017-08-04 12:07:41 +02:00
|
|
|
#endif
|
|
|
|
);
|
2017-08-06 23:56:10 +01:00
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
2017-08-04 12:07:41 +02:00
|
|
|
|
2017-08-15 16:28:24 +02:00
|
|
|
fprintf (stderr, "test_curve_security_invalid_hello_wrong_length\n");
|
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint);
|
|
|
|
test_curve_security_invalid_hello_wrong_length (my_endpoint, server,
|
|
|
|
server_mon, timeout);
|
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
|
|
|
fprintf (stderr, "test_curve_security_invalid_hello_command_name\n");
|
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint);
|
|
|
|
test_curve_security_invalid_hello_command_name (my_endpoint, server,
|
|
|
|
server_mon, timeout);
|
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
|
|
|
|
|
|
|
fprintf (stderr, "test_curve_security_invalid_hello_command_version\n");
|
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint);
|
|
|
|
test_curve_security_invalid_hello_version (my_endpoint, server, server_mon,
|
|
|
|
timeout);
|
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
|
|
|
|
|
|
|
fprintf (stderr, "test_curve_security_invalid_initiate_command_length\n");
|
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint);
|
|
|
|
test_curve_security_invalid_initiate_length (my_endpoint, server,
|
|
|
|
server_mon, timeout);
|
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
|
|
|
|
|
|
|
fprintf (stderr, "test_curve_security_invalid_initiate_command_name\n");
|
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint);
|
|
|
|
test_curve_security_invalid_initiate_command_name (my_endpoint, server,
|
|
|
|
server_mon, timeout);
|
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
|
|
|
|
|
|
|
fprintf (stderr, "test_curve_security_invalid_initiate_command_encrypted_cookie\n");
|
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint);
|
|
|
|
test_curve_security_invalid_initiate_command_encrypted_cookie (
|
|
|
|
my_endpoint, server, server_mon, timeout);
|
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
|
|
|
|
|
|
|
fprintf (stderr, "test_curve_security_invalid_initiate_command_encrypted_content\n");
|
|
|
|
setup_context_and_server_side (&ctx, &handler, &zap_thread, &server,
|
|
|
|
&server_mon, my_endpoint);
|
|
|
|
test_curve_security_invalid_initiate_command_encrypted_content (
|
|
|
|
my_endpoint, server, server_mon, timeout);
|
|
|
|
shutdown_context_and_server_side (ctx, zap_thread, server, server_mon,
|
|
|
|
handler);
|
|
|
|
|
2017-08-03 15:15:56 +02:00
|
|
|
ctx = zmq_ctx_new ();
|
|
|
|
test_curve_security_invalid_keysize (ctx);
|
|
|
|
rc = zmq_ctx_term (ctx);
|
|
|
|
assert (rc == 0);
|
2013-06-22 16:17:25 +01:00
|
|
|
|
2017-08-15 16:28:24 +02:00
|
|
|
zmq::random_close ();
|
|
|
|
|
2013-06-22 16:17:25 +01:00
|
|
|
return 0;
|
|
|
|
}
|