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

Server-side handshake functions. More...

Go to the source code of this file.

Functions

Server Handshake Protocol
asciichat_error_t crypto_handshake_server_start (crypto_handshake_context_t *ctx, acip_transport_t *transport)
 Server: Start crypto handshake by sending public key.
asciichat_error_t crypto_handshake_server_send_parameters (crypto_handshake_context_t *ctx, acip_transport_t *transport)
 Server: Send CRYPTO_PARAMETERS and set handshake context sizes.
asciichat_error_t crypto_handshake_server_auth_challenge (crypto_handshake_context_t *ctx, acip_transport_t *transport, packet_type_t packet_type, const uint8_t *payload, size_t payload_len)
 Server: Process client's public key and send auth challenge.
asciichat_error_t crypto_handshake_server_complete (crypto_handshake_context_t *ctx, acip_transport_t *transport, packet_type_t packet_type, const uint8_t *payload, size_t payload_len)
 Server: Process auth response and complete handshake.

Detailed Description

Server-side handshake functions.

Definition in file include/ascii-chat/crypto/handshake/server.h.

Function Documentation

◆ crypto_handshake_server_auth_challenge()

asciichat_error_t crypto_handshake_server_auth_challenge ( crypto_handshake_context_t * ctx,
acip_transport_t * transport,
packet_type_t packet_type,
const uint8_t * payload,
size_t payload_len )

Server: Process client's public key and send auth challenge.

Parameters
ctxHandshake context (must be in CRYPTO_HANDSHAKE_KEY_EXCHANGE state)
transportACIP transport to send on
packet_typePacket type received (should be PACKET_TYPE_CRYPTO_KEY_EXCHANGE_RESP or PACKET_TYPE_CRYPTO_NO_ENCRYPTION)
payloadReceived packet payload
payload_lenLength of received payload
Returns
ASCIICHAT_OK on success, error code on failure

Server processes client's KEY_EXCHANGE_RESP packet and sends AUTH_CHALLENGE. Computes shared secret and generates authentication challenge nonce.

Note
Packet must be received by ACIP handler before calling this function
State transition: CRYPTO_HANDSHAKE_KEY_EXCHANGE -> CRYPTO_HANDSHAKE_AUTHENTICATING

Definition at line 206 of file lib/crypto/handshake/server.c.

208 {
209 ASCII_OTEL_SCOPE(CRYPTO_HANDSHAKE_SERVER_AUTH_CHALLENGE);
210 if (!ctx || ctx->state != CRYPTO_HANDSHAKE_KEY_EXCHANGE) {
211 return SET_ERRNO(ERROR_INVALID_STATE, "Invalid state: ctx=%p, state=%d",
212 ctx, ctx ? (int)ctx->state : -1);
213 }
214 if (!transport) {
215 return SET_ERRNO(ERROR_INVALID_PARAM, "transport is NULL");
216 }
217
218 // Note: Packet already received by ACIP handler
219 int result;
220
221 // Check if client sent NO_ENCRYPTION response
222 if (packet_type == PACKET_TYPE_CRYPTO_NO_ENCRYPTION) {
223
224 // Send AUTH_FAILED to inform client (though they already know)
225 auth_failure_packet_t failure = {0};
226 failure.reason_flags =
227 0; // No specific auth failure, just encryption mismatch
228 int send_result =
230 &failure, sizeof(failure), 0);
231 if (send_result != 0) {
232 return SET_ERRNO(ERROR_NETWORK, "Failed to send AUTH_FAILED packet");
233 }
234
235 return SET_ERRNO(
237 "SECURITY: Client sent NO_ENCRYPTION response - encryption mode "
238 "mismatch. Server requires encryption, but "
239 "client has --no-encrypt. Use matching encryption settings on "
240 "both client and server");
241 }
242
243 // Verify packet type
244 if (packet_type != PACKET_TYPE_CRYPTO_KEY_EXCHANGE_RESP) {
246 "Expected KEY_EXCHANGE_RESPONSE, got packet type %d",
247 packet_type);
248 }
249
250 // Verify payload size - client can send either simple or authenticated format
251 // Simple: kex_public_key_size bytes
252 // Authenticated: public_key_size + client_auth_key_size + client_sig_size
253 // bytes
254 size_t simple_size = ctx->crypto_ctx.public_key_size;
255 // Ed25519 public key is always 32 bytes
256 // Ed25519 signature is always 64 bytes
257 size_t authenticated_size = ctx->crypto_ctx.public_key_size +
259
260 bool client_sent_identity = false;
261 const size_t identity_size = ED25519_PUBLIC_KEY_SIZE;
262 const size_t signature_size = ED25519_SIGNATURE_SIZE;
263 SAFE_MALLOC_DEFER_FREE(client_ephemeral_key, ctx->crypto_ctx.public_key_size,
264 uint8_t *);
265 SAFE_MALLOC_DEFER_FREE(client_identity_key, identity_size, uint8_t *);
266 SAFE_MALLOC_DEFER_FREE(client_signature, signature_size, uint8_t *);
267
268 if (!client_ephemeral_key || !client_identity_key || !client_signature) {
269 return SET_ERRNO(ERROR_MEMORY, "Failed to allocate memory for client keys");
270 }
271
272 // Validate packet size using session parameters
274 ctx, PACKET_TYPE_CRYPTO_KEY_EXCHANGE_RESP, payload_len);
275 if (validation_result != ASCIICHAT_OK) {
276 // Payload ownership remains with caller
277
278 return validation_result;
279 }
280
281 // Handle both authenticated and non-authenticated responses
282 // authenticated_size is now a minimum - packet may be larger with GPG key ID
283 if (payload_len >= authenticated_size) {
284 // Authenticated format (may have optional GPG key ID):
285 // [ephemeral:kex_size][identity:auth_size][signature:sig_size][gpg_key_id_len:1][gpg_key_id:0-16]
286 memcpy(client_ephemeral_key, payload, ctx->crypto_ctx.public_key_size);
287 memcpy(client_identity_key, payload + ctx->crypto_ctx.public_key_size,
289 memcpy(client_signature,
292 client_sent_identity = true;
293 ctx->client_sent_identity = true;
294
295 // Extract GPG key ID if present
296 const char *client_gpg_key_id = NULL;
297 char gpg_key_id_buffer[GPG_FINGERPRINT_HEX_BUFFER_SIZE] = {0};
298 size_t gpg_offset = ctx->crypto_ctx.public_key_size +
300 if (payload_len > gpg_offset) {
301 uint8_t gpg_key_id_len = payload[gpg_offset];
302 if (gpg_key_id_len > 0 && gpg_key_id_len <= 40 &&
303 payload_len >= gpg_offset + 1 + gpg_key_id_len) {
304 memcpy(gpg_key_id_buffer, payload + gpg_offset + 1, gpg_key_id_len);
305 gpg_key_id_buffer[gpg_key_id_len] = '\0';
306 client_gpg_key_id = gpg_key_id_buffer;
307 log_debug("Extracted client GPG key ID from KEY_EXCHANGE_RESPONSE: %s",
308 client_gpg_key_id);
309 }
310 }
311
312 // Check if client sent a null identity key (all zeros)
313 bool client_has_null_identity = true;
314 for (size_t i = 0; i < ED25519_PUBLIC_KEY_SIZE; i++) {
315 if (client_identity_key[i] != 0) {
316 client_has_null_identity = false;
317 break;
318 }
319 }
320
321 if (client_has_null_identity) {
322 // Client has no identity key - this is allowed for servers without client
323 // authentication
324 log_debug(
325 "Client sent null identity key - no client authentication required");
326 client_sent_identity = false;
327 ctx->client_sent_identity = false;
328 NOTICE(WARNING, "UNVERIFIED CLIENT IDENTITY",
329 "Client connected without identity authentication");
330 } else {
331 // Client has a real identity key
332 // If server didn't specify --client-keys, skip signature verification
333 // (server doesn't care about client identity verification)
334 if (!ctx->require_client_auth) {
335 log_info("Skipping client signature verification (no --client-keys "
336 "specified)");
337 NOTICE(WARNING, "UNVERIFIED CLIENT IDENTITY",
338 "Connection is encrypted but client identity is NOT verified");
339 } else {
340 // Verify client's signature
341 log_debug("Verifying client's signature");
342 // Pass client's GPG key ID if available
343 if (ed25519_verify_signature(client_identity_key, client_ephemeral_key,
345 client_signature,
346 client_gpg_key_id) != 0) {
347 // Send AUTH_FAILED with specific reason
348 auth_failure_packet_t failure = {0};
350 int send_result = packet_send_via_transport(
351 transport, PACKET_TYPE_CRYPTO_AUTH_FAILED, &failure,
352 sizeof(failure), 0);
353 if (send_result != 0) {
355 "Failed to send AUTH_FAILED packet");
356 }
357
358 return SET_ERRNO(
360 "Client signature verification FAILED - rejecting connection");
361 }
362 }
363 }
364
365 // Store the verified client identity for whitelist checking (only if client
366 // has identity)
367 if (client_sent_identity) {
369 memcpy(ctx->client_ed25519_key.key, client_identity_key,
371 }
372 } else if (payload_len == simple_size) {
373 // Non-authenticated format: [ephemeral:public_key_size] only
374 log_debug("Client sent non-authenticated response (%zu bytes)",
375 payload_len);
376 memcpy(client_ephemeral_key, payload, ctx->crypto_ctx.public_key_size);
377 client_sent_identity = false;
378 ctx->client_sent_identity = false;
379 NOTICE(WARNING, "UNVERIFIED CLIENT IDENTITY",
380 "Client connected without identity authentication");
381 } else {
382 // Payload ownership remains with caller
383
384 return SET_ERRNO(
386 "Invalid client key response size: %zu bytes (expected %zu for "
387 "authenticated or %zu for simple)",
388 payload_len, authenticated_size, simple_size);
389 }
390
391 // Extract pointers for compatibility with existing code
392 const uint8_t *client_x25519 = client_ephemeral_key;
393 const uint8_t *client_ed25519 =
394 client_sent_identity ? client_identity_key : NULL;
395
396 // Check client Ed25519 key against whitelist if client provided one and
397 // whitelist is enabled
398 if (client_sent_identity && ctx->require_client_auth &&
399 ctx->client_whitelist && ctx->num_whitelisted_clients > 0) {
400 bool key_found = false;
401
402 // Debug: print client's Ed25519 identity key
403 char client_ed25519_hex[HEX_STRING_SIZE_32];
404 for (int i = 0; i < ED25519_PUBLIC_KEY_SIZE; i++) {
405 safe_snprintf(client_ed25519_hex + i * 2, 3, "%02x", client_ed25519[i]);
406 }
407 log_debug("Client Ed25519 identity key: %s", client_ed25519_hex);
408
409 // Compare against whitelist (direct Ed25519 comparison - no conversion!)
410 for (size_t i = 0; i < ctx->num_whitelisted_clients; i++) {
411 // Debug: print whitelist Ed25519 key
412 char whitelist_ed25519_hex[HEX_STRING_SIZE_32];
413 for (int j = 0; j < ED25519_PUBLIC_KEY_SIZE; j++) {
414 safe_snprintf(whitelist_ed25519_hex + j * 2, 3, "%02x",
415 ctx->client_whitelist[i].key[j]);
416 }
417 log_debug("Whitelist[%zu] Ed25519 key: %s", i, whitelist_ed25519_hex);
418
419 // Direct comparison of Ed25519 keys (constant-time to prevent timing
420 // attacks)
421 if (sodium_memcmp(client_ed25519, ctx->client_whitelist[i].key,
423 key_found = true;
424 ctx->client_ed25519_key_verified = true;
425
426 // Store the client's Ed25519 key for signature verification
427 memcpy(&ctx->client_ed25519_key, &ctx->client_whitelist[i],
428 sizeof(public_key_t));
429
430 log_debug("Client Ed25519 key authorized (whitelist entry %zu)", i);
431 if (strlen(ctx->client_whitelist[i].comment) > 0) {
432 log_info("Client identity: %s", ctx->client_whitelist[i].comment);
433 }
434 break;
435 }
436 }
437
438 if (!key_found) {
440 "Client Ed25519 key not in whitelist - rejecting connection");
441 // Don't send AUTH_FAILED here - wait until server_complete
442 // Just mark that the key was rejected
443 ctx->client_ed25519_key_verified = false;
444 }
445 } else if (client_sent_identity) {
446 // No whitelist checking - just store the client's Ed25519 key for later
447 // (Already stored at line 313-314, but keep this for clarity)
448 // Discovery can require proof of identity without restricting which
449 // identities may join. require_client_auth ensured that the signature was
450 // verified above.
453 }
454
455 // Set peer's X25519 encryption key - this also derives the shared secret
456 crypto_result_t crypto_result =
457 crypto_set_peer_public_key(&ctx->crypto_ctx, client_x25519);
458 if (crypto_result != CRYPTO_OK) {
459 return SET_ERRNO(
461 "Failed to set peer public key and derive shared secret: %s",
462 crypto_result_to_string(crypto_result));
463 }
464
465 // Do authentication challenge if client provided identity key OR server
466 // requires password
467 if (client_sent_identity || ctx->crypto_ctx.has_password ||
468 ctx->require_client_auth) {
469 // Generate nonce and store it in the context
470 crypto_result = crypto_generate_nonce(ctx->crypto_ctx.auth_nonce);
471 if (crypto_result != CRYPTO_OK) {
472 return SET_ERRNO(ERROR_CRYPTO, "Failed to generate nonce: %s",
473 crypto_result_to_string(crypto_result));
474 }
475
476 // Prepare AUTH_CHALLENGE packet: 1 byte flags + auth_challenge_size byte
477 // nonce
478 size_t challenge_packet_size =
480 uint8_t challenge_packet[1 + HMAC_SHA256_SIZE]; // Maximum size buffer
481 uint8_t auth_flags = 0;
482
483 // Set flags based on server requirements
484 if (ctx->crypto_ctx.has_password) {
485 auth_flags |= AUTH_REQUIRE_PASSWORD;
486 }
487 if (ctx->require_client_auth) {
488 auth_flags |= AUTH_REQUIRE_CLIENT_KEY;
489 }
490
491 challenge_packet[0] = auth_flags;
492 memcpy(challenge_packet + 1, ctx->crypto_ctx.auth_nonce,
494
495 // Send AUTH_CHALLENGE with flags + nonce (challenge_packet_size bytes)
496 result =
498 challenge_packet, challenge_packet_size, 0);
499 if (result != 0) {
500 return SET_ERRNO(ERROR_NETWORK, "Failed to send AUTH_CHALLENGE packet");
501 }
502
504 } else {
505 // No authentication needed - skip to completion
506 log_debug(
507 "Skipping authentication (no password and client has no identity key)");
508
509 // Send HANDSHAKE_COMPLETE immediately
511 transport, PACKET_TYPE_CRYPTO_HANDSHAKE_COMPLETE, NULL, 0, 0);
512 if (result != 0) {
514 "Failed to send HANDSHAKE_COMPLETE packet");
515 }
516
519 true; // Mark crypto context as ready for rekeying
520 log_debug("Crypto handshake completed successfully (no authentication)");
521 }
522
523 return ASCIICHAT_OK;
524}
#define SET_ERRNO(code,...)
asciichat_error_t crypto_handshake_validate_packet_size(const crypto_handshake_context_t *ctx, uint16_t packet_type, size_t packet_size)
Validate crypto packet size based on session parameters.
#define SAFE_MALLOC_DEFER_FREE(name, size, cast)
unsigned char uint8_t
crypto_result_t crypto_set_peer_public_key(crypto_context_t *ctx, const uint8_t *peer_public_key)
Set peer's public key and compute shared secret (step 2 of handshake).
const char * crypto_result_to_string(crypto_result_t result)
Convert crypto result to human-readable string.
crypto_result_t
Cryptographic operation result codes.
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
@ ERROR_INVALID_STATE
@ ERROR_NETWORK
Definition error_codes.h:77
@ ERROR_NETWORK_PROTOCOL
Definition error_codes.h:81
@ ERROR_MEMORY
Definition error_codes.h:55
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_CRYPTO_AUTH
@ ERROR_CRYPTO
@ ERROR_INVALID_PARAM
uint8_t key[CRYPTO_PUBLIC_KEY_SIZE]
Definition key_types.h:85
char comment[MAX_COMMENT_LEN]
Definition key_types.h:86
key_type_t type
Definition key_types.h:84
@ KEY_TYPE_ED25519
Definition key_types.h:61
#define log_info(...)
Log an INFO message.
Definition log/log.h:578
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:565
@ AUTH_FAIL_SIGNATURE_INVALID
Client signature verification failed (invalid signature).
Definition packet.h:822
@ PACKET_TYPE_CRYPTO_HANDSHAKE_COMPLETE
Server -> Client: "encryption ready" (UNENCRYPTED).
Definition packet.h:352
@ PACKET_TYPE_CRYPTO_KEY_EXCHANGE_RESP
Client -> Server: {client_pubkey[32]} (UNENCRYPTED).
Definition packet.h:342
@ PACKET_TYPE_CRYPTO_AUTH_FAILED
Server -> Client: "authentication failed" (UNENCRYPTED).
Definition packet.h:348
@ PACKET_TYPE_CRYPTO_NO_ENCRYPTION
Client -> Server: "I want to proceed without encryption" (UNENCRYPTED).
Definition packet.h:354
@ PACKET_TYPE_CRYPTO_AUTH_CHALLENGE
Server -> Client: {nonce[32]} (UNENCRYPTED).
Definition packet.h:344
#define AUTH_REQUIRE_PASSWORD
Server requires password authentication.
#define AUTH_REQUIRE_CLIENT_KEY
Server requires client key authentication (whitelist).
crypto_result_t crypto_generate_nonce(uint8_t nonce[AUTH_CHALLENGE_SIZE])
#define NOTICE(severity, title,...)
Definition notice.h:86
#define ASCII_OTEL_SCOPE(id)
Definition otel.h:102
asciichat_error_t packet_send_via_transport(acip_transport_t *transport, packet_type_t type, const void *payload, size_t payload_len, uint32_t client_id)
Definition send.c:183
#define ED25519_SIGNATURE_SIZE
Ed25519 signature size in bytes.
Definition sizes.h:42
#define HMAC_SHA256_SIZE
HMAC-SHA256 output size in bytes.
Definition sizes.h:48
#define GPG_FINGERPRINT_HEX_BUFFER_SIZE
Definition sizes.h:178
#define ED25519_PUBLIC_KEY_SIZE
Ed25519 public key size in bytes.
Definition sizes.h:38
#define HEX_STRING_SIZE_32
Hex string size for 32-byte values (64 hex chars + null terminator).
Definition sizes.h:163
#define AUTH_CHALLENGE_FLAGS_SIZE
Authentication flags size (1 byte).
Definition sizes.h:120
asciichat_error_t ed25519_verify_signature(const uint8_t public_key[ED25519_PUBLIC_KEY_SIZE], const uint8_t *message, size_t message_len, const uint8_t signature[ED25519_SIGNATURE_SIZE], const char *gpg_key_id)
Definition ssh_keys.c:1454
Authentication failure packet structure.
Definition packet.h:833
uint8_t reason_flags
Bitmask of auth_failure_reason_t values indicating failure causes.
Definition packet.h:835
bool allow_unlisted_client_identity
Require proof of key possession without whitelist membership (discovery).
The normalized public identity used by ascii-chat's crypto and key-management code.
Definition key_types.h:83

References crypto_handshake_context_t::allow_unlisted_client_identity, ASCII_OTEL_SCOPE, ASCIICHAT_OK, AUTH_CHALLENGE_FLAGS_SIZE, crypto_context_t::auth_challenge_size, AUTH_FAIL_SIGNATURE_INVALID, crypto_context_t::auth_nonce, AUTH_REQUIRE_CLIENT_KEY, AUTH_REQUIRE_PASSWORD, crypto_handshake_context_t::client_ed25519_key, crypto_handshake_context_t::client_ed25519_key_verified, crypto_handshake_context_t::client_sent_identity, crypto_handshake_context_t::client_whitelist, public_key_t::comment, crypto_handshake_context_t::crypto_ctx, crypto_generate_nonce(), CRYPTO_HANDSHAKE_AUTHENTICATING, CRYPTO_HANDSHAKE_KEY_EXCHANGE, CRYPTO_HANDSHAKE_READY, crypto_handshake_validate_packet_size(), CRYPTO_OK, crypto_result_to_string(), crypto_set_peer_public_key(), ED25519_PUBLIC_KEY_SIZE, ED25519_SIGNATURE_SIZE, ed25519_verify_signature(), ERROR_CRYPTO, ERROR_CRYPTO_AUTH, ERROR_INVALID_PARAM, ERROR_INVALID_STATE, ERROR_MEMORY, ERROR_NETWORK, ERROR_NETWORK_PROTOCOL, GPG_FINGERPRINT_HEX_BUFFER_SIZE, crypto_context_t::handshake_complete, crypto_context_t::has_password, HEX_STRING_SIZE_32, HMAC_SHA256_SIZE, public_key_t::key, KEY_TYPE_ED25519, log_debug, log_info, NOTICE, crypto_handshake_context_t::num_whitelisted_clients, packet_send_via_transport(), PACKET_TYPE_CRYPTO_AUTH_CHALLENGE, PACKET_TYPE_CRYPTO_AUTH_FAILED, PACKET_TYPE_CRYPTO_HANDSHAKE_COMPLETE, PACKET_TYPE_CRYPTO_KEY_EXCHANGE_RESP, PACKET_TYPE_CRYPTO_NO_ENCRYPTION, crypto_context_t::public_key_size, auth_failure_packet_t::reason_flags, crypto_handshake_context_t::require_client_auth, SAFE_MALLOC_DEFER_FREE, SET_ERRNO, crypto_handshake_context_t::state, and public_key_t::type.

Referenced by acip_security_receive(), and network_negotiation_receive().

◆ crypto_handshake_server_complete()

asciichat_error_t crypto_handshake_server_complete ( crypto_handshake_context_t * ctx,
acip_transport_t * transport,
packet_type_t packet_type,
const uint8_t * payload,
size_t payload_len )

Server: Process auth response and complete handshake.

Parameters
ctxHandshake context (must be in CRYPTO_HANDSHAKE_AUTHENTICATING state)
transportACIP transport to send on
packet_typePacket type received (should be PACKET_TYPE_CRYPTO_AUTH_RESPONSE)
payloadReceived packet payload
payload_lenLength of received payload
Returns
ASCIICHAT_OK on success, error code on failure

Server processes client's AUTH_RESPONSE packet and sends SERVER_AUTH_RESP. Verifies authentication HMAC or signature and completes handshake.

Note
Packet must be received by ACIP handler before calling this function
State transition: CRYPTO_HANDSHAKE_AUTHENTICATING -> CRYPTO_HANDSHAKE_READY

Definition at line 526 of file lib/crypto/handshake/server.c.

528 {
529 ASCII_OTEL_SCOPE(CRYPTO_HANDSHAKE_SERVER_COMPLETE);
530 if (!ctx || ctx->state != CRYPTO_HANDSHAKE_AUTHENTICATING) {
531 return SET_ERRNO(ERROR_INVALID_STATE, "Invalid state: ctx=%p, state=%d",
532 ctx, ctx ? (int)ctx->state : -1);
533 }
534 if (!transport) {
535 return SET_ERRNO(ERROR_INVALID_PARAM, "transport is NULL");
536 }
537
538 // Note: Packet already received by ACIP handler
539 int result;
540
541 // Verify packet type
542 if (packet_type != PACKET_TYPE_CRYPTO_AUTH_RESPONSE) {
544 "Expected AUTH_RESPONSE, got packet type %d", packet_type);
545 }
546
547 // Verify password if required
548 if (ctx->crypto_ctx.has_password) {
549 // Validate packet size using session parameters
551 ctx, PACKET_TYPE_CRYPTO_AUTH_RESPONSE, payload_len);
552 if (validation_result != ASCIICHAT_OK) {
553 return validation_result;
554 }
555
556 // Ensure shared secret is derived before password verification
557 // This is critical for password HMAC verification which binds to the shared
558 // secret
561 "Password authentication failed - key exchange not complete");
562
563 // Send AUTH_FAILED with specific reason
564 auth_failure_packet_t failure = {0};
566 if (ctx->require_client_auth) {
568 }
570 &failure, sizeof(failure), 0);
571 return ERROR_NETWORK;
572 }
573
574 // Verify password HMAC (binds to DH shared_secret to prevent MITM)
575 log_debug(
576 "Verifying password HMAC: has_password=%d, key_exchange_complete=%d",
578 if (!payload) {
580 "Payload is NULL in password authentication");
581 return ERROR_CRYPTO;
582 }
584 ctx->crypto_ctx.auth_nonce, payload)) {
585 log_debug("Password HMAC verification failed");
586 // Enhanced error message when both password and whitelist are required
587 if (ctx->require_client_auth) {
589 "Password authentication failed - incorrect password (server "
590 "also requires whitelisted client key)");
591 } else {
593 "Password authentication failed - incorrect password");
594 }
595
596 // Send AUTH_FAILED with specific reason
597 auth_failure_packet_t failure = {0};
599 if (ctx->require_client_auth) {
601 }
603 &failure, sizeof(failure), 0);
604 return ERROR_NETWORK;
605 }
606
607 // Extract client challenge nonce for mutual authentication
608 // Use ctx->crypto_ctx.hmac_size and ctx->crypto_ctx.auth_challenge_size
609 // (negotiated during handshake)
610 memcpy(ctx->client_challenge_nonce, payload + ctx->crypto_ctx.hmac_size,
612 log_info("Password authentication successful");
613 } else {
614 // Ed25519 signature auth (payload format: signature + client_nonce +
615 // gpg_key_id_len + gpg_key_id)
616 size_t expected_min_signature_size = ctx->crypto_ctx.signature_size +
618 1; // +1 for gpg_key_id_len byte
619 size_t expected_password_size =
621 if (!payload) {
623 "Payload is NULL in signature authentication");
624 return ERROR_CRYPTO;
625 }
626 if (payload_len >= expected_min_signature_size) {
627 // Signature + client nonce + optional GPG key ID - VERIFY the signature
628 // on the challenge nonce
629 const uint8_t *signature = payload;
630 const uint8_t *client_nonce = payload + ctx->crypto_ctx.signature_size;
631
632 // Extract GPG key ID if present
633 size_t gpg_offset =
635 uint8_t gpg_key_id_len = payload[gpg_offset];
636 const char *client_gpg_key_id = NULL;
637 char gpg_key_id_buffer[GPG_FINGERPRINT_HEX_BUFFER_SIZE] = {0};
638
639 if (gpg_key_id_len > 0 && gpg_key_id_len <= 40) {
640 // Validate packet has enough bytes for GPG key ID
641 if (payload_len >= gpg_offset + 1 + gpg_key_id_len) {
642 memcpy(gpg_key_id_buffer, payload + gpg_offset + 1, gpg_key_id_len);
643 gpg_key_id_buffer[gpg_key_id_len] = '\0';
644 client_gpg_key_id = gpg_key_id_buffer;
645 log_debug("Extracted client GPG key ID from AUTH_RESPONSE: %s",
646 client_gpg_key_id);
647 }
648 }
649
650 // Actually verify the Ed25519/GPG signature on the challenge nonce
651 // This was missing, allowing authentication bypass
653 // Use unified verification function that handles both Ed25519 and GPG
654 // keys This matches the KEY_EXCHANGE verification path
655 log_debug("Verifying %s signature on challenge nonce",
656 ctx->client_ed25519_key.type == KEY_TYPE_GPG ? "GPG"
657 : "Ed25519");
658
661 ctx->crypto_ctx.auth_challenge_size, signature,
662 client_gpg_key_id // GPG key ID for fallback verification
663 );
664
665 if (verify_result != ASCIICHAT_OK) {
666 auth_failure_packet_t failure = {0};
669 "%s signature verification failed on challenge nonce",
670 ctx->client_ed25519_key.type == KEY_TYPE_GPG ? "GPG"
671 : "Ed25519");
673 &failure, sizeof(failure), 0);
674 return ERROR_CRYPTO_AUTH;
675 }
676 log_debug("%s signature on challenge nonce verified successfully",
677 ctx->client_ed25519_key.type == KEY_TYPE_GPG ? "GPG"
678 : "Ed25519");
679 }
680
681 memcpy(ctx->client_challenge_nonce, client_nonce,
683 } else if (payload_len == expected_password_size) {
684 // Just client nonce (legacy or password-only mode without password
685 // enabled) Use ctx->crypto_ctx.hmac_size and
686 // ctx->crypto_ctx.auth_challenge_size (negotiated during handshake)
687 memcpy(ctx->client_challenge_nonce, payload + ctx->crypto_ctx.hmac_size,
689 } else {
690 // Validate packet size using session parameters
691 asciichat_error_t validation_result =
693 ctx, PACKET_TYPE_CRYPTO_AUTH_RESPONSE, payload_len);
694 if (validation_result != ASCIICHAT_OK) {
695 return validation_result;
696 }
697 }
698 }
699
700 // Verify client key if required (whitelist)
701 if (ctx->require_client_auth) {
702 if (!ctx->client_ed25519_key_verified) {
703 // Send AUTH_FAILED with specific reason
704 auth_failure_packet_t failure = {0};
705
706 // Check if client provided a key but it wasn't in whitelist
707 if (ctx->client_sent_identity) {
708 SET_ERRNO(ERROR_CRYPTO_AUTH, "Client key authentication failed - your "
709 "key is not in the server's whitelist");
711 } else {
712 SET_ERRNO(
714 "Client key authentication failed - client did not provide a key");
716 }
717
718 if (ctx->crypto_ctx.has_password) {
719 // Password was verified, but key was not
721 "Note: Password was correct, but client key is required");
722 }
724 &failure, sizeof(failure), 0);
725 return ERROR_NETWORK;
726 }
727 log_info("Client key authentication successful (whitelist verified)");
728 if (strlen(ctx->client_ed25519_key.comment) > 0) {
729 log_info("Authenticated client: %s", ctx->client_ed25519_key.comment);
730 }
731 }
732
733 // Send SERVER_AUTH_RESPONSE with server's HMAC for mutual authentication
734 // Bind to DH shared_secret to prevent MITM (even if attacker knows password)
735 // Allocate buffer using negotiated hmac_size (should match AUTH_HMAC_SIZE)
736 uint8_t server_hmac[HMAC_SHA256_SIZE]; // Maximum size, actual size is
737 // ctx->hmac_size
739 &ctx->crypto_ctx, ctx->client_challenge_nonce, server_hmac);
740 if (crypto_result != CRYPTO_OK) {
742 "Failed to compute server HMAC for mutual authentication: %s",
743 crypto_result_to_string(crypto_result));
744 return ERROR_NETWORK;
745 }
746
747 log_debug("Sending SERVER_AUTH_RESPONSE packet with server HMAC (%u bytes) "
748 "for mutual authentication",
749 ctx->crypto_ctx.hmac_size);
750 result =
752 server_hmac, ctx->crypto_ctx.hmac_size, 0);
753 if (result != ASCIICHAT_OK) {
754 SET_ERRNO(ERROR_NETWORK, "Failed to send SERVER_AUTH_RESPONSE packet");
755 return ERROR_NETWORK;
756 }
757
759 ctx->crypto_ctx.handshake_complete = true;
760 log_debug("Crypto handshake completed successfully (mutual authentication)");
761
762 return ASCIICHAT_OK;
763}
@ KEY_TYPE_GPG
Definition key_types.h:64
@ AUTH_FAIL_PASSWORD_INCORRECT
Password verification failed (incorrect password).
Definition packet.h:816
@ AUTH_FAIL_CLIENT_KEY_REQUIRED
Server requires client key but client didn't provide one.
Definition packet.h:818
@ AUTH_FAIL_CLIENT_KEY_REJECTED
Client key not in whitelist (access denied).
Definition packet.h:820
@ PACKET_TYPE_CRYPTO_AUTH_RESPONSE
Client -> Server: {HMAC[32]} (UNENCRYPTED).
Definition packet.h:346
@ PACKET_TYPE_CRYPTO_SERVER_AUTH_RESP
Server -> Client: {HMAC[32]} server proves knowledge (UNENCRYPTED).
Definition packet.h:350
bool crypto_verify_auth_response(const crypto_context_t *ctx, const uint8_t nonce[AUTH_CHALLENGE_SIZE], const uint8_t expected_hmac[HMAC_SHA256_SIZE])
crypto_result_t crypto_compute_auth_response(const crypto_context_t *ctx, const uint8_t nonce[AUTH_CHALLENGE_SIZE], uint8_t hmac_out[HMAC_SHA256_SIZE])

References ASCII_OTEL_SCOPE, ASCIICHAT_OK, crypto_context_t::auth_challenge_size, AUTH_FAIL_CLIENT_KEY_REJECTED, AUTH_FAIL_CLIENT_KEY_REQUIRED, AUTH_FAIL_PASSWORD_INCORRECT, crypto_context_t::auth_nonce, crypto_handshake_context_t::client_challenge_nonce, crypto_handshake_context_t::client_ed25519_key, crypto_handshake_context_t::client_ed25519_key_verified, crypto_handshake_context_t::client_sent_identity, public_key_t::comment, crypto_compute_auth_response(), crypto_handshake_context_t::crypto_ctx, CRYPTO_HANDSHAKE_AUTHENTICATING, CRYPTO_HANDSHAKE_READY, crypto_handshake_validate_packet_size(), CRYPTO_OK, crypto_result_to_string(), crypto_verify_auth_response(), ed25519_verify_signature(), ERROR_CRYPTO, ERROR_CRYPTO_AUTH, ERROR_INVALID_PARAM, ERROR_INVALID_STATE, ERROR_NETWORK, ERROR_NETWORK_PROTOCOL, GPG_FINGERPRINT_HEX_BUFFER_SIZE, crypto_context_t::handshake_complete, crypto_context_t::has_password, HMAC_SHA256_SIZE, crypto_context_t::hmac_size, public_key_t::key, crypto_context_t::key_exchange_complete, KEY_TYPE_GPG, log_debug, log_info, packet_send_via_transport(), PACKET_TYPE_CRYPTO_AUTH_FAILED, PACKET_TYPE_CRYPTO_AUTH_RESPONSE, PACKET_TYPE_CRYPTO_SERVER_AUTH_RESP, auth_failure_packet_t::reason_flags, crypto_handshake_context_t::require_client_auth, SET_ERRNO, crypto_context_t::signature_size, crypto_handshake_context_t::state, and public_key_t::type.

Referenced by acip_security_receive(), and network_negotiation_receive().

◆ crypto_handshake_server_send_parameters()

asciichat_error_t crypto_handshake_server_send_parameters ( crypto_handshake_context_t * ctx,
acip_transport_t * transport )

Server: Send CRYPTO_PARAMETERS and set handshake context sizes.

Parameters
ctxHandshake context
transportACIP transport to send on
Returns
ASCIICHAT_OK on success, error code on failure

Must be called before crypto_handshake_server_start(). Builds crypto parameters based on server state (identity key presence), sends them to the client, and updates context sizes to match.

TCP server path calls this indirectly via its own negotiation in src/server/crypto.c (which customizes parameters based on client capabilities). WebSocket and discovery-service paths call this directly.

<X25519 key exchange (Curve25519)

<Ed25519 authentication (Edwards-curve signatures)

<No authentication (plaintext mode)

<XSalsa20-Poly1305 authenticated encryption

<No encryption (plaintext mode)

Definition at line 29 of file lib/crypto/handshake/server.c.

30 {
31 if (!ctx || !transport) {
33 "Invalid parameters: ctx=%p, transport=%p", (void *)ctx,
34 (void *)transport);
35 }
36
37 bool has_identity_key = (ctx->server_private_key.type == KEY_TYPE_ED25519);
38
40 memset(&params, 0, sizeof(params));
41
43 params.selected_auth = has_identity_key ? AUTH_ALGO_ED25519 : AUTH_ALGO_NONE;
47 params.verification_enabled = ctx->require_client_auth ? 1 : 0;
52 params.hmac_size = 32; // SHA256 output size
53
54 if (has_identity_key) {
57 }
58
59 // Set context sizes to match what we send (host byte order)
61
62 // Convert to network byte order for the wire
63 params.kex_public_key_size = htons(params.kex_public_key_size);
64 params.auth_public_key_size = htons(params.auth_public_key_size);
65 params.signature_size = htons(params.signature_size);
66 params.shared_secret_size = htons(params.shared_secret_size);
67
68 int result =
70 (uint8_t *)&params, sizeof(params), 0);
71 if (result != ASCIICHAT_OK) {
72 return SET_ERRNO(ERROR_NETWORK, "Failed to send CRYPTO_PARAMETERS packet");
73 }
74
76 "[HANDSHAKE] CRYPTO_PARAMETERS sent: auth=%s, cipher=XSALSA20_POLY1305",
77 has_identity_key ? "ED25519" : "NONE");
78 return ASCIICHAT_OK;
79}
asciichat_error_t crypto_handshake_set_parameters(crypto_handshake_context_t *ctx, const crypto_parameters_packet_t *params)
Set crypto parameters from crypto_parameters_packet_t.
key_type_t type
Definition key_types.h:114
#define AUTH_ALGO_ED25519
Ed25519 authentication (Edwards-curve signatures).
Definition packet.h:1144
#define KEX_ALGO_X25519
X25519 key exchange (Curve25519).
Definition packet.h:1143
#define AUTH_ALGO_NONE
No authentication (plaintext mode).
Definition packet.h:1145
#define CIPHER_ALGO_NONE
No encryption (plaintext mode).
Definition packet.h:1147
#define CIPHER_ALGO_XSALSA20_POLY1305
XSalsa20-Poly1305 authenticated encryption.
Definition packet.h:1146
@ PACKET_TYPE_CRYPTO_PARAMETERS
Server -> Client: Chosen algorithms + data sizes (UNENCRYPTED).
Definition packet.h:338
#define CRYPTO_SHARED_KEY_SIZE
Shared key size (X25519).
Definition sizes.h:76
#define XSALSA20_NONCE_SIZE
XSalsa20 nonce size in bytes.
Definition sizes.h:44
#define POLY1305_MAC_SIZE
Poly1305 MAC size in bytes.
Definition sizes.h:46
Crypto parameters packet structure (Packet Type 15).
Definition packet.h:1060
uint8_t hmac_size
HMAC size in bytes (e.g., 32 for HMAC-SHA256).
Definition packet.h:1082
uint8_t selected_kex
Selected key exchange algorithm (KEX_ALGO_*).
Definition packet.h:1062
uint8_t selected_cipher
Selected cipher algorithm (CIPHER_ALGO_*).
Definition packet.h:1066
uint16_t auth_public_key_size
Authentication public key size in bytes (e.g., 32 for Ed25519, 1952 for Dilithium3).
Definition packet.h:1072
uint8_t selected_auth
Selected authentication algorithm (AUTH_ALGO_*).
Definition packet.h:1064
uint8_t verification_enabled
Server verification enabled flag (1=enabled, 0=disabled).
Definition packet.h:1068
uint16_t signature_size
Signature size in bytes (e.g., 64 for Ed25519, 3309 for Dilithium3).
Definition packet.h:1074
uint8_t nonce_size
Nonce size in bytes (e.g., 24 for XSalsa20).
Definition packet.h:1078
uint8_t mac_size
MAC size in bytes (e.g., 16 for Poly1305).
Definition packet.h:1080
uint16_t shared_secret_size
Shared secret size in bytes (e.g., 32 for X25519).
Definition packet.h:1076
uint16_t kex_public_key_size
Key exchange public key size in bytes (e.g., 32 for X25519, 1568 for Kyber1024).
Definition packet.h:1070

References ASCIICHAT_OK, AUTH_ALGO_ED25519, AUTH_ALGO_NONE, crypto_parameters_packet_t::auth_public_key_size, CIPHER_ALGO_NONE, CIPHER_ALGO_XSALSA20_POLY1305, crypto_handshake_context_t::crypto_ctx, crypto_handshake_set_parameters(), CRYPTO_SHARED_KEY_SIZE, ED25519_PUBLIC_KEY_SIZE, ED25519_SIGNATURE_SIZE, crypto_context_t::encrypt_data, ERROR_INVALID_PARAM, ERROR_NETWORK, crypto_parameters_packet_t::hmac_size, KEX_ALGO_X25519, crypto_parameters_packet_t::kex_public_key_size, KEY_TYPE_ED25519, log_debug, crypto_parameters_packet_t::mac_size, crypto_parameters_packet_t::nonce_size, packet_send_via_transport(), PACKET_TYPE_CRYPTO_PARAMETERS, POLY1305_MAC_SIZE, crypto_context_t::public_key_size, crypto_handshake_context_t::require_client_auth, crypto_parameters_packet_t::selected_auth, crypto_parameters_packet_t::selected_cipher, crypto_parameters_packet_t::selected_kex, crypto_handshake_context_t::server_private_key, SET_ERRNO, crypto_parameters_packet_t::shared_secret_size, crypto_parameters_packet_t::signature_size, private_key_t::type, crypto_parameters_packet_t::verification_enabled, and XSALSA20_NONCE_SIZE.

Referenced by acip_security_receive(), and network_negotiation_receive().

◆ crypto_handshake_server_start()

asciichat_error_t crypto_handshake_server_start ( crypto_handshake_context_t * ctx,
acip_transport_t * transport )

Server: Start crypto handshake by sending public key.

Parameters
ctxHandshake context (must be in CRYPTO_HANDSHAKE_INIT state)
transportACIP transport to send on
Returns
ASCIICHAT_OK on success, error code on failure

Server initiates handshake by sending KEY_EXCHANGE_INIT packet. Supports both simple and authenticated formats based on server identity key.

Note
Packet formats:
  • Simple: [ephemeral_key:public_key_size] (when server has no identity key)
  • Authenticated: [ephemeral_key:public_key_size][identity_key:auth_public_key_size][signature:signature_size] (when server has Ed25519 identity key)
State transition: CRYPTO_HANDSHAKE_INIT -> CRYPTO_HANDSHAKE_KEY_EXCHANGE

Definition at line 82 of file lib/crypto/handshake/server.c.

83 {
84 ASCII_OTEL_SCOPE(CRYPTO_HANDSHAKE_SERVER_START);
85 log_debug("[HANDSHAKE_START] ctx=%p, transport=%p", (void *)ctx,
86 (void *)transport);
87
88 if (!ctx || ctx->state != CRYPTO_HANDSHAKE_INIT) {
89 log_error("[HANDSHAKE_START] FAILED: Invalid state - ctx=%p, state=%d",
90 (void *)ctx, ctx ? (int)ctx->state : -1);
91 return SET_ERRNO(ERROR_INVALID_STATE, "Invalid state: ctx=%p, state=%d",
92 (void *)ctx, ctx ? (int)ctx->state : -1);
93 }
95 "[HANDSHAKE_START] State check OK: state=%d (CRYPTO_HANDSHAKE_INIT)",
96 ctx->state);
97
98 int result;
99
100 // Caller is responsible for sending CRYPTO_PARAMETERS and calling
101 // crypto_handshake_set_parameters() before this function. This function
102 // only handles KEY_EXCHANGE_INIT.
103
104 // Calculate packet size based on negotiated crypto parameters
105 size_t expected_packet_size = ctx->crypto_ctx.public_key_size +
106 ctx->crypto_ctx.auth_public_key_size +
107 ctx->crypto_ctx.signature_size;
108
109 log_debug("SERVER_KEY_EXCHANGE: kex_size=%u, auth_size=%u, sig_size=%u, "
110 "expected_size=%zu",
111 ctx->crypto_ctx.public_key_size,
112 ctx->crypto_ctx.auth_public_key_size,
113 ctx->crypto_ctx.signature_size, expected_packet_size);
114
115 // Check if we have an identity key to send authenticated packet
116 if (ctx->server_private_key.type == KEY_TYPE_ED25519) {
117 // Extended packet format:
118 // [ephemeral_key:kex_size][identity_key:auth_size][signature:sig_size]
119 uint8_t *extended_packet;
120 extended_packet = SAFE_MALLOC(expected_packet_size, uint8_t *);
121 if (!extended_packet) {
122 return SET_ERRNO(ERROR_MEMORY,
123 "Failed to allocate memory for extended packet");
124 }
125
126 // Copy ephemeral public key
127 memcpy(extended_packet, ctx->crypto_ctx.public_key,
128 ctx->crypto_ctx.public_key_size);
129
130 // Copy identity public key
131 memcpy(extended_packet + ctx->crypto_ctx.public_key_size,
132 ctx->server_public_key.key, ctx->crypto_ctx.auth_public_key_size);
133
134 // DEBUG: Print identity key being sent
135 char hex[HEX_STRING_SIZE_32];
136 for (int i = 0; i < ED25519_PUBLIC_KEY_SIZE; i++) {
137 safe_snprintf(hex + i * 2, 3, "%02x", ctx->server_public_key.key[i]);
138 }
139 hex[HEX_STRING_SIZE_32 - 1] = '\0';
140
141 // Sign the ephemeral key with our identity key
142 log_debug("Signing ephemeral key with server identity key");
143
144 // Log key details in debug mode
145 char hex_ephemeral[HEX_STRING_SIZE_32],
147 for (int i = 0; i < 32; i++) {
148 safe_snprintf(hex_ephemeral + i * 2, 3, "%02x",
149 ctx->crypto_ctx.public_key[i]);
150 safe_snprintf(hex_identity + i * 2, 3, "%02x",
151 ctx->server_public_key.key[i]);
152 }
153 hex_ephemeral[64] = hex_identity[64] = '\0';
154 log_debug("SERVER: Ephemeral key (32 bytes): %s", hex_ephemeral);
155 log_debug("SERVER: Identity public key: %s", hex_identity);
156
157 if (ed25519_sign_message(&ctx->server_private_key,
158 ctx->crypto_ctx.public_key,
159 ctx->crypto_ctx.public_key_size,
160 extended_packet + ctx->crypto_ctx.public_key_size +
161 ctx->crypto_ctx.auth_public_key_size) != 0) {
162 SAFE_FREE(extended_packet);
163 return SET_ERRNO(ERROR_CRYPTO,
164 "Failed to sign ephemeral key with identity key");
165 }
166
167 log_debug("Sending authenticated KEY_EXCHANGE_INIT (%zu bytes: ephemeral + "
168 "identity + signature)",
169 expected_packet_size);
170 log_debug("[HANDSHAKE_START] Calling packet_send_via_transport(type=%d, "
171 "payload_len=%zu, 0)...",
172 PACKET_TYPE_CRYPTO_KEY_EXCHANGE_INIT, expected_packet_size);
174 transport, PACKET_TYPE_CRYPTO_KEY_EXCHANGE_INIT, extended_packet,
175 expected_packet_size, 0);
176 log_debug("[HANDSHAKE_START] packet_send_via_transport returned %d",
177 result);
178 SAFE_FREE(extended_packet);
179 } else {
180 // No identity key - send just the ephemeral key
181 log_debug(
182 "Sending simple KEY_EXCHANGE_INIT (%zu bytes: ephemeral key only)",
183 ctx->crypto_ctx.public_key_size);
184 log_debug("[HANDSHAKE_START] Calling packet_send_via_transport(type=%d, "
185 "payload_len=%zu, 0)...",
187 ctx->crypto_ctx.public_key_size);
190 ctx->crypto_ctx.public_key, ctx->crypto_ctx.public_key_size, 0);
191 log_debug("[HANDSHAKE_START] packet_send_via_transport returned %d",
192 result);
193 }
194
195 if (result != ASCIICHAT_OK) {
196 log_error("[HANDSHAKE_START] FAILED: packet_send returned %d", result);
197 return SET_ERRNO(ERROR_NETWORK, "Failed to send KEY_EXCHANGE_INIT packet");
198 }
199 log_debug("[HANDSHAKE_START] ===== SUCCESS: KEY_EXCHANGE_INIT sent =====");
200
202
203 return ASCIICHAT_OK;
204}
#define SAFE_FREE(ptr)
#define SAFE_MALLOC(size, cast)
#define log_error(...)
Log an ERROR message.
Definition log/log.h:604
@ PACKET_TYPE_CRYPTO_KEY_EXCHANGE_INIT
Server -> Client: {server_pubkey[32]} (UNENCRYPTED).
Definition packet.h:340
#define CRYPTO_HANDSHAKE_SERVER_HEX_IDENTITY_BUFFER_SIZE
asciichat_error_t ed25519_sign_message(const private_key_t *key, const uint8_t *message, size_t message_len, uint8_t signature[ED25519_SIGNATURE_SIZE])
Definition ssh_keys.c:1331

References ASCII_OTEL_SCOPE, ASCIICHAT_OK, crypto_context_t::auth_public_key_size, crypto_handshake_context_t::crypto_ctx, CRYPTO_HANDSHAKE_INIT, CRYPTO_HANDSHAKE_KEY_EXCHANGE, CRYPTO_HANDSHAKE_SERVER_HEX_IDENTITY_BUFFER_SIZE, ED25519_PUBLIC_KEY_SIZE, ed25519_sign_message(), ERROR_CRYPTO, ERROR_INVALID_STATE, ERROR_MEMORY, ERROR_NETWORK, HEX_STRING_SIZE_32, public_key_t::key, KEY_TYPE_ED25519, log_debug, log_error, packet_send_via_transport(), PACKET_TYPE_CRYPTO_KEY_EXCHANGE_INIT, crypto_context_t::public_key, crypto_context_t::public_key_size, SAFE_FREE, SAFE_MALLOC, crypto_handshake_context_t::server_private_key, crypto_handshake_context_t::server_public_key, SET_ERRNO, crypto_context_t::signature_size, crypto_handshake_context_t::state, and private_key_t::type.

Referenced by acip_security_receive(), and network_negotiation_receive().