1/*
2 Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
3
4 This file is part of libzmq, the ZeroMQ core engine in C++.
5
6 libzmq is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License (LGPL) as published
8 by the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 As a special exception, the Contributors give you permission to link
12 this library with independent modules to produce an executable,
13 regardless of the license terms of these independent modules, and to
14 copy and distribute the resulting executable under terms of your choice,
15 provided that you also meet, for each linked independent module, the
16 terms and conditions of the license of that module. An independent
17 module is a module which is not derived from or based on this library.
18 If you modify this library, you must extend this exception to your
19 version of the library.
20
21 libzmq is distributed in the hope that it will be useful, but WITHOUT
22 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24 License for more details.
25
26 You should have received a copy of the GNU Lesser General Public License
27 along with this program. If not, see <http://www.gnu.org/licenses/>.
28*/
29
30#ifndef __ZMQ_CURVE_SERVER_HPP_INCLUDED__
31#define __ZMQ_CURVE_SERVER_HPP_INCLUDED__
32
33#ifdef ZMQ_HAVE_CURVE
34
35#include "curve_mechanism_base.hpp"
36#include "options.hpp"
37#include "zap_client.hpp"
38
39namespace zmq
40{
41#ifdef _MSC_VER
42#pragma warning(push)
43#pragma warning(disable : 4250)
44#endif
45class curve_server_t : public zap_client_common_handshake_t,
46 public curve_mechanism_base_t
47{
48 public:
49 curve_server_t (session_base_t *session_,
50 const std::string &peer_address_,
51 const options_t &options_);
52 virtual ~curve_server_t ();
53
54 // mechanism implementation
55 virtual int next_handshake_command (msg_t *msg_);
56 virtual int process_handshake_command (msg_t *msg_);
57 virtual int encode (msg_t *msg_);
58 virtual int decode (msg_t *msg_);
59
60 private:
61 // Our secret key (s)
62 uint8_t _secret_key[crypto_box_SECRETKEYBYTES];
63
64 // Our short-term public key (S')
65 uint8_t _cn_public[crypto_box_PUBLICKEYBYTES];
66
67 // Our short-term secret key (s')
68 uint8_t _cn_secret[crypto_box_SECRETKEYBYTES];
69
70 // Client's short-term public key (C')
71 uint8_t _cn_client[crypto_box_PUBLICKEYBYTES];
72
73 // Key used to produce cookie
74 uint8_t _cookie_key[crypto_secretbox_KEYBYTES];
75
76 int process_hello (msg_t *msg_);
77 int produce_welcome (msg_t *msg_);
78 int process_initiate (msg_t *msg_);
79 int produce_ready (msg_t *msg_);
80 int produce_error (msg_t *msg_) const;
81
82 void send_zap_request (const uint8_t *key_);
83};
84#ifdef _MSC_VER
85#pragma warning(pop)
86#endif
87}
88
89#endif
90
91#endif
92