Commit abcb2243 authored by Mike Gatny's avatar Mike Gatny Committed by Chris Busbey

stubbed in TOKEN command

parent 4b1c851d
......@@ -38,6 +38,7 @@ zmq::gssapi_mechanism_t::gssapi_mechanism_t (session_base_t *session_,
session (session_),
peer_address (peer_address_),
expecting_zap_reply (false),
expecting_another_token (true),
state (options.as_server? waiting_for_hello: sending_hello)
{
}
......@@ -64,7 +65,12 @@ int zmq::gssapi_mechanism_t::next_handshake_command (msg_t *msg_)
case sending_initiate:
rc = produce_initiate (msg_);
if (rc == 0)
state = waiting_for_ready;
state = waiting_for_token;
break;
case sending_token:
rc = produce_token (msg_);
if (rc == 0)
state = waiting_for_ready; //state = expecting_another_token? waiting_for_token: waiting_for_ready;
break;
case sending_ready:
rc = produce_ready (msg_);
......@@ -96,7 +102,12 @@ int zmq::gssapi_mechanism_t::process_handshake_command (msg_t *msg_)
case waiting_for_initiate:
rc = process_initiate (msg_);
if (rc == 0)
state = sending_ready;
state = sending_token;
break;
case waiting_for_token:
rc = process_token (msg_);
if (rc == 0)
state = sending_ready; // state = expecting_another_token? sending_token: sending_ready;
break;
case waiting_for_ready:
rc = process_ready (msg_);
......@@ -291,6 +302,55 @@ int zmq::gssapi_mechanism_t::process_initiate (msg_t *msg_)
return parse_metadata (ptr, bytes_left);
}
int zmq::gssapi_mechanism_t::produce_token (msg_t *msg_) const
{
unsigned char * const command_buffer = (unsigned char *) malloc (512);
alloc_assert (command_buffer);
unsigned char *ptr = command_buffer;
// Add command name
memcpy (ptr, "\x05TOKEN", 6);
ptr += 6;
// Add socket type property
const char *socket_type = socket_type_string (options.type);
ptr += add_property (ptr, "Socket-Type", socket_type, strlen (socket_type));
// Add identity property
if (options.type == ZMQ_REQ
|| options.type == ZMQ_DEALER
|| options.type == ZMQ_ROUTER) {
ptr += add_property (ptr, "Identity",
options.identity, options.identity_size);
}
const size_t command_size = ptr - command_buffer;
const int rc = msg_->init_size (command_size);
errno_assert (rc == 0);
memcpy (msg_->data (), command_buffer, command_size);
free (command_buffer);
return 0;
}
int zmq::gssapi_mechanism_t::process_token (msg_t *msg_)
{
const unsigned char *ptr = static_cast <unsigned char *> (msg_->data ());
size_t bytes_left = msg_->size ();
if (bytes_left < 6 || memcmp (ptr, "\x05TOKEN", 6)) {
errno = EPROTO;
return -1;
}
ptr += 6;
bytes_left -= 6;
expecting_another_token = false;
return parse_metadata (ptr, bytes_left);
}
int zmq::gssapi_mechanism_t::produce_ready (msg_t *msg_) const
{
unsigned char * const command_buffer = (unsigned char *) malloc (512);
......
......@@ -53,6 +53,8 @@ namespace zmq
waiting_for_welcome,
sending_initiate,
waiting_for_initiate,
sending_token,
waiting_for_token,
sending_ready,
waiting_for_ready,
waiting_for_zap_reply,
......@@ -65,18 +67,22 @@ namespace zmq
// True iff we are awaiting reply from ZAP reply.
bool expecting_zap_reply;
// True iff we are awaiting another GSS token.
bool expecting_another_token;
state_t state;
int produce_hello (msg_t *msg_) const;
int produce_welcome (msg_t *msg_) const;
int produce_initiate (msg_t *msg_) const;
int produce_token (msg_t *msg_) const;
int produce_ready (msg_t *msg_) const;
int process_hello (msg_t *msg_);
int process_welcome (msg_t *msg);
int process_ready (msg_t *msg_);
int process_initiate (msg_t *msg_);
int process_token (msg_t *msg_);
int process_ready (msg_t *msg_);
void send_zap_request (const std::string &username,
const std::string &password);
......
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