Unverified Commit 718ad8ab authored by grmt's avatar grmt Committed by GitHub

add wss transport and fix tipc tests when building using cmake on linux (#3857)

* Allow CMAKE to generate ws and wss transports
I guess there is little use of just ws transport, so by default
GnuTLS (and libsodium) are enabled

* cmake libzmq including wss transport (ubuntu 19.10 and ubuntu 19.10 + wsl 1.0)
test_security_fails (libsodium assert !?)

* updated relicense

* make external libs gnutls nss sodium optional

* #ifdef WSS classes and functions, build test*ws* only if correct libs are included, warning if libs not present

* make libsodium optional

* cmake fix tests TIPC transport

* clang-format pointed out a wrongly placed #ifdef

* GnuTLS before 3.6.7 is not safe

* msvc doesn't agree with strlen in array declaration, test_socks now at least compiles on windows

* windows: libsodium build fails, missing include dirs set by env var

* ws transport test only works when GnuTLS is found

* Fixed condition to use NSS / built in SHA1, so that test_ws_transport should now pass, also when GnuTLS is not found
parent 7276b680
......@@ -26,6 +26,8 @@ build/
builds/android/prefix
## IntelliJ
.idea/
## Visual Code
.vscode/
## other results-like folders
bin/
lib/
......
This diff is collapsed.
# Permission to Relicense under MPLv2
This is a statement by grmt.
that grants permission to relicense its copyrights in the libzmq C++
library (ZeroMQ) under the Mozilla Public License v2 (MPLv2).
A portion of the commits made by the Github handle "grmt", with
commit author "grmt", are copyright of grmt.
This document hereby grants the libzmq project team to relicense libzmq,
including all past, present and future contributions of the author listed above.
grmt (garmt.noname@gmail.com)
2020/05/04
......@@ -4,7 +4,7 @@
################################################################################
if (NOT MSVC)
include(FindPkgConfig)
find_package(PkgConfig REQUIRED)
pkg_check_modules(PC_SODIUM "libsodium")
if (PC_SODIUM_FOUND)
set(pkg_config_names_private "${pkg_config_names_private} libsodium")
......@@ -39,7 +39,7 @@ find_library(
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SODIUM DEFAULT_MSG SODIUM_LIBRARIES SODIUM_INCLUDE_DIRS)
find_package_handle_standard_args(sodium DEFAULT_MSG SODIUM_LIBRARIES SODIUM_INCLUDE_DIRS)
mark_as_advanced(SODIUM_FOUND SODIUM_LIBRARIES SODIUM_INCLUDE_DIRS)
################################################################################
......
......@@ -59,14 +59,19 @@
#cmakedefine ZMQ_USE_BUILTIN_SHA1
#cmakedefine ZMQ_USE_NSS
#cmakedefine ZMQ_HAVE_WS
#cmakedefine ZMQ_HAVE_WSS
#cmakedefine ZMQ_HAVE_TIPC
#cmakedefine ZMQ_HAVE_OPENPGM
#cmakedefine ZMQ_MAKE_VALGRIND_HAPPY
#cmakedefine ZMQ_BUILD_DRAFT_API
#cmakedefine ZMQ_HAVE_CURVE
#cmakedefine ZMQ_USE_TWEETNACL
#cmakedefine ZMQ_USE_LIBSODIUM
#cmakedefine SODIUM_STATIC
#cmakedefine ZMQ_USE_GNUTLS
#cmakedefine ZMQ_USE_RADIX_TREE
#ifdef _AIX
#define ZMQ_HAVE_AIX
......
<?xml version="1.0" encoding="utf-8"?>
<!-- These values are populated into the package.gsl templates by package.bat. -->
<!-- The target attribute controls path and file name only, id controls package naming. -->
<package id="libzmq-vc120" target="libzmq" version = "4.2.3.0" pathversion="4_2_3_0" platformtoolset="v120">
<package id="libzmq-vc142" target="libzmq" version = "4.2.3.0" pathversion="4_2_3_0" platformtoolset="v142">
<!--<dependency id="libsodium_vc120" version="1.0.12.0" />-->
</package>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
<?xml version="1.0" encoding="utf-8"?>
<!--
#################################################################
# GENERATED SOURCE CODE, DO NOT EDIT EXCEPT EXPERIMENTALLY #
#################################################################
-->
<ProjectSchemaDefinitions xmlns="clr-namespace:Microsoft.Build.Framework.XamlTypes;assembly=Microsoft.Build.Framework">
<Rule Name="Linkage-libzmq-uiextension" PageTemplate="tool" DisplayName="NuGet Dependencies" SwitchPrefix="/" Order="1">
<Rule.Categories>
<Category Name="libzmq" DisplayName="libzmq" />
</Rule.Categories>
<Rule.DataSource>
<DataSource Persistence="ProjectFile" ItemType="" />
</Rule.DataSource>
<EnumProperty Name="Linkage-libzmq" DisplayName="Linkage" Description="How NuGet libzmq will be linked into the output of this project" Category="libzmq">
<EnumValue Name="" DisplayName="Not linked" />
<EnumValue Name="dynamic" DisplayName="Dynamic (DLL)" />
<EnumValue Name="static" DisplayName="Static (LIB)" />
<EnumValue Name="ltcg" DisplayName="Static using link time compile generation (LTCG)" />
</EnumProperty>
</Rule>
<?xml version="1.0" encoding="utf-8"?>
<!--
#################################################################
# GENERATED SOURCE CODE, DO NOT EDIT EXCEPT EXPERIMENTALLY #
#################################################################
-->
<ProjectSchemaDefinitions xmlns="clr-namespace:Microsoft.Build.Framework.XamlTypes;assembly=Microsoft.Build.Framework">
<Rule Name="Linkage-libzmq-uiextension" PageTemplate="tool" DisplayName="NuGet Dependencies" SwitchPrefix="/" Order="1">
<Rule.Categories>
<Category Name="libzmq" DisplayName="libzmq" />
</Rule.Categories>
<Rule.DataSource>
<DataSource Persistence="ProjectFile" ItemType="" />
</Rule.DataSource>
<EnumProperty Name="Linkage-libzmq" DisplayName="Linkage" Description="How NuGet libzmq will be linked into the output of this project" Category="libzmq">
<EnumValue Name="" DisplayName="Not linked" />
<EnumValue Name="dynamic" DisplayName="Dynamic (DLL)" />
<EnumValue Name="static" DisplayName="Static (LIB)" />
<EnumValue Name="ltcg" DisplayName="Static using link time compile generation (LTCG)" />
</EnumProperty>
</Rule>
</ProjectSchemaDefinitions>
\ No newline at end of file
......@@ -46,7 +46,9 @@ class ctx_t;
class tcp_address_t;
class udp_address_t;
class ws_address_t;
#ifdef ZMQ_HAVE_WSS
class wss_address_t;
#endif
#if defined ZMQ_HAVE_IPC
class ipc_address_t;
#endif
......@@ -107,6 +109,8 @@ struct address_t
udp_address_t *udp_addr;
#ifdef ZMQ_HAVE_WS
ws_address_t *ws_addr;
#endif
#ifdef ZMQ_HAVE_WSS
wss_address_t *wss_addr;
#endif
#if defined ZMQ_HAVE_IPC
......
......@@ -112,7 +112,8 @@ f_compatible_get_tick_count64 init_compatible_get_tick_count64 ()
func = compatible_get_tick_count64;
#if !defined ZMQ_HAVE_WINDOWS_UWP
::FreeLibrary (module);
if (module != NULL)
::FreeLibrary (module);
#endif
return func;
......
......@@ -54,8 +54,9 @@
#include "ipc_listener.hpp"
#include "tipc_listener.hpp"
#include "tcp_connecter.hpp"
#ifdef ZMQ_HAVE_WS
#include "ws_address.hpp"
#include "wss_address.hpp"
#endif
#include "io_thread.hpp"
#include "session_base.hpp"
#include "config.hpp"
......@@ -72,6 +73,9 @@
#include "mailbox.hpp"
#include "mailbox_safe.hpp"
#ifdef ZMQ_HAVE_WSS
#include "wss_address.hpp"
#endif
#if defined ZMQ_HAVE_VMCI
#include "vmci_address.hpp"
#include "vmci_listener.hpp"
......
......@@ -71,7 +71,7 @@ class stream_engine_base_t : public io_object_t, public i_engine
// i_poll_events interface implementation.
void in_event () ZMQ_FINAL;
void out_event () ZMQ_FINAL;
void out_event ();
void timer_event (int id_) ZMQ_FINAL;
protected:
......
......@@ -39,12 +39,12 @@
#include "tcp.hpp"
#include "address.hpp"
#include "ws_address.hpp"
#include "wss_address.hpp"
#include "session_base.hpp"
#include "ws_engine.hpp"
#include "session_base.hpp"
#ifdef ZMQ_HAVE_WSS
#include "wss_engine.hpp"
#include "wss_address.hpp"
#endif
#if !defined ZMQ_HAVE_WINDOWS
......@@ -120,8 +120,12 @@ void zmq::ws_connecter_t::out_event ()
}
if (_wss)
#ifdef ZMQ_HAVE_WSS
create_engine (fd,
get_socket_name<wss_address_t> (fd, socket_end_local));
#else
assert (false);
#endif
else
create_engine (fd,
get_socket_name<ws_address_t> (fd, socket_end_local));
......@@ -190,7 +194,7 @@ int zmq::ws_connecter_t::open ()
unblock_socket (_s);
// Connect to the remote peer.
#if defined ZMQ_HAVE_VXWORKS
#ifdef ZMQ_HAVE_VXWORKS
int rc = ::connect (_s, (sockaddr *) tcp_addr.addr (), tcp_addr.addrlen ());
#else
const int rc = ::connect (_s, tcp_addr.addr (), tcp_addr.addrlen ());
......
......@@ -128,7 +128,7 @@ zmq::ws_engine_t::ws_engine_t (fd_t fd_,
{
memset (_websocket_key, 0, MAX_HEADER_VALUE_LENGTH + 1);
memset (_websocket_accept, 0, MAX_HEADER_VALUE_LENGTH + 1);
memset (_websocket_protocol, 0, MAX_HEADER_VALUE_LENGTH + 1);
memset (_websocket_protocol, 0, 256);
_next_msg = &ws_engine_t::next_handshake_command;
_process_msg = &ws_engine_t::process_handshake_command;
......@@ -488,7 +488,7 @@ bool zmq::ws_engine_t::server_handshake ()
// Sec-WebSocket-Protocol can appear multiple times or be a comma separated list
// if _websocket_protocol is already set we skip the check
if (_websocket_protocol[0] == '\0') {
char *rest;
char *rest = 0;
char *p = strtok_r (_header_value, ",", &rest);
while (p != NULL) {
if (*p == ' ')
......
......@@ -124,7 +124,7 @@ typedef enum
client_handshake_error = -1
} ws_client_handshake_state_t;
class ws_engine_t ZMQ_FINAL : public stream_engine_base_t
class ws_engine_t : public stream_engine_base_t
{
public:
ws_engine_t (fd_t fd_,
......
......@@ -42,11 +42,11 @@
#include "socket_base.hpp"
#include "address.hpp"
#include "ws_engine.hpp"
#include "wss_address.hpp"
#include "session_base.hpp"
#ifdef ZMQ_HAVE_WSS
#include "wss_engine.hpp"
#include "wss_address.hpp"
#endif
#ifndef ZMQ_HAVE_WINDOWS
......@@ -126,9 +126,11 @@ std::string zmq::ws_listener_t::get_socket_name (zmq::fd_t fd_,
{
std::string socket_name;
#ifdef ZMQ_HAVE_WSS
if (_wss)
socket_name = zmq::get_socket_name<wss_address_t> (fd_, socket_end_);
else
#endif
socket_name = zmq::get_socket_name<ws_address_t> (fd_, socket_end_);
return socket_name + _address.path ();
......@@ -313,6 +315,7 @@ void zmq::ws_listener_t::create_engine (fd_t fd_)
else
engine = new (std::nothrow)
ws_engine_t (fd_, options, endpoint_pair, _address, false);
alloc_assert (engine);
// Choose I/O thread to run connecter in. Given that we are already
......
......@@ -34,7 +34,7 @@
#include "ws_address.hpp"
#include "stream_listener_base.hpp"
#if ZMQ_USE_GNUTLS
#ifdef ZMQ_USE_GNUTLS
#include <gnutls/gnutls.h>
#endif
......@@ -73,7 +73,7 @@ class ws_listener_t ZMQ_FINAL : public stream_listener_base_t
ws_address_t _address;
bool _wss;
#if ZMQ_HAVE_WSS
#ifdef ZMQ_HAVE_WSS
gnutls_certificate_credentials_t _tls_cred;
#endif
......
This diff is collapsed.
......@@ -27,10 +27,15 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef _WIN32
#include "../src/windows.hpp"
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
......@@ -104,7 +109,12 @@ void *setup_socks_server (char *socks_server_address,
TEST_ASSERT_NOT_EQUAL (-1, server_fd);
int flag = 1;
int res;
#ifdef _WIN32
res = setsockopt (server_fd, SOL_SOCKET, SO_REUSEADDR, (const char *) &flag,
sizeof (int));
#else
res = setsockopt (server_fd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof (int));
#endif
TEST_ASSERT_SUCCESS_RAW_ERRNO (res);
struct sockaddr_in saddr = bind_bsd_socket (server_fd);
int nbytes = snprintf (socks_server_address, socks_server_address_len,
......
......@@ -35,18 +35,27 @@ SETUP_TEARDOWN_TESTCONTEXT
void test_roundtrip ()
{
char connect_address[MAX_SOCKET_STRING + strlen ("/roundtrip")];
char bind_address[MAX_SOCKET_STRING];
char connect_address[MAX_SOCKET_STRING];
size_t addr_length = sizeof (connect_address);
void *sb = test_context_socket (ZMQ_REP);
void *sc = test_context_socket (ZMQ_REQ);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://*:*/roundtrip"));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, connect_address, &addr_length));
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, bind_address, &addr_length));
// Windows can't connect to 0.0.0.0
sprintf (connect_address, "ws://127.0.0.1%s", strrchr (bind_address, ':'));
void *sc = test_context_socket (ZMQ_REQ);
TEST_ASSERT_SUCCESS_ERRNO (zmq_connect (sc, connect_address));
bounce (sb, sc);
TEST_ASSERT_SUCCESS_ERRNO (zmq_disconnect (sc, connect_address));
TEST_ASSERT_SUCCESS_ERRNO (zmq_unbind (sb, bind_address));
test_context_socket_close (sc);
test_context_socket_close (sb);
}
......@@ -56,7 +65,7 @@ void test_roundtrip_without_path ()
char connect_address[MAX_SOCKET_STRING];
size_t addr_length = sizeof (connect_address);
void *sb = test_context_socket (ZMQ_REP);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://*:*"));
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://127.0.0.1:*"));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, connect_address, &addr_length));
......@@ -72,10 +81,10 @@ void test_roundtrip_without_path ()
void test_heartbeat ()
{
char connect_address[MAX_SOCKET_STRING + strlen ("/heartbeat")];
char connect_address[MAX_SOCKET_STRING];
size_t addr_length = sizeof (connect_address);
void *sb = test_context_socket (ZMQ_REP);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://*:*/heartbeat"));
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://127.0.0.1:*/heartbeat"));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, connect_address, &addr_length));
......@@ -105,10 +114,10 @@ void test_heartbeat ()
void test_short_message ()
{
char connect_address[MAX_SOCKET_STRING + strlen ("/short")];
char connect_address[MAX_SOCKET_STRING];
size_t addr_length = sizeof (connect_address);
void *sb = test_context_socket (ZMQ_REP);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://*:*/short"));
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://127.0.0.1:*/short"));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, connect_address, &addr_length));
......@@ -138,10 +147,10 @@ void test_short_message ()
void test_large_message ()
{
char connect_address[MAX_SOCKET_STRING + strlen ("/large")];
char connect_address[MAX_SOCKET_STRING];
size_t addr_length = sizeof (connect_address);
void *sb = test_context_socket (ZMQ_REP);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://*:*/large"));
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://127.0.0.1:*/large"));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, connect_address, &addr_length));
......@@ -172,7 +181,7 @@ void test_large_message ()
void test_curve ()
{
char connect_address[MAX_SOCKET_STRING + strlen ("/roundtrip")];
char connect_address[MAX_SOCKET_STRING];
size_t addr_length = sizeof (connect_address);
char client_public[41];
char client_secret[41];
......@@ -190,7 +199,7 @@ void test_curve ()
zmq_setsockopt (server, ZMQ_CURVE_SERVER, &as_server, sizeof (int)));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_setsockopt (server, ZMQ_CURVE_SECRETKEY, server_secret, 41));
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (server, "ws://*:*/roundtrip"));
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (server, "ws://127.0.0.1:*/roundtrip"));
TEST_ASSERT_SUCCESS_ERRNO (zmq_getsockopt (server, ZMQ_LAST_ENDPOINT,
connect_address, &addr_length));
......@@ -212,10 +221,10 @@ void test_curve ()
void test_mask_shared_msg ()
{
char connect_address[MAX_SOCKET_STRING + strlen ("/mask-shared")];
char connect_address[MAX_SOCKET_STRING];
size_t addr_length = sizeof (connect_address);
void *sb = test_context_socket (ZMQ_DEALER);
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://*:*/mask-shared"));
TEST_ASSERT_SUCCESS_ERRNO (zmq_bind (sb, "ws://127.0.0.1:*/mask-shared"));
TEST_ASSERT_SUCCESS_ERRNO (
zmq_getsockopt (sb, ZMQ_LAST_ENDPOINT, connect_address, &addr_length));
......@@ -268,8 +277,8 @@ int main ()
setup_test_environment ();
UNITY_BEGIN ();
RUN_TEST (test_roundtrip);
RUN_TEST (test_roundtrip_without_path);
RUN_TEST (test_roundtrip);
RUN_TEST (test_short_message);
RUN_TEST (test_large_message);
RUN_TEST (test_heartbeat);
......
......@@ -2,19 +2,15 @@
cmake_minimum_required(VERSION "2.8.1")
set(unittests
unittest_ypipe
unittest_poller
unittest_mtrie
unittest_ip_resolver
unittest_udp_address
unittest_radix_tree
unittest_curve_encoding
)
unittest_ypipe
unittest_poller
unittest_mtrie
unittest_ip_resolver
unittest_udp_address
unittest_radix_tree
unittest_curve_encoding)
#if(ENABLE_DRAFTS)
# list(APPEND tests
# )
#endif(ENABLE_DRAFTS)
# if(ENABLE_DRAFTS) list(APPEND tests ) endif(ENABLE_DRAFTS)
# add location of platform.hpp for Windows builds
if(WIN32)
......@@ -48,7 +44,10 @@ foreach(test ${unittests})
endif()
if(WIN32)
add_test(NAME ${test} WORKING_DIRECTORY ${LIBRARY_OUTPUT_PATH} COMMAND ${test})
add_test(
NAME ${test}
WORKING_DIRECTORY ${LIBRARY_OUTPUT_PATH}
COMMAND ${test})
else()
add_test(NAME ${test} COMMAND ${test})
endif()
......@@ -61,8 +60,8 @@ foreach(test ${unittests})
set_target_properties(${test} PROPERTIES LINK_LIBRARIES "${LIBS}")
endforeach()
#Check whether all tests in the current folder are present
#TODO duplicated with tests/CMakeLists.txt, define as a function?
# Check whether all tests in the current folder are present TODO duplicated with tests/CMakeLists.txt, define as a
# function?
file(READ "${CMAKE_CURRENT_LIST_FILE}" CURRENT_LIST_FILE_CONTENT)
file(GLOB ALL_TEST_SOURCES "test_*.cpp")
foreach(TEST_SOURCE ${ALL_TEST_SOURCES})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment