Prepare signed existing members before end-to-end CHAT joining
This commit is contained in:
1 parent
e6e866a41a
commit
da5cf6fc99
1 file changed
+19
-10
+19
-10
@@ -343,13 +343,22 @@ static void member_put_self(struct UTUN_INSTANCE* inst, const char* name) {
|
||||
join_sig, join_ts, NULL, 0, userinfo, NULL, NULL, 0, 0, root_sig);
|
||||
}
|
||||
|
||||
static void member_put_placeholder(struct UTUN_INSTANCE* inst, int idx, const char* name) {
|
||||
/* Ключи fixture известны родителю; плейсхолдер не создаёт общую запись узла сам. */
|
||||
if (topo_node_sqlite_node_update_verified(inst->topo_sqlite_db, g_sh.nid[idx], name, g_sh.x_pub[idx], g_sh.ed_pub[idx],
|
||||
(uint64_t)ntp_time_get_seconds(inst), 0) < 0)
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMBER_SYNC, "test: cannot initialize fixture node=%016llx", (unsigned long long)g_sh.nid[idx]);
|
||||
if (topo_node_sqlite_member_placeholder_put(inst->topo_sqlite_db, g_sh.ch_id, g_sh.nid[idx], g_sh.x_pub[idx], g_sh.ed_pub[idx]) < 0)
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMBER_SYNC, "test: cannot create member placeholder node=%016llx", (unsigned long long)g_sh.nid[idx]);
|
||||
static void member_put_fixture(struct UTUN_INSTANCE* inst, int idx, const char* name) {
|
||||
/* A/C уже члены канала: подписать полную запись известными родителю ключами.
|
||||
* J этим путём не добавляется: он проходит настоящий протокол приглашения. */
|
||||
uint64_t ts = (uint64_t)ntp_time_get_seconds(inst);
|
||||
uint8_t private_key[32], public_key[32], message[128], join_sig[64], root_sig[64];
|
||||
x25519_to_ed25519(g_sh.x_priv[idx], private_key, public_key);
|
||||
int size = member_sync_build_join_msg(g_sh.ch_x_pub, g_sh.ch_ed_pub, g_sh.nid[idx], g_sh.x_pub[idx], ts,
|
||||
message, sizeof(message));
|
||||
char userinfo[128]; snprintf(userinfo, sizeof(userinfo), "{\"name\":\"%s\"}", name);
|
||||
if (size <= 0 || sc_ed25519_sign(private_key, message, (size_t)size, join_sig) != SC_OK ||
|
||||
member_sync_sign_pubkey(g_sh.ch_ed_priv, g_sh.x_pub[idx], root_sig) != 0 ||
|
||||
member_sync_put(inst, g_sh.ch_id, g_sh.nid[idx], g_sh.x_pub[idx], public_key,
|
||||
join_sig, ts, NULL, 0, userinfo, NULL, NULL, 0, 0, root_sig) < 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_MEMBER_SYNC, "test: signed member fixture failed node=%016llx", (unsigned long long)g_sh.nid[idx]);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
/* C специально откладывает обработку KEY_REGISTER. Ссылки до этого момента быть не должно. */
|
||||
@@ -554,7 +563,7 @@ static int child_main(const char* role, const char* dir, int invalid_key) {
|
||||
channel_put_shared(inst, 1);
|
||||
member_put_self(inst, "A");
|
||||
if (!g_sh.degraded) {
|
||||
member_put_placeholder(inst, IDX_C, "C");
|
||||
member_put_fixture(inst, IDX_C, "C");
|
||||
/* канал добавлен уже после коннекта — явно запускаем merkle-сессию A↔C */
|
||||
member_sync_start(inst, g_sh.nid[IDX_C], g_sh.ch_id, NULL, NULL);
|
||||
}
|
||||
@@ -607,8 +616,8 @@ static int child_main(const char* role, const char* dir, int invalid_key) {
|
||||
fprintf(stderr, "C: no conn to A\n"); goto out;
|
||||
}
|
||||
channel_put_shared(inst, 0);
|
||||
member_put_placeholder(inst, IDX_C, "C");
|
||||
member_put_placeholder(inst, IDX_A, "A");
|
||||
member_put_fixture(inst, IDX_C, "C");
|
||||
member_put_fixture(inst, IDX_A, "A");
|
||||
/* явно запускаем merkle-сессию C↔A */
|
||||
member_sync_start(inst, g_sh.nid[IDX_A], g_sh.ch_id, NULL, NULL);
|
||||
if (!wait_bgp(inst, g_sh.nid[IDX_A], 8000)) {
|
||||
|
||||
Reference in new issue
Block a user