mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
dns3_test now automatically does the DNS request.
tox_decrypt_dns3_TXT no longer needs id_record to be null terminated.
This commit is contained in:
parent
db724df189
commit
3c64c87ea7
|
@ -2,8 +2,45 @@
|
|||
|
||||
#include "../toxdns/toxdns.h"
|
||||
#include "../toxcore/tox.h"
|
||||
#include "../toxcore/network.h"
|
||||
#include "misc_tools.c"
|
||||
|
||||
#if defined(_WIN32) || defined(__WIN32__) || defined (WIN32)
|
||||
|
||||
#define c_sleep(x) Sleep(1*x)
|
||||
|
||||
#else
|
||||
#define c_sleep(x) usleep(1000*x)
|
||||
|
||||
#endif
|
||||
|
||||
uint32_t create_packet(uint8_t *packet, uint8_t *string, uint8_t str_len, uint8_t id)
|
||||
{
|
||||
memset(packet, 0, str_len + 13 + 16);
|
||||
packet[0] = id;
|
||||
packet[1] = rand();
|
||||
packet[5] = 1;
|
||||
packet[11] = 1;
|
||||
packet[12] = '.';
|
||||
memcpy(packet + 13, string, str_len);
|
||||
uint32_t i, c = 0;
|
||||
|
||||
for (i = str_len + 12; i != 11; --i) {
|
||||
if (packet[i] == '.') {
|
||||
packet[i] = c;
|
||||
c = 0;
|
||||
} else {
|
||||
++c;
|
||||
}
|
||||
}
|
||||
|
||||
packet[str_len + 13 + 2] = 16;
|
||||
packet[str_len + 13 + 4] = 1;
|
||||
packet[str_len + 13 + 7] = 0x29;
|
||||
packet[str_len + 13 + 8] = 16;
|
||||
packet[str_len + 13 + 12] = 0x80;
|
||||
return str_len + 13 + 16;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
@ -13,6 +50,22 @@ int main(int argc, char *argv[])
|
|||
exit(0);
|
||||
}
|
||||
|
||||
IP ip = {0};
|
||||
ip.family = AF_INET;
|
||||
sock_t sock = socket(ip.family, SOCK_DGRAM, IPPROTO_UDP);
|
||||
|
||||
if (!sock_valid(sock))
|
||||
return -1;
|
||||
|
||||
if (!addr_resolve_or_parse_ip(argv[1], &ip, 0))
|
||||
return -1;
|
||||
|
||||
struct sockaddr_in target;
|
||||
size_t addrsize = sizeof(struct sockaddr_in);
|
||||
target.sin_family = AF_INET;
|
||||
target.sin_addr = ip.ip4.in_addr;
|
||||
target.sin_port = htons(53);
|
||||
|
||||
uint8_t string[1024] = {0};
|
||||
void *d = tox_dns3_new(hex_string_to_bin(argv[2]));
|
||||
unsigned int i;
|
||||
|
@ -30,13 +83,24 @@ int main(int argc, char *argv[])
|
|||
string[0] = '_';
|
||||
memcpy(string + len + 1, "._tox.", sizeof("._tox."));
|
||||
memcpy((char *)(string + len + 1 + sizeof("._tox.") - 1), argv[1], strlen(argv[1]));
|
||||
printf("Do a DNS request and find the TXT record for:\n%s\nThen paste the contents of the data contained in the id field here:\n",
|
||||
string);
|
||||
uint8_t packet[512];
|
||||
uint8_t id = rand();
|
||||
uint32_t p_len = create_packet(packet, string, strlen((char *)string), id);
|
||||
|
||||
if (sendto(sock, (char *) packet, p_len, 0, (struct sockaddr *)&target, addrsize) != p_len)
|
||||
return -1;
|
||||
|
||||
uint8_t buffer[512] = {};
|
||||
int r_len = recv(sock, buffer, sizeof(buffer), 0);
|
||||
|
||||
if (r_len < (int)p_len)
|
||||
return -1;
|
||||
|
||||
for (i = r_len - 1; i != 0 && buffer[i] != '='; --i);
|
||||
|
||||
scanf("%s", string);
|
||||
uint8_t tox_id[TOX_FRIEND_ADDRESS_SIZE];
|
||||
|
||||
if (tox_decrypt_dns3_TXT(d, tox_id, string, strlen((char *)string), request_id) != 0)
|
||||
if (tox_decrypt_dns3_TXT(d, tox_id, buffer + i + 1, r_len - (i + 1), request_id) != 0)
|
||||
return -1;
|
||||
|
||||
printf("The Tox id for username %s is:\n", argv[3]);
|
||||
|
|
|
@ -216,8 +216,11 @@ int tox_decrypt_dns3_TXT(void *dns3_object, uint8_t *tox_id, uint8_t *id_record,
|
|||
/*if (id_record_len > 255 || id_record_len <= (sizeof(uint32_t) + crypto_box_MACBYTES))
|
||||
return -1;*/
|
||||
|
||||
uint8_t id_record_null[id_record_len + 1];
|
||||
memcpy(id_record_null, id_record, id_record_len);
|
||||
id_record_null[id_record_len] = 0;
|
||||
uint8_t data[id_record_len];
|
||||
int length = decode(data, id_record);
|
||||
int length = decode(data, id_record_null);
|
||||
|
||||
if (length == -1)
|
||||
return -1;
|
||||
|
|
Loading…
Reference in New Issue
Block a user