libzmq/tests/test_security_curve.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

578 lines
18 KiB
C++
Raw Normal View History

/* SPDX-License-Identifier: MPL-2.0 */
// TODO remove this workaround for handling libsodium
// To define SIZE_MAX with older compilers
#define __STDC_LIMIT_MACROS
#if defined ZMQ_CUSTOM_PLATFORM_HPP
#include "platform.hpp"
#else
#include "../src/platform.hpp"
#endif
#ifndef ZMQ_USE_LIBSODIUM
#define ZMQ_USE_LIBSODIUM
#endif
#include "testutil.hpp"
#include "testutil_security.hpp"
#include <unity.h>
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
#include "../src/curve_client_tools.hpp"
#include "../src/random.hpp"
char error_message_buffer[256];
void *handler;
void *zap_thread;
void *server;
void *server_mon;
char my_endpoint[MAX_SOCKET_STRING];
void setUp ()
{
setup_test_context ();
setup_context_and_server_side (&handler, &zap_thread, &server, &server_mon,
my_endpoint);
}
void tearDown ()
{
shutdown_context_and_server_side (zap_thread, server, server_mon, handler);
teardown_test_context ();
}
const int timeout = 250;
const char large_routing_id[] = "0123456789012345678901234567890123456789"
"0123456789012345678901234567890123456789"
"0123456789012345678901234567890123456789"
"0123456789012345678901234567890123456789"
"0123456789012345678901234567890123456789"
"0123456789012345678901234567890123456789"
"012345678901234";
static void zap_handler_large_routing_id (void * /*unused_*/)
{
zap_handler_generic (zap_ok, large_routing_id);
}
void expect_new_client_curve_bounce_fail (const char *server_public_,
const char *client_public_,
const char *client_secret_,
char *my_endpoint_,
void *server_,
void **client_mon_ = NULL,
int expected_client_event_ = 0,
int expected_client_value_ = 0)
{
curve_client_data_t curve_client_data = {server_public_, client_public_,
client_secret_};
expect_new_client_bounce_fail (
my_endpoint_, server_, socket_config_curve_client, &curve_client_data,
client_mon_, expected_client_event_, expected_client_value_);
}
void test_null_key (void *server_,
void *server_mon_,
char *my_endpoint_,
char *server_public_,
char *client_public_,
char *client_secret_)
{
expect_new_client_curve_bounce_fail (server_public_, client_public_,
client_secret_, my_endpoint_, server_);
int handshake_failed_encryption_event_count =
expect_monitor_event_multiple (server_mon_,
ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL,
ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
// handshake_failed_encryption_event_count should be at least two because
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
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)
fprintf (stderr,
"count of "
"ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL/"
"ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC events: %i\n",
handshake_failed_encryption_event_count);
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
}
void test_curve_security_with_valid_credentials ()
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
{
curve_client_data_t curve_client_data = {
valid_server_public, valid_client_public, valid_client_secret};
void *client_mon;
void *client = create_and_connect_client (
my_endpoint, socket_config_curve_client, &curve_client_data, &client_mon);
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
bounce (server, client);
test_context_socket_close (client);
int event = get_monitor_event_with_timeout (server_mon, NULL, NULL, -1);
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
assert (event == ZMQ_EVENT_HANDSHAKE_SUCCEEDED);
assert_no_more_monitor_events_with_timeout (server_mon, timeout);
event = get_monitor_event_with_timeout (client_mon, NULL, NULL, -1);
assert (event == ZMQ_EVENT_HANDSHAKE_SUCCEEDED);
assert_no_more_monitor_events_with_timeout (client_mon, timeout);
test_context_socket_close (client_mon);
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
}
void test_curve_security_with_bogus_client_credentials ()
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
{
// This must be caught by the ZAP handler
char bogus_public[41];
char bogus_secret[41];
zmq_curve_keypair (bogus_public, bogus_secret);
expect_new_client_curve_bounce_fail (
valid_server_public, bogus_public, bogus_secret, my_endpoint, server,
NULL, ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, 400);
int server_event_count = 0;
server_event_count = expect_monitor_event_multiple (
server_mon, ZMQ_EVENT_HANDSHAKE_FAILED_AUTH, 400);
TEST_ASSERT_LESS_OR_EQUAL_INT (1, server_event_count);
// there may be more than one ZAP request due to repeated attempts by the client
TEST_ASSERT (0 == server_event_count
|| 1 <= zmq_atomic_counter_value (zap_requests_handled));
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
}
void expect_zmtp_mechanism_mismatch (void *client_,
char *my_endpoint_,
void *server_,
void *server_mon_)
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
{
// This must be caught by the curve_server class, not passed to ZAP
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (client_, my_endpoint_));
expect_bounce_fail (server_, client_);
test_context_socket_close_zero_linger (client_);
expect_monitor_event_multiple (server_mon_,
ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL,
ZMQ_PROTOCOL_ERROR_ZMTP_MECHANISM_MISMATCH);
TEST_ASSERT_EQUAL_INT (0, zmq_atomic_counter_value (zap_requests_handled));
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
}
void test_curve_security_with_null_client_credentials ()
{
void *client = test_context_socket (ZMQ_DEALER);
expect_zmtp_mechanism_mismatch (client, my_endpoint, server, server_mon);
}
void test_curve_security_with_plain_client_credentials ()
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
{
void *client = test_context_socket (ZMQ_DEALER);
TEST_ASSERT_SUCCESS_ERRNO (
zmq_setsockopt (client, ZMQ_PLAIN_USERNAME, "admin", 5));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_setsockopt (client, ZMQ_PLAIN_PASSWORD, "password", 8));
expect_zmtp_mechanism_mismatch (client, my_endpoint, server, server_mon);
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
}
2014-11-07 17:35:41 +01:00
void test_curve_security_unauthenticated_message ()
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
// Unauthenticated messages from a vanilla socket shouldn't be received
fd_t s = connect_socket (my_endpoint);
// 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);
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof (timeout));
char *buf = s_recv (server);
TEST_ASSERT_NULL_MESSAGE (buf, "Received unauthenticated message");
close (s);
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
}
void send_all (fd_t fd_, const char *data_, socket_size_t size_)
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
while (size_ > 0) {
int res = send (fd_, data_, size_, 0);
TEST_ASSERT_GREATER_THAN_INT (0, res);
size_ -= res;
data_ += res;
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
}
}
template <size_t N> void send (fd_t fd_, const char (&data_)[N])
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
send_all (fd_, data_, N - 1);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
}
template <size_t N> void send (fd_t fd_, const uint8_t (&data_)[N])
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
send_all (fd_, reinterpret_cast<const char *> (&data_), N);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
}
void test_curve_security_invalid_hello_wrong_length ()
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
fd_t s = connect_socket (my_endpoint);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
send (s, zmtp_greeting_curve);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
// send CURVE HELLO of wrong size
send (s, "\x04\x06\x05HELLO");
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
expect_monitor_event_multiple (
server_mon, ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL,
ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_HELLO);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
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);
}
// same as htonll, which is only available on few platforms (recent Windows, but not on Linux, e.g.(
static uint64_t host_to_network (uint64_t value_)
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
// 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));
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
const uint32_t low_part =
htonl (static_cast<uint32_t> (value_ & 0xFFFFFFFFLL));
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
return (static_cast<uint64_t> (low_part) << 32) | high_part;
}
return value_;
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
}
template <size_t N> void send_command (fd_t s_, char (&command_)[N])
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
if (N < 256) {
send (s_, "\x04");
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
char len = (char) N;
send_all (s_, &len, 1);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
} else {
send (s_, "\x06");
uint64_t len = host_to_network (N);
send_all (s_, reinterpret_cast<char *> (&len), 8);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
}
send_all (s_, command_, N);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
}
void test_curve_security_invalid_hello_command_name ()
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
fd_t s = connect_socket (my_endpoint);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
send (s, zmtp_greeting_curve);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
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];
TEST_ASSERT_SUCCESS_ERRNO (tools.produce_hello (hello, 0));
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
hello[5] = 'X';
send_command (s, hello);
expect_monitor_event_multiple (server_mon,
ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL,
ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
close (s);
}
void test_curve_security_invalid_hello_version ()
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
fd_t s = connect_socket (my_endpoint);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
send (s, zmtp_greeting_curve);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
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];
TEST_ASSERT_SUCCESS_ERRNO (tools.produce_hello (hello, 0));
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
hello[6] = 2;
send_command (s, hello);
expect_monitor_event_multiple (
server_mon, ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL,
ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_HELLO);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
close (s);
}
void flush_read (fd_t fd_)
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
int res;
char buf[256];
while ((res = recv (fd_, buf, 256, 0)) == 256) {
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
}
TEST_ASSERT_NOT_EQUAL (-1, res);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
}
void recv_all (fd_t fd_, uint8_t *data_, socket_size_t len_)
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
socket_size_t received = 0;
while (received < len_) {
int res = recv (fd_, reinterpret_cast<char *> (data_), len_, 0);
TEST_ASSERT_GREATER_THAN_INT (0, res);
data_ += res;
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
received += res;
}
}
void recv_greeting (fd_t fd_)
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
uint8_t greeting[64];
recv_all (fd_, greeting, 64);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
// TODO assert anything about the greeting received from the server?
}
fd_t connect_exchange_greeting_and_send_hello (
char *my_endpoint_, zmq::curve_client_tools_t &tools_)
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
fd_t s = connect_socket (my_endpoint_);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
send (s, zmtp_greeting_curve);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
recv_greeting (s);
// send valid CURVE HELLO
char hello[hello_length];
TEST_ASSERT_SUCCESS_ERRNO (tools_.produce_hello (hello, 0));
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
send_command (s, hello);
return s;
}
void test_curve_security_invalid_initiate_wrong_length ()
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
zmq::curve_client_tools_t tools = make_curve_client_tools ();
fd_t s = connect_exchange_greeting_and_send_hello (my_endpoint, tools);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
// receive but ignore WELCOME
flush_read (s);
int res = get_monitor_event_with_timeout (server_mon, NULL, NULL, timeout);
TEST_ASSERT_EQUAL_INT (-1, res);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
send (s, "\x04\x09\x08INITIATE");
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
expect_monitor_event_multiple (
server_mon, ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL,
ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_INITIATE);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
close (s);
}
fd_t connect_exchange_greeting_and_hello_welcome (
char *my_endpoint_,
void *server_mon_,
int timeout_,
zmq::curve_client_tools_t &tools_)
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
fd_t s = connect_exchange_greeting_and_send_hello (my_endpoint_, tools_);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
// receive but ignore WELCOME
uint8_t welcome[welcome_length + 2];
recv_all (s, welcome, welcome_length + 2);
uint8_t cn_precom[crypto_box_BEFORENMBYTES];
TEST_ASSERT_SUCCESS_ERRNO (
tools_.process_welcome (welcome + 2, welcome_length, cn_precom));
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
const int res =
get_monitor_event_with_timeout (server_mon_, NULL, NULL, timeout_);
TEST_ASSERT_EQUAL_INT (-1, res);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
return s;
}
void test_curve_security_invalid_initiate_command_name ()
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
zmq::curve_client_tools_t tools = make_curve_client_tools ();
fd_t s = connect_exchange_greeting_and_hello_welcome (
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
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);
expect_monitor_event_multiple (server_mon,
ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL,
ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
close (s);
}
void test_curve_security_invalid_initiate_command_encrypted_cookie ()
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
zmq::curve_client_tools_t tools = make_curve_client_tools ();
fd_t s = connect_exchange_greeting_and_hello_welcome (
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
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);
expect_monitor_event_multiple (server_mon,
ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL,
ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
close (s);
}
void test_curve_security_invalid_initiate_command_encrypted_content ()
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
{
zmq::curve_client_tools_t tools = make_curve_client_tools ();
fd_t s = connect_exchange_greeting_and_hello_welcome (
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
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);
expect_monitor_event_multiple (server_mon,
ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL,
ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
close (s);
}
void test_curve_security_invalid_keysize (void *ctx_)
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
{
2014-11-07 17:35:41 +01:00
// Check return codes for invalid buffer sizes
void *client = zmq_socket (ctx_, ZMQ_DEALER);
TEST_ASSERT_NOT_NULL (client);
2014-11-07 17:35:41 +01:00
errno = 0;
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;
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;
rc = zmq_setsockopt (client, ZMQ_CURVE_SECRETKEY, valid_client_secret, 123);
2014-11-07 17:35:41 +01:00
assert (rc == -1 && errno == EINVAL);
TEST_ASSERT_SUCCESS_ERRNO (zmq_close (client));
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
}
2014-11-07 17:35:41 +01:00
// TODO why isn't this const?
char null_key[] = "0000000000000000000000000000000000000000";
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
void test_null_server_key ()
{
// Check CURVE security with a null server key
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
// This will be caught by the curve_server class, not passed to ZAP
test_null_key (server, server_mon, my_endpoint, null_key,
valid_client_public, valid_client_secret);
}
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
void test_null_client_public_key ()
{
// Check CURVE security with a null client public key
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
// This will be caught by the curve_server class, not passed to ZAP
test_null_key (server, server_mon, my_endpoint, valid_server_public,
null_key, valid_client_secret);
}
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
void test_null_client_secret_key ()
{
// Check CURVE security with a null client public key
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
// This will be caught by the curve_server class, not passed to ZAP
test_null_key (server, server_mon, my_endpoint, valid_server_public,
valid_client_public, null_key);
}
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
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;
}
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
zmq::random_open ();
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
setup_testutil_security_curve ();
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
setup_test_environment (180);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
UNITY_BEGIN ();
RUN_TEST (test_curve_security_with_valid_credentials);
RUN_TEST (test_null_server_key);
RUN_TEST (test_null_client_public_key);
RUN_TEST (test_null_client_secret_key);
RUN_TEST (test_curve_security_with_bogus_client_credentials);
RUN_TEST (test_curve_security_with_null_client_credentials);
RUN_TEST (test_curve_security_with_plain_client_credentials);
RUN_TEST (test_curve_security_unauthenticated_message);
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
// tests with misbehaving CURVE client
RUN_TEST (test_curve_security_invalid_hello_wrong_length);
RUN_TEST (test_curve_security_invalid_hello_command_name);
RUN_TEST (test_curve_security_invalid_hello_version);
RUN_TEST (test_curve_security_invalid_initiate_wrong_length);
RUN_TEST (test_curve_security_invalid_initiate_command_name);
RUN_TEST (test_curve_security_invalid_initiate_command_encrypted_cookie);
RUN_TEST (test_curve_security_invalid_initiate_command_encrypted_content);
// TODO this requires a deviating test setup, must be moved to a separate executable/fixture
// test with a large routing id (resulting in large metadata)
fprintf (stderr,
"test_curve_security_with_valid_credentials (large routing id)\n");
setup_test_context ();
setup_context_and_server_side (&handler, &zap_thread, &server, &server_mon,
my_endpoint, &zap_handler_large_routing_id,
&socket_config_curve_server,
&valid_server_secret, large_routing_id);
test_curve_security_with_valid_credentials ();
shutdown_context_and_server_side (zap_thread, server, server_mon, handler);
teardown_test_context ();
void *ctx = zmq_ctx_new ();
Replace console output by monitoring events for curve security issues (#2645) * Fixing #2002 one way of doing it * Mechanisms can implement a new method `error_detail()` * This error detail have three values for the moment: no_detail (default), protocol, encryption. + generic enough to make sense for all mechanisms. - low granularity level on information. * Fixing #2002: implementation of the error details The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details as value. * Removed Microsoft extenstion for enum member access This was leading to compilation error under linux. * Adaptation of CURVE test cases * Monitoring event: changed API for detailed events Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by: - ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL, - ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL, - ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION Adaptation of text case `security_curve` * Removed event value comparison This was introduced for the previous API model adaptation * Removed the prints in std output and added missing details `current_error_detail` was not set in every protocol error cases * Fixed initialization of current_error_detail * Fixed error in greeting test case The handshake failure due to mechanism mismatch in greeting is actually a protocol error. The error handling method consider it like so and send a protocol handshake failure monitoring event instead of no_detail. Fixed the test_security_curve expectation as well. * Upgraded tests of monitoring events The tests check the number of monitoring events received * Problem: does not build under Linux or without ZMQ_DRAFT_API Solution: - properly use ZMQ_DRAFT_API conditional compilation - use receive timeouts instead of Sleep * Problem: duplicate definition of variable 'timeout' Solution: merged definitions * Problem: inconsistent timing dependencies Solution: reduce timing dependency by using timeouts at more places * Problem: assertion failure under Linux due to unexpected monitor event Solution: output event type to aid debugging * Problem: erroneous assertion code * Problem: assertion failure with a garbage server key due to an extra third event Solution: changed assertion to expect three events (needs to be checked) * Problem: extra include directive to non-existent file Solution: removed include directive * Problem: assertion failure on appveyor for unknown reason Solution: improve debug output * Problem: no build with libsodium and draft api Solution: add build configurations with libsodium and draft api * Problem: assertion failure on CI Solution: change assertion to reflect actual behaviour on CI (at least temporarily) * Problem: error in condition in assertion code * Problem: assertion failure on CI Solution: generalize assertion to match behavior on CI * Problem: assertion failures on CI Solution: removed inconsistent assertion on no monitor events before flushing improved debuggability by converting function into macro * Problem: diverging test code for three analogous test cases with garbage key Solution: extract common code into function * Problem: does not build without ZMQ_BUILD_DRAFT_API Solution: introduce dummy variable * Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again * Problem: EAGAIN error after handshake complete if there is no more data in inbuffer Solution: Skip tcp_read attempt in that case * Problem: handshaking event emitted after handshaking failed Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking * Include error code in debug output * Improve debugging output: output flushed events * Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP * Fixed compilation without ZMQ_BUILD_DRAFT_API * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency * Fixed assert_monitor_event (require event instead of allowing no event) Reverted erroneous change to handshaking condition Renamed test_wrong_key to test_garbage_key Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE * Better isolate test cases from each other by providing a fresh context & server for each * Added diagnostic output * Changed assertion to reflect actual behavior on CI * Fixed formatting, observe maximum line length * Fixed formatting, observe maximum line length * Increase timeout to check if this fixes valgrind run * Close server with close_zero_linger * Increase timeout to check if this fixes valgrind run * Increase timeout to check if this fixes valgrind run * Generalize assertion to also work with valgrind * Fixed formatting * Add more diagnostic output * Generalize assertion to also work with valgrind
2017-08-03 15:15:56 +02:00
test_curve_security_invalid_keysize (ctx);
TEST_ASSERT_SUCCESS_ERRNO (zmq_ctx_term (ctx));
[WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680) * Extracted connect_vanilla_socket function * Problem: no tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO commands * Problem: insufficient tests for ZMTP-CURVE protocol errors Solution: added two test cases with erroneous HELLO command version * Problem: test HELLO message is invalid apart from deliberate errors Solution: create cryptographically correct HELLO message add tweetnacl.c to test_security_curve * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: nonce is incorrect, build fails with GCC Solution: use correct non prefix * Problem: make builds are failing Solution: transfer CMake changes to (auto)make files * Problem: no test with INITIATE command with invalid length Solution: added test case * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function * Problem: code duplication between test_security_curve.cpp and curve_client.cpp Solution: extracted further parts of zmq::curve_client_t into reusable functions added missing file * Problem: mechanism_t::add_property can be declared static Solution: declare mechanism_t::add_property static * Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t Solution: add non-static member functions * Problem: msg_t instance may be closed twice Solution: remove offending close * Problem: prepare_hello uses static curve_client_tools_t::produce_hello Solution: Use non-static curve_client_tools_t::produce_hello * Problem: no test with invalid command name where INITIATE command is expected Solution: added test case * Problem: make builds are failing due to curve_client_tools.hpp not being found Solution: add curve_client_tools.hpp to list of source files * Problem: wrong initializer order in zmq::curve_client_t Solution: reorder * Problem: under non-Windows systems, test fails because random_open was not called Solution: call random_open/random_close within test * Problem: conflict between custom function htonll and macro definition on Darwin Solution: define htonll function only if not defined as a macro * Problem: nullptr not defined on all platforms Solution: replace nullptr by NULL * Problem: libsodium builds not working Solution: adapt compile and link file sets for libsodium builds * Problem: Makefile.am broken Solution: Fix syntax * Problem: no tests for garbage encrypted cookie or content in INITIATE Solution: added test cases * Problem: test cases accidentally excluded from build Solution: remove #if/#endif * Solution: some error cases are unreachable Problem: for the time being, added some comments without changing the code * Added comments on hard-to-test cases
2017-08-15 16:28:24 +02:00
zmq::random_close ();
return UNITY_END ();
}