Skip to content

Commit

Permalink
update amalgamation
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Feb 11, 2024
1 parent 8644504 commit 100c640
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
27 changes: 22 additions & 5 deletions amalgamation/toxcore_amalgamation.c
Original file line number Diff line number Diff line change
Expand Up @@ -4211,6 +4211,8 @@ typedef struct GC_Chat {

uint8_t m_group_public_key[CRYPTO_PUBLIC_KEY_SIZE]; // public key for group's messenger friend connection
int friend_connection_id; // identifier for group's messenger friend connection

bool flag_exit; // true if the group will be deleted after the next do_gc() iteration
} GC_Chat;

#ifndef MESSENGER_DEFINED
Expand Down Expand Up @@ -32792,6 +32794,11 @@ static int handle_gc_key_exchange(const GC_Chat *chat, GC_Connection *gconn, con
memcpy(response + 1, new_session_pk, ENC_PUBLIC_KEY_SIZE);

if (!send_lossless_group_packet(chat, gconn, response, sizeof(response), GP_KEY_ROTATION)) {
// Don't really care about zeroing the secret key here, because we failed, but
// we're doing it anyway for symmetry with the memzero+munlock below, where we
// really do care about it.
crypto_memzero(new_session_sk, sizeof(new_session_sk));
crypto_memunlock(new_session_sk, sizeof(new_session_sk));
return -3;
}

Expand All @@ -32801,6 +32808,7 @@ static int handle_gc_key_exchange(const GC_Chat *chat, GC_Connection *gconn, con

gcc_make_session_shared_key(gconn, sender_public_session_key);

crypto_memzero(new_session_sk, sizeof(new_session_sk));
crypto_memunlock(new_session_sk, sizeof(new_session_sk));

gconn->last_key_rotation = mono_time_get(chat->mono_time);
Expand Down Expand Up @@ -36036,6 +36044,10 @@ void do_gc(GC_Session *c, void *userdata)
c->connection_status_change(c->messenger, chat->group_number, chat->connection_state, userdata);
}
}

if (chat->flag_exit) { // should always come last as it modifies the chats array
group_delete(c, chat);
}
}
}

Expand Down Expand Up @@ -37024,7 +37036,14 @@ static void group_delete(GC_Session *c, GC_Chat *chat)

int gc_group_exit(GC_Session *c, GC_Chat *chat, const uint8_t *message, uint16_t length)
{
const int ret = group_can_handle_packets(chat) ? send_gc_self_exit(chat, message, length) : 0;
chat->flag_exit = true;
return group_can_handle_packets(chat) ? send_gc_self_exit(chat, message, length) : 0;
}

non_null()
static int kill_group(GC_Session *c, GC_Chat *chat)
{
const int ret = gc_group_exit(c, chat, nullptr, 0);
group_delete(c, chat);
return ret;
}
Expand All @@ -37042,11 +37061,9 @@ void kill_dht_groupchats(GC_Session *c)
continue;
}

if (group_can_handle_packets(chat)) {
send_gc_self_exit(chat, nullptr, 0);
if (kill_group(c, chat) != 0) {
LOGGER_WARNING(chat->log, "Failed to send group exit packet");
}

group_cleanup(c, chat);
}

networking_registerhandler(c->messenger->net, NET_PACKET_GC_LOSSY, nullptr, nullptr);
Expand Down
27 changes: 22 additions & 5 deletions amalgamation/toxcore_amalgamation_no_toxav.c
Original file line number Diff line number Diff line change
Expand Up @@ -4211,6 +4211,8 @@ typedef struct GC_Chat {

uint8_t m_group_public_key[CRYPTO_PUBLIC_KEY_SIZE]; // public key for group's messenger friend connection
int friend_connection_id; // identifier for group's messenger friend connection

bool flag_exit; // true if the group will be deleted after the next do_gc() iteration
} GC_Chat;

#ifndef MESSENGER_DEFINED
Expand Down Expand Up @@ -30358,6 +30360,11 @@ static int handle_gc_key_exchange(const GC_Chat *chat, GC_Connection *gconn, con
memcpy(response + 1, new_session_pk, ENC_PUBLIC_KEY_SIZE);

if (!send_lossless_group_packet(chat, gconn, response, sizeof(response), GP_KEY_ROTATION)) {
// Don't really care about zeroing the secret key here, because we failed, but
// we're doing it anyway for symmetry with the memzero+munlock below, where we
// really do care about it.
crypto_memzero(new_session_sk, sizeof(new_session_sk));
crypto_memunlock(new_session_sk, sizeof(new_session_sk));
return -3;
}

Expand All @@ -30367,6 +30374,7 @@ static int handle_gc_key_exchange(const GC_Chat *chat, GC_Connection *gconn, con

gcc_make_session_shared_key(gconn, sender_public_session_key);

crypto_memzero(new_session_sk, sizeof(new_session_sk));
crypto_memunlock(new_session_sk, sizeof(new_session_sk));

gconn->last_key_rotation = mono_time_get(chat->mono_time);
Expand Down Expand Up @@ -33602,6 +33610,10 @@ void do_gc(GC_Session *c, void *userdata)
c->connection_status_change(c->messenger, chat->group_number, chat->connection_state, userdata);
}
}

if (chat->flag_exit) { // should always come last as it modifies the chats array
group_delete(c, chat);
}
}
}

Expand Down Expand Up @@ -34590,7 +34602,14 @@ static void group_delete(GC_Session *c, GC_Chat *chat)

int gc_group_exit(GC_Session *c, GC_Chat *chat, const uint8_t *message, uint16_t length)
{
const int ret = group_can_handle_packets(chat) ? send_gc_self_exit(chat, message, length) : 0;
chat->flag_exit = true;
return group_can_handle_packets(chat) ? send_gc_self_exit(chat, message, length) : 0;
}

non_null()
static int kill_group(GC_Session *c, GC_Chat *chat)
{
const int ret = gc_group_exit(c, chat, nullptr, 0);
group_delete(c, chat);
return ret;
}
Expand All @@ -34608,11 +34627,9 @@ void kill_dht_groupchats(GC_Session *c)
continue;
}

if (group_can_handle_packets(chat)) {
send_gc_self_exit(chat, nullptr, 0);
if (kill_group(c, chat) != 0) {
LOGGER_WARNING(chat->log, "Failed to send group exit packet");
}

group_cleanup(c, chat);
}

networking_registerhandler(c->messenger->net, NET_PACKET_GC_LOSSY, nullptr, nullptr);
Expand Down

0 comments on commit 100c640

Please sign in to comment.