Commit 3e394fdd authored by Simon Giesecke's avatar Simon Giesecke

Problem: naming convention violated by curve_mechanism_base

Solution: change to conform with naming convention
parent 75dfbae0
...@@ -137,7 +137,7 @@ int zmq::curve_client_t::produce_hello (msg_t *msg_) ...@@ -137,7 +137,7 @@ int zmq::curve_client_t::produce_hello (msg_t *msg_)
int rc = msg_->init_size (200); int rc = msg_->init_size (200);
errno_assert (rc == 0); errno_assert (rc == 0);
rc = _tools.produce_hello (msg_->data (), cn_nonce); rc = _tools.produce_hello (msg_->data (), _cn_nonce);
if (rc == -1) { if (rc == -1) {
session->get_socket ()->event_handshake_failed_protocol ( session->get_socket ()->event_handshake_failed_protocol (
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC); session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_CRYPTOGRAPHIC);
...@@ -150,7 +150,7 @@ int zmq::curve_client_t::produce_hello (msg_t *msg_) ...@@ -150,7 +150,7 @@ int zmq::curve_client_t::produce_hello (msg_t *msg_)
return -1; return -1;
} }
cn_nonce++; _cn_nonce++;
return 0; return 0;
} }
...@@ -158,7 +158,7 @@ int zmq::curve_client_t::produce_hello (msg_t *msg_) ...@@ -158,7 +158,7 @@ int zmq::curve_client_t::produce_hello (msg_t *msg_)
int zmq::curve_client_t::process_welcome (const uint8_t *msg_data_, int zmq::curve_client_t::process_welcome (const uint8_t *msg_data_,
size_t msg_size_) size_t msg_size_)
{ {
const int rc = _tools.process_welcome (msg_data_, msg_size_, cn_precom); const int rc = _tools.process_welcome (msg_data_, msg_size_, _cn_precom);
if (rc == -1) { if (rc == -1) {
session->get_socket ()->event_handshake_failed_protocol ( session->get_socket ()->event_handshake_failed_protocol (
...@@ -186,7 +186,7 @@ int zmq::curve_client_t::produce_initiate (msg_t *msg_) ...@@ -186,7 +186,7 @@ int zmq::curve_client_t::produce_initiate (msg_t *msg_)
int rc = msg_->init_size (msg_size); int rc = msg_->init_size (msg_size);
errno_assert (rc == 0); errno_assert (rc == 0);
rc = _tools.produce_initiate (msg_->data (), msg_size, cn_nonce, rc = _tools.produce_initiate (msg_->data (), msg_size, _cn_nonce,
&metadata_plaintext[0], metadata_length); &metadata_plaintext[0], metadata_length);
if (-1 == rc) { if (-1 == rc) {
...@@ -197,7 +197,7 @@ int zmq::curve_client_t::produce_initiate (msg_t *msg_) ...@@ -197,7 +197,7 @@ int zmq::curve_client_t::produce_initiate (msg_t *msg_)
return -1; return -1;
} }
cn_nonce++; _cn_nonce++;
return 0; return 0;
} }
...@@ -227,10 +227,10 @@ int zmq::curve_client_t::process_ready (const uint8_t *msg_data_, ...@@ -227,10 +227,10 @@ int zmq::curve_client_t::process_ready (const uint8_t *msg_data_,
memcpy (ready_nonce, "CurveZMQREADY---", 16); memcpy (ready_nonce, "CurveZMQREADY---", 16);
memcpy (ready_nonce + 16, msg_data_ + 6, 8); memcpy (ready_nonce + 16, msg_data_ + 6, 8);
cn_peer_nonce = get_uint64 (msg_data_ + 6); _cn_peer_nonce = get_uint64 (msg_data_ + 6);
int rc = crypto_box_open_afternm (&ready_plaintext[0], &ready_box[0], clen, int rc = crypto_box_open_afternm (&ready_plaintext[0], &ready_box[0], clen,
ready_nonce, cn_precom); ready_nonce, _cn_precom);
if (rc != 0) { if (rc != 0) {
session->get_socket ()->event_handshake_failed_protocol ( session->get_socket ()->event_handshake_failed_protocol (
......
...@@ -42,10 +42,10 @@ zmq::curve_mechanism_base_t::curve_mechanism_base_t ( ...@@ -42,10 +42,10 @@ zmq::curve_mechanism_base_t::curve_mechanism_base_t (
const char *encode_nonce_prefix_, const char *encode_nonce_prefix_,
const char *decode_nonce_prefix_) : const char *decode_nonce_prefix_) :
mechanism_base_t (session_, options_), mechanism_base_t (session_, options_),
encode_nonce_prefix (encode_nonce_prefix_), _encode_nonce_prefix (encode_nonce_prefix_),
decode_nonce_prefix (decode_nonce_prefix_), _decode_nonce_prefix (decode_nonce_prefix_),
cn_nonce (1), _cn_nonce (1),
cn_peer_nonce (1) _cn_peer_nonce (1)
{ {
} }
...@@ -54,8 +54,8 @@ int zmq::curve_mechanism_base_t::encode (msg_t *msg_) ...@@ -54,8 +54,8 @@ int zmq::curve_mechanism_base_t::encode (msg_t *msg_)
const size_t mlen = crypto_box_ZEROBYTES + 1 + msg_->size (); const size_t mlen = crypto_box_ZEROBYTES + 1 + msg_->size ();
uint8_t message_nonce[crypto_box_NONCEBYTES]; uint8_t message_nonce[crypto_box_NONCEBYTES];
memcpy (message_nonce, encode_nonce_prefix, 16); memcpy (message_nonce, _encode_nonce_prefix, 16);
put_uint64 (message_nonce + 16, cn_nonce); put_uint64 (message_nonce + 16, _cn_nonce);
uint8_t flags = 0; uint8_t flags = 0;
if (msg_->flags () & msg_t::more) if (msg_->flags () & msg_t::more)
...@@ -77,7 +77,7 @@ int zmq::curve_mechanism_base_t::encode (msg_t *msg_) ...@@ -77,7 +77,7 @@ int zmq::curve_mechanism_base_t::encode (msg_t *msg_)
std::vector<uint8_t> message_box (mlen); std::vector<uint8_t> message_box (mlen);
int rc = crypto_box_afternm (&message_box[0], &message_plaintext[0], mlen, int rc = crypto_box_afternm (&message_box[0], &message_plaintext[0], mlen,
message_nonce, cn_precom); message_nonce, _cn_precom);
zmq_assert (rc == 0); zmq_assert (rc == 0);
rc = msg_->close (); rc = msg_->close ();
...@@ -93,7 +93,7 @@ int zmq::curve_mechanism_base_t::encode (msg_t *msg_) ...@@ -93,7 +93,7 @@ int zmq::curve_mechanism_base_t::encode (msg_t *msg_)
memcpy (message + 16, &message_box[crypto_box_BOXZEROBYTES], memcpy (message + 16, &message_box[crypto_box_BOXZEROBYTES],
mlen - crypto_box_BOXZEROBYTES); mlen - crypto_box_BOXZEROBYTES);
cn_nonce++; _cn_nonce++;
return 0; return 0;
} }
...@@ -123,16 +123,16 @@ int zmq::curve_mechanism_base_t::decode (msg_t *msg_) ...@@ -123,16 +123,16 @@ int zmq::curve_mechanism_base_t::decode (msg_t *msg_)
} }
uint8_t message_nonce[crypto_box_NONCEBYTES]; uint8_t message_nonce[crypto_box_NONCEBYTES];
memcpy (message_nonce, decode_nonce_prefix, 16); memcpy (message_nonce, _decode_nonce_prefix, 16);
memcpy (message_nonce + 16, message + 8, 8); memcpy (message_nonce + 16, message + 8, 8);
const uint64_t nonce = get_uint64 (message + 8); const uint64_t nonce = get_uint64 (message + 8);
if (nonce <= cn_peer_nonce) { if (nonce <= _cn_peer_nonce) {
session->get_socket ()->event_handshake_failed_protocol ( session->get_socket ()->event_handshake_failed_protocol (
session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_INVALID_SEQUENCE); session->get_endpoint (), ZMQ_PROTOCOL_ERROR_ZMTP_INVALID_SEQUENCE);
errno = EPROTO; errno = EPROTO;
return -1; return -1;
} }
cn_peer_nonce = nonce; _cn_peer_nonce = nonce;
const size_t clen = crypto_box_BOXZEROBYTES + msg_->size () - 16; const size_t clen = crypto_box_BOXZEROBYTES + msg_->size () - 16;
...@@ -145,7 +145,7 @@ int zmq::curve_mechanism_base_t::decode (msg_t *msg_) ...@@ -145,7 +145,7 @@ int zmq::curve_mechanism_base_t::decode (msg_t *msg_)
msg_->size () - 16); msg_->size () - 16);
rc = crypto_box_open_afternm (&message_plaintext[0], &message_box[0], clen, rc = crypto_box_open_afternm (&message_plaintext[0], &message_box[0], clen,
message_nonce, cn_precom); message_nonce, _cn_precom);
if (rc == 0) { if (rc == 0) {
rc = msg_->close (); rc = msg_->close ();
zmq_assert (rc == 0); zmq_assert (rc == 0);
......
...@@ -64,15 +64,16 @@ class curve_mechanism_base_t : public virtual mechanism_base_t ...@@ -64,15 +64,16 @@ class curve_mechanism_base_t : public virtual mechanism_base_t
int encode (msg_t *msg_) ZMQ_OVERRIDE; int encode (msg_t *msg_) ZMQ_OVERRIDE;
int decode (msg_t *msg_) ZMQ_OVERRIDE; int decode (msg_t *msg_) ZMQ_OVERRIDE;
protected: private:
const char *encode_nonce_prefix; const char *_encode_nonce_prefix;
const char *decode_nonce_prefix; const char *_decode_nonce_prefix;
uint64_t cn_nonce; protected:
uint64_t cn_peer_nonce; uint64_t _cn_nonce;
uint64_t _cn_peer_nonce;
// Intermediary buffer used to speed up boxing and unboxing. // Intermediary buffer used to speed up boxing and unboxing.
uint8_t cn_precom[crypto_box_BEFORENMBYTES]; uint8_t _cn_precom[crypto_box_BEFORENMBYTES];
}; };
} }
......
...@@ -181,7 +181,7 @@ int zmq::curve_server_t::process_hello (msg_t *msg_) ...@@ -181,7 +181,7 @@ int zmq::curve_server_t::process_hello (msg_t *msg_)
memcpy (hello_nonce, "CurveZMQHELLO---", 16); memcpy (hello_nonce, "CurveZMQHELLO---", 16);
memcpy (hello_nonce + 16, hello + 112, 8); memcpy (hello_nonce + 16, hello + 112, 8);
cn_peer_nonce = get_uint64 (hello + 112); _cn_peer_nonce = get_uint64 (hello + 112);
memset (hello_box, 0, crypto_box_BOXZEROBYTES); memset (hello_box, 0, crypto_box_BOXZEROBYTES);
memcpy (hello_box + crypto_box_BOXZEROBYTES, hello + 120, 80); memcpy (hello_box + crypto_box_BOXZEROBYTES, hello + 120, 80);
...@@ -345,7 +345,7 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_) ...@@ -345,7 +345,7 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
memcpy (initiate_nonce, "CurveZMQINITIATE", 16); memcpy (initiate_nonce, "CurveZMQINITIATE", 16);
memcpy (initiate_nonce + 16, initiate + 105, 8); memcpy (initiate_nonce + 16, initiate + 105, 8);
cn_peer_nonce = get_uint64 (initiate + 105); _cn_peer_nonce = get_uint64 (initiate + 105);
const uint8_t *client_key = &initiate_plaintext[crypto_box_ZEROBYTES]; const uint8_t *client_key = &initiate_plaintext[crypto_box_ZEROBYTES];
...@@ -396,7 +396,7 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_) ...@@ -396,7 +396,7 @@ int zmq::curve_server_t::process_initiate (msg_t *msg_)
} }
// Precompute connection secret from client key // Precompute connection secret from client key
rc = crypto_box_beforenm (cn_precom, _cn_client, _cn_secret); rc = crypto_box_beforenm (_cn_precom, _cn_client, _cn_secret);
zmq_assert (rc == 0); zmq_assert (rc == 0);
// Given this is a backward-incompatible change, it's behind a socket // Given this is a backward-incompatible change, it's behind a socket
...@@ -449,13 +449,13 @@ int zmq::curve_server_t::produce_ready (msg_t *msg_) ...@@ -449,13 +449,13 @@ int zmq::curve_server_t::produce_ready (msg_t *msg_)
const size_t mlen = ptr - &ready_plaintext[0]; const size_t mlen = ptr - &ready_plaintext[0];
memcpy (ready_nonce, "CurveZMQREADY---", 16); memcpy (ready_nonce, "CurveZMQREADY---", 16);
put_uint64 (ready_nonce + 16, cn_nonce); put_uint64 (ready_nonce + 16, _cn_nonce);
std::vector<uint8_t> ready_box (crypto_box_BOXZEROBYTES + 16 std::vector<uint8_t> ready_box (crypto_box_BOXZEROBYTES + 16
+ metadata_length); + metadata_length);
int rc = crypto_box_afternm (&ready_box[0], &ready_plaintext[0], mlen, int rc = crypto_box_afternm (&ready_box[0], &ready_plaintext[0], mlen,
ready_nonce, cn_precom); ready_nonce, _cn_precom);
zmq_assert (rc == 0); zmq_assert (rc == 0);
rc = msg_->init_size (14 + mlen - crypto_box_BOXZEROBYTES); rc = msg_->init_size (14 + mlen - crypto_box_BOXZEROBYTES);
...@@ -470,7 +470,7 @@ int zmq::curve_server_t::produce_ready (msg_t *msg_) ...@@ -470,7 +470,7 @@ int zmq::curve_server_t::produce_ready (msg_t *msg_)
memcpy (ready + 14, &ready_box[crypto_box_BOXZEROBYTES], memcpy (ready + 14, &ready_box[crypto_box_BOXZEROBYTES],
mlen - crypto_box_BOXZEROBYTES); mlen - crypto_box_BOXZEROBYTES);
cn_nonce++; _cn_nonce++;
return 0; return 0;
} }
......
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