fix: accept invite public keys with a leading zero byte
This commit is contained in:
1 parent
904a9fbda1
commit
c63e93715f
3 files changed
+134
-152
No files matched your search
@@ -439,7 +439,23 @@ void topo_group_invite_init(struct UTUN_INSTANCE* inst) {
|
||||
int topo_group_invite_join(struct UTUN_INSTANCE* inst, uint64_t group_id,
|
||||
struct TOPO_NODE* ni, uint64_t node_id,
|
||||
tgi_cb_t cb, void* cb_arg) {
|
||||
if (!inst || !inst->topo_groups || !cb || !ni) return -1;
|
||||
if (!inst || !inst->topo_groups || !cb || !ni) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "invite: invalid join arguments group=%016llx", (unsigned long long)group_id);
|
||||
return -1;
|
||||
}
|
||||
uint64_t nid = node_id;
|
||||
if (!nid || nid == inst->node_id) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_GENERAL, "invite: invalid peer=%016llx group=%016llx",
|
||||
(unsigned long long)nid, (unsigned long long)group_id); return -1;
|
||||
}
|
||||
if (!ni->v4_addrs && !ni->v6_addrs) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_GENERAL, "invite: no addresses for peer=%016llx", (unsigned long long)nid); return -1;
|
||||
}
|
||||
/* Нулевой первый байт допустим; отсутствующим считаем только полностью пустой ключ. */
|
||||
static const uint8_t empty_key[SC_PUBKEY_SIZE] = {0};
|
||||
if (!memcmp(ni->public_key, empty_key, sizeof(empty_key))) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_GENERAL, "invite: empty public key for peer=%016llx", (unsigned long long)nid); return -1;
|
||||
}
|
||||
|
||||
/* 1. Найти или создать группу */
|
||||
struct TOPO_GROUP* group = topo_groups_find(inst->topo_groups, group_id);
|
||||
@@ -449,11 +465,6 @@ int topo_group_invite_join(struct UTUN_INSTANCE* inst, uint64_t group_id,
|
||||
if (!group) return -1;
|
||||
}
|
||||
|
||||
uint64_t nid = node_id;
|
||||
if (!nid || nid == inst->node_id) return -1;
|
||||
if (!ni->v4_addrs && !ni->v6_addrs) return -1;
|
||||
if (!ni->public_key[0]) return -1;
|
||||
|
||||
/* 2. Копировать ni в group_ni */
|
||||
struct TOPO_GROUPS* groups = inst->topo_groups;
|
||||
struct TOPO_NODE* gni = u_calloc(1, sizeof(*gni)); if (!gni) return -1;
|
||||
|
||||
Reference in new issue
Block a user