Test both attachment key envelopes and context isolation

This commit is contained in:
evgeny committed 2026-11-03 12:26:40 +01:00
1 parent b3460e2039
commit 2cb9d7a9c5
1 file changed
+29
+29
View File
@@ -80,6 +80,34 @@ static void protocol(struct UTUN_INSTANCE* inst, const struct dm_party parties[2
assert(!dm_message_parse(body, size, &view) && view.mode == DM_MODE_DEVICE && view.media == body + 55);
}
/* Обе стороны получают один файловый ключ; неверный адресат/контекст не раскрывает упаковку. */
static void file_keys(struct UTUN_INSTANCE* inst, const struct dm_party parties[2], const uint8_t private_keys[2][32]) {
uint8_t id[16] = {42}, keys[DM_FILE_KEYS_SIZE], second[DM_FILE_KEYS_SIZE], key[32], other[32], opened[32];
uint64_t conv = dm_identity_conv_id(DM_MODE_GROUPS, parties);
assert(!dm_file_keys_create(conv, inst->node_id, id, parties, keys, key));
for (unsigned side = 0; side < 2; side++) {
assert(!dm_file_keys_open(conv, inst->node_id, id, parties, side, private_keys[side], keys, opened));
assert(!memcmp(key, opened, 32));
}
assert(!dm_file_keys_create(conv, inst->node_id, id, parties, second, other));
assert(memcmp(keys, second, 32) && memcmp(keys + 32, second + 32, 32) && memcmp(key, other, 32));
memset(opened, 0x5a, sizeof(opened)); memcpy(other, opened, sizeof(other));
assert(dm_file_keys_open(conv, inst->node_id, id, parties, 0, private_keys[1], keys, opened) < 0);
assert(!memcmp(opened, other, 32));
assert(dm_file_keys_open(conv + 1, inst->node_id, id, parties, 0, private_keys[0], keys, opened) < 0);
id[0] ^= 1;
assert(dm_file_keys_open(conv, inst->node_id, id, parties, 0, private_keys[0], keys, opened) < 0); id[0] ^= 1;
assert(dm_file_keys_open(conv, inst->node_id + 1, id, parties, 0, private_keys[0], keys, opened) < 0);
keys[0] ^= 1;
assert(dm_file_keys_open(conv, inst->node_id, id, parties, 0, private_keys[0], keys, opened) < 0); keys[0] ^= 1;
keys[32] ^= 1;
assert(dm_file_keys_open(conv, inst->node_id, id, parties, 0, private_keys[0], keys, opened) < 0); keys[32] ^= 1;
keys[64 + DM_KEY_WRAP_SIZE - 1] ^= 1;
assert(dm_file_keys_open(conv, inst->node_id, id, parties, 0, private_keys[0], keys, opened) < 0);
assert(!memcmp(opened, other, 32));
assert(!dm_file_keys_open(conv, inst->node_id, id, parties, 1, private_keys[1], keys, opened) && !memcmp(key, opened, 32));
}
int main(void) {
debug_config_init(); debug_set_level(DEBUG_LEVEL_DEBUG);
struct UTUN_INSTANCE inst = {0};
@@ -111,6 +139,7 @@ int main(void) {
assert(!dm_party_resolve(&inst, nodes[2].node_id, DM_MODE_GROUPS, parties + 1));
assert(parties[0].kind == DM_PARTY_GROUP && parties[1].kind == DM_PARTY_GROUP);
protocol(&inst, parties);
file_keys(&inst, parties, group_x);
reversed[0] = parties[1]; reversed[1] = parties[0];
uint64_t conv = dm_identity_conv_id(DM_MODE_GROUPS, parties);
assert(conv && conv == dm_identity_conv_id(DM_MODE_GROUPS, reversed));