Commit f06bf8d2 authored by Richard Newton's avatar Richard Newton

Merge branch 'master' of https://github.com/zeromq/libzmq

parents 9db0791c b0b2567f
...@@ -68,6 +68,8 @@ tests/test_inproc_connect ...@@ -68,6 +68,8 @@ tests/test_inproc_connect
tests/test_linger tests/test_linger
tests/test_security_null tests/test_security_null
tests/test_security_plain tests/test_security_plain
tests/test*.log
tests/test*.trs
src/platform.hpp* src/platform.hpp*
src/stamp-h1 src/stamp-h1
perf/local_lat perf/local_lat
......
...@@ -29,9 +29,10 @@ AC_SUBST(PACKAGE_VERSION) ...@@ -29,9 +29,10 @@ AC_SUBST(PACKAGE_VERSION)
# ZeroMQ versions 2.1.x: 1:0:0 (ABI version 1) # ZeroMQ versions 2.1.x: 1:0:0 (ABI version 1)
# ZeroMQ version 3.0: 2:0:0 (ABI version 2) # ZeroMQ version 3.0: 2:0:0 (ABI version 2)
# ZeroMQ version 3.1: 3:0:0 (ABI version 3) # ZeroMQ version 3.1: 3:0:0 (ABI version 3)
# ZeroMQ version 4.0: 4:0:1 (ABI version 4)
# #
# libzmq -version-info current:revision:age # libzmq -version-info current:revision:age
LTVER="3:0:0" LTVER="4:0:1"
AC_SUBST(LTVER) AC_SUBST(LTVER)
# Take a copy of original flags # Take a copy of original flags
...@@ -62,6 +63,45 @@ LIBZMQ_CHECK_ENABLE_DEBUG ...@@ -62,6 +63,45 @@ LIBZMQ_CHECK_ENABLE_DEBUG
# Check wheter to enable code coverage # Check wheter to enable code coverage
LIBZMQ_WITH_GCOV LIBZMQ_WITH_GCOV
# Allow libsodium to be installed in a custom path:
AC_ARG_WITH([libsodium],
[AS_HELP_STRING([--with-libsodium],
[Specify libsodium prefix])],
[zmq_search_libsodium="yes"],
[])
if test "x$zmq_search_libsodium" = "xyes"; then
if test -r "${with_libsodium}/include/sodium.h"; then
CXXFLAGS="-I${with_libsodium}/include ${CXXFLAGS}"
LDFLAGS="-L${with_libsodium}/lib ${LDFLAGS}"
fi
fi
AC_ARG_WITH([libsodium-include-dir],
[AS_HELP_STRING([--with-libsodium-include-dir],
[Specify libsodium include prefix])],
[zmq_search_libsodium_include="yes"],
[])
if test "x$zmq_search_libsodium_include" = "xyes"; then
if test -r "${with_libsodium_include_dir}/sodium.h"; then
CXXFLAGS="-I${with_libsodium_include_dir}/include ${CXXFLAGS}"
fi
fi
AC_ARG_WITH([libsodium_lib_dir],
[AS_HELP_STRING([--with-libsodium-lib-dir],
[Specify libsodium library prefix])],
[zmq_search_libsodium_lib="yes"],
[])
if test "x$zmq_search_libsodium_lib" = "xyes"; then
if test -r "${with_libsodium_lib_dir}/libsodium.{a|so|dylib}"; then
LDFLAGS="-L${with_libsodium}/lib ${LDFLAGS}"
fi
fi
# Checks for libraries # Checks for libraries
AC_CHECK_LIB([pthread], [pthread_create]) AC_CHECK_LIB([pthread], [pthread_create])
AC_CHECK_LIB([rt], [clock_gettime]) AC_CHECK_LIB([rt], [clock_gettime])
......
...@@ -62,6 +62,9 @@ typedef __int32 int32_t; ...@@ -62,6 +62,9 @@ typedef __int32 int32_t;
# ifndef uint16_t # ifndef uint16_t
typedef unsigned __int16 uint16_t; typedef unsigned __int16 uint16_t;
# endif # endif
# ifndef uint8_t
typedef unsigned __int8 uint8_t;
# endif
#else #else
# include <stdint.h> # include <stdint.h>
#endif #endif
......
...@@ -22,9 +22,22 @@ ...@@ -22,9 +22,22 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
/* Define integer types needed for event interface */
#if defined ZMQ_HAVE_SOLARIS || defined ZMQ_HAVE_OPENVMS
# include <inttypes.h>
#elif defined _MSC_VER && _MSC_VER < 1600
# ifndef int32_t
typedef __int32 int32_t;
# endif
# ifndef uint16_t
typedef unsigned __int16 uint16_t;
# endif
#else
# include <stdint.h>
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
......
...@@ -297,34 +297,38 @@ int zmq::curve_client_t::process_welcome (msg_t *msg_) ...@@ -297,34 +297,38 @@ int zmq::curve_client_t::process_welcome (msg_t *msg_)
int zmq::curve_client_t::produce_initiate (msg_t *msg_) int zmq::curve_client_t::produce_initiate (msg_t *msg_)
{ {
uint8_t vouch_nonce [crypto_box_NONCEBYTES]; uint8_t vouch_nonce [crypto_box_NONCEBYTES];
uint8_t vouch_plaintext [crypto_box_ZEROBYTES + 32]; uint8_t vouch_plaintext [crypto_box_ZEROBYTES + 64];
uint8_t vouch_box [crypto_box_BOXZEROBYTES + 48]; uint8_t vouch_box [crypto_box_BOXZEROBYTES + 80];
// Create vouch = Box [C'](C->S) // Create vouch = Box [C',S](C->S')
memset (vouch_plaintext, 0, crypto_box_ZEROBYTES); memset (vouch_plaintext, 0, crypto_box_ZEROBYTES);
memcpy (vouch_plaintext + crypto_box_ZEROBYTES, cn_public, 32); memcpy (vouch_plaintext + crypto_box_ZEROBYTES, cn_public, 32);
memcpy (vouch_plaintext + crypto_box_ZEROBYTES + 32, server_key, 32);
memcpy (vouch_nonce, "VOUCH---", 8); memcpy (vouch_nonce, "VOUCH---", 8);
randombytes (vouch_nonce + 8, 16); randombytes (vouch_nonce + 8, 16);
int rc = crypto_box (vouch_box, vouch_plaintext, int rc = crypto_box (vouch_box, vouch_plaintext,
sizeof vouch_plaintext, sizeof vouch_plaintext,
vouch_nonce, server_key, secret_key); vouch_nonce, cn_server, secret_key);
zmq_assert (rc == 0); zmq_assert (rc == 0);
// Assume here that metadata is limited to 256 bytes
uint8_t initiate_nonce [crypto_box_NONCEBYTES]; uint8_t initiate_nonce [crypto_box_NONCEBYTES];
uint8_t initiate_plaintext [crypto_box_ZEROBYTES + 96 + 256]; uint8_t initiate_plaintext [crypto_box_ZEROBYTES + 128 + 256];
uint8_t initiate_box [crypto_box_BOXZEROBYTES + 112 + 256]; uint8_t initiate_box [crypto_box_BOXZEROBYTES + 144 + 256];
// Create Box [C + vouch + metadata](C'->S') // Create Box [C + vouch + metadata](C'->S')
memset (initiate_plaintext, 0, crypto_box_ZEROBYTES); memset (initiate_plaintext, 0, crypto_box_ZEROBYTES);
memcpy (initiate_plaintext + crypto_box_ZEROBYTES, public_key, 32); memcpy (initiate_plaintext + crypto_box_ZEROBYTES,
public_key, 32);
memcpy (initiate_plaintext + crypto_box_ZEROBYTES + 32, memcpy (initiate_plaintext + crypto_box_ZEROBYTES + 32,
vouch_nonce + 8, 16); vouch_nonce + 8, 16);
memcpy (initiate_plaintext + crypto_box_ZEROBYTES + 48, memcpy (initiate_plaintext + crypto_box_ZEROBYTES + 48,
vouch_box + crypto_box_BOXZEROBYTES, 48); vouch_box + crypto_box_BOXZEROBYTES, 80);
uint8_t *ptr = initiate_plaintext + crypto_box_ZEROBYTES + 96; // Metadata starts after vouch
uint8_t *ptr = initiate_plaintext + crypto_box_ZEROBYTES + 128;
// Add socket type property // Add socket type property
const char *socket_type = socket_type_string (options.type); const char *socket_type = socket_type_string (options.type);
...@@ -359,7 +363,6 @@ int zmq::curve_client_t::produce_initiate (msg_t *msg_) ...@@ -359,7 +363,6 @@ int zmq::curve_client_t::produce_initiate (msg_t *msg_)
// Box [C + vouch + metadata](C'->S') // Box [C + vouch + metadata](C'->S')
memcpy (initiate + 113, initiate_box + crypto_box_BOXZEROBYTES, memcpy (initiate + 113, initiate_box + crypto_box_BOXZEROBYTES,
mlen - crypto_box_BOXZEROBYTES); mlen - crypto_box_BOXZEROBYTES);
cn_nonce++; cn_nonce++;
return 0; return 0;
......
...@@ -338,7 +338,7 @@ int zmq::curve_server_t::produce_welcome (msg_t *msg_) ...@@ -338,7 +338,7 @@ int zmq::curve_server_t::produce_welcome (msg_t *msg_)
int zmq::curve_server_t::process_initiate (msg_t *msg_) int zmq::curve_server_t::process_initiate (msg_t *msg_)
{ {
if (msg_->size () < 225) { if (msg_->size () < 257) {
errno = EPROTO; errno = EPROTO;
return -1; return -1;
} }
...@@ -369,10 +369,8 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_) ...@@ -369,10 +369,8 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
} }
// Check cookie plain text is as expected [C' + s'] // Check cookie plain text is as expected [C' + s']
if (memcmp (cookie_plaintext + crypto_secretbox_ZEROBYTES, if (memcmp (cookie_plaintext + crypto_secretbox_ZEROBYTES, cn_client, 32)
cn_client, 32) || memcmp (cookie_plaintext + crypto_secretbox_ZEROBYTES + 32, cn_secret, 32)) {
|| memcmp (cookie_plaintext + crypto_secretbox_ZEROBYTES + 32,
cn_secret, 32)) {
errno = EAGAIN; errno = EAGAIN;
return -1; return -1;
} }
...@@ -380,8 +378,8 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_) ...@@ -380,8 +378,8 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
const size_t clen = (msg_->size () - 113) + crypto_box_BOXZEROBYTES; const size_t clen = (msg_->size () - 113) + crypto_box_BOXZEROBYTES;
uint8_t initiate_nonce [crypto_box_NONCEBYTES]; uint8_t initiate_nonce [crypto_box_NONCEBYTES];
uint8_t initiate_plaintext [crypto_box_ZEROBYTES + 96 + 256]; uint8_t initiate_plaintext [crypto_box_ZEROBYTES + 128 + 256];
uint8_t initiate_box [crypto_box_BOXZEROBYTES + 112 + 256]; uint8_t initiate_box [crypto_box_BOXZEROBYTES + 144 + 256];
// Open Box [C + vouch + metadata](C'->S') // Open Box [C + vouch + metadata](C'->S')
memset (initiate_box, 0, crypto_box_BOXZEROBYTES); memset (initiate_box, 0, crypto_box_BOXZEROBYTES);
...@@ -401,13 +399,13 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_) ...@@ -401,13 +399,13 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
const uint8_t *client_key = initiate_plaintext + crypto_box_ZEROBYTES; const uint8_t *client_key = initiate_plaintext + crypto_box_ZEROBYTES;
uint8_t vouch_nonce [crypto_box_NONCEBYTES]; uint8_t vouch_nonce [crypto_box_NONCEBYTES];
uint8_t vouch_plaintext [crypto_box_ZEROBYTES + 32]; uint8_t vouch_plaintext [crypto_box_ZEROBYTES + 64];
uint8_t vouch_box [crypto_box_BOXZEROBYTES + 48]; uint8_t vouch_box [crypto_box_BOXZEROBYTES + 80];
// Open Box [C'](C->S) and check contents // Open Box Box [C',S](C->S') and check contents
memset (vouch_box, 0, crypto_box_BOXZEROBYTES); memset (vouch_box, 0, crypto_box_BOXZEROBYTES);
memcpy (vouch_box + crypto_box_BOXZEROBYTES, memcpy (vouch_box + crypto_box_BOXZEROBYTES,
initiate_plaintext + crypto_box_ZEROBYTES + 48, 48); initiate_plaintext + crypto_box_ZEROBYTES + 48, 80);
memcpy (vouch_nonce, "VOUCH---", 8); memcpy (vouch_nonce, "VOUCH---", 8);
memcpy (vouch_nonce + 8, memcpy (vouch_nonce + 8,
...@@ -415,7 +413,7 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_) ...@@ -415,7 +413,7 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
rc = crypto_box_open (vouch_plaintext, vouch_box, rc = crypto_box_open (vouch_plaintext, vouch_box,
sizeof vouch_box, sizeof vouch_box,
vouch_nonce, client_key, secret_key); vouch_nonce, client_key, cn_secret);
if (rc != 0) { if (rc != 0) {
errno = EPROTO; errno = EPROTO;
return -1; return -1;
...@@ -443,8 +441,8 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_) ...@@ -443,8 +441,8 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
} }
} }
return parse_metadata (initiate_plaintext + crypto_box_ZEROBYTES + 96, return parse_metadata (initiate_plaintext + crypto_box_ZEROBYTES + 128,
clen - crypto_box_ZEROBYTES - 96); clen - crypto_box_ZEROBYTES - 128);
} }
int zmq::curve_server_t::produce_ready (msg_t *msg_) int zmq::curve_server_t::produce_ready (msg_t *msg_)
......
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