From 697530af3b5a0f8e783f32caee3ebf48f7e7a3a7 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Fri, 9 Dec 2016 03:01:36 -0500 Subject: [PATCH 1/3] Improve toxencryptsave documentation --- toxencryptsave/toxencryptsave.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/toxencryptsave/toxencryptsave.h b/toxencryptsave/toxencryptsave.h index a6537fad..5b2eea75 100644 --- a/toxencryptsave/toxencryptsave.h +++ b/toxencryptsave/toxencryptsave.h @@ -203,6 +203,9 @@ bool tox_derive_key_with_salt(const uint8_t *passphrase, size_t pplength, const * derive_key_with_salt to produce the same key as was previously used. Any encrpyted * data with this module can be used as input. * + * The data must be at least TOX_PASS_ENCRYPTION_EXTRA_LENGTH bytes in length. + * The salt must be TOX_PASS_SALT_LENGTH bytes in length. + * * returns true if magic number matches * success does not say anything about the validity of the data, only that data of * the appropriate size was copied @@ -232,7 +235,11 @@ bool tox_pass_key_encrypt(const uint8_t *data, size_t data_len, const TOX_PASS_K bool tox_pass_key_decrypt(const uint8_t *data, size_t length, const TOX_PASS_KEY *key, uint8_t *out, TOX_ERR_DECRYPTION *error); -/* Determines whether or not the given data is encrypted (by checking the magic number) +/* Determines whether or not the given data is encrypted (by checking the magic number). + * + * The data must be at least TOX_PASS_ENCRYPTION_EXTRA_LENGTH bytes in length. + * + * returns true on success */ bool tox_is_data_encrypted(const uint8_t *data); From d68505a2d3a1210e24514a562808e27f77c295d9 Mon Sep 17 00:00:00 2001 From: "Gregory Mullen (grayhatter)" Date: Sat, 3 Dec 2016 10:39:30 -0800 Subject: [PATCH 2/3] net_crypto give handle_data_packet_helper a better name --- toxcore/net_crypto.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 84276c62..269d03a3 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -1321,8 +1321,8 @@ static void connection_kill(Net_Crypto *c, int crypt_connection_id, void *userda * return -1 on failure. * return 0 on success. */ -static int handle_data_packet_helper(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length, - bool udp, void *userdata) +static int handle_data_packet_core(Net_Crypto *c, int crypt_connection_id, const uint8_t *packet, uint16_t length, + bool udp, void *userdata) { if (length > MAX_CRYPTO_PACKET_SIZE || length <= CRYPTO_DATA_PACKET_MIN_SIZE) { return -1; @@ -1542,7 +1542,7 @@ static int handle_packet_connection(Net_Crypto *c, int crypt_connection_id, cons case NET_PACKET_CRYPTO_DATA: { if (conn->status == CRYPTO_CONN_NOT_CONFIRMED || conn->status == CRYPTO_CONN_ESTABLISHED) { - return handle_data_packet_helper(c, crypt_connection_id, packet, length, udp, userdata); + return handle_data_packet_core(c, crypt_connection_id, packet, length, udp, userdata); } return -1; From c8d7cf5002b1a8ccdf09a91cbd1bbdc11cf96753 Mon Sep 17 00:00:00 2001 From: iphydf Date: Sat, 10 Dec 2016 14:41:32 +0000 Subject: [PATCH 3/3] Fix off by one error in saving our own status message. --- auto_tests/tox_one_test.c | 43 +++++++++++++++++++++++++++++++-------- toxcore/Messenger.c | 2 +- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/auto_tests/tox_one_test.c b/auto_tests/tox_one_test.c index 350fafe9..ca5fde01 100644 --- a/auto_tests/tox_one_test.c +++ b/auto_tests/tox_one_test.c @@ -14,6 +14,19 @@ #include "helpers.h" +static void set_random_name_and_status_message(Tox *tox, uint8_t *name, uint8_t *status_message) +{ + int i; + + for (i = 0; i < TOX_MAX_NAME_LENGTH; ++i) { + name[i] = rand(); + } + + for (i = 0; i < TOX_MAX_STATUS_MESSAGE_LENGTH; ++i) { + status_message[i] = rand(); + } +} + START_TEST(test_one) { { @@ -26,9 +39,17 @@ START_TEST(test_one) tox_options_free(o1); } + uint8_t name[TOX_MAX_NAME_LENGTH]; + uint8_t status_message[TOX_MAX_STATUS_MESSAGE_LENGTH]; + + uint8_t name2[TOX_MAX_NAME_LENGTH]; + uint8_t status_message2[TOX_MAX_STATUS_MESSAGE_LENGTH]; + uint32_t index[] = { 1, 2 }; Tox *tox1 = tox_new_log(0, 0, &index[0]); + set_random_name_and_status_message(tox1, name, status_message); Tox *tox2 = tox_new_log(0, 0, &index[1]); + set_random_name_and_status_message(tox2, name2, status_message2); uint8_t address[TOX_ADDRESS_SIZE]; tox_self_get_address(tox1, address); @@ -57,16 +78,13 @@ START_TEST(test_one) ret = tox_friend_add(tox1, address, message, TOX_MAX_FRIEND_REQUEST_LENGTH, &error); ck_assert_msg(ret == UINT32_MAX && error == TOX_ERR_FRIEND_ADD_ALREADY_SENT, "Adding friend twice worked."); - uint8_t name[TOX_MAX_NAME_LENGTH]; - int i; - - for (i = 0; i < TOX_MAX_NAME_LENGTH; ++i) { - name[i] = rand(); - } - tox_self_set_name(tox1, name, sizeof(name), 0); ck_assert_msg(tox_self_get_name_size(tox1) == sizeof(name), "Can't set name of TOX_MAX_NAME_LENGTH"); + tox_self_set_status_message(tox1, status_message, sizeof(status_message), 0); + ck_assert_msg(tox_self_get_status_message_size(tox1) == sizeof(status_message), + "Can't set status message of TOX_MAX_STATUS_MESSAGE_LENGTH"); + tox_self_get_address(tox1, address); size_t save_size = tox_get_savedata_size(tox1); uint8_t data[save_size]; @@ -84,8 +102,17 @@ START_TEST(test_one) ck_assert_msg(err_n == TOX_ERR_NEW_OK, "Load failed"); ck_assert_msg(tox_self_get_name_size(tox2) == sizeof name, "Wrong name size."); + ck_assert_msg(tox_self_get_status_message_size(tox2) == sizeof status_message, "Wrong status message size"); - uint8_t address2[TOX_ADDRESS_SIZE]; + uint8_t name_loaded[TOX_MAX_NAME_LENGTH] = { 0 }; + tox_self_get_name(tox2, name_loaded); + ck_assert_msg(!memcmp(name, name_loaded, sizeof name), "Wrong name."); + + uint8_t status_message_loaded[TOX_MAX_STATUS_MESSAGE_LENGTH] = { 0 }; + tox_self_get_status_message(tox2, status_message_loaded); + ck_assert_msg(!memcmp(status_message, status_message_loaded, sizeof status_message_loaded), "Wrong status message."); + + uint8_t address2[TOX_ADDRESS_SIZE] = { 0 }; tox_self_get_address(tox2, address2); ck_assert_msg(memcmp(address2, address, TOX_ADDRESS_SIZE) == 0, "Wrong address."); uint8_t new_name[TOX_MAX_NAME_LENGTH] = { 0 }; diff --git a/toxcore/Messenger.c b/toxcore/Messenger.c index 1771059a..858e952b 100644 --- a/toxcore/Messenger.c +++ b/toxcore/Messenger.c @@ -2988,7 +2988,7 @@ static int messenger_load_state_callback(void *outer, const uint8_t *data, uint3 break; case MESSENGER_STATE_TYPE_STATUSMESSAGE: - if ((length > 0) && (length < MAX_STATUSMESSAGE_LENGTH)) { + if ((length > 0) && (length <= MAX_STATUSMESSAGE_LENGTH)) { m_set_statusmessage(m, data, length); }