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

« back to all changes in this revision

Viewing changes to tests/test_security_plain.cpp

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2015-05-05 21:06:02 UTC
  • Revision ID: package-import@ubuntu.com-20150505210602-7nmw5z31bei3puj6
Tags: 4.0.5+dfsg-3
V3 protocol handler vulnerable to downgrade attacks, use upstream
backported fix for this issue (closes: #784366).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
    Copyright (c) 2007-2013 Contributors as noted in the AUTHORS file
 
2
    Copyright (c) 2007-2014 Contributors as noted in the AUTHORS file
3
3
 
4
4
    This file is part of 0MQ.
5
5
 
18
18
*/
19
19
 
20
20
#include "testutil.hpp"
 
21
#if defined (ZMQ_HAVE_WINDOWS)
 
22
#   include <winsock2.h>
 
23
#   include <ws2tcpip.h>
 
24
#   include <stdexcept>
 
25
#   define close closesocket
 
26
#else
 
27
#   include <sys/socket.h>
 
28
#   include <netinet/in.h>
 
29
#   include <arpa/inet.h>
 
30
#   include <unistd.h>
 
31
#endif
21
32
 
22
33
static void
23
34
zap_handler (void *ctx)
137
148
    expect_bounce_fail (server, client);
138
149
    close_zero_linger (client);
139
150
 
 
151
    // Unauthenticated messages from a vanilla socket shouldn't be received
 
152
    struct sockaddr_in ip4addr;
 
153
    int s;
 
154
 
 
155
    ip4addr.sin_family = AF_INET;
 
156
    ip4addr.sin_port = htons (9998);
 
157
    inet_pton (AF_INET, "127.0.0.1", &ip4addr.sin_addr);
 
158
 
 
159
    s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
 
160
    rc = connect (s, (struct sockaddr*) &ip4addr, sizeof (ip4addr));
 
161
    assert (rc > -1);
 
162
    // send anonymous ZMTP/1.0 greeting
 
163
    send (s, "\x01\x00", 2, 0);
 
164
    // send sneaky message that shouldn't be received
 
165
    send (s, "\x08\x00sneaky\0", 9, 0);
 
166
    int timeout = 150;
 
167
    zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof (timeout));
 
168
    char *buf = s_recv (server);
 
169
    if (buf != NULL) {
 
170
        printf ("Received unauthenticated message: %s\n", buf);
 
171
        assert (buf == NULL);
 
172
    }
 
173
    close (s);
 
174
 
140
175
    //  Shutdown
141
176
    rc = zmq_close (server);
142
177
    assert (rc == 0);