rbczmq 1.7.1 → 1.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitmodules +1 -1
- data/CHANGELOG.rdoc +4 -0
- data/Gemfile.lock +1 -1
- data/README.rdoc +5 -4
- data/ext/czmq/.gitignore +5 -0
- data/ext/czmq/.travis.yml +10 -1
- data/ext/czmq/AUTHORS +2 -0
- data/ext/czmq/COPYING.LESSER +3 -0
- data/ext/czmq/Makefile.am +13 -3
- data/ext/czmq/NEWS +132 -0
- data/ext/czmq/README.md +1553 -615
- data/ext/czmq/README.txt +188 -72
- data/ext/czmq/addons/Makefile.am +9 -0
- data/ext/czmq/addons/makecert.c +72 -0
- data/ext/czmq/builds/mingw32/Makefile.mingw32 +11 -3
- data/ext/czmq/builds/msvc/.gitignore +4 -1
- data/ext/czmq/builds/msvc/czmq.vcproj +4 -0
- data/ext/czmq/builds/msvc/czmq.vcxproj +6 -1
- data/ext/czmq/builds/msvc/czmq.vcxproj.filters +4 -1
- data/ext/{zeromq/cmake/Modules/zmq_version.cpp → czmq/builds/msvc/platform.h} +10 -9
- data/ext/czmq/configure.ac +64 -5
- data/ext/czmq/doc/Makefile.am +8 -1
- data/ext/czmq/doc/mkmans +17 -0
- data/ext/czmq/doc/zauth.txt +191 -0
- data/ext/czmq/doc/zbeacon.txt +13 -22
- data/ext/czmq/doc/zcert.txt +122 -0
- data/ext/czmq/doc/zcertstore.txt +107 -0
- data/ext/czmq/doc/zchunk.txt +77 -0
- data/ext/czmq/doc/zclock.txt +8 -0
- data/ext/czmq/doc/zconfig.txt +9 -63
- data/ext/czmq/doc/zctx.txt +26 -7
- data/ext/czmq/doc/zdir.txt +83 -0
- data/ext/czmq/doc/zfile.txt +130 -35
- data/ext/czmq/doc/zframe.txt +6 -39
- data/ext/czmq/doc/zhash.txt +55 -10
- data/ext/czmq/doc/zlist.txt +2 -4
- data/ext/czmq/doc/zloop.txt +7 -1
- data/ext/czmq/doc/zmsg.txt +75 -32
- data/ext/czmq/doc/zpoller.txt +88 -0
- data/ext/czmq/doc/zsocket.txt +50 -1
- data/ext/czmq/doc/zsockopt.txt +185 -251
- data/ext/czmq/doc/zstr.txt +14 -3
- data/ext/czmq/doc/zsys.txt +89 -1
- data/ext/czmq/doc/ztree.txt +21 -11
- data/ext/czmq/examples/security/LICENSE +18 -0
- data/ext/czmq/examples/security/README.txt +9 -0
- data/ext/czmq/examples/security/grasslands.c +29 -0
- data/ext/czmq/examples/security/hello.c +10 -0
- data/ext/czmq/examples/security/ironhouse.c +55 -0
- data/ext/czmq/examples/security/ironhouse2.c +103 -0
- data/ext/czmq/examples/security/stonehouse.c +51 -0
- data/ext/czmq/examples/security/strawhouse.c +44 -0
- data/ext/czmq/examples/security/woodhouse.c +40 -0
- data/ext/czmq/images/README_1.png +0 -0
- data/ext/czmq/images/README_2.png +0 -0
- data/ext/czmq/include/czmq.h +10 -4
- data/ext/czmq/include/czmq_prelude.h +42 -42
- data/ext/czmq/include/zauth.h +97 -0
- data/ext/czmq/include/zbeacon.h +0 -5
- data/ext/czmq/include/zcert.h +118 -0
- data/ext/czmq/include/zcertstore.h +78 -0
- data/ext/czmq/include/zchunk.h +87 -0
- data/ext/czmq/include/zclock.h +4 -0
- data/ext/czmq/include/zconfig.h +21 -12
- data/ext/czmq/include/zctx.h +34 -11
- data/ext/czmq/include/zdir.h +90 -0
- data/ext/czmq/include/zfile.h +104 -25
- data/ext/czmq/include/zframe.h +7 -20
- data/ext/czmq/include/zhash.h +13 -0
- data/ext/czmq/include/zlist.h +0 -4
- data/ext/czmq/include/zloop.h +5 -5
- data/ext/czmq/include/zmsg.h +59 -29
- data/ext/czmq/include/zmutex.h +5 -0
- data/ext/czmq/include/zpoller.h +72 -0
- data/ext/czmq/include/zsocket.h +12 -15
- data/ext/czmq/include/zsockopt.h +124 -121
- data/ext/czmq/include/zstr.h +12 -9
- data/ext/czmq/include/zsys.h +50 -2
- data/ext/czmq/mkdoc +1 -1
- data/ext/czmq/model/sockopts.xml +101 -21
- data/ext/czmq/scripts/sockopts.gsl +95 -41
- data/ext/czmq/src/Makefile.am +13 -0
- data/ext/czmq/src/czmq_selftest.c +16 -10
- data/ext/czmq/src/selftest +2 -2
- data/ext/czmq/src/zauth.c +714 -0
- data/ext/czmq/src/zbeacon.c +27 -35
- data/ext/czmq/src/zcert.c +463 -0
- data/ext/czmq/src/zcertstore.c +265 -0
- data/ext/czmq/src/zchunk.c +207 -0
- data/ext/czmq/src/zclock.c +18 -0
- data/ext/czmq/src/zconfig.c +116 -99
- data/ext/czmq/src/zctx.c +103 -18
- data/ext/czmq/src/zdir.c +409 -0
- data/ext/czmq/src/zfile.c +421 -130
- data/ext/czmq/src/zframe.c +28 -127
- data/ext/czmq/src/zhash.c +255 -139
- data/ext/czmq/src/zlist.c +2 -8
- data/ext/czmq/src/zloop.c +40 -13
- data/ext/czmq/src/zmsg.c +109 -141
- data/ext/czmq/src/zmutex.c +27 -1
- data/ext/czmq/src/zpoller.c +218 -0
- data/ext/czmq/src/zsocket.c +53 -66
- data/ext/czmq/src/zsockopt.c +2337 -682
- data/ext/czmq/src/zstr.c +48 -118
- data/ext/czmq/src/zsys.c +270 -3
- data/ext/czmq/src/zthread.c +2 -2
- data/ext/czmq/src/ztree.c +179 -180
- data/ext/rbczmq/beacon.c +1 -1
- data/ext/rbczmq/context.c +12 -3
- data/ext/rbczmq/context.h +7 -0
- data/ext/rbczmq/extconf.rb +13 -4
- data/ext/rbczmq/pollitem.c +1 -1
- data/ext/rbczmq/socket.c +34 -24
- data/ext/rbczmq/socket.h +3 -2
- data/ext/zeromq/AUTHORS +17 -3
- data/ext/zeromq/CMakeLists.txt +742 -339
- data/ext/zeromq/COPYING.LESSER +2 -0
- data/ext/zeromq/Makefile.am +3 -3
- data/ext/zeromq/NEWS +130 -1
- data/ext/zeromq/{README → README.md} +8 -9
- data/ext/zeromq/builds/cmake/Modules/FindAsciiDoc.cmake +24 -0
- data/ext/zeromq/builds/cmake/Modules/TestZMQVersion.cmake +18 -0
- data/ext/zeromq/builds/cmake/Modules/ZMQSourceRunChecks.cmake +129 -0
- data/ext/zeromq/{cmake → builds/cmake}/NSIS.template32.in +1 -1
- data/ext/zeromq/{cmake → builds/cmake}/NSIS.template64.in +1 -1
- data/ext/zeromq/builds/cmake/platform.hpp.in +88 -0
- data/ext/zeromq/builds/mingw32/Makefile.mingw32 +47 -0
- data/ext/zeromq/{src/i_msg_sink.hpp → builds/mingw32/platform.hpp} +10 -21
- data/ext/zeromq/builds/msvc/Makefile.am +5 -2
- data/ext/zeromq/builds/msvc/c_local_lat/c_local_lat.vcxproj +1 -1
- data/ext/zeromq/builds/msvc/c_local_lat/c_local_lat11.vcxproj +91 -0
- data/ext/zeromq/builds/msvc/c_local_thr/c_local_thr.vcproj +2 -0
- data/ext/zeromq/builds/msvc/c_local_thr/c_local_thr.vcxproj +21 -1
- data/ext/zeromq/builds/msvc/c_local_thr/c_local_thr11.vcxproj +111 -0
- data/ext/zeromq/builds/msvc/c_remote_lat/c_remote_lat.vcxproj +1 -1
- data/ext/zeromq/builds/msvc/c_remote_lat/c_remote_lat11.vcxproj +91 -0
- data/ext/zeromq/builds/msvc/c_remote_thr/c_remote_thr.vcproj +2 -0
- data/ext/zeromq/builds/msvc/c_remote_thr/c_remote_thr.vcxproj +21 -1
- data/ext/zeromq/builds/msvc/c_remote_thr/c_remote_thr11.vcxproj +111 -0
- data/ext/zeromq/builds/msvc/errno.cpp +1 -1
- data/ext/zeromq/builds/msvc/errno.hpp +1 -1
- data/ext/zeromq/builds/msvc/inproc_lat/inproc_lat.vcproj +176 -174
- data/ext/zeromq/builds/msvc/inproc_lat/inproc_lat.vcxproj +21 -1
- data/ext/zeromq/builds/msvc/inproc_lat/inproc_lat11.vcxproj +110 -0
- data/ext/zeromq/builds/msvc/inproc_thr/inproc_thr.vcproj +176 -174
- data/ext/zeromq/builds/msvc/inproc_thr/inproc_thr.vcxproj +21 -1
- data/ext/zeromq/builds/msvc/inproc_thr/inproc_thr11.vcxproj +110 -0
- data/ext/zeromq/builds/msvc/libzmq/libzmq.vcproj +997 -804
- data/ext/zeromq/builds/msvc/libzmq/libzmq.vcxproj +78 -2
- data/ext/zeromq/builds/msvc/libzmq/libzmq.vcxproj.filters +42 -6
- data/ext/zeromq/builds/msvc/libzmq/libzmq11.vcxproj +362 -0
- data/ext/zeromq/builds/msvc/msvc.sln +6 -0
- data/ext/zeromq/builds/msvc/msvc10.sln +36 -2
- data/ext/zeromq/builds/msvc/msvc11.sln +150 -0
- data/ext/zeromq/builds/msvc/properties/Static.props +15 -0
- data/ext/zeromq/builds/msvc/properties/ZeroMQ.props +0 -1
- data/ext/zeromq/builds/msvc/properties/ZeroMQ_Static.props +23 -0
- data/ext/zeromq/builds/redhat/zeromq.spec.in +2 -1
- data/ext/zeromq/{configure.in → configure.ac} +74 -15
- data/ext/zeromq/doc/Makefile.am +6 -4
- data/ext/zeromq/doc/zmq.txt +30 -3
- data/ext/zeromq/doc/zmq_bind.txt +2 -2
- data/ext/zeromq/doc/zmq_close.txt +2 -2
- data/ext/zeromq/doc/zmq_connect.txt +9 -7
- data/ext/zeromq/doc/zmq_ctx_destroy.txt +4 -3
- data/ext/zeromq/doc/zmq_ctx_get.txt +8 -3
- data/ext/zeromq/doc/zmq_ctx_new.txt +3 -2
- data/ext/zeromq/doc/zmq_ctx_set.txt +13 -1
- data/ext/zeromq/doc/zmq_ctx_shutdown.txt +52 -0
- data/ext/zeromq/doc/zmq_ctx_term.txt +67 -0
- data/ext/zeromq/doc/zmq_curve.txt +92 -0
- data/ext/zeromq/doc/zmq_curve_keypair.txt +56 -0
- data/ext/zeromq/doc/zmq_disconnect.txt +2 -2
- data/ext/zeromq/doc/zmq_epgm.txt +5 -4
- data/ext/zeromq/doc/zmq_errno.txt +2 -2
- data/ext/zeromq/doc/zmq_getsockopt.txt +149 -24
- data/ext/zeromq/doc/zmq_init.txt +2 -2
- data/ext/zeromq/doc/zmq_inproc.txt +2 -2
- data/ext/zeromq/doc/zmq_ipc.txt +10 -5
- data/ext/zeromq/doc/zmq_msg_close.txt +4 -3
- data/ext/zeromq/doc/zmq_msg_copy.txt +2 -2
- data/ext/zeromq/doc/zmq_msg_data.txt +2 -2
- data/ext/zeromq/doc/zmq_msg_get.txt +3 -3
- data/ext/zeromq/doc/zmq_msg_init.txt +2 -2
- data/ext/zeromq/doc/zmq_msg_init_data.txt +2 -2
- data/ext/zeromq/doc/zmq_msg_init_size.txt +2 -2
- data/ext/zeromq/doc/zmq_msg_more.txt +6 -4
- data/ext/zeromq/doc/zmq_msg_move.txt +2 -2
- data/ext/zeromq/doc/zmq_msg_recv.txt +3 -4
- data/ext/zeromq/doc/zmq_msg_send.txt +10 -7
- data/ext/zeromq/doc/zmq_msg_set.txt +2 -1
- data/ext/zeromq/doc/zmq_msg_size.txt +2 -2
- data/ext/zeromq/doc/zmq_null.txt +27 -0
- data/ext/zeromq/doc/zmq_pgm.txt +5 -4
- data/ext/zeromq/doc/zmq_plain.txt +37 -0
- data/ext/zeromq/doc/zmq_poll.txt +2 -6
- data/ext/zeromq/doc/zmq_proxy.txt +2 -1
- data/ext/zeromq/doc/zmq_recv.txt +2 -5
- data/ext/zeromq/doc/zmq_recvmsg.txt +3 -5
- data/ext/zeromq/doc/zmq_send.txt +9 -7
- data/ext/zeromq/doc/zmq_send_const.txt +103 -0
- data/ext/zeromq/doc/zmq_sendmsg.txt +8 -8
- data/ext/zeromq/doc/zmq_setsockopt.txt +291 -37
- data/ext/zeromq/doc/zmq_socket.txt +92 -21
- data/ext/zeromq/doc/zmq_socket_monitor.txt +102 -131
- data/ext/zeromq/doc/zmq_strerror.txt +3 -2
- data/ext/zeromq/doc/zmq_tcp.txt +4 -2
- data/ext/zeromq/doc/zmq_term.txt +3 -3
- data/ext/zeromq/doc/zmq_unbind.txt +2 -2
- data/ext/zeromq/doc/zmq_version.txt +3 -2
- data/ext/zeromq/doc/zmq_z85_decode.txt +50 -0
- data/ext/zeromq/doc/zmq_z85_encode.txt +57 -0
- data/ext/zeromq/foreign/openpgm/libpgm-5.2.122~dfsg.tar.gz +0 -0
- data/ext/zeromq/include/zmq.h +179 -136
- data/ext/zeromq/include/zmq_utils.h +44 -3
- data/ext/zeromq/perf/inproc_lat.cpp +2 -4
- data/ext/zeromq/perf/inproc_thr.cpp +1 -1
- data/ext/zeromq/perf/local_lat.cpp +1 -3
- data/ext/zeromq/perf/local_thr.cpp +1 -3
- data/ext/zeromq/perf/remote_lat.cpp +1 -3
- data/ext/zeromq/perf/remote_thr.cpp +1 -8
- data/ext/zeromq/src/Makefile.am +26 -7
- data/ext/zeromq/src/address.cpp +7 -8
- data/ext/zeromq/src/address.hpp +1 -2
- data/ext/zeromq/src/array.hpp +1 -3
- data/ext/zeromq/src/atomic_counter.hpp +11 -3
- data/ext/zeromq/src/atomic_ptr.hpp +9 -3
- data/ext/zeromq/src/blob.hpp +2 -2
- data/ext/zeromq/src/clock.cpp +3 -4
- data/ext/zeromq/src/clock.hpp +1 -2
- data/ext/zeromq/src/command.hpp +2 -3
- data/ext/zeromq/src/config.hpp +1 -3
- data/ext/zeromq/src/ctx.cpp +154 -15
- data/ext/zeromq/src/ctx.hpp +34 -3
- data/ext/zeromq/src/curve_client.cpp +410 -0
- data/ext/zeromq/src/curve_client.hpp +109 -0
- data/ext/zeromq/src/curve_server.cpp +629 -0
- data/ext/zeromq/src/curve_server.hpp +120 -0
- data/ext/zeromq/src/dbuffer.hpp +134 -0
- data/ext/zeromq/src/dealer.cpp +52 -60
- data/ext/zeromq/src/dealer.hpp +12 -26
- data/ext/zeromq/src/decoder.hpp +27 -102
- data/ext/zeromq/src/devpoll.cpp +1 -3
- data/ext/zeromq/src/devpoll.hpp +1 -3
- data/ext/zeromq/src/dist.cpp +17 -15
- data/ext/zeromq/src/dist.hpp +5 -6
- data/ext/zeromq/src/encoder.hpp +32 -52
- data/ext/zeromq/src/epoll.cpp +1 -3
- data/ext/zeromq/src/epoll.hpp +1 -3
- data/ext/zeromq/src/err.cpp +2 -4
- data/ext/zeromq/src/err.hpp +7 -4
- data/ext/zeromq/src/fd.hpp +1 -2
- data/ext/zeromq/src/fq.cpp +2 -5
- data/ext/zeromq/src/fq.hpp +2 -4
- data/ext/zeromq/src/i_decoder.hpp +11 -9
- data/ext/zeromq/src/i_encoder.hpp +7 -11
- data/ext/zeromq/src/i_engine.hpp +3 -3
- data/ext/zeromq/src/i_poll_events.hpp +1 -3
- data/ext/zeromq/src/io_object.cpp +1 -3
- data/ext/zeromq/src/io_object.hpp +1 -3
- data/ext/zeromq/src/io_thread.cpp +1 -3
- data/ext/zeromq/src/io_thread.hpp +1 -3
- data/ext/zeromq/src/ip.cpp +46 -5
- data/ext/zeromq/src/ip.hpp +7 -4
- data/ext/zeromq/src/ipc_address.cpp +13 -2
- data/ext/zeromq/src/ipc_address.hpp +1 -2
- data/ext/zeromq/src/ipc_connecter.cpp +3 -3
- data/ext/zeromq/src/ipc_connecter.hpp +1 -2
- data/ext/zeromq/src/ipc_listener.cpp +15 -10
- data/ext/zeromq/src/ipc_listener.hpp +1 -2
- data/ext/zeromq/src/kqueue.cpp +11 -3
- data/ext/zeromq/src/kqueue.hpp +7 -3
- data/ext/zeromq/src/lb.cpp +13 -11
- data/ext/zeromq/src/lb.hpp +10 -5
- data/ext/zeromq/src/libzmq.pc.cmake.in +10 -0
- data/ext/zeromq/src/likely.hpp +1 -2
- data/ext/zeromq/src/mailbox.cpp +1 -4
- data/ext/zeromq/src/mailbox.hpp +8 -3
- data/ext/zeromq/src/mechanism.cpp +163 -0
- data/ext/zeromq/src/mechanism.hpp +101 -0
- data/ext/zeromq/src/msg.cpp +38 -18
- data/ext/zeromq/src/msg.hpp +19 -7
- data/ext/zeromq/src/mtrie.cpp +16 -14
- data/ext/zeromq/src/mtrie.hpp +1 -3
- data/ext/zeromq/src/mutex.hpp +42 -3
- data/ext/zeromq/src/null_mechanism.cpp +282 -0
- data/ext/zeromq/src/null_mechanism.hpp +65 -0
- data/ext/zeromq/src/object.cpp +29 -3
- data/ext/zeromq/src/object.hpp +8 -5
- data/ext/zeromq/src/options.cpp +557 -485
- data/ext/zeromq/src/options.hpp +38 -24
- data/ext/zeromq/src/own.cpp +1 -2
- data/ext/zeromq/src/own.hpp +1 -2
- data/ext/zeromq/src/pair.cpp +8 -25
- data/ext/zeromq/src/pair.hpp +5 -22
- data/ext/zeromq/src/pgm_receiver.cpp +80 -67
- data/ext/zeromq/src/pgm_receiver.hpp +11 -10
- data/ext/zeromq/src/pgm_sender.cpp +37 -16
- data/ext/zeromq/src/pgm_sender.hpp +12 -6
- data/ext/zeromq/src/pgm_socket.cpp +8 -8
- data/ext/zeromq/src/pgm_socket.hpp +1 -4
- data/ext/zeromq/src/pipe.cpp +110 -72
- data/ext/zeromq/src/pipe.hpp +36 -27
- data/ext/zeromq/src/plain_mechanism.cpp +482 -0
- data/ext/zeromq/src/plain_mechanism.hpp +88 -0
- data/ext/zeromq/src/poll.cpp +1 -3
- data/ext/zeromq/src/poll.hpp +1 -3
- data/ext/zeromq/src/poller.hpp +1 -3
- data/ext/zeromq/src/poller_base.cpp +3 -3
- data/ext/zeromq/src/poller_base.hpp +1 -2
- data/ext/zeromq/src/precompiled.cpp +1 -2
- data/ext/zeromq/src/precompiled.hpp +1 -2
- data/ext/zeromq/src/proxy.cpp +1 -2
- data/ext/zeromq/src/proxy.hpp +1 -2
- data/ext/zeromq/src/pub.cpp +2 -16
- data/ext/zeromq/src/pub.hpp +2 -19
- data/ext/zeromq/src/pull.cpp +7 -24
- data/ext/zeromq/src/pull.hpp +4 -21
- data/ext/zeromq/src/push.cpp +8 -22
- data/ext/zeromq/src/push.hpp +4 -21
- data/ext/zeromq/src/random.cpp +1 -2
- data/ext/zeromq/src/random.hpp +1 -2
- data/ext/zeromq/src/raw_decoder.cpp +63 -0
- data/ext/zeromq/src/raw_decoder.hpp +66 -0
- data/ext/zeromq/src/raw_encoder.cpp +40 -0
- data/ext/zeromq/src/raw_encoder.hpp +60 -0
- data/ext/zeromq/src/reaper.cpp +12 -2
- data/ext/zeromq/src/reaper.hpp +6 -2
- data/ext/zeromq/src/rep.cpp +7 -21
- data/ext/zeromq/src/rep.hpp +3 -20
- data/ext/zeromq/src/req.cpp +132 -38
- data/ext/zeromq/src/req.hpp +27 -8
- data/ext/zeromq/src/router.cpp +109 -65
- data/ext/zeromq/src/router.hpp +9 -23
- data/ext/zeromq/src/select.cpp +1 -3
- data/ext/zeromq/src/select.hpp +1 -3
- data/ext/zeromq/src/session_base.cpp +164 -118
- data/ext/zeromq/src/session_base.hpp +29 -22
- data/ext/zeromq/src/signaler.cpp +127 -19
- data/ext/zeromq/src/signaler.hpp +20 -3
- data/ext/zeromq/src/socket_base.cpp +167 -134
- data/ext/zeromq/src/socket_base.hpp +18 -20
- data/ext/zeromq/src/stdint.hpp +1 -2
- data/ext/zeromq/src/stream.cpp +257 -0
- data/ext/zeromq/src/stream.hpp +97 -0
- data/ext/zeromq/src/stream_engine.cpp +405 -157
- data/ext/zeromq/src/stream_engine.hpp +72 -23
- data/ext/zeromq/src/sub.cpp +5 -18
- data/ext/zeromq/src/sub.hpp +2 -19
- data/ext/zeromq/src/tcp.cpp +23 -3
- data/ext/zeromq/src/tcp.hpp +7 -3
- data/ext/zeromq/src/tcp_address.cpp +35 -46
- data/ext/zeromq/src/tcp_address.hpp +7 -12
- data/ext/zeromq/src/tcp_connecter.cpp +10 -5
- data/ext/zeromq/src/tcp_connecter.hpp +1 -3
- data/ext/zeromq/src/tcp_listener.cpp +19 -8
- data/ext/zeromq/src/tcp_listener.hpp +1 -3
- data/ext/zeromq/src/thread.cpp +2 -4
- data/ext/zeromq/src/thread.hpp +1 -3
- data/ext/zeromq/src/trie.cpp +122 -125
- data/ext/zeromq/src/trie.hpp +1 -4
- data/ext/zeromq/src/v1_decoder.cpp +77 -91
- data/ext/zeromq/src/v1_decoder.hpp +10 -21
- data/ext/zeromq/src/v1_encoder.cpp +24 -62
- data/ext/zeromq/src/v1_encoder.hpp +7 -18
- data/ext/zeromq/src/v2_decoder.cpp +142 -0
- data/ext/zeromq/src/v2_decoder.hpp +57 -0
- data/ext/zeromq/src/v2_encoder.cpp +67 -0
- data/ext/zeromq/src/{i_msg_source.hpp → v2_encoder.hpp} +20 -15
- data/ext/zeromq/src/{v1_protocol.hpp → v2_protocol.hpp} +7 -11
- data/ext/zeromq/src/windows.hpp +2 -4
- data/ext/zeromq/src/wire.hpp +5 -6
- data/ext/zeromq/src/xpub.cpp +37 -46
- data/ext/zeromq/src/xpub.hpp +7 -23
- data/ext/zeromq/src/xsub.cpp +26 -40
- data/ext/zeromq/src/xsub.hpp +5 -21
- data/ext/zeromq/src/ypipe.hpp +3 -4
- data/ext/zeromq/src/ypipe_base.hpp +44 -0
- data/ext/zeromq/src/ypipe_conflate.hpp +127 -0
- data/ext/zeromq/src/yqueue.hpp +3 -7
- data/ext/zeromq/src/zmq.cpp +76 -96
- data/ext/zeromq/src/zmq_utils.cpp +146 -8
- data/ext/zeromq/tests/Makefile.am +56 -8
- data/ext/zeromq/tests/test_abstract_ipc.cpp +57 -0
- data/ext/zeromq/tests/test_conflate.cpp +75 -0
- data/ext/zeromq/tests/test_connect_resolve.cpp +14 -15
- data/ext/zeromq/tests/test_ctx_destroy.cpp +90 -0
- data/ext/zeromq/tests/test_ctx_options.cpp +52 -0
- data/ext/zeromq/tests/test_disconnect_inproc.cpp +35 -30
- data/ext/zeromq/tests/test_fork.cpp +81 -0
- data/ext/zeromq/tests/test_hwm.cpp +251 -35
- data/ext/zeromq/tests/test_immediate.cpp +229 -0
- data/ext/zeromq/tests/test_inproc_connect.cpp +339 -0
- data/ext/zeromq/tests/test_invalid_rep.cpp +9 -13
- data/ext/zeromq/tests/test_iov.cpp +106 -0
- data/ext/zeromq/tests/test_issue_566.cpp +85 -0
- data/ext/zeromq/tests/test_last_endpoint.cpp +14 -18
- data/ext/zeromq/tests/test_linger.cpp +93 -0
- data/ext/zeromq/tests/test_monitor.cpp +112 -129
- data/ext/zeromq/tests/test_msg_flags.cpp +17 -16
- data/ext/zeromq/tests/test_pair_inproc.cpp +25 -7
- data/ext/zeromq/tests/test_pair_ipc.cpp +4 -7
- data/ext/zeromq/tests/test_pair_tcp.cpp +4 -8
- data/ext/zeromq/tests/test_probe_router.cpp +72 -0
- data/ext/zeromq/tests/test_req_correlate.cpp +177 -0
- data/ext/zeromq/tests/test_req_relaxed.cpp +116 -0
- data/ext/zeromq/tests/test_reqrep_device.cpp +9 -17
- data/ext/zeromq/tests/test_reqrep_inproc.cpp +4 -7
- data/ext/zeromq/tests/test_reqrep_ipc.cpp +4 -7
- data/ext/zeromq/tests/test_reqrep_tcp.cpp +4 -8
- data/ext/zeromq/tests/test_router_mandatory.cpp +41 -22
- data/ext/zeromq/tests/test_security_curve.cpp +212 -0
- data/ext/zeromq/tests/test_security_null.cpp +148 -0
- data/ext/zeromq/tests/test_security_plain.cpp +150 -0
- data/ext/zeromq/tests/test_shutdown_stress.cpp +10 -23
- data/ext/zeromq/tests/test_spec_dealer.cpp +254 -0
- data/ext/zeromq/tests/test_spec_pushpull.cpp +293 -0
- data/ext/zeromq/tests/test_spec_rep.cpp +155 -0
- data/ext/zeromq/tests/test_spec_req.cpp +253 -0
- data/ext/zeromq/tests/test_spec_router.cpp +204 -0
- data/ext/zeromq/tests/test_stream.cpp +228 -0
- data/ext/zeromq/tests/test_sub_forward.cpp +14 -22
- data/ext/zeromq/tests/test_system.cpp +82 -0
- data/ext/zeromq/tests/test_term_endpoint.cpp +17 -31
- data/ext/zeromq/tests/test_timeo.cpp +34 -78
- data/ext/zeromq/tests/testutil.hpp +211 -26
- data/ext/zeromq/tools/Makefile.am +9 -0
- data/ext/zeromq/tools/curve_keygen.c +58 -0
- data/lib/zmq/version.rb +1 -1
- data/test/test_socket.rb +4 -3
- metadata +114 -15
- data/ext/zeromq/cmake/Modules/TestZMQVersion.cmake +0 -35
- data/ext/zeromq/foreign/openpgm/libpgm-5.1.118~dfsg.tar.gz +0 -0
- data/ext/zeromq/src/decoder.cpp +0 -166
- data/ext/zeromq/src/encoder.cpp +0 -102
- data/ext/zeromq/tests/test_connect_delay.cpp +0 -260
@@ -0,0 +1,109 @@
|
|
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_CLIENT_HPP_INCLUDED__
|
21
|
+
#define __ZMQ_CURVE_CLIENT_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
|
+
#error "libsodium not built properly"
|
34
|
+
#endif
|
35
|
+
|
36
|
+
#include "mechanism.hpp"
|
37
|
+
#include "options.hpp"
|
38
|
+
|
39
|
+
namespace zmq
|
40
|
+
{
|
41
|
+
|
42
|
+
class msg_t;
|
43
|
+
class session_base_t;
|
44
|
+
|
45
|
+
class curve_client_t : public mechanism_t
|
46
|
+
{
|
47
|
+
public:
|
48
|
+
|
49
|
+
curve_client_t (const options_t &options_);
|
50
|
+
virtual ~curve_client_t ();
|
51
|
+
|
52
|
+
// mechanism implementation
|
53
|
+
virtual int next_handshake_command (msg_t *msg_);
|
54
|
+
virtual int process_handshake_command (msg_t *msg_);
|
55
|
+
virtual int encode (msg_t *msg_);
|
56
|
+
virtual int decode (msg_t *msg_);
|
57
|
+
virtual bool is_handshake_complete () const;
|
58
|
+
|
59
|
+
private:
|
60
|
+
|
61
|
+
enum state_t {
|
62
|
+
send_hello,
|
63
|
+
expect_welcome,
|
64
|
+
send_initiate,
|
65
|
+
expect_ready,
|
66
|
+
connected
|
67
|
+
};
|
68
|
+
|
69
|
+
// Current FSM state
|
70
|
+
state_t state;
|
71
|
+
|
72
|
+
// Our public key (C)
|
73
|
+
uint8_t public_key [crypto_box_PUBLICKEYBYTES];
|
74
|
+
|
75
|
+
// Our secret key (c)
|
76
|
+
uint8_t secret_key [crypto_box_SECRETKEYBYTES];
|
77
|
+
|
78
|
+
// Our short-term public key (C')
|
79
|
+
uint8_t cn_public [crypto_box_PUBLICKEYBYTES];
|
80
|
+
|
81
|
+
// Our short-term secret key (c')
|
82
|
+
uint8_t cn_secret [crypto_box_SECRETKEYBYTES];
|
83
|
+
|
84
|
+
// Server's public key (S)
|
85
|
+
uint8_t server_key [crypto_box_PUBLICKEYBYTES];
|
86
|
+
|
87
|
+
// Server's short-term public key (S')
|
88
|
+
uint8_t cn_server [crypto_box_PUBLICKEYBYTES];
|
89
|
+
|
90
|
+
// Cookie received from server
|
91
|
+
uint8_t cn_cookie [16 + 80];
|
92
|
+
|
93
|
+
// Intermediary buffer used to seepd up boxing and unboxing.
|
94
|
+
uint8_t cn_precom [crypto_box_BEFORENMBYTES];
|
95
|
+
|
96
|
+
// Nonce
|
97
|
+
uint64_t cn_nonce;
|
98
|
+
|
99
|
+
int produce_hello (msg_t *msg_);
|
100
|
+
int process_welcome (msg_t *msg_);
|
101
|
+
int produce_initiate (msg_t *msg_);
|
102
|
+
int process_ready (msg_t *msg_);
|
103
|
+
};
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
#endif
|
108
|
+
|
109
|
+
#endif
|
@@ -0,0 +1,629 @@
|
|
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
|
+
#include "platform.hpp"
|
21
|
+
|
22
|
+
#ifdef HAVE_LIBSODIUM
|
23
|
+
#include <sodium.h>
|
24
|
+
|
25
|
+
#ifdef ZMQ_HAVE_WINDOWS
|
26
|
+
#include "windows.hpp"
|
27
|
+
#endif
|
28
|
+
|
29
|
+
#include "msg.hpp"
|
30
|
+
#include "session_base.hpp"
|
31
|
+
#include "err.hpp"
|
32
|
+
#include "curve_server.hpp"
|
33
|
+
#include "wire.hpp"
|
34
|
+
|
35
|
+
zmq::curve_server_t::curve_server_t (session_base_t *session_,
|
36
|
+
const std::string &peer_address_,
|
37
|
+
const options_t &options_) :
|
38
|
+
mechanism_t (options_),
|
39
|
+
session (session_),
|
40
|
+
peer_address (peer_address_),
|
41
|
+
state (expect_hello),
|
42
|
+
expecting_zap_reply (false),
|
43
|
+
cn_nonce (1)
|
44
|
+
{
|
45
|
+
// Fetch our secret key from socket options
|
46
|
+
memcpy (secret_key, options_.curve_secret_key, crypto_box_SECRETKEYBYTES);
|
47
|
+
|
48
|
+
// Generate short-term key pair
|
49
|
+
const int rc = crypto_box_keypair (cn_public, cn_secret);
|
50
|
+
zmq_assert (rc == 0);
|
51
|
+
}
|
52
|
+
|
53
|
+
zmq::curve_server_t::~curve_server_t ()
|
54
|
+
{
|
55
|
+
}
|
56
|
+
|
57
|
+
int zmq::curve_server_t::next_handshake_command (msg_t *msg_)
|
58
|
+
{
|
59
|
+
int rc = 0;
|
60
|
+
|
61
|
+
switch (state) {
|
62
|
+
case send_welcome:
|
63
|
+
rc = produce_welcome (msg_);
|
64
|
+
if (rc == 0)
|
65
|
+
state = expect_initiate;
|
66
|
+
break;
|
67
|
+
case send_ready:
|
68
|
+
rc = produce_ready (msg_);
|
69
|
+
if (rc == 0)
|
70
|
+
state = connected;
|
71
|
+
break;
|
72
|
+
default:
|
73
|
+
errno = EAGAIN;
|
74
|
+
rc = -1;
|
75
|
+
break;
|
76
|
+
}
|
77
|
+
return rc;
|
78
|
+
}
|
79
|
+
|
80
|
+
int zmq::curve_server_t::process_handshake_command (msg_t *msg_)
|
81
|
+
{
|
82
|
+
int rc = 0;
|
83
|
+
|
84
|
+
switch (state) {
|
85
|
+
case expect_hello:
|
86
|
+
rc = process_hello (msg_);
|
87
|
+
if (rc == 0)
|
88
|
+
state = send_welcome;
|
89
|
+
break;
|
90
|
+
case expect_initiate:
|
91
|
+
rc = process_initiate (msg_);
|
92
|
+
if (rc == 0)
|
93
|
+
state = expecting_zap_reply? expect_zap_reply: send_ready;
|
94
|
+
break;
|
95
|
+
default:
|
96
|
+
errno = EPROTO;
|
97
|
+
rc = -1;
|
98
|
+
break;
|
99
|
+
}
|
100
|
+
if (rc == 0) {
|
101
|
+
rc = msg_->close ();
|
102
|
+
errno_assert (rc == 0);
|
103
|
+
rc = msg_->init ();
|
104
|
+
errno_assert (rc == 0);
|
105
|
+
}
|
106
|
+
return rc;
|
107
|
+
}
|
108
|
+
|
109
|
+
int zmq::curve_server_t::encode (msg_t *msg_)
|
110
|
+
{
|
111
|
+
zmq_assert (state == connected);
|
112
|
+
|
113
|
+
const size_t mlen = crypto_box_ZEROBYTES + 1 + msg_->size ();
|
114
|
+
|
115
|
+
uint8_t message_nonce [crypto_box_NONCEBYTES];
|
116
|
+
memcpy (message_nonce, "CurveZMQMESSAGES", 16);
|
117
|
+
memcpy (message_nonce + 16, &cn_nonce, 8);
|
118
|
+
|
119
|
+
uint8_t flags = 0;
|
120
|
+
if (msg_->flags () & msg_t::more)
|
121
|
+
flags |= 0x01;
|
122
|
+
|
123
|
+
uint8_t *message_plaintext = static_cast <uint8_t *> (malloc (mlen));
|
124
|
+
alloc_assert (message_plaintext);
|
125
|
+
|
126
|
+
memset (message_plaintext, 0, crypto_box_ZEROBYTES);
|
127
|
+
message_plaintext [crypto_box_ZEROBYTES] = flags;
|
128
|
+
memcpy (message_plaintext + crypto_box_ZEROBYTES + 1,
|
129
|
+
msg_->data (), msg_->size ());
|
130
|
+
|
131
|
+
uint8_t *message_box = static_cast <uint8_t *> (malloc (mlen));
|
132
|
+
alloc_assert (message_box);
|
133
|
+
|
134
|
+
int rc = crypto_box_afternm (message_box, message_plaintext,
|
135
|
+
mlen, message_nonce, cn_precom);
|
136
|
+
zmq_assert (rc == 0);
|
137
|
+
|
138
|
+
rc = msg_->close ();
|
139
|
+
zmq_assert (rc == 0);
|
140
|
+
|
141
|
+
rc = msg_->init_size (16 + mlen - crypto_box_BOXZEROBYTES);
|
142
|
+
zmq_assert (rc == 0);
|
143
|
+
|
144
|
+
uint8_t *message = static_cast <uint8_t *> (msg_->data ());
|
145
|
+
|
146
|
+
memcpy (message, "\x07MESSAGE", 8);
|
147
|
+
memcpy (message + 8, &cn_nonce, 8);
|
148
|
+
memcpy (message + 16, message_box + crypto_box_BOXZEROBYTES,
|
149
|
+
mlen - crypto_box_BOXZEROBYTES);
|
150
|
+
|
151
|
+
free (message_plaintext);
|
152
|
+
free (message_box);
|
153
|
+
|
154
|
+
cn_nonce++;
|
155
|
+
|
156
|
+
return 0;
|
157
|
+
}
|
158
|
+
|
159
|
+
int zmq::curve_server_t::decode (msg_t *msg_)
|
160
|
+
{
|
161
|
+
zmq_assert (state == connected);
|
162
|
+
|
163
|
+
if (msg_->size () < 33) {
|
164
|
+
errno = EPROTO;
|
165
|
+
return -1;
|
166
|
+
}
|
167
|
+
|
168
|
+
const uint8_t *message = static_cast <uint8_t *> (msg_->data ());
|
169
|
+
if (memcmp (message, "\x07MESSAGE", 8)) {
|
170
|
+
errno = EPROTO;
|
171
|
+
return -1;
|
172
|
+
}
|
173
|
+
|
174
|
+
uint8_t message_nonce [crypto_box_NONCEBYTES];
|
175
|
+
memcpy (message_nonce, "CurveZMQMESSAGEC", 16);
|
176
|
+
memcpy (message_nonce + 16, message + 8, 8);
|
177
|
+
|
178
|
+
const size_t clen = crypto_box_BOXZEROBYTES + msg_->size () - 16;
|
179
|
+
|
180
|
+
uint8_t *message_plaintext = static_cast <uint8_t *> (malloc (clen));
|
181
|
+
alloc_assert (message_plaintext);
|
182
|
+
|
183
|
+
uint8_t *message_box = static_cast <uint8_t *> (malloc (clen));
|
184
|
+
alloc_assert (message_box);
|
185
|
+
|
186
|
+
memset (message_box, 0, crypto_box_BOXZEROBYTES);
|
187
|
+
memcpy (message_box + crypto_box_BOXZEROBYTES,
|
188
|
+
message + 16, msg_->size () - 16);
|
189
|
+
|
190
|
+
int rc = crypto_box_open_afternm (message_plaintext, message_box,
|
191
|
+
clen, message_nonce, cn_precom);
|
192
|
+
if (rc == 0) {
|
193
|
+
rc = msg_->close ();
|
194
|
+
zmq_assert (rc == 0);
|
195
|
+
|
196
|
+
rc = msg_->init_size (clen - 1 - crypto_box_ZEROBYTES);
|
197
|
+
zmq_assert (rc == 0);
|
198
|
+
|
199
|
+
const uint8_t flags = message_plaintext [crypto_box_ZEROBYTES];
|
200
|
+
if (flags & 0x01)
|
201
|
+
msg_->set_flags (msg_t::more);
|
202
|
+
|
203
|
+
memcpy (msg_->data (),
|
204
|
+
message_plaintext + crypto_box_ZEROBYTES + 1,
|
205
|
+
msg_->size ());
|
206
|
+
}
|
207
|
+
else
|
208
|
+
errno = EPROTO;
|
209
|
+
|
210
|
+
free (message_plaintext);
|
211
|
+
free (message_box);
|
212
|
+
|
213
|
+
return rc;
|
214
|
+
}
|
215
|
+
|
216
|
+
int zmq::curve_server_t::zap_msg_available ()
|
217
|
+
{
|
218
|
+
if (state != expect_zap_reply) {
|
219
|
+
errno = EFSM;
|
220
|
+
return -1;
|
221
|
+
}
|
222
|
+
const int rc = receive_and_process_zap_reply ();
|
223
|
+
if (rc == 0)
|
224
|
+
state = send_ready;
|
225
|
+
return rc;
|
226
|
+
}
|
227
|
+
|
228
|
+
bool zmq::curve_server_t::is_handshake_complete () const
|
229
|
+
{
|
230
|
+
return state == connected;
|
231
|
+
}
|
232
|
+
|
233
|
+
int zmq::curve_server_t::process_hello (msg_t *msg_)
|
234
|
+
{
|
235
|
+
if (msg_->size () != 200) {
|
236
|
+
errno = EPROTO;
|
237
|
+
return -1;
|
238
|
+
}
|
239
|
+
|
240
|
+
const uint8_t * const hello = static_cast <uint8_t *> (msg_->data ());
|
241
|
+
if (memcmp (hello, "\x05HELLO", 6)) {
|
242
|
+
errno = EPROTO;
|
243
|
+
return -1;
|
244
|
+
}
|
245
|
+
|
246
|
+
const uint8_t major = hello [6];
|
247
|
+
const uint8_t minor = hello [7];
|
248
|
+
|
249
|
+
if (major != 1 || minor != 0) {
|
250
|
+
errno = EPROTO;
|
251
|
+
return -1;
|
252
|
+
}
|
253
|
+
|
254
|
+
// Save client's short-term public key (C')
|
255
|
+
memcpy (cn_client, hello + 80, 32);
|
256
|
+
|
257
|
+
uint8_t hello_nonce [crypto_box_NONCEBYTES];
|
258
|
+
uint8_t hello_plaintext [crypto_box_ZEROBYTES + 64];
|
259
|
+
uint8_t hello_box [crypto_box_BOXZEROBYTES + 80];
|
260
|
+
|
261
|
+
memcpy (hello_nonce, "CurveZMQHELLO---", 16);
|
262
|
+
memcpy (hello_nonce + 16, hello + 112, 8);
|
263
|
+
|
264
|
+
memset (hello_box, 0, crypto_box_BOXZEROBYTES);
|
265
|
+
memcpy (hello_box + crypto_box_BOXZEROBYTES, hello + 120, 80);
|
266
|
+
|
267
|
+
// Open Box [64 * %x0](C'->S)
|
268
|
+
int rc = crypto_box_open (hello_plaintext, hello_box,
|
269
|
+
sizeof hello_box,
|
270
|
+
hello_nonce, cn_client, secret_key);
|
271
|
+
if (rc != 0) {
|
272
|
+
errno = EPROTO;
|
273
|
+
return -1;
|
274
|
+
}
|
275
|
+
|
276
|
+
return rc;
|
277
|
+
}
|
278
|
+
|
279
|
+
int zmq::curve_server_t::produce_welcome (msg_t *msg_)
|
280
|
+
{
|
281
|
+
uint8_t cookie_nonce [crypto_secretbox_NONCEBYTES];
|
282
|
+
uint8_t cookie_plaintext [crypto_secretbox_ZEROBYTES + 64];
|
283
|
+
uint8_t cookie_ciphertext [crypto_secretbox_BOXZEROBYTES + 80];
|
284
|
+
|
285
|
+
// Create full nonce for encryption
|
286
|
+
// 8-byte prefix plus 16-byte random nonce
|
287
|
+
memcpy (cookie_nonce, "COOKIE--", 8);
|
288
|
+
randombytes (cookie_nonce + 8, 16);
|
289
|
+
|
290
|
+
// Generate cookie = Box [C' + s'](t)
|
291
|
+
memset (cookie_plaintext, 0, crypto_secretbox_ZEROBYTES);
|
292
|
+
memcpy (cookie_plaintext + crypto_secretbox_ZEROBYTES,
|
293
|
+
cn_client, 32);
|
294
|
+
memcpy (cookie_plaintext + crypto_secretbox_ZEROBYTES + 32,
|
295
|
+
cn_secret, 32);
|
296
|
+
|
297
|
+
// Generate fresh cookie key
|
298
|
+
randombytes (cookie_key, crypto_secretbox_KEYBYTES);
|
299
|
+
|
300
|
+
// Encrypt using symmetric cookie key
|
301
|
+
int rc = crypto_secretbox (cookie_ciphertext, cookie_plaintext,
|
302
|
+
sizeof cookie_plaintext,
|
303
|
+
cookie_nonce, cookie_key);
|
304
|
+
zmq_assert (rc == 0);
|
305
|
+
|
306
|
+
uint8_t welcome_nonce [crypto_box_NONCEBYTES];
|
307
|
+
uint8_t welcome_plaintext [crypto_box_ZEROBYTES + 128];
|
308
|
+
uint8_t welcome_ciphertext [crypto_box_BOXZEROBYTES + 144];
|
309
|
+
|
310
|
+
// Create full nonce for encryption
|
311
|
+
// 8-byte prefix plus 16-byte random nonce
|
312
|
+
memcpy (welcome_nonce, "WELCOME-", 8);
|
313
|
+
randombytes (welcome_nonce + 8, crypto_box_NONCEBYTES - 8);
|
314
|
+
|
315
|
+
// Create 144-byte Box [S' + cookie](S->C')
|
316
|
+
memset (welcome_plaintext, 0, crypto_box_ZEROBYTES);
|
317
|
+
memcpy (welcome_plaintext + crypto_box_ZEROBYTES, cn_public, 32);
|
318
|
+
memcpy (welcome_plaintext + crypto_box_ZEROBYTES + 32,
|
319
|
+
cookie_nonce + 8, 16);
|
320
|
+
memcpy (welcome_plaintext + crypto_box_ZEROBYTES + 48,
|
321
|
+
cookie_ciphertext + crypto_secretbox_BOXZEROBYTES, 80);
|
322
|
+
|
323
|
+
rc = crypto_box (welcome_ciphertext, welcome_plaintext,
|
324
|
+
sizeof welcome_plaintext,
|
325
|
+
welcome_nonce, cn_client, secret_key);
|
326
|
+
zmq_assert (rc == 0);
|
327
|
+
|
328
|
+
rc = msg_->init_size (168);
|
329
|
+
errno_assert (rc == 0);
|
330
|
+
|
331
|
+
uint8_t * const welcome = static_cast <uint8_t *> (msg_->data ());
|
332
|
+
memcpy (welcome, "\x07WELCOME", 8);
|
333
|
+
memcpy (welcome + 8, welcome_nonce + 8, 16);
|
334
|
+
memcpy (welcome + 24, welcome_ciphertext + crypto_box_BOXZEROBYTES, 144);
|
335
|
+
|
336
|
+
return 0;
|
337
|
+
}
|
338
|
+
|
339
|
+
int zmq::curve_server_t::process_initiate (msg_t *msg_)
|
340
|
+
{
|
341
|
+
if (msg_->size () < 257) {
|
342
|
+
errno = EPROTO;
|
343
|
+
return -1;
|
344
|
+
}
|
345
|
+
|
346
|
+
const uint8_t *initiate = static_cast <uint8_t *> (msg_->data ());
|
347
|
+
if (memcmp (initiate, "\x08INITIATE", 9)) {
|
348
|
+
errno = EPROTO;
|
349
|
+
return -1;
|
350
|
+
}
|
351
|
+
|
352
|
+
uint8_t cookie_nonce [crypto_secretbox_NONCEBYTES];
|
353
|
+
uint8_t cookie_plaintext [crypto_secretbox_ZEROBYTES + 64];
|
354
|
+
uint8_t cookie_box [crypto_secretbox_BOXZEROBYTES + 80];
|
355
|
+
|
356
|
+
// Open Box [C' + s'](t)
|
357
|
+
memset (cookie_box, 0, crypto_secretbox_BOXZEROBYTES);
|
358
|
+
memcpy (cookie_box + crypto_secretbox_BOXZEROBYTES, initiate + 25, 80);
|
359
|
+
|
360
|
+
memcpy (cookie_nonce, "COOKIE--", 8);
|
361
|
+
memcpy (cookie_nonce + 8, initiate + 9, 16);
|
362
|
+
|
363
|
+
int rc = crypto_secretbox_open (cookie_plaintext, cookie_box,
|
364
|
+
sizeof cookie_box,
|
365
|
+
cookie_nonce, cookie_key);
|
366
|
+
if (rc != 0) {
|
367
|
+
errno = EPROTO;
|
368
|
+
return -1;
|
369
|
+
}
|
370
|
+
|
371
|
+
// Check cookie plain text is as expected [C' + s']
|
372
|
+
if (memcmp (cookie_plaintext + crypto_secretbox_ZEROBYTES, cn_client, 32)
|
373
|
+
|| memcmp (cookie_plaintext + crypto_secretbox_ZEROBYTES + 32, cn_secret, 32)) {
|
374
|
+
errno = EPROTO;
|
375
|
+
return -1;
|
376
|
+
}
|
377
|
+
|
378
|
+
const size_t clen = (msg_->size () - 113) + crypto_box_BOXZEROBYTES;
|
379
|
+
|
380
|
+
uint8_t initiate_nonce [crypto_box_NONCEBYTES];
|
381
|
+
uint8_t initiate_plaintext [crypto_box_ZEROBYTES + 128 + 256];
|
382
|
+
uint8_t initiate_box [crypto_box_BOXZEROBYTES + 144 + 256];
|
383
|
+
|
384
|
+
// Open Box [C + vouch + metadata](C'->S')
|
385
|
+
memset (initiate_box, 0, crypto_box_BOXZEROBYTES);
|
386
|
+
memcpy (initiate_box + crypto_box_BOXZEROBYTES,
|
387
|
+
initiate + 113, clen - crypto_box_BOXZEROBYTES);
|
388
|
+
|
389
|
+
memcpy (initiate_nonce, "CurveZMQINITIATE", 16);
|
390
|
+
memcpy (initiate_nonce + 16, initiate + 105, 8);
|
391
|
+
|
392
|
+
rc = crypto_box_open (initiate_plaintext, initiate_box,
|
393
|
+
clen, initiate_nonce, cn_client, cn_secret);
|
394
|
+
if (rc != 0) {
|
395
|
+
errno = EPROTO;
|
396
|
+
return -1;
|
397
|
+
}
|
398
|
+
|
399
|
+
const uint8_t *client_key = initiate_plaintext + crypto_box_ZEROBYTES;
|
400
|
+
|
401
|
+
uint8_t vouch_nonce [crypto_box_NONCEBYTES];
|
402
|
+
uint8_t vouch_plaintext [crypto_box_ZEROBYTES + 64];
|
403
|
+
uint8_t vouch_box [crypto_box_BOXZEROBYTES + 80];
|
404
|
+
|
405
|
+
// Open Box Box [C',S](C->S') and check contents
|
406
|
+
memset (vouch_box, 0, crypto_box_BOXZEROBYTES);
|
407
|
+
memcpy (vouch_box + crypto_box_BOXZEROBYTES,
|
408
|
+
initiate_plaintext + crypto_box_ZEROBYTES + 48, 80);
|
409
|
+
|
410
|
+
memcpy (vouch_nonce, "VOUCH---", 8);
|
411
|
+
memcpy (vouch_nonce + 8,
|
412
|
+
initiate_plaintext + crypto_box_ZEROBYTES + 32, 16);
|
413
|
+
|
414
|
+
rc = crypto_box_open (vouch_plaintext, vouch_box,
|
415
|
+
sizeof vouch_box,
|
416
|
+
vouch_nonce, client_key, cn_secret);
|
417
|
+
if (rc != 0) {
|
418
|
+
errno = EPROTO;
|
419
|
+
return -1;
|
420
|
+
}
|
421
|
+
|
422
|
+
// What we decrypted must be the client's short-term public key
|
423
|
+
if (memcmp (vouch_plaintext + crypto_box_ZEROBYTES, cn_client, 32)) {
|
424
|
+
errno = EPROTO;
|
425
|
+
return -1;
|
426
|
+
}
|
427
|
+
|
428
|
+
// Precompute connection secret from client key
|
429
|
+
rc = crypto_box_beforenm (cn_precom, cn_client, cn_secret);
|
430
|
+
zmq_assert (rc == 0);
|
431
|
+
|
432
|
+
// Use ZAP protocol (RFC 27) to authenticate the user.
|
433
|
+
rc = session->zap_connect ();
|
434
|
+
if (rc == 0) {
|
435
|
+
send_zap_request (client_key);
|
436
|
+
rc = receive_and_process_zap_reply ();
|
437
|
+
if (rc != 0) {
|
438
|
+
if (errno != EAGAIN)
|
439
|
+
return -1;
|
440
|
+
expecting_zap_reply = true;
|
441
|
+
}
|
442
|
+
}
|
443
|
+
|
444
|
+
return parse_metadata (initiate_plaintext + crypto_box_ZEROBYTES + 128,
|
445
|
+
clen - crypto_box_ZEROBYTES - 128);
|
446
|
+
}
|
447
|
+
|
448
|
+
int zmq::curve_server_t::produce_ready (msg_t *msg_)
|
449
|
+
{
|
450
|
+
uint8_t ready_nonce [crypto_box_NONCEBYTES];
|
451
|
+
uint8_t ready_plaintext [crypto_box_ZEROBYTES + 256];
|
452
|
+
uint8_t ready_box [crypto_box_BOXZEROBYTES + 16 + 256];
|
453
|
+
|
454
|
+
// Create Box [metadata](S'->C')
|
455
|
+
memset (ready_plaintext, 0, crypto_box_ZEROBYTES);
|
456
|
+
uint8_t *ptr = ready_plaintext + crypto_box_ZEROBYTES;
|
457
|
+
|
458
|
+
// Add socket type property
|
459
|
+
const char *socket_type = socket_type_string (options.type);
|
460
|
+
ptr += add_property (ptr, "Socket-Type", socket_type, strlen (socket_type));
|
461
|
+
|
462
|
+
// Add identity property
|
463
|
+
if (options.type == ZMQ_REQ
|
464
|
+
|| options.type == ZMQ_DEALER
|
465
|
+
|| options.type == ZMQ_ROUTER)
|
466
|
+
ptr += add_property (ptr, "Identity",
|
467
|
+
options.identity, options.identity_size);
|
468
|
+
|
469
|
+
const size_t mlen = ptr - ready_plaintext;
|
470
|
+
|
471
|
+
memcpy (ready_nonce, "CurveZMQREADY---", 16);
|
472
|
+
memcpy (ready_nonce + 16, &cn_nonce, 8);
|
473
|
+
|
474
|
+
int rc = crypto_box_afternm (ready_box, ready_plaintext,
|
475
|
+
mlen, ready_nonce, cn_precom);
|
476
|
+
zmq_assert (rc == 0);
|
477
|
+
|
478
|
+
rc = msg_->init_size (14 + mlen - crypto_box_BOXZEROBYTES);
|
479
|
+
errno_assert (rc == 0);
|
480
|
+
|
481
|
+
uint8_t *ready = static_cast <uint8_t *> (msg_->data ());
|
482
|
+
|
483
|
+
memcpy (ready, "\x05READY", 6);
|
484
|
+
// Short nonce, prefixed by "CurveZMQREADY---"
|
485
|
+
memcpy (ready + 6, &cn_nonce, 8);
|
486
|
+
// Box [metadata](S'->C')
|
487
|
+
memcpy (ready + 14, ready_box + crypto_box_BOXZEROBYTES,
|
488
|
+
mlen - crypto_box_BOXZEROBYTES);
|
489
|
+
|
490
|
+
cn_nonce++;
|
491
|
+
|
492
|
+
return 0;
|
493
|
+
}
|
494
|
+
|
495
|
+
void zmq::curve_server_t::send_zap_request (const uint8_t *key)
|
496
|
+
{
|
497
|
+
int rc;
|
498
|
+
msg_t msg;
|
499
|
+
|
500
|
+
// Address delimiter frame
|
501
|
+
rc = msg.init ();
|
502
|
+
errno_assert (rc == 0);
|
503
|
+
msg.set_flags (msg_t::more);
|
504
|
+
rc = session->write_zap_msg (&msg);
|
505
|
+
errno_assert (rc == 0);
|
506
|
+
|
507
|
+
// Version frame
|
508
|
+
rc = msg.init_size (3);
|
509
|
+
errno_assert (rc == 0);
|
510
|
+
memcpy (msg.data (), "1.0", 3);
|
511
|
+
msg.set_flags (msg_t::more);
|
512
|
+
rc = session->write_zap_msg (&msg);
|
513
|
+
errno_assert (rc == 0);
|
514
|
+
|
515
|
+
// Request ID frame
|
516
|
+
rc = msg.init_size (1);
|
517
|
+
errno_assert (rc == 0);
|
518
|
+
memcpy (msg.data (), "1", 1);
|
519
|
+
msg.set_flags (msg_t::more);
|
520
|
+
rc = session->write_zap_msg (&msg);
|
521
|
+
errno_assert (rc == 0);
|
522
|
+
|
523
|
+
// Domain frame
|
524
|
+
rc = msg.init_size (options.zap_domain.length ());
|
525
|
+
errno_assert (rc == 0);
|
526
|
+
memcpy (msg.data (), options.zap_domain.c_str (), options.zap_domain.length ());
|
527
|
+
msg.set_flags (msg_t::more);
|
528
|
+
rc = session->write_zap_msg (&msg);
|
529
|
+
errno_assert (rc == 0);
|
530
|
+
|
531
|
+
// Address frame
|
532
|
+
rc = msg.init_size (peer_address.length ());
|
533
|
+
errno_assert (rc == 0);
|
534
|
+
memcpy (msg.data (), peer_address.c_str (), peer_address.length ());
|
535
|
+
msg.set_flags (msg_t::more);
|
536
|
+
rc = session->write_zap_msg (&msg);
|
537
|
+
errno_assert (rc == 0);
|
538
|
+
|
539
|
+
// Identity frame
|
540
|
+
rc = msg.init_size (options.identity_size);
|
541
|
+
errno_assert (rc == 0);
|
542
|
+
memcpy (msg.data (), options.identity, options.identity_size);
|
543
|
+
msg.set_flags (msg_t::more);
|
544
|
+
rc = session->write_zap_msg (&msg);
|
545
|
+
errno_assert (rc == 0);
|
546
|
+
|
547
|
+
// Mechanism frame
|
548
|
+
rc = msg.init_size (5);
|
549
|
+
errno_assert (rc == 0);
|
550
|
+
memcpy (msg.data (), "CURVE", 5);
|
551
|
+
msg.set_flags (msg_t::more);
|
552
|
+
rc = session->write_zap_msg (&msg);
|
553
|
+
errno_assert (rc == 0);
|
554
|
+
|
555
|
+
// Credentials frame
|
556
|
+
rc = msg.init_size (crypto_box_PUBLICKEYBYTES);
|
557
|
+
errno_assert (rc == 0);
|
558
|
+
memcpy (msg.data (), key, crypto_box_PUBLICKEYBYTES);
|
559
|
+
rc = session->write_zap_msg (&msg);
|
560
|
+
errno_assert (rc == 0);
|
561
|
+
}
|
562
|
+
|
563
|
+
int zmq::curve_server_t::receive_and_process_zap_reply ()
|
564
|
+
{
|
565
|
+
int rc = 0;
|
566
|
+
msg_t msg [7]; // ZAP reply consists of 7 frames
|
567
|
+
|
568
|
+
// Initialize all reply frames
|
569
|
+
for (int i = 0; i < 7; i++) {
|
570
|
+
rc = msg [i].init ();
|
571
|
+
errno_assert (rc == 0);
|
572
|
+
}
|
573
|
+
|
574
|
+
for (int i = 0; i < 7; i++) {
|
575
|
+
rc = session->read_zap_msg (&msg [i]);
|
576
|
+
if (rc == -1)
|
577
|
+
break;
|
578
|
+
if ((msg [i].flags () & msg_t::more) == (i < 6? 0: msg_t::more)) {
|
579
|
+
errno = EPROTO;
|
580
|
+
rc = -1;
|
581
|
+
break;
|
582
|
+
}
|
583
|
+
}
|
584
|
+
|
585
|
+
if (rc != 0)
|
586
|
+
goto error;
|
587
|
+
|
588
|
+
// Address delimiter frame
|
589
|
+
if (msg [0].size () > 0) {
|
590
|
+
rc = -1;
|
591
|
+
errno = EPROTO;
|
592
|
+
goto error;
|
593
|
+
}
|
594
|
+
|
595
|
+
// Version frame
|
596
|
+
if (msg [1].size () != 3 || memcmp (msg [1].data (), "1.0", 3)) {
|
597
|
+
rc = -1;
|
598
|
+
errno = EPROTO;
|
599
|
+
goto error;
|
600
|
+
}
|
601
|
+
|
602
|
+
// Request id frame
|
603
|
+
if (msg [2].size () != 1 || memcmp (msg [2].data (), "1", 1)) {
|
604
|
+
rc = -1;
|
605
|
+
errno = EPROTO;
|
606
|
+
goto error;
|
607
|
+
}
|
608
|
+
|
609
|
+
// Status code frame
|
610
|
+
if (msg [3].size () != 3 || memcmp (msg [3].data (), "200", 3)) {
|
611
|
+
rc = -1;
|
612
|
+
errno = EACCES;
|
613
|
+
goto error;
|
614
|
+
}
|
615
|
+
|
616
|
+
// Process metadata frame
|
617
|
+
rc = parse_metadata (static_cast <const unsigned char*> (msg [6].data ()),
|
618
|
+
msg [6].size ());
|
619
|
+
|
620
|
+
error:
|
621
|
+
for (int i = 0; i < 7; i++) {
|
622
|
+
const int rc2 = msg [i].close ();
|
623
|
+
errno_assert (rc2 == 0);
|
624
|
+
}
|
625
|
+
|
626
|
+
return rc;
|
627
|
+
}
|
628
|
+
|
629
|
+
#endif
|