SETUP_TEARDOWN_TESTCONTEXT void test_reconnect_ivl_against_pair_socket (const char *my_endpoint_, void *sb_) { void *sc = test_context_socket (ZMQ_PAIR); int interval = -1; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (sc, ZMQ_RECONNECT_IVL, &interval, sizeof (int))); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint_)); bounce (sb_, sc); TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb_, my_endpoint_)); expect_bounce_fail (sb_, sc); TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb_, my_endpoint_)); expect_bounce_fail (sb_, sc); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, my_endpoint_)); bounce (sb_, sc); test_context_socket_close (sc); }
void test_plain_wrong_credentials_fails () { // Check PLAIN security -- failed authentication void *client = test_context_socket (ZMQ_DEALER); const char username[] = "wronguser"; const char password[] = "wrongpass"; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client, ZMQ_PLAIN_USERNAME, username, strlen (username))); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client, ZMQ_PLAIN_PASSWORD, password, strlen (password))); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, my_endpoint)); expect_bounce_fail (server, client); test_context_socket_close_zero_linger (client); }
void test_plain_client_as_server_fails () { // Check PLAIN security with badly configured client (as_server) // This will be caught by the plain_server class, not passed to ZAP void *client = test_context_socket (ZMQ_DEALER); TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client, ZMQ_ZAP_DOMAIN, domain, strlen (domain))); const int as_server = 1; TEST_ASSERT_SUCCESS_ERRNO ( zmq_setsockopt (client, ZMQ_PLAIN_SERVER, &as_server, sizeof (int))); TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client, my_endpoint)); expect_bounce_fail (server, client); test_context_socket_close_zero_linger (client); }
int main (void) { setup_test_environment(); void *ctx = zmq_ctx_new (); assert (ctx); // Spawn ZAP handler // We create and bind ZAP socket in main thread to avoid case // where child thread does not start up fast enough. void *handler = zmq_socket (ctx, ZMQ_REP); assert (handler); int rc = zmq_bind (handler, "inproc://zeromq.zap.01"); assert (rc == 0); void *zap_thread = zmq_threadstart (&zap_handler, handler); // We bounce between a binding server and a connecting client // We first test client/server with no ZAP domain // Libzmq does not call our ZAP handler, the connect must succeed void *server = zmq_socket (ctx, ZMQ_DEALER); assert (server); void *client = zmq_socket (ctx, ZMQ_DEALER); assert (client); rc = zmq_bind (server, "tcp://127.0.0.1:9000"); assert (rc == 0); rc = zmq_connect (client, "tcp://127.0.0.1:9000"); assert (rc == 0); bounce (server, client); close_zero_linger (client); close_zero_linger (server); // Now define a ZAP domain for the server; this enables // authentication. We're using the wrong domain so this test // must fail. server = zmq_socket (ctx, ZMQ_DEALER); assert (server); client = zmq_socket (ctx, ZMQ_DEALER); assert (client); rc = zmq_setsockopt (server, ZMQ_ZAP_DOMAIN, "WRONG", 5); assert (rc == 0); rc = zmq_bind (server, "tcp://127.0.0.1:9001"); assert (rc == 0); rc = zmq_connect (client, "tcp://127.0.0.1:9001"); assert (rc == 0); expect_bounce_fail (server, client); close_zero_linger (client); close_zero_linger (server); // Now use the right domain, the test must pass server = zmq_socket (ctx, ZMQ_DEALER); assert (server); client = zmq_socket (ctx, ZMQ_DEALER); assert (client); rc = zmq_setsockopt (server, ZMQ_ZAP_DOMAIN, "TEST", 4); assert (rc == 0); rc = zmq_bind (server, "tcp://127.0.0.1:9002"); assert (rc == 0); rc = zmq_connect (client, "tcp://127.0.0.1:9002"); assert (rc == 0); bounce (server, client); close_zero_linger (client); close_zero_linger (server); // Shutdown rc = zmq_ctx_term (ctx); assert (rc == 0); // Wait until ZAP handler terminates zmq_threadclose (zap_thread); return 0; }
int main (void) { #ifndef HAVE_LIBSODIUM printf ("libsodium not installed, skipping CURVE test\n"); return 0; #endif // Generate new keypairs for this test int rc = zmq_curve_keypair (client_public, client_secret); assert (rc == 0); rc = zmq_curve_keypair (server_public, server_secret); assert (rc == 0); setup_test_environment (); void *ctx = zmq_ctx_new (); assert (ctx); // Spawn ZAP handler // We create and bind ZAP socket in main thread to avoid case // where child thread does not start up fast enough. void *handler = zmq_socket (ctx, ZMQ_REP); assert (handler); rc = zmq_bind (handler, "inproc://zeromq.zap.01"); assert (rc == 0); void *zap_thread = zmq_threadstart (&zap_handler, handler); // Server socket will accept connections void *server = zmq_socket (ctx, ZMQ_DEALER); assert (server); int as_server = 1; rc = zmq_setsockopt (server, ZMQ_CURVE_SERVER, &as_server, sizeof (int)); assert (rc == 0); rc = zmq_setsockopt (server, ZMQ_CURVE_SECRETKEY, server_secret, 40); assert (rc == 0); rc = zmq_setsockopt (server, ZMQ_IDENTITY, "IDENT", 6); assert (rc == 0); rc = zmq_bind (server, "tcp://127.0.0.1:9998"); assert (rc == 0); // Check CURVE security with valid credentials void *client = zmq_socket (ctx, ZMQ_DEALER); assert (client); rc = zmq_setsockopt (client, ZMQ_CURVE_SERVERKEY, server_public, 40); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_CURVE_PUBLICKEY, client_public, 40); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_CURVE_SECRETKEY, client_secret, 40); assert (rc == 0); rc = zmq_connect (client, "tcp://localhost:9998"); assert (rc == 0); bounce (server, client); rc = zmq_close (client); assert (rc == 0); // Check CURVE security with a garbage server key // This will be caught by the curve_server class, not passed to ZAP char garbage_key [] = "0000111122223333444455556666777788889999"; client = zmq_socket (ctx, ZMQ_DEALER); assert (client); rc = zmq_setsockopt (client, ZMQ_CURVE_SERVERKEY, garbage_key, 40); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_CURVE_PUBLICKEY, client_public, 40); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_CURVE_SECRETKEY, client_secret, 40); assert (rc == 0); rc = zmq_connect (client, "tcp://localhost:9998"); assert (rc == 0); expect_bounce_fail (server, client); close_zero_linger (client); // Check CURVE security with a garbage client public key // This will be caught by the curve_server class, not passed to ZAP client = zmq_socket (ctx, ZMQ_DEALER); assert (client); rc = zmq_setsockopt (client, ZMQ_CURVE_SERVERKEY, server_public, 40); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_CURVE_PUBLICKEY, garbage_key, 40); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_CURVE_SECRETKEY, client_secret, 40); assert (rc == 0); rc = zmq_connect (client, "tcp://localhost:9998"); assert (rc == 0); expect_bounce_fail (server, client); close_zero_linger (client); // Check CURVE security with a garbage client secret key // This will be caught by the curve_server class, not passed to ZAP client = zmq_socket (ctx, ZMQ_DEALER); assert (client); rc = zmq_setsockopt (client, ZMQ_CURVE_SERVERKEY, server_public, 40); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_CURVE_PUBLICKEY, client_public, 40); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_CURVE_SECRETKEY, garbage_key, 40); assert (rc == 0); rc = zmq_connect (client, "tcp://localhost:9998"); assert (rc == 0); expect_bounce_fail (server, client); close_zero_linger (client); // Check CURVE security with bogus client credentials // This must be caught by the ZAP handler char bogus_public [40]; char bogus_secret [40]; zmq_curve_keypair (bogus_public, bogus_secret); client = zmq_socket (ctx, ZMQ_DEALER); assert (client); rc = zmq_setsockopt (client, ZMQ_CURVE_SERVERKEY, server_public, 40); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_CURVE_PUBLICKEY, bogus_public, 40); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_CURVE_SECRETKEY, bogus_secret, 40); assert (rc == 0); rc = zmq_connect (client, "tcp://localhost:9998"); assert (rc == 0); 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); rc = zmq_ctx_term (ctx); assert (rc == 0); // Wait until ZAP handler terminates zmq_threadclose (zap_thread); return 0; }
int main (void) { setup_test_environment(); void *ctx = zmq_ctx_new (); assert (ctx); // Spawn ZAP handler // We create and bind ZAP socket in main thread to avoid case // where child thread does not start up fast enough. void *handler = zmq_socket (ctx, ZMQ_REP); assert (handler); int rc = zmq_bind (handler, "inproc://zeromq.zap.01"); assert (rc == 0); void *zap_thread = zmq_threadstart (&zap_handler, handler); // We bounce between a binding server and a connecting client // We first test client/server with no ZAP domain // Libzmq does not call our ZAP handler, the connect must succeed void *server = zmq_socket (ctx, ZMQ_DEALER); assert (server); void *client = zmq_socket (ctx, ZMQ_DEALER); assert (client); rc = zmq_bind (server, "tcp://127.0.0.1:9000"); assert (rc == 0); rc = zmq_connect (client, "tcp://127.0.0.1:9000"); assert (rc == 0); bounce (server, client); close_zero_linger (client); close_zero_linger (server); // Now define a ZAP domain for the server; this enables // authentication. We're using the wrong domain so this test // must fail. server = zmq_socket (ctx, ZMQ_DEALER); assert (server); client = zmq_socket (ctx, ZMQ_DEALER); assert (client); rc = zmq_setsockopt (server, ZMQ_ZAP_DOMAIN, "WRONG", 5); assert (rc == 0); rc = zmq_bind (server, "tcp://127.0.0.1:9001"); assert (rc == 0); rc = zmq_connect (client, "tcp://127.0.0.1:9001"); assert (rc == 0); expect_bounce_fail (server, client); close_zero_linger (client); close_zero_linger (server); // Now use the right domain, the test must pass server = zmq_socket (ctx, ZMQ_DEALER); assert (server); client = zmq_socket (ctx, ZMQ_DEALER); assert (client); rc = zmq_setsockopt (server, ZMQ_ZAP_DOMAIN, "TEST", 4); assert (rc == 0); rc = zmq_bind (server, "tcp://127.0.0.1:9002"); assert (rc == 0); rc = zmq_connect (client, "tcp://127.0.0.1:9002"); assert (rc == 0); bounce (server, client); close_zero_linger (client); close_zero_linger (server); // Unauthenticated messages from a vanilla socket shouldn't be received server = zmq_socket (ctx, ZMQ_DEALER); assert (server); rc = zmq_setsockopt (server, ZMQ_ZAP_DOMAIN, "WRONG", 5); assert (rc == 0); rc = zmq_bind (server, "tcp://127.0.0.1:9003"); assert (rc == 0); struct sockaddr_in ip4addr; int s; ip4addr.sin_family = AF_INET; ip4addr.sin_port = htons(9003); #if (_WIN32_WINNT < 0x0600) ip4addr.sin_addr.s_addr = inet_addr ("127.0.0.1"); #else inet_pton(AF_INET, "127.0.0.1", &ip4addr.sin_addr); #endif s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); rc = connect (s, (struct sockaddr*) &ip4addr, sizeof ip4addr); assert (rc > -1); // 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); int timeout = 250; zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof (timeout)); char *buf = s_recv (server); if (buf != NULL) { printf ("Received unauthenticated message: %s\n", buf); assert (buf == NULL); } close (s); close_zero_linger (server); // Shutdown rc = zmq_ctx_term (ctx); assert (rc == 0); // Wait until ZAP handler terminates zmq_threadclose (zap_thread); return 0; }
int main (void) { setup_test_environment(); void *ctx = zmq_ctx_new (); assert (ctx); // Spawn ZAP handler void *zap_thread = zmq_threadstart (&zap_handler, ctx); // Server socket will accept connections void *server = zmq_socket (ctx, ZMQ_DEALER); assert (server); int rc = zmq_setsockopt (server, ZMQ_IDENTITY, "IDENT", 6); assert (rc == 0); int as_server = 1; rc = zmq_setsockopt (server, ZMQ_PLAIN_SERVER, &as_server, sizeof (int)); assert (rc == 0); rc = zmq_bind (server, "tcp://127.0.0.1:9998"); assert (rc == 0); char username [256]; char password [256]; // Check PLAIN security with correct username/password void *client = zmq_socket (ctx, ZMQ_DEALER); assert (client); strcpy (username, "admin"); rc = zmq_setsockopt (client, ZMQ_PLAIN_USERNAME, username, strlen (username)); assert (rc == 0); strcpy (password, "password"); rc = zmq_setsockopt (client, ZMQ_PLAIN_PASSWORD, password, strlen (password)); assert (rc == 0); rc = zmq_connect (client, "tcp://localhost:9998"); assert (rc == 0); bounce (server, client); rc = zmq_close (client); assert (rc == 0); // Check PLAIN security with badly configured client (as_server) // This will be caught by the plain_server class, not passed to ZAP client = zmq_socket (ctx, ZMQ_DEALER); assert (client); as_server = 1; rc = zmq_setsockopt (client, ZMQ_PLAIN_SERVER, &as_server, sizeof (int)); assert (rc == 0); rc = zmq_connect (client, "tcp://localhost:9998"); assert (rc == 0); expect_bounce_fail (server, client); close_zero_linger (client); // Check PLAIN security -- failed authentication client = zmq_socket (ctx, ZMQ_DEALER); assert (client); strcpy (username, "wronguser"); strcpy (password, "wrongpass"); rc = zmq_setsockopt (client, ZMQ_PLAIN_USERNAME, username, strlen (username)); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_PLAIN_PASSWORD, password, strlen (password)); assert (rc == 0); rc = zmq_connect (client, "tcp://localhost:9998"); assert (rc == 0); expect_bounce_fail (server, client); close_zero_linger (client); // Unauthenticated messages from a vanilla socket shouldn't be received struct sockaddr_in ip4addr; int s; ip4addr.sin_family = AF_INET; ip4addr.sin_port = htons (9998); inet_pton (AF_INET, "127.0.0.1", &ip4addr.sin_addr); s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); rc = connect (s, (struct sockaddr*) &ip4addr, sizeof (ip4addr)); assert (rc > -1); // 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); int timeout = 250; zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof (timeout)); char *buf = s_recv (server); if (buf != NULL) { printf ("Received unauthenticated message: %s\n", buf); assert (buf == NULL); } close (s); // Shutdown rc = zmq_close (server); assert (rc == 0); rc = zmq_ctx_term (ctx); assert (rc == 0); // Wait until ZAP handler terminates zmq_threadclose (zap_thread); return 0; }
int main (void) { setup_test_environment(); void *ctx = zmq_ctx_new (); assert (ctx); // Spawn ZAP handler void *zap_thread = zmq_threadstart (&zap_handler, ctx); // Server socket will accept connections void *server = zmq_socket (ctx, ZMQ_DEALER); assert (server); int rc = zmq_setsockopt (server, ZMQ_IDENTITY, "IDENT", 6); assert (rc == 0); int as_server = 1; rc = zmq_setsockopt (server, ZMQ_PLAIN_SERVER, &as_server, sizeof (int)); assert (rc == 0); rc = zmq_bind (server, "tcp://127.0.0.1:9998"); assert (rc == 0); char username [256]; char password [256]; // Check PLAIN security with correct username/password void *client = zmq_socket (ctx, ZMQ_DEALER); assert (client); strcpy (username, "admin"); rc = zmq_setsockopt (client, ZMQ_PLAIN_USERNAME, username, strlen (username)); assert (rc == 0); strcpy (password, "password"); rc = zmq_setsockopt (client, ZMQ_PLAIN_PASSWORD, password, strlen (password)); assert (rc == 0); rc = zmq_connect (client, "tcp://localhost:9998"); assert (rc == 0); bounce (server, client); rc = zmq_close (client); assert (rc == 0); // Check PLAIN security with badly configured client (as_server) // This will be caught by the plain_server class, not passed to ZAP client = zmq_socket (ctx, ZMQ_DEALER); assert (client); as_server = 1; rc = zmq_setsockopt (client, ZMQ_PLAIN_SERVER, &as_server, sizeof (int)); assert (rc == 0); rc = zmq_connect (client, "tcp://localhost:9998"); assert (rc == 0); expect_bounce_fail (server, client); close_zero_linger (client); // Check PLAIN security -- failed authentication client = zmq_socket (ctx, ZMQ_DEALER); assert (client); strcpy (username, "wronguser"); strcpy (password, "wrongpass"); rc = zmq_setsockopt (client, ZMQ_PLAIN_USERNAME, username, strlen (username)); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_PLAIN_PASSWORD, password, strlen (password)); assert (rc == 0); rc = zmq_connect (client, "tcp://localhost:9998"); assert (rc == 0); expect_bounce_fail (server, client); close_zero_linger (client); // Shutdown rc = zmq_close (server); assert (rc == 0); rc = zmq_ctx_term (ctx); assert (rc == 0); // Wait until ZAP handler terminates zmq_threadclose (zap_thread); return 0; }
int main (void) { #ifndef HAVE_LIBSODIUM printf ("libsodium not installed, skipping CURVE test\n"); return 0; #endif // Generate new keypairs for this test int rc = zmq_curve_keypair (client_public, client_secret); assert (rc == 0); rc = zmq_curve_keypair (server_public, server_secret); assert (rc == 0); setup_test_environment (); void *ctx = zmq_ctx_new (); assert (ctx); // Spawn ZAP handler // We create and bind ZAP socket in main thread to avoid case // where child thread does not start up fast enough. void *handler = zmq_socket (ctx, ZMQ_REP); assert (handler); rc = zmq_bind (handler, "inproc://zeromq.zap.01"); assert (rc == 0); void *zap_thread = zmq_threadstart (&zap_handler, handler); // Server socket will accept connections void *server = zmq_socket (ctx, ZMQ_DEALER); assert (server); int as_server = 1; rc = zmq_setsockopt (server, ZMQ_CURVE_SERVER, &as_server, sizeof (int)); assert (rc == 0); rc = zmq_setsockopt (server, ZMQ_CURVE_SECRETKEY, server_secret, 41); assert (rc == 0); rc = zmq_setsockopt (server, ZMQ_IDENTITY, "IDENT", 6); assert (rc == 0); rc = zmq_bind (server, "tcp://127.0.0.1:9998"); assert (rc == 0); // Check CURVE security with valid credentials void *client = zmq_socket (ctx, ZMQ_DEALER); assert (client); rc = zmq_setsockopt (client, ZMQ_CURVE_SERVERKEY, server_public, 41); assert (rc == 0); 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, "tcp://localhost:9998"); assert (rc == 0); bounce (server, client); rc = zmq_close (client); assert (rc == 0); // Check CURVE security with a garbage server key // This will be caught by the curve_server class, not passed to ZAP char garbage_key [] = "0000111122223333444455556666777788889999"; client = zmq_socket (ctx, ZMQ_DEALER); assert (client); rc = zmq_setsockopt (client, ZMQ_CURVE_SERVERKEY, garbage_key, 41); assert (rc == 0); 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, "tcp://localhost:9998"); assert (rc == 0); expect_bounce_fail (server, client); close_zero_linger (client); // Check CURVE security with a garbage client public key // This will be caught by the curve_server class, not passed to ZAP client = zmq_socket (ctx, ZMQ_DEALER); assert (client); rc = zmq_setsockopt (client, ZMQ_CURVE_SERVERKEY, server_public, 41); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_CURVE_PUBLICKEY, garbage_key, 41); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_CURVE_SECRETKEY, client_secret, 41); assert (rc == 0); rc = zmq_connect (client, "tcp://localhost:9998"); assert (rc == 0); expect_bounce_fail (server, client); close_zero_linger (client); // Check CURVE security with a garbage client secret key // This will be caught by the curve_server class, not passed to ZAP client = zmq_socket (ctx, ZMQ_DEALER); assert (client); rc = zmq_setsockopt (client, ZMQ_CURVE_SERVERKEY, server_public, 41); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_CURVE_PUBLICKEY, client_public, 41); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_CURVE_SECRETKEY, garbage_key, 41); assert (rc == 0); rc = zmq_connect (client, "tcp://localhost:9998"); assert (rc == 0); expect_bounce_fail (server, client); close_zero_linger (client); // Check CURVE security with bogus client credentials // This must be caught by the ZAP handler char bogus_public [41]; char bogus_secret [41]; zmq_curve_keypair (bogus_public, bogus_secret); client = zmq_socket (ctx, ZMQ_DEALER); assert (client); rc = zmq_setsockopt (client, ZMQ_CURVE_SERVERKEY, server_public, 41); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_CURVE_PUBLICKEY, bogus_public, 41); assert (rc == 0); rc = zmq_setsockopt (client, ZMQ_CURVE_SECRETKEY, bogus_secret, 41); assert (rc == 0); rc = zmq_connect (client, "tcp://localhost:9998"); assert (rc == 0); 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); // Unauthenticated messages from a vanilla socket shouldn't be received struct sockaddr_in ip4addr; int s; ip4addr.sin_family = AF_INET; ip4addr.sin_port = htons (9998); #if (_WIN32_WINNT < 0x0600) ip4addr.sin_addr.s_addr = inet_addr ("127.0.0.1"); #else inet_pton(AF_INET, "127.0.0.1", &ip4addr.sin_addr); #endif s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); rc = connect (s, (struct sockaddr*) &ip4addr, sizeof (ip4addr)); assert (rc > -1); // 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); int timeout = 250; zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof (timeout)); char *buf = s_recv (server); if (buf != NULL) { printf ("Received unauthenticated message: %s\n", buf); assert (buf == NULL); } close (s); // Check return codes for invalid buffer sizes client = zmq_socket (ctx, ZMQ_DEALER); assert (client); errno = 0; rc = zmq_setsockopt (client, ZMQ_CURVE_SERVERKEY, server_public, 123); assert (rc == -1 && errno == EINVAL); errno = 0; rc = zmq_setsockopt (client, ZMQ_CURVE_PUBLICKEY, client_public, 123); assert (rc == -1 && errno == EINVAL); errno = 0; rc = zmq_setsockopt (client, ZMQ_CURVE_SECRETKEY, client_secret, 123); assert (rc == -1 && errno == EINVAL); rc = zmq_close (client); assert (rc == 0); // Shutdown rc = zmq_close (server); assert (rc == 0); rc = zmq_ctx_term (ctx); assert (rc == 0); // Wait until ZAP handler terminates zmq_threadclose (zap_thread); return 0; }