ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
Video chat in your terminal
Loading...
Searching...
No Matches
key_set.c File Reference

Go to the source code of this file.

Functions

asciichat_error_t acds_create_key_set_collect (acds_create_key_set_t *set, const acip_session_create_t *req, bool require_identity, bool *complete)

Function Documentation

◆ acds_create_key_set_collect()

asciichat_error_t acds_create_key_set_collect ( acds_create_key_set_t * set,
const acip_session_create_t * req,
bool require_identity,
bool * complete )

Validate order, bounds, deduplication and individual possession proofs. Errors clear the sequence. complete is true only when every key is present.

Definition at line 6 of file key_set.c.

9 {
10 if (!set || !req || !complete)
11 return SET_ERRNO(ERROR_INVALID_PARAM, "Missing create sequence parameters");
12 *complete = false;
13 size_t total = req->total_keys ? req->total_keys : 1;
14 if (total > MAX_SESSION_KEYS || req->key_index >= total ||
15 req->key_index != set->count || (!req->total_keys && set->count) ||
16 (set->count &&
17 (req->total_keys != set->request.total_keys ||
18 req->capabilities != set->request.capabilities ||
19 req->max_participants != set->request.max_participants)) ||
20 req->reserved_string_len >= ACIP_MAX_SESSION_STRING_LEN ||
21 !memchr(req->server_address, '\0', sizeof(req->server_address)) ||
22 (req->has_password &&
23 !memchr(req->password_hash, '\0', sizeof(req->password_hash)))) {
24 memset(set, 0, sizeof(*set));
26 "Malformed or out-of-order create sequence");
27 }
28 for (size_t i = 0; i < set->count; ++i) {
29 if (memcmp(set->keys[i], req->identity_pubkey,
30 sizeof(req->identity_pubkey)) == 0) {
31 memset(set, 0, sizeof(*set));
32 return SET_ERRNO(ERROR_INVALID_PARAM, "Duplicate Ed25519 identity");
33 }
34 }
35 // Every member of a restricted set proves possession. Optional single-key
36 // identity keeps its existing service-wide policy.
37 if (require_identity || total > 1) {
38 if (!acds_validate_timestamp(req->timestamp, 300) ||
39 acds_verify_session_create(req->identity_pubkey, req->timestamp,
40 req->capabilities, req->max_participants,
41 req->signature) != ASCIICHAT_OK) {
42 memset(set, 0, sizeof(*set));
44 "Invalid create identity proof");
45 }
46 }
47 if (!set->count) {
48 memcpy(&set->request, req, sizeof(*req));
49 if (req->reserved_string_len)
50 memcpy(set->reserved_string, req + 1, (size_t)req->reserved_string_len);
51 }
52 memcpy(set->keys[set->count++], req->identity_pubkey,
53 sizeof(req->identity_pubkey));
54 *complete = set->count == total;
55 return ASCIICHAT_OK;
56}
asciichat_error_t acds_verify_session_create(const uint8_t identity_pubkey[32], uint64_t timestamp, uint8_t capabilities, uint8_t max_participants, const uint8_t signature[64])
Verify SESSION_CREATE signature.
Definition acds_client.c:72
bool acds_validate_timestamp(uint64_t timestamp_ms, uint32_t window_seconds)
Check if timestamp is within acceptable window.
#define ACIP_MAX_SESSION_STRING_LEN
Definition acds_sizes.h:10
#define SET_ERRNO(code,...)
@ ERROR_CRYPTO_VERIFICATION
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_INVALID_PARAM
#define MAX_SESSION_KEYS
char reserved_string[ACIP_MAX_SESSION_STRING_LEN]
Definition key_set.h:18
uint8_t keys[MAX_SESSION_KEYS][ED25519_PUBLIC_KEY_SIZE]
Definition key_set.h:19
acip_session_create_t request
Definition key_set.h:17

References acds_validate_timestamp(), acds_verify_session_create(), ACIP_MAX_SESSION_STRING_LEN, acip_session_create_t, ASCIICHAT_OK, acds_create_key_set_t::count, ERROR_CRYPTO_VERIFICATION, ERROR_INVALID_PARAM, acds_create_key_set_t::keys, MAX_SESSION_KEYS, acds_create_key_set_t::request, acds_create_key_set_t::reserved_string, and SET_ERRNO.