2013-06-18 23:38:24 +02:00
|
|
|
/*
|
2016-01-28 15:07:31 +01:00
|
|
|
Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
|
2013-06-18 23:38:24 +02:00
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
This file is part of libzmq, the ZeroMQ core engine in C++.
|
2013-06-18 23:38:24 +02:00
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
libzmq is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License (LGPL) as published
|
|
|
|
by the Free Software Foundation; either version 3 of the License, or
|
2013-06-18 23:38:24 +02:00
|
|
|
(at your option) any later version.
|
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
As a special exception, the Contributors give you permission to link
|
|
|
|
this library with independent modules to produce an executable,
|
|
|
|
regardless of the license terms of these independent modules, and to
|
|
|
|
copy and distribute the resulting executable under terms of your choice,
|
|
|
|
provided that you also meet, for each linked independent module, the
|
|
|
|
terms and conditions of the license of that module. An independent
|
|
|
|
module is a module which is not derived from or based on this library.
|
|
|
|
If you modify this library, you must extend this exception to your
|
|
|
|
version of the library.
|
|
|
|
|
|
|
|
libzmq is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
2013-06-18 23:38:24 +02:00
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-02-18 10:56:52 -06:00
|
|
|
#include "precompiled.hpp"
|
|
|
|
#include "macros.hpp"
|
2013-06-18 23:38:24 +02:00
|
|
|
|
2016-02-11 13:32:01 +01:00
|
|
|
#ifdef ZMQ_HAVE_CURVE
|
2013-06-18 23:38:24 +02:00
|
|
|
|
|
|
|
#include "msg.hpp"
|
|
|
|
#include "session_base.hpp"
|
|
|
|
#include "err.hpp"
|
|
|
|
#include "curve_client.hpp"
|
|
|
|
#include "wire.hpp"
|
2017-08-15 16:28:24 +02:00
|
|
|
#include "curve_client_tools.hpp"
|
2013-06-18 23:38:24 +02:00
|
|
|
|
2017-08-17 18:32:44 +02:00
|
|
|
zmq::curve_client_t::curve_client_t (session_base_t *session_,
|
|
|
|
const options_t &options_) :
|
2017-08-18 10:04:58 +02:00
|
|
|
mechanism_base_t (session_, options_),
|
2014-05-08 23:43:16 +02:00
|
|
|
state (send_hello),
|
2017-08-15 16:28:24 +02:00
|
|
|
tools (options_.curve_public_key,
|
|
|
|
options_.curve_secret_key,
|
|
|
|
options_.curve_server_key),
|
|
|
|
cn_nonce (1),
|
|
|
|
cn_peer_nonce (1)
|
2013-06-18 23:38:24 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
zmq::curve_client_t::~curve_client_t ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-09-04 17:59:45 +02:00
|
|
|
int zmq::curve_client_t::next_handshake_command (msg_t *msg_)
|
2013-06-18 23:38:24 +02:00
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case send_hello:
|
2013-09-04 17:59:45 +02:00
|
|
|
rc = produce_hello (msg_);
|
2013-06-18 23:38:24 +02:00
|
|
|
if (rc == 0)
|
|
|
|
state = expect_welcome;
|
|
|
|
break;
|
|
|
|
case send_initiate:
|
2013-09-04 17:59:45 +02:00
|
|
|
rc = produce_initiate (msg_);
|
2013-06-18 23:38:24 +02:00
|
|
|
if (rc == 0)
|
|
|
|
state = expect_ready;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errno = EAGAIN;
|
|
|
|
rc = -1;
|
|
|
|
}
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2013-09-04 17:59:45 +02:00
|
|
|
int zmq::curve_client_t::process_handshake_command (msg_t *msg_)
|
2013-06-18 23:38:24 +02:00
|
|
|
{
|
2014-05-15 06:38:17 +02:00
|
|
|
const unsigned char *msg_data =
|
|
|
|
static_cast <unsigned char *> (msg_->data ());
|
|
|
|
const size_t msg_size = msg_->size ();
|
2013-06-18 23:38:24 +02:00
|
|
|
|
2014-05-15 06:38:17 +02:00
|
|
|
int rc = 0;
|
2017-08-15 16:28:24 +02:00
|
|
|
if (curve_client_tools_t::is_handshake_command_welcome (msg_data, msg_size))
|
2014-05-15 06:38:17 +02:00
|
|
|
rc = process_welcome (msg_data, msg_size);
|
2017-08-15 16:28:24 +02:00
|
|
|
else if (curve_client_tools_t::is_handshake_command_ready (msg_data,
|
|
|
|
msg_size))
|
2014-05-15 06:38:17 +02:00
|
|
|
rc = process_ready (msg_data, msg_size);
|
2017-08-15 16:28:24 +02:00
|
|
|
else if (curve_client_tools_t::is_handshake_command_error (msg_data,
|
|
|
|
msg_size))
|
2014-05-15 06:38:17 +02:00
|
|
|
rc = process_error (msg_data, msg_size);
|
|
|
|
else {
|
2017-08-17 18:32:44 +02:00
|
|
|
session->get_socket ()->event_handshake_failed_protocol (
|
|
|
|
session->get_endpoint (),
|
|
|
|
ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
2014-05-15 06:38:17 +02:00
|
|
|
errno = EPROTO;
|
|
|
|
rc = -1;
|
2013-06-18 23:38:24 +02:00
|
|
|
}
|
2014-05-15 06:38:17 +02:00
|
|
|
|
2013-06-18 23:38:24 +02:00
|
|
|
if (rc == 0) {
|
|
|
|
rc = msg_->close ();
|
|
|
|
errno_assert (rc == 0);
|
|
|
|
rc = msg_->init ();
|
|
|
|
errno_assert (rc == 0);
|
|
|
|
}
|
2014-05-15 06:38:17 +02:00
|
|
|
|
2013-06-18 23:38:24 +02:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2013-06-22 11:46:40 +02:00
|
|
|
int zmq::curve_client_t::encode (msg_t *msg_)
|
|
|
|
{
|
|
|
|
zmq_assert (state == connected);
|
|
|
|
|
|
|
|
uint8_t flags = 0;
|
|
|
|
if (msg_->flags () & msg_t::more)
|
|
|
|
flags |= 0x01;
|
2015-03-16 21:39:16 -04:00
|
|
|
if (msg_->flags () & msg_t::command)
|
|
|
|
flags |= 0x02;
|
2013-06-22 11:46:40 +02:00
|
|
|
|
|
|
|
uint8_t message_nonce [crypto_box_NONCEBYTES];
|
|
|
|
memcpy (message_nonce, "CurveZMQMESSAGEC", 16);
|
2014-09-19 18:07:57 -06:00
|
|
|
put_uint64 (message_nonce + 16, cn_nonce);
|
2013-06-22 11:46:40 +02:00
|
|
|
|
|
|
|
const size_t mlen = crypto_box_ZEROBYTES + 1 + msg_->size ();
|
|
|
|
|
|
|
|
uint8_t *message_plaintext = static_cast <uint8_t *> (malloc (mlen));
|
|
|
|
alloc_assert (message_plaintext);
|
|
|
|
|
|
|
|
memset (message_plaintext, 0, crypto_box_ZEROBYTES);
|
|
|
|
message_plaintext [crypto_box_ZEROBYTES] = flags;
|
|
|
|
memcpy (message_plaintext + crypto_box_ZEROBYTES + 1,
|
|
|
|
msg_->data (), msg_->size ());
|
|
|
|
|
|
|
|
uint8_t *message_box = static_cast <uint8_t *> (malloc (mlen));
|
|
|
|
alloc_assert (message_box);
|
|
|
|
|
2017-08-15 16:28:24 +02:00
|
|
|
int rc = crypto_box_afternm (message_box, message_plaintext, mlen,
|
|
|
|
message_nonce, tools.cn_precom);
|
2013-06-22 11:46:40 +02:00
|
|
|
zmq_assert (rc == 0);
|
|
|
|
|
|
|
|
rc = msg_->close ();
|
|
|
|
zmq_assert (rc == 0);
|
|
|
|
|
|
|
|
rc = msg_->init_size (16 + mlen - crypto_box_BOXZEROBYTES);
|
|
|
|
zmq_assert (rc == 0);
|
|
|
|
|
|
|
|
uint8_t *message = static_cast <uint8_t *> (msg_->data ());
|
|
|
|
|
2013-09-04 17:59:45 +02:00
|
|
|
memcpy (message, "\x07MESSAGE", 8);
|
2014-09-19 18:07:57 -06:00
|
|
|
memcpy (message + 8, message_nonce + 16, 8);
|
2013-06-22 11:46:40 +02:00
|
|
|
memcpy (message + 16, message_box + crypto_box_BOXZEROBYTES,
|
|
|
|
mlen - crypto_box_BOXZEROBYTES);
|
|
|
|
|
|
|
|
free (message_plaintext);
|
|
|
|
free (message_box);
|
|
|
|
|
2013-09-17 14:05:55 +02:00
|
|
|
cn_nonce++;
|
2013-06-22 11:46:40 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int zmq::curve_client_t::decode (msg_t *msg_)
|
|
|
|
{
|
|
|
|
zmq_assert (state == connected);
|
2017-08-18 10:04:58 +02:00
|
|
|
int rc = check_basic_command_structure (msg_);
|
|
|
|
if (rc == -1)
|
|
|
|
return rc;
|
2013-06-22 11:46:40 +02:00
|
|
|
|
2017-08-18 10:04:58 +02:00
|
|
|
const uint8_t *message = static_cast <uint8_t *> (msg_->data ());
|
|
|
|
if (msg_->size() < 8 || memcmp (message, "\x07MESSAGE", 8)) {
|
2017-08-17 18:32:44 +02:00
|
|
|
session->get_socket ()->event_handshake_failed_protocol (
|
|
|
|
session->get_endpoint (),
|
2017-08-18 10:04:58 +02:00
|
|
|
ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
2013-06-22 11:46:40 +02:00
|
|
|
errno = EPROTO;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-08-18 10:04:58 +02:00
|
|
|
if (msg_->size () < 33) {
|
2017-08-17 18:32:44 +02:00
|
|
|
session->get_socket ()->event_handshake_failed_protocol (
|
|
|
|
session->get_endpoint (),
|
2017-08-18 10:04:58 +02:00
|
|
|
ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_MESSAGE);
|
2013-06-22 11:46:40 +02:00
|
|
|
errno = EPROTO;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t message_nonce [crypto_box_NONCEBYTES];
|
|
|
|
memcpy (message_nonce, "CurveZMQMESSAGES", 16);
|
|
|
|
memcpy (message_nonce + 16, message + 8, 8);
|
2014-09-19 18:07:57 -06:00
|
|
|
uint64_t nonce = get_uint64(message + 8);
|
|
|
|
if (nonce <= cn_peer_nonce) {
|
2017-08-17 18:32:44 +02:00
|
|
|
session->get_socket ()->event_handshake_failed_protocol (
|
|
|
|
session->get_endpoint (),
|
|
|
|
ZMQ_PROTOCOL_ERROR_ZMTP_INVALID_SEQUENCE);
|
2014-09-19 18:07:57 -06:00
|
|
|
errno = EPROTO;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
cn_peer_nonce = nonce;
|
|
|
|
|
2013-06-22 11:46:40 +02:00
|
|
|
const size_t clen = crypto_box_BOXZEROBYTES + (msg_->size () - 16);
|
|
|
|
|
|
|
|
uint8_t *message_plaintext = static_cast <uint8_t *> (malloc (clen));
|
|
|
|
alloc_assert (message_plaintext);
|
|
|
|
|
|
|
|
uint8_t *message_box = static_cast <uint8_t *> (malloc (clen));
|
|
|
|
alloc_assert (message_box);
|
|
|
|
|
|
|
|
memset (message_box, 0, crypto_box_BOXZEROBYTES);
|
|
|
|
memcpy (message_box + crypto_box_BOXZEROBYTES,
|
|
|
|
message + 16, msg_->size () - 16);
|
|
|
|
|
2017-08-18 10:04:58 +02:00
|
|
|
rc = crypto_box_open_afternm (message_plaintext, message_box, clen,
|
|
|
|
message_nonce, tools.cn_precom);
|
2013-06-22 11:46:40 +02:00
|
|
|
if (rc == 0) {
|
|
|
|
rc = msg_->close ();
|
|
|
|
zmq_assert (rc == 0);
|
|
|
|
|
|
|
|
rc = msg_->init_size (clen - 1 - crypto_box_ZEROBYTES);
|
|
|
|
zmq_assert (rc == 0);
|
|
|
|
|
|
|
|
const uint8_t flags = message_plaintext [crypto_box_ZEROBYTES];
|
|
|
|
if (flags & 0x01)
|
|
|
|
msg_->set_flags (msg_t::more);
|
2015-03-16 21:39:16 -04:00
|
|
|
if (flags & 0x02)
|
|
|
|
msg_->set_flags (msg_t::command);
|
2013-06-22 11:46:40 +02:00
|
|
|
|
|
|
|
memcpy (msg_->data (),
|
|
|
|
message_plaintext + crypto_box_ZEROBYTES + 1,
|
|
|
|
msg_->size ());
|
|
|
|
}
|
2017-08-17 18:32:44 +02:00
|
|
|
else {
|
|
|
|
session->get_socket ()->event_handshake_failed_protocol (
|
|
|
|
session->get_endpoint (),
|
|
|
|
ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
|
2013-06-22 11:46:40 +02:00
|
|
|
errno = EPROTO;
|
2017-08-17 18:32:44 +02:00
|
|
|
}
|
2013-06-22 11:46:40 +02:00
|
|
|
|
|
|
|
free (message_plaintext);
|
|
|
|
free (message_box);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-05-06 17:07:50 +02:00
|
|
|
zmq::mechanism_t::status_t zmq::curve_client_t::status () const
|
2013-06-18 23:38:24 +02:00
|
|
|
{
|
2014-05-15 06:38:17 +02:00
|
|
|
if (state == connected)
|
|
|
|
return mechanism_t::ready;
|
|
|
|
else
|
|
|
|
if (state == error_received)
|
|
|
|
return mechanism_t::error;
|
|
|
|
else
|
|
|
|
return mechanism_t::handshaking;
|
2013-06-18 23:38:24 +02:00
|
|
|
}
|
|
|
|
|
2013-09-04 17:59:45 +02:00
|
|
|
int zmq::curve_client_t::produce_hello (msg_t *msg_)
|
2013-06-18 23:38:24 +02:00
|
|
|
{
|
2017-08-15 16:28:24 +02:00
|
|
|
int rc = msg_->init_size (200);
|
|
|
|
errno_assert (rc == 0);
|
2013-06-18 23:38:24 +02:00
|
|
|
|
2017-08-15 16:28:24 +02:00
|
|
|
rc = tools.produce_hello (msg_->data (), cn_nonce);
|
|
|
|
if (rc == -1) {
|
2017-08-17 18:32:44 +02:00
|
|
|
session->get_socket ()->event_handshake_failed_protocol (
|
|
|
|
session->get_endpoint (),
|
|
|
|
ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
|
|
|
|
|
2017-08-15 16:28:24 +02:00
|
|
|
// TODO this is somewhat inconsistent: we call init_size, but we may
|
|
|
|
// not close msg_; i.e. we assume that msg_ is initialized but empty
|
|
|
|
// (if it were non-empty, calling init_size might cause a leak!)
|
2013-06-18 23:38:24 +02:00
|
|
|
|
2017-08-15 16:28:24 +02:00
|
|
|
// msg_->close ();
|
2016-03-01 15:01:23 +01:00
|
|
|
return -1;
|
2017-08-15 16:28:24 +02:00
|
|
|
}
|
2013-06-18 23:38:24 +02:00
|
|
|
|
2013-09-17 14:05:55 +02:00
|
|
|
cn_nonce++;
|
2013-06-18 23:38:24 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-15 16:28:24 +02:00
|
|
|
int zmq::curve_client_t::process_welcome (const uint8_t *msg_data,
|
|
|
|
size_t msg_size)
|
2013-06-18 23:38:24 +02:00
|
|
|
{
|
2017-08-15 16:28:24 +02:00
|
|
|
int rc = tools.process_welcome (msg_data, msg_size);
|
2013-06-18 23:38:24 +02:00
|
|
|
|
2017-08-15 16:28:24 +02:00
|
|
|
if (rc == -1) {
|
2017-08-17 18:32:44 +02:00
|
|
|
session->get_socket ()->event_handshake_failed_protocol (
|
|
|
|
session->get_endpoint (),
|
|
|
|
ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
|
|
|
|
|
2013-06-18 23:38:24 +02:00
|
|
|
errno = EPROTO;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-05-15 06:38:17 +02:00
|
|
|
state = send_initiate;
|
|
|
|
|
2013-06-18 23:38:24 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-09-04 17:59:45 +02:00
|
|
|
int zmq::curve_client_t::produce_initiate (msg_t *msg_)
|
2013-06-18 23:38:24 +02:00
|
|
|
{
|
2017-08-15 19:42:31 +02:00
|
|
|
const size_t metadata_length = basic_properties_len ();
|
|
|
|
unsigned char *metadata_plaintext =
|
|
|
|
(unsigned char *) malloc (metadata_length);
|
|
|
|
alloc_assert (metadata_plaintext);
|
2013-06-18 23:38:24 +02:00
|
|
|
|
2017-08-15 19:42:31 +02:00
|
|
|
add_basic_properties (metadata_plaintext, metadata_length);
|
2013-06-18 23:38:24 +02:00
|
|
|
|
2017-08-15 16:28:24 +02:00
|
|
|
size_t msg_size = 113 + 128 + crypto_box_BOXZEROBYTES + metadata_length;
|
|
|
|
int rc = msg_->init_size (msg_size);
|
2013-06-18 23:38:24 +02:00
|
|
|
errno_assert (rc == 0);
|
|
|
|
|
2017-08-15 19:42:31 +02:00
|
|
|
rc = tools.produce_initiate (msg_->data (), msg_size, cn_nonce,
|
|
|
|
metadata_plaintext, metadata_length);
|
|
|
|
|
|
|
|
free (metadata_plaintext);
|
|
|
|
|
|
|
|
if (-1 == rc) {
|
2017-08-17 18:32:44 +02:00
|
|
|
session->get_socket ()->event_handshake_failed_protocol (
|
|
|
|
session->get_endpoint (),
|
|
|
|
ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
|
|
|
|
|
2017-08-15 16:28:24 +02:00
|
|
|
// TODO see comment in produce_hello
|
|
|
|
return -1;
|
|
|
|
}
|
2013-06-18 23:38:24 +02:00
|
|
|
|
2013-09-17 14:05:55 +02:00
|
|
|
cn_nonce++;
|
2013-06-18 23:38:24 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-15 06:38:17 +02:00
|
|
|
int zmq::curve_client_t::process_ready (
|
|
|
|
const uint8_t *msg_data, size_t msg_size)
|
2013-06-18 23:38:24 +02:00
|
|
|
{
|
2014-05-15 06:38:17 +02:00
|
|
|
if (msg_size < 30) {
|
2017-08-17 18:32:44 +02:00
|
|
|
session->get_socket ()->event_handshake_failed_protocol (
|
|
|
|
session->get_endpoint (),
|
|
|
|
ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_READY);
|
2013-06-18 23:38:24 +02:00
|
|
|
errno = EPROTO;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-05-15 06:38:17 +02:00
|
|
|
const size_t clen = (msg_size - 14) + crypto_box_BOXZEROBYTES;
|
2013-06-18 23:38:24 +02:00
|
|
|
|
|
|
|
uint8_t ready_nonce [crypto_box_NONCEBYTES];
|
2017-08-15 19:42:31 +02:00
|
|
|
uint8_t *ready_plaintext = (uint8_t *) malloc (crypto_box_ZEROBYTES + clen);
|
|
|
|
alloc_assert (ready_plaintext);
|
|
|
|
uint8_t *ready_box =
|
|
|
|
(uint8_t *) malloc (crypto_box_BOXZEROBYTES + 16 + clen);
|
|
|
|
alloc_assert (ready_box);
|
2013-06-18 23:38:24 +02:00
|
|
|
|
|
|
|
memset (ready_box, 0, crypto_box_BOXZEROBYTES);
|
|
|
|
memcpy (ready_box + crypto_box_BOXZEROBYTES,
|
2014-05-15 06:38:17 +02:00
|
|
|
msg_data + 14, clen - crypto_box_BOXZEROBYTES);
|
2013-06-18 23:38:24 +02:00
|
|
|
|
|
|
|
memcpy (ready_nonce, "CurveZMQREADY---", 16);
|
2014-05-15 06:38:17 +02:00
|
|
|
memcpy (ready_nonce + 16, msg_data + 6, 8);
|
2014-09-19 18:07:57 -06:00
|
|
|
cn_peer_nonce = get_uint64(msg_data + 6);
|
2013-06-18 23:38:24 +02:00
|
|
|
|
|
|
|
int rc = crypto_box_open_afternm (ready_plaintext, ready_box,
|
2017-08-15 16:28:24 +02:00
|
|
|
clen, ready_nonce, tools.cn_precom);
|
2017-08-15 19:42:31 +02:00
|
|
|
free (ready_box);
|
2013-06-18 23:38:24 +02:00
|
|
|
|
|
|
|
if (rc != 0) {
|
2017-08-17 18:32:44 +02:00
|
|
|
session->get_socket ()->event_handshake_failed_protocol (
|
|
|
|
session->get_endpoint (),
|
|
|
|
ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
|
2013-06-18 23:38:24 +02:00
|
|
|
errno = EPROTO;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-06-23 08:52:27 +02:00
|
|
|
rc = parse_metadata (ready_plaintext + crypto_box_ZEROBYTES,
|
|
|
|
clen - crypto_box_ZEROBYTES);
|
2017-08-15 19:42:31 +02:00
|
|
|
free (ready_plaintext);
|
|
|
|
|
2014-05-15 06:38:17 +02:00
|
|
|
if (rc == 0)
|
|
|
|
state = connected;
|
2017-08-17 18:32:44 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
session->get_socket ()->event_handshake_failed_protocol (
|
|
|
|
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_INVALID_METADATA);
|
|
|
|
errno = EPROTO;
|
|
|
|
}
|
2014-05-15 06:38:17 +02:00
|
|
|
|
2013-06-18 23:38:24 +02:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2014-05-15 06:38:17 +02:00
|
|
|
int zmq::curve_client_t::process_error (
|
|
|
|
const uint8_t *msg_data, size_t msg_size)
|
|
|
|
{
|
|
|
|
if (state != expect_welcome && state != expect_ready) {
|
2017-08-17 18:32:44 +02:00
|
|
|
session->get_socket ()->event_handshake_failed_protocol (
|
|
|
|
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_UNEXPECTED_COMMAND);
|
2014-05-15 06:38:17 +02:00
|
|
|
errno = EPROTO;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (msg_size < 7) {
|
2017-08-17 18:32:44 +02:00
|
|
|
session->get_socket ()->event_handshake_failed_protocol (
|
|
|
|
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_ERROR);
|
2014-05-15 06:38:17 +02:00
|
|
|
errno = EPROTO;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
const size_t error_reason_len = static_cast <size_t> (msg_data [6]);
|
|
|
|
if (error_reason_len > msg_size - 7) {
|
2017-08-17 18:32:44 +02:00
|
|
|
session->get_socket ()->event_handshake_failed_protocol (
|
|
|
|
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_MALFORMED_COMMAND_ERROR);
|
2014-05-15 06:38:17 +02:00
|
|
|
errno = EPROTO;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
state = error_received;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-18 23:38:24 +02:00
|
|
|
#endif
|