2
Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file
4
This file is part of 0MQ.
6
0MQ is free software; you can redistribute it and/or modify it under
7
the terms of the GNU Lesser General Public License as published by
8
the Free Software Foundation; either version 3 of the License, or
9
(at your option) any later version.
11
0MQ is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU Lesser General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public License
17
along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#ifndef __ZMQ_CURVE_SERVER_HPP_INCLUDED__
21
#define __ZMQ_CURVE_SERVER_HPP_INCLUDED__
23
#include "platform.hpp"
28
#if crypto_box_NONCEBYTES != 24 \
29
|| crypto_box_PUBLICKEYBYTES != 32 \
30
|| crypto_box_SECRETKEYBYTES != 32 \
31
|| crypto_box_ZEROBYTES != 32 \
32
|| crypto_box_BOXZEROBYTES != 16 \
33
|| crypto_secretbox_NONCEBYTES != 24 \
34
|| crypto_secretbox_ZEROBYTES != 32 \
35
|| crypto_secretbox_BOXZEROBYTES != 16
36
#error "libsodium not built properly"
39
#include "mechanism.hpp"
40
#include "options.hpp"
48
class curve_server_t : public mechanism_t
52
curve_server_t (session_base_t *session_,
53
const std::string &peer_address_,
54
const options_t &options_);
55
virtual ~curve_server_t ();
57
// mechanism implementation
58
virtual int next_handshake_command (msg_t *msg_);
59
virtual int process_handshake_command (msg_t *msg_);
60
virtual int encode (msg_t *msg_);
61
virtual int decode (msg_t *msg_);
62
virtual int zap_msg_available ();
63
virtual bool is_handshake_complete () const;
76
session_base_t * const session;
78
const std::string peer_address;
83
// True iff we are awaiting reply from ZAP handler.
84
bool expecting_zap_reply;
89
uint8_t secret_key [crypto_box_SECRETKEYBYTES];
91
// Our short-term public key (S')
92
uint8_t cn_public [crypto_box_PUBLICKEYBYTES];
94
// Our short-term secret key (s')
95
uint8_t cn_secret [crypto_box_SECRETKEYBYTES];
97
// Client's short-term public key (C')
98
uint8_t cn_client [crypto_box_PUBLICKEYBYTES];
100
// Key used to produce cookie
101
uint8_t cookie_key [crypto_secretbox_KEYBYTES];
103
// Intermediary buffer used to speed up boxing and unboxing.
104
uint8_t cn_precom [crypto_box_BEFORENMBYTES];
106
int process_hello (msg_t *msg_);
107
int produce_welcome (msg_t *msg_);
108
int process_initiate (msg_t *msg_);
109
int produce_ready (msg_t *msg_);
111
void send_zap_request (const uint8_t *key);
112
int receive_and_process_zap_reply ();