mirror of
https://github.com/zeromq/libzmq.git
synced 2025-03-17 00:23:58 +00:00
craft vanilla socket security test messages
use explicit ZMTP/1.0 anonymous greeting rather than HTTP request that just happened to work
This commit is contained in:
parent
4cff7bf372
commit
fffaf6fd42
@ -240,11 +240,17 @@ int main (void)
|
|||||||
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
rc = connect (s, (struct sockaddr*) &ip4addr, sizeof (ip4addr));
|
rc = connect (s, (struct sockaddr*) &ip4addr, sizeof (ip4addr));
|
||||||
assert (rc > -1);
|
assert (rc > -1);
|
||||||
send (s, "GET / HTTP/1.0\r\nUser-Agent: some_really_long_user_agent\r\nHost: localhost\r\nHeader: shouldn't arrive\r\n\r\n", 102, 0);
|
// send anonymous ZMTP/1.0 greeting
|
||||||
|
send (s, "\x01\x00", 2, 0);
|
||||||
|
// send sneaky message that shouldn't be received
|
||||||
|
send (s, "\x08\x00sneaky\0", 9, 0);
|
||||||
int timeout = 150;
|
int timeout = 150;
|
||||||
zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof (timeout));
|
zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof (timeout));
|
||||||
char *buf = s_recv (server);
|
char *buf = s_recv (server);
|
||||||
assert (buf == NULL);
|
if (buf != NULL) {
|
||||||
|
printf ("Received unauthenticated message: %s\n", buf);
|
||||||
|
assert (buf == NULL);
|
||||||
|
}
|
||||||
close (s);
|
close (s);
|
||||||
|
|
||||||
// Check return codes for invalid buffer sizes
|
// Check return codes for invalid buffer sizes
|
||||||
|
@ -153,11 +153,17 @@ int main (void)
|
|||||||
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
rc = connect (s, (struct sockaddr*) &ip4addr, sizeof ip4addr);
|
rc = connect (s, (struct sockaddr*) &ip4addr, sizeof ip4addr);
|
||||||
assert (rc > -1);
|
assert (rc > -1);
|
||||||
send (s, "GET / HTTP/1.0\r\nUser-Agent: some_really_long_user_agent\r\nHost: localhost\r\nHeader: shouldn't arrive\r\n\r\n", 102, 0);
|
// send anonymous ZMTP/1.0 greeting
|
||||||
|
send (s, "\x01\x00", 2, 0);
|
||||||
|
// send sneaky message that shouldn't be received
|
||||||
|
send (s, "\x08\x00sneaky\0", 9, 0);
|
||||||
int timeout = 150;
|
int timeout = 150;
|
||||||
zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof(timeout));
|
zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof (timeout));
|
||||||
char *buf = s_recv (server);
|
char *buf = s_recv (server);
|
||||||
assert (buf == NULL);
|
if (buf != NULL) {
|
||||||
|
printf ("Received unauthenticated message: %s\n", buf);
|
||||||
|
assert (buf == NULL);
|
||||||
|
}
|
||||||
close (s);
|
close (s);
|
||||||
close_zero_linger (server);
|
close_zero_linger (server);
|
||||||
|
|
||||||
|
@ -159,11 +159,17 @@ int main (void)
|
|||||||
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
rc = connect (s, (struct sockaddr*) &ip4addr, sizeof (ip4addr));
|
rc = connect (s, (struct sockaddr*) &ip4addr, sizeof (ip4addr));
|
||||||
assert (rc > -1);
|
assert (rc > -1);
|
||||||
send (s, "GET / HTTP/1.0\r\nUser-Agent: some_really_long_user_agent\r\nHost: localhost\r\nHeader: shouldn't arrive\r\n\r\n", 102, 0);
|
// send anonymous ZMTP/1.0 greeting
|
||||||
|
send (s, "\x01\x00", 2, 0);
|
||||||
|
// send sneaky message that shouldn't be received
|
||||||
|
send (s, "\x08\x00sneaky\0", 9, 0);
|
||||||
int timeout = 150;
|
int timeout = 150;
|
||||||
zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof (timeout));
|
zmq_setsockopt (server, ZMQ_RCVTIMEO, &timeout, sizeof (timeout));
|
||||||
char *buf = s_recv (server);
|
char *buf = s_recv (server);
|
||||||
assert (buf == NULL);
|
if (buf != NULL) {
|
||||||
|
printf ("Received unauthenticated message: %s\n", buf);
|
||||||
|
assert (buf == NULL);
|
||||||
|
}
|
||||||
close (s);
|
close (s);
|
||||||
|
|
||||||
// Shutdown
|
// Shutdown
|
||||||
|
Loading…
x
Reference in New Issue
Block a user