diff --git a/src/chat/chat_channel.c b/src/chat/chat_channel.c index 0c0bec18..a67d8462 100644 --- a/src/chat/chat_channel.c +++ b/src/chat/chat_channel.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -191,6 +192,7 @@ void chat_core_create_channel_trampoline(void* arg) { struct chat_channel_create* req = (struct chat_channel_create*)arg; if (!req) return; chat_core_create_channel(req->inst, req); + OPENSSL_cleanse(req, sizeof(*req)); u_free(req); } diff --git a/src/chat/chat_sync.c b/src/chat/chat_sync.c index e60a7f3e..a1bd6f5e 100644 --- a/src/chat/chat_sync.c +++ b/src/chat/chat_sync.c @@ -1220,13 +1220,9 @@ static void cs_handle_join_info_resp(struct chat_sync* cs, uint64_t peer, (unsigned long long)ch_x_prefix, (unsigned long long)ch_ed_prefix, name, (unsigned long long)c_node_id); /* verify channel signature */ - uint8_t vmsg[1024]; size_t vlen = 0; - vlen += snprintf((char*)vmsg + vlen, sizeof(vmsg) - vlen, "%s", ch_id) + 1; - vlen += snprintf((char*)vmsg + vlen, sizeof(vmsg) - vlen, "%s", name) + 1; - memcpy(vmsg + vlen, &owner, 8); vlen += 8; - memcpy(vmsg + vlen, ch_x25519, 32); vlen += 32; - memcpy(vmsg + vlen, ch_ed, 32); vlen += 32; - if (cs_ed25519_verify(ch_ed, vmsg, vlen, ch_sig) != 0) { + uint8_t vmsg[CHAT_CHANNEL_DESCRIPTION_MAX]; + int vlen = chat_channel_description_data(ch_id, name, owner, ch_x25519, ch_ed, vmsg, sizeof(vmsg)); + if (vlen < 0 || cs_ed25519_verify(ch_ed, vmsg, (size_t)vlen, ch_sig) != 0) { DEBUG_ERROR(DEBUG_CATEGORY_MEMBER_SYNC, "%s: JOIN_INFO_RESP invalid ch_sig ch=%s", CS_ID, ch_id); return; } @@ -1521,13 +1517,9 @@ static void cs_handle_channel_invite(struct chat_sync* cs, uint64_t peer, memcpy(&join_key, p, 8); p += 8; /* Verify channel signature */ - uint8_t vmsg[1024]; size_t vlen = 0; - vlen += snprintf((char*)vmsg + vlen, sizeof(vmsg) - vlen, "%s", ch_id) + 1; - vlen += snprintf((char*)vmsg + vlen, sizeof(vmsg) - vlen, "%s", name) + 1; - memcpy(vmsg + vlen, &owner, 8); vlen += 8; - memcpy(vmsg + vlen, x25519, 32); vlen += 32; - memcpy(vmsg + vlen, ed_pub, 32); vlen += 32; - if (cs_ed25519_verify(ed_pub, vmsg, vlen, ch_sig) != 0) { + uint8_t vmsg[CHAT_CHANNEL_DESCRIPTION_MAX]; + int vlen = chat_channel_description_data(ch_id, name, owner, x25519, ed_pub, vmsg, sizeof(vmsg)); + if (vlen < 0 || cs_ed25519_verify(ed_pub, vmsg, (size_t)vlen, ch_sig) != 0) { DEBUG_ERROR(DEBUG_CATEGORY_MEMBER_SYNC, "%s: CHANNEL_INVITE invalid ch_sig ch=%s from=%016llx", CS_ID, ch_id, (unsigned long long)peer); return; }