Ключи: node_id из SHA-256(privkey) через весь конфиг; приоритет privkey — pubkey/node_id всегда выводятся из него; CHANNEL_INFO_RESP: верификация inviter_join_sig через ETCP-ключи

This commit is contained in:
Evgeny committed 2026-07-15 23:13:29 +03:00
1 parent da86841516
commit ef24af7d24
3 files changed
+76 -74

No files matched your search

+11 -13
View File
@@ -853,25 +853,23 @@ static void cs_handle_channel_info_resp(struct chat_sync* cs, uint64_t peer,
ch_id, name, (int)is_dm, owner, x25519, NULL, ed_pub, NULL, ch_sig);
chat_core_ensure_channel_ready(ch_id);
/* verify inviter's join_sig */
{ sqlite3* vdb = cs->inst->topo_groups->topo_sqlite_db;
/* read inviter's Ed25519 pubkey */
uint8_t inv_ed[32] = {0};
sqlite3_stmt* es = NULL;
sqlite3_prepare_v2(vdb, "SELECT ed25519_pubkey FROM nodes WHERE node_id=?", -1, &es, NULL);
if (es) { sqlite3_bind_int64(es, 1, (sqlite3_int64)peer);
if (sqlite3_step(es) == SQLITE_ROW) memcpy(inv_ed, sqlite3_column_blob(es, 0), 32);
sqlite3_finalize(es); }
/* verify */
/* verify inviter's join_sig using ETCP-authenticated keys */
{ struct ETCP_CONN* inv_conn = cs_find_conn_for_node(cs->inst, peer);
if (!inv_conn) {
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTIVITY, "%s: CHANNEL_INFO_RESP no ETCP conn for inviter peer=%016llx", CS_ID, (unsigned long long)peer);
return;
}
const uint8_t* inv_x25519 = inv_conn->crypto_ctx.peer_public_key;
const uint8_t* inv_ed = inv_conn->peer_ed25519_pubkey;
uint8_t ivmsg[256]; size_t ilen = 0;
ilen += snprintf((char*)ivmsg + ilen, sizeof(ivmsg) - ilen, "%s", ch_id) + 1;
memcpy(ivmsg + ilen, &peer, 8); ilen += 8;
memcpy(ivmsg + ilen, x25519, 32); ilen += 32;
{ char nnm[64] = ""; _get_node_name(vdb, peer, nnm, sizeof(nnm));
memcpy(ivmsg + ilen, inv_x25519, 32); ilen += 32;
{ char nnm[64] = ""; _get_node_name(cs->inst->topo_groups->topo_sqlite_db, peer, nnm, sizeof(nnm));
size_t nl = strlen(nnm); memcpy(ivmsg + ilen, nnm, nl); ilen += nl; ivmsg[ilen++] = '\0';
if (cs_ed25519_verify(inv_ed, ivmsg, ilen, inviter_join_sig) != 0) {
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTIVITY, "%s: CHANNEL_INFO_RESP invalid inviter_join_sig peer=%016llx x25519=%016llx inv_ed=%016llx name=%s",
CS_ID, (unsigned long long)peer, *(const uint64_t*)x25519, *(const uint64_t*)inv_ed, nnm);
CS_ID, (unsigned long long)peer, *(const uint64_t*)inv_x25519, *(const uint64_t*)inv_ed, nnm);
}
}
}