Skip to content

Commit

Permalink
Merge 6b97acb into 09478f9
Browse files Browse the repository at this point in the history
  • Loading branch information
kurnevsky committed Apr 16, 2018
2 parents 09478f9 + 6b97acb commit dd41e4c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
18 changes: 9 additions & 9 deletions auto_tests/onion_test.c
Expand Up @@ -48,12 +48,12 @@ static int handle_test_1(void *object, IP_Port source, const uint8_t *packet, ui
{
Onion *onion = (Onion *)object;

if (memcmp(packet, "Install Gentoo", sizeof("Install Gentoo")) != 0) {
if (memcmp(packet, "\x83 Install Gentoo", sizeof("\x83 Install Gentoo")) != 0) {
return 1;
}

if (send_onion_response(onion->net, source, (const uint8_t *)"install gentoo", sizeof("install gentoo"),
packet + sizeof("Install Gentoo")) == -1) {
if (send_onion_response(onion->net, source, (const uint8_t *)"\x84 install gentoo", sizeof("\x84 install gentoo"),
packet + sizeof("\x84 install gentoo")) == -1) {
return 1;
}

Expand All @@ -64,11 +64,11 @@ static int handle_test_1(void *object, IP_Port source, const uint8_t *packet, ui
static int handled_test_2;
static int handle_test_2(void *object, IP_Port source, const uint8_t *packet, uint16_t length, void *userdata)
{
if (length != sizeof("install Gentoo")) {
if (length != sizeof("\x84 install gentoo")) {
return 1;
}

if (memcmp(packet, (const uint8_t *)"install gentoo", sizeof("install gentoo")) != 0) {
if (memcmp(packet, (const uint8_t *)"\x84 install gentoo", sizeof("\x84 install gentoo")) != 0) {
return 1;
}

Expand Down Expand Up @@ -170,7 +170,7 @@ START_TEST(test_basic)
Onion *onion1 = new_onion(new_DHT(log1, new_networking(log1, ip, 34567), true));
Onion *onion2 = new_onion(new_DHT(log2, new_networking(log2, ip, 34568), true));
ck_assert_msg((onion1 != nullptr) && (onion2 != nullptr), "Onion failed initializing.");
networking_registerhandler(onion2->net, 'I', &handle_test_1, onion2);
networking_registerhandler(onion2->net, NET_PACKET_ANNOUNCE_REQUEST, &handle_test_1, onion2);

IP_Port on1 = {ip, net_port(onion1->net)};
Node_format n1;
Expand All @@ -189,8 +189,8 @@ START_TEST(test_basic)
nodes[3] = n2;
Onion_Path path;
create_onion_path(onion1->dht, &path, nodes);
int ret = send_onion_packet(onion1->net, &path, nodes[3].ip_port, (const uint8_t *)"Install Gentoo",
sizeof("Install Gentoo"));
int ret = send_onion_packet(onion1->net, &path, nodes[3].ip_port, (const uint8_t *)"\x83 Install Gentoo",
sizeof("\x83 Install Gentoo"));
ck_assert_msg(ret == 0, "Failed to create/send onion packet.");

handled_test_1 = 0;
Expand All @@ -200,7 +200,7 @@ START_TEST(test_basic)
do_onion(onion2);
}

networking_registerhandler(onion1->net, 'i', &handle_test_2, onion1);
networking_registerhandler(onion1->net, NET_PACKET_ANNOUNCE_RESPONSE, &handle_test_2, onion1);
handled_test_2 = 0;

while (handled_test_2 == 0) {
Expand Down
24 changes: 24 additions & 0 deletions toxcore/onion.c
Expand Up @@ -471,6 +471,15 @@ static int handle_send_2(void *object, IP_Port source, const uint8_t *packet, ui
return 1;
}

if (len <= SIZE_IPPORT) {
return 1;
}

if (plain[SIZE_IPPORT] != NET_PACKET_ANNOUNCE_REQUEST &&
plain[SIZE_IPPORT] != NET_PACKET_ONION_DATA_REQUEST) {
return 1;
}

IP_Port send_to;

if (ipport_unpack(&send_to, plain, len, 0) == -1) {
Expand Down Expand Up @@ -514,6 +523,11 @@ static int handle_recv_3(void *object, IP_Port source, const uint8_t *packet, ui
return 1;
}

if (packet[1 + RETURN_3] != NET_PACKET_ANNOUNCE_RESPONSE &&
packet[1 + RETURN_3] != NET_PACKET_ONION_DATA_RESPONSE) {
return 1;
}

change_symmetric_key(onion);

uint8_t plain[SIZE_IPPORT + RETURN_2];
Expand Down Expand Up @@ -555,6 +569,11 @@ static int handle_recv_2(void *object, IP_Port source, const uint8_t *packet, ui
return 1;
}

if (packet[1 + RETURN_2] != NET_PACKET_ANNOUNCE_RESPONSE &&
packet[1 + RETURN_2] != NET_PACKET_ONION_DATA_RESPONSE) {
return 1;
}

change_symmetric_key(onion);

uint8_t plain[SIZE_IPPORT + RETURN_1];
Expand Down Expand Up @@ -596,6 +615,11 @@ static int handle_recv_1(void *object, IP_Port source, const uint8_t *packet, ui
return 1;
}

if (packet[1 + RETURN_1] != NET_PACKET_ANNOUNCE_RESPONSE &&
packet[1 + RETURN_1] != NET_PACKET_ONION_DATA_RESPONSE) {
return 1;
}

change_symmetric_key(onion);

uint8_t plain[SIZE_IPPORT];
Expand Down

0 comments on commit dd41e4c

Please sign in to comment.