~ubuntu-branches/ubuntu/wily/zeromq3/wily-proposed

« back to all changes in this revision

Viewing changes to src/curve_server.hpp

  • Committer: Package Import Robot
  • Author(s): Alessandro Ghedini
  • Date: 2014-03-16 14:02:28 UTC
  • mfrom: (1.1.6) (6.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20140316140228-ig1sgh7czk59m9ux
Tags: 4.0.4+dfsg-1
* QA upload; orphan the package
  - Upload to unstable
* New upstream release
* Update repack.stub script
* Drop 02_fix-exported-symbols.patch and 03_fix-s390-rdtsc.patch
  (merged upstream)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file
 
3
 
 
4
    This file is part of 0MQ.
 
5
 
 
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.
 
10
 
 
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.
 
15
 
 
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/>.
 
18
*/
 
19
 
 
20
#ifndef __ZMQ_CURVE_SERVER_HPP_INCLUDED__
 
21
#define __ZMQ_CURVE_SERVER_HPP_INCLUDED__
 
22
 
 
23
#include "platform.hpp"
 
24
 
 
25
#ifdef HAVE_LIBSODIUM
 
26
#include <sodium.h>
 
27
 
 
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"
 
37
#endif
 
38
 
 
39
#include "mechanism.hpp"
 
40
#include "options.hpp"
 
41
 
 
42
namespace zmq
 
43
{
 
44
 
 
45
    class msg_t;
 
46
    class session_base_t;
 
47
 
 
48
    class curve_server_t : public mechanism_t
 
49
    {
 
50
    public:
 
51
 
 
52
        curve_server_t (session_base_t *session_,
 
53
                        const std::string &peer_address_,
 
54
                        const options_t &options_);
 
55
        virtual ~curve_server_t ();
 
56
 
 
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;
 
64
 
 
65
    private:
 
66
 
 
67
        enum state_t {
 
68
            expect_hello,
 
69
            send_welcome,
 
70
            expect_initiate,
 
71
            expect_zap_reply,
 
72
            send_ready,
 
73
            connected
 
74
        };
 
75
 
 
76
        session_base_t * const session;
 
77
 
 
78
        const std::string peer_address;
 
79
 
 
80
        //  Current FSM state
 
81
        state_t state;
 
82
 
 
83
        //  True iff we are awaiting reply from ZAP handler.
 
84
        bool expecting_zap_reply;
 
85
 
 
86
        uint64_t cn_nonce;
 
87
 
 
88
        //  Our secret key (s)
 
89
        uint8_t secret_key [crypto_box_SECRETKEYBYTES];
 
90
 
 
91
        //  Our short-term public key (S')
 
92
        uint8_t cn_public [crypto_box_PUBLICKEYBYTES];
 
93
 
 
94
        //  Our short-term secret key (s')
 
95
        uint8_t cn_secret [crypto_box_SECRETKEYBYTES];
 
96
 
 
97
        //  Client's short-term public key (C')
 
98
        uint8_t cn_client [crypto_box_PUBLICKEYBYTES];
 
99
 
 
100
        //  Key used to produce cookie
 
101
        uint8_t cookie_key [crypto_secretbox_KEYBYTES];
 
102
 
 
103
        //  Intermediary buffer used to speed up boxing and unboxing.
 
104
        uint8_t cn_precom [crypto_box_BEFORENMBYTES];
 
105
 
 
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_);
 
110
 
 
111
        void send_zap_request (const uint8_t *key);
 
112
        int receive_and_process_zap_reply ();
 
113
    };
 
114
 
 
115
}
 
116
 
 
117
#endif
 
118
 
 
119
#endif
 
120