feat(core): run bounded real gateway sessions

This commit is contained in:
sechmachine
2026-08-12 22:03:10 +07:00
parent 86a95952b6
commit 519c04e18f
10 changed files with 1598 additions and 178 deletions
+53 -32
View File
@@ -8,7 +8,7 @@
static const char MANIFEST[] =
"{\"version\":\"1\",\"purpose\":\"launch\",\"session_id\":\"session\","
"\"reconnect_sequence\":0,\"gateway\":{\"id\":\"gateway\",\"addresses\":["
"\"gateway.test:443\"],\"public_identity\":\"gateway.test\"},\"tunnel\":{"
"\"127.0.0.1:9\"],\"public_identity\":\"gateway.test\"},\"tunnel\":{"
"\"versions\":[\"verse-gateway-v1/1\"],\"features\":[\"control.v1\"]},"
"\"profile\":{\"id\":\"standard\",\"bounds\":{\"minimum_kbps\":1000,"
"\"target_kbps\":5000,\"maximum_kbps\":10000},\"display_mode\":null},"
@@ -24,36 +24,28 @@ static const char CREDENTIAL[] =
typedef struct smoke_context {
atomic_uint admission_calls;
atomic_uint tls_calls;
atomic_uint state_calls;
} smoke_context_t;
static verse_status_t sign_admission(
static verse_status_t reject_admission(
void *raw,
verse_bytes_view_t input,
uint8_t signature[64]) {
smoke_context_t *context = raw;
assert(input.length == sizeof(MANIFEST) - 1U);
memset(signature, 0xA5, 64U);
(void)input;
(void)signature;
atomic_fetch_add(&context->admission_calls, 1U);
return VERSE_STATUS_OK;
return VERSE_STATUS_INTERNAL;
}
static verse_status_t sign_tls(
static verse_status_t reject_tls(
void *raw,
verse_bytes_view_t input,
uint8_t signature[64]) {
smoke_context_t *context = raw;
assert(input.length == sizeof(CREDENTIAL) - 1U);
memset(signature, 0x5A, 64U);
(void)input;
(void)signature;
atomic_fetch_add(&context->tls_calls, 1U);
return VERSE_STATUS_OK;
}
static void on_state(void *raw, const verse_state_event_v1_t *event) {
smoke_context_t *context = raw;
assert(event->struct_size == sizeof(*event));
assert(event->abi_version == VERSE_CORE_ABI_VERSION_1);
atomic_fetch_add(&context->state_calls, 1U);
return VERSE_STATUS_INTERNAL;
}
int main(void) {
@@ -62,35 +54,64 @@ int main(void) {
.struct_size = sizeof(config),
.abi_version = VERSE_CORE_ABI_VERSION_1,
.context = &context,
.sign_admission = sign_admission,
.sign_tls_ed25519 = sign_tls,
.on_state = on_state,
.sign_admission = reject_admission,
.sign_tls_ed25519 = reject_tls,
};
verse_core_t *core = NULL;
assert(verse_core_abi_version() == VERSE_CORE_ABI_VERSION_1);
assert(verse_core_create_v1(NULL, &core) == VERSE_STATUS_INVALID_ARGUMENT);
assert(verse_core_create_v1(&config, NULL) == VERSE_STATUS_INVALID_ARGUMENT);
config.struct_size = 8U;
assert(verse_core_create_v1(&config, &core) == VERSE_STATUS_INVALID_ARGUMENT);
config.struct_size = sizeof(config);
config.abi_version = VERSE_CORE_ABI_VERSION_1 + 1U;
assert(verse_core_create_v1(&config, &core) == VERSE_STATUS_UNSUPPORTED_ABI);
config.abi_version = VERSE_CORE_ABI_VERSION_1;
assert(verse_core_create_v1(&config, &core) == VERSE_STATUS_OK);
assert(core != NULL);
const verse_connect_request_v1_t request = {
.struct_size = sizeof(request),
.abi_version = VERSE_CORE_ABI_VERSION_1,
.manifest_json = {(const uint8_t *)MANIFEST, sizeof(MANIFEST) - 1U},
.tunnel_credential_json = {(const uint8_t *)CREDENTIAL, sizeof(CREDENTIAL) - 1U},
};
assert(verse_core_connect_v1(core, &request) == VERSE_STATUS_OK);
verse_input_event_v1_t input = {
.struct_size = sizeof(input),
.abi_version = VERSE_CORE_ABI_VERSION_1,
.kind = VERSE_INPUT_KEYBOARD,
.values = {1, 0, 30},
};
assert(verse_core_send_input_v1(core, &input) == VERSE_STATUS_OK);
assert(verse_core_request_idr_v1(core) == VERSE_STATUS_OK);
assert(verse_core_send_input_v1(core, &input) == VERSE_STATUS_INVALID_STATE);
assert(verse_core_request_idr_v1(core) == VERSE_STATUS_INVALID_STATE);
char manifest[sizeof(MANIFEST)];
char credential[sizeof(CREDENTIAL)];
memcpy(manifest, MANIFEST, sizeof(manifest));
memcpy(credential, CREDENTIAL, sizeof(credential));
verse_connect_request_v1_t request = {
.struct_size = sizeof(request),
.abi_version = VERSE_CORE_ABI_VERSION_1,
.manifest_json = {(const uint8_t *)manifest, sizeof(manifest) - 1U},
.tunnel_credential_json = {(const uint8_t *)credential, sizeof(credential) - 1U},
};
assert(verse_core_connect_v1(NULL, &request) == VERSE_STATUS_INVALID_ARGUMENT);
request.struct_size = 8U;
assert(verse_core_connect_v1(core, &request) == VERSE_STATUS_INVALID_ARGUMENT);
request.struct_size = sizeof(request);
request.abi_version = VERSE_CORE_ABI_VERSION_1 + 1U;
assert(verse_core_connect_v1(core, &request) == VERSE_STATUS_UNSUPPORTED_ABI);
request.abi_version = VERSE_CORE_ABI_VERSION_1;
request.manifest_json.data = NULL;
assert(verse_core_connect_v1(core, &request) == VERSE_STATUS_INVALID_ARGUMENT);
request.manifest_json.data = (const uint8_t *)manifest;
assert(verse_core_connect_v1(core, &request) == VERSE_STATUS_TLS);
memset(manifest, 0, sizeof(manifest));
memset(credential, 0, sizeof(credential));
assert(verse_core_send_input_v1(core, &input) == VERSE_STATUS_CANCELLED);
assert(verse_core_request_idr_v1(core) == VERSE_STATUS_CANCELLED);
assert(verse_core_cancel_v1(core) == VERSE_STATUS_OK);
assert(verse_core_cancel_v1(core) == VERSE_STATUS_OK);
assert(atomic_load(&context.admission_calls) == 0U);
assert(atomic_load(&context.tls_calls) == 0U);
assert(verse_core_destroy_v1(core, 2000U) == VERSE_STATUS_OK);
assert(atomic_load(&context.admission_calls) == 1U);
assert(atomic_load(&context.tls_calls) == 1U);
assert(atomic_load(&context.admission_calls) == 0U);
assert(atomic_load(&context.tls_calls) == 0U);
return EXIT_SUCCESS;
}