Commit 0ce18eac authored by Luca Boccassi's avatar Luca Boccassi

Problem: CURVE can no longer be used without ZAP

Solution: revert change that made ZAP mandatory.
The "Stonehouse" pattern, where CURVE is used only for encryption and
without authentication, is a valid use case so we should still
support it.
Also restore CURVE testing in the test_heartbeat.

Fixes #2594
parent 33695d1d
...@@ -494,21 +494,23 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_) ...@@ -494,21 +494,23 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
// encryption without authentication), but if it was requested and it does // encryption without authentication), but if it was requested and it does
// not work properly the program will abort. // not work properly the program will abort.
rc = session->zap_connect (); rc = session->zap_connect ();
if (rc != 0) if (rc == 0) {
return -1; rc = send_zap_request (client_key);
rc = send_zap_request (client_key); if (rc != 0)
if (rc != 0) return -1;
return -1; rc = receive_and_process_zap_reply ();
rc = receive_and_process_zap_reply (); if (rc == 0)
if (rc == 0) state = status_code == "200"
state = status_code == "200" ? send_ready
? send_ready : send_error;
: send_error; else
else if (errno == EAGAIN)
if (errno == EAGAIN) state = expect_zap_reply;
state = expect_zap_reply; else
return -1;
}
else else
return -1; state = send_ready;
return parse_metadata (initiate_plaintext + crypto_box_ZEROBYTES + 128, return parse_metadata (initiate_plaintext + crypto_box_ZEROBYTES + 128,
clen - crypto_box_ZEROBYTES - 128); clen - crypto_box_ZEROBYTES - 128);
......
...@@ -102,7 +102,32 @@ mock_handshake (raw_socket fd) { ...@@ -102,7 +102,32 @@ mock_handshake (raw_socket fd) {
} }
static void static void
prep_server_socket(void * ctx, int set_heartbeats, void ** server_out, void ** mon_out, setup_curve (void * socket, int is_server) {
const char *secret_key;
const char *public_key;
const char *server_key;
if (is_server) {
secret_key = "JTKVSB%%)wK0E.X)V>+}o?pNmC{O&4W4b!Ni{Lh6";
public_key = "rq:rM>}U?@Lns47E1%kR.o@n%FcmmsL/@{H8]yf7";
server_key = NULL;
}
else {
secret_key = "D:)Q[IlAW!ahhC2ac:9*A}h:p?([4%wOTJ%JR%cs";
public_key = "Yne@$w-vo<fVvi]a<NY6T1ed:M$fCG*[IaLV{hID";
server_key = "rq:rM>}U?@Lns47E1%kR.o@n%FcmmsL/@{H8]yf7";
}
zmq_setsockopt (socket, ZMQ_CURVE_SECRETKEY, secret_key, strlen(secret_key));
zmq_setsockopt (socket, ZMQ_CURVE_PUBLICKEY, public_key, strlen(public_key));
if (is_server)
zmq_setsockopt (socket, ZMQ_CURVE_SERVER, &is_server, sizeof(is_server));
else
zmq_setsockopt (socket, ZMQ_CURVE_SERVERKEY, server_key, strlen(server_key));
}
static void
prep_server_socket(void * ctx, int set_heartbeats, int is_curve, void ** server_out, void ** mon_out,
char *endpoint, size_t ep_length) char *endpoint, size_t ep_length)
{ {
int rc; int rc;
...@@ -120,6 +145,9 @@ prep_server_socket(void * ctx, int set_heartbeats, void ** server_out, void ** m ...@@ -120,6 +145,9 @@ prep_server_socket(void * ctx, int set_heartbeats, void ** server_out, void ** m
assert (rc == 0); assert (rc == 0);
} }
if (is_curve)
setup_curve(server, 1);
rc = zmq_bind (server, "tcp://127.0.0.1:*"); rc = zmq_bind (server, "tcp://127.0.0.1:*");
assert (rc == 0); assert (rc == 0);
rc = zmq_getsockopt (server, ZMQ_LAST_ENDPOINT, endpoint, &ep_length); rc = zmq_getsockopt (server, ZMQ_LAST_ENDPOINT, endpoint, &ep_length);
...@@ -155,7 +183,7 @@ test_heartbeat_timeout (void) ...@@ -155,7 +183,7 @@ test_heartbeat_timeout (void)
assert (ctx); assert (ctx);
void * server, * server_mon; void * server, * server_mon;
prep_server_socket (ctx, 1, &server, &server_mon, my_endpoint, prep_server_socket (ctx, 1, 0, &server, &server_mon, my_endpoint,
MAX_SOCKET_STRING); MAX_SOCKET_STRING);
struct sockaddr_in ip4addr; struct sockaddr_in ip4addr;
...@@ -212,7 +240,7 @@ test_heartbeat_ttl (void) ...@@ -212,7 +240,7 @@ test_heartbeat_ttl (void)
assert (ctx); assert (ctx);
void * server, * server_mon, *client; void * server, * server_mon, *client;
prep_server_socket (ctx, 0, &server, &server_mon, my_endpoint, prep_server_socket (ctx, 0, 0, &server, &server_mon, my_endpoint,
MAX_SOCKET_STRING); MAX_SOCKET_STRING);
client = zmq_socket (ctx, ZMQ_DEALER); client = zmq_socket (ctx, ZMQ_DEALER);
...@@ -259,7 +287,7 @@ test_heartbeat_ttl (void) ...@@ -259,7 +287,7 @@ test_heartbeat_ttl (void)
// exchanged normally. There should be an accepted event on the server, // exchanged normally. There should be an accepted event on the server,
// and then no event afterwards. // and then no event afterwards.
static void static void
test_heartbeat_notimeout (void) test_heartbeat_notimeout (int is_curve)
{ {
int rc; int rc;
char my_endpoint[MAX_SOCKET_STRING]; char my_endpoint[MAX_SOCKET_STRING];
...@@ -269,10 +297,12 @@ test_heartbeat_notimeout (void) ...@@ -269,10 +297,12 @@ test_heartbeat_notimeout (void)
assert (ctx); assert (ctx);
void * server, * server_mon; void * server, * server_mon;
prep_server_socket(ctx, 1, &server, &server_mon, my_endpoint, prep_server_socket(ctx, 1, is_curve, &server, &server_mon, my_endpoint,
MAX_SOCKET_STRING); MAX_SOCKET_STRING);
void * client = zmq_socket (ctx, ZMQ_DEALER); void * client = zmq_socket (ctx, ZMQ_DEALER);
if (is_curve)
setup_curve(client, 0);
rc = zmq_connect (client, my_endpoint); rc = zmq_connect (client, my_endpoint);
// Give it a sec to connect and handshake // Give it a sec to connect and handshake
...@@ -304,5 +334,8 @@ int main (void) ...@@ -304,5 +334,8 @@ int main (void)
setup_test_environment (); setup_test_environment ();
test_heartbeat_timeout (); test_heartbeat_timeout ();
test_heartbeat_ttl (); test_heartbeat_ttl ();
test_heartbeat_notimeout (); // Run this test without curve
test_heartbeat_notimeout (0);
// Then rerun it with curve
test_heartbeat_notimeout (1);
} }
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