ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
key_set.c
Go to the documentation of this file.
3#include <sodium.h>
4#include <string.h>
5
7 bool require_identity, bool *complete) {
8 if (!set || !req || !complete)
9 return SET_ERRNO(ERROR_INVALID_PARAM, "Missing create sequence parameters");
10 *complete = false;
11 size_t total = req->total_keys ? req->total_keys : 1;
12 if (total > MAX_SESSION_KEYS || req->key_index >= total || req->key_index != set->count ||
13 (!req->total_keys && set->count) ||
14 (set->count && (req->total_keys != set->request.total_keys || req->capabilities != set->request.capabilities ||
15 req->max_participants != set->request.max_participants)) ||
16 req->reserved_string_len >= ACIP_MAX_SESSION_STRING_LEN ||
17 !memchr(req->server_address, '\0', sizeof(req->server_address)) ||
18 (req->has_password && !memchr(req->password_hash, '\0', sizeof(req->password_hash)))) {
19 memset(set, 0, sizeof(*set));
20 return SET_ERRNO(ERROR_INVALID_PARAM, "Malformed or out-of-order create sequence");
21 }
22 for (size_t i = 0; i < set->count; ++i) {
23 if (memcmp(set->keys[i], req->identity_pubkey, sizeof(req->identity_pubkey)) == 0) {
24 memset(set, 0, sizeof(*set));
25 return SET_ERRNO(ERROR_INVALID_PARAM, "Duplicate Ed25519 identity");
26 }
27 }
28 // Every member of a restricted set proves possession. Optional single-key
29 // identity keeps its existing service-wide policy.
30 if (require_identity || total > 1) {
31 if (!acds_validate_timestamp(req->timestamp, 300) ||
32 acds_verify_session_create(req->identity_pubkey, req->timestamp, req->capabilities, req->max_participants,
33 req->signature) != ASCIICHAT_OK) {
34 memset(set, 0, sizeof(*set));
35 return SET_ERRNO(ERROR_CRYPTO_VERIFICATION, "Invalid create identity proof");
36 }
37 }
38 if (!set->count) {
39 memcpy(&set->request, req, sizeof(*req));
40 if (req->reserved_string_len)
41 memcpy(set->reserved_string, req + 1, (size_t)req->reserved_string_len);
42 }
43 memcpy(set->keys[set->count++], req->identity_pubkey, sizeof(req->identity_pubkey));
44 *complete = set->count == total;
45 return ASCIICHAT_OK;
46}
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:74
bool acds_validate_timestamp(uint64_t timestamp_ms, uint32_t window_seconds)
Check if timestamp is within acceptable window.
ACIP client-side protocol library and ACDS client connection API.
#define ACIP_MAX_SESSION_STRING_LEN
Definition acds_sizes.h:6
#define SET_ERRNO(code,...)
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:44
@ ERROR_CRYPTO_VERIFICATION
Definition error_codes.h:97
@ ASCIICHAT_OK
Definition error_codes.h:46
@ ERROR_INVALID_PARAM
#define MAX_SESSION_KEYS
acip_session_create_t
Definition acds.h:226
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)
Definition key_set.c:6
🔤 String Manipulation and Shell Escaping Utilities
The useful part of acds create key set is in request, count: together they describe what is pending,...
Definition key_set.h:8
char reserved_string[ACIP_MAX_SESSION_STRING_LEN]
Definition key_set.h:10
uint8_t keys[MAX_SESSION_KEYS][ED25519_PUBLIC_KEY_SIZE]
Definition key_set.h:11
acip_session_create_t request
Definition key_set.h:9