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

Client-side handshake functions. More...

Go to the source code of this file.

Functions

Client Handshake Protocol
asciichat_error_t crypto_handshake_client_key_exchange (crypto_handshake_context_t *ctx, acip_transport_t *transport, packet_type_t packet_type, const uint8_t *payload, size_t payload_len)
 Client: Process server's public key and send our public key.
asciichat_error_t crypto_handshake_client_auth_response (crypto_handshake_context_t *ctx, acip_transport_t *transport, packet_type_t packet_type, const uint8_t *payload, size_t payload_len)
 Client: Process auth challenge and send response.
asciichat_error_t crypto_handshake_client_complete (crypto_handshake_context_t *ctx, acip_transport_t *transport, packet_type_t packet_type, const uint8_t *payload, size_t payload_len)
 Client: Wait for handshake complete confirmation.

Detailed Description

Client-side handshake functions.

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

Function Documentation

◆ crypto_handshake_client_auth_response()

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

Client: Process auth challenge and send response.

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_AUTH_CHALLENGE or PACKET_TYPE_CRYPTO_HANDSHAKE_COMPLETE)
payloadReceived packet payload
payload_lenLength of received payload
Returns
ASCIICHAT_OK on success, error code on failure

Client processes server's AUTH_CHALLENGE packet and sends AUTH_RESPONSE. Generates HMAC bound to shared secret using password or client key.

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

Definition at line 720 of file lib/crypto/handshake/client.c.

722 {
723 ASCII_OTEL_SCOPE(CRYPTO_HANDSHAKE_CLIENT_AUTH_RESPONSE);
724 if (!ctx || ctx->state != CRYPTO_HANDSHAKE_KEY_EXCHANGE) {
725 return SET_ERRNO(ERROR_INVALID_STATE, "Invalid state: ctx=%p, state=%d",
726 ctx, ctx ? (int)ctx->state : -1);
727 }
728 if (!transport) {
729 return SET_ERRNO(ERROR_INVALID_PARAM, "transport is NULL");
730 }
731
732 // Note: Packet already received by ACIP handler
733 int result;
734
735 // If server sent HANDSHAKE_COMPLETE, authentication was skipped (client has
736 // no key)
737 if (packet_type == PACKET_TYPE_CRYPTO_HANDSHAKE_COMPLETE) {
740 true; // Mark crypto context as ready for rekeying
741 log_debug(
742 "Crypto handshake completed successfully (no authentication required)");
743 return ASCIICHAT_OK;
744 }
745
746 // If server sent AUTH_FAILED, client is not authorized
747 if (packet_type == PACKET_TYPE_CRYPTO_AUTH_FAILED) {
748 return SET_ERRNO(
750 "Server rejected authentication - client key not authorized");
751 }
752
753 // Otherwise, verify packet type is AUTH_CHALLENGE
754 if (packet_type != PACKET_TYPE_CRYPTO_AUTH_CHALLENGE) {
755 return SET_ERRNO(
757 "Expected AUTH_CHALLENGE, HANDSHAKE_COMPLETE, or AUTH_FAILED, "
758 "got packet type %d",
759 packet_type);
760 }
761
762 // Validate packet size using session parameters
764 ctx, PACKET_TYPE_CRYPTO_AUTH_CHALLENGE, payload_len);
765 if (validation_result != ASCIICHAT_OK) {
766 return validation_result;
767 }
768
769 // Parse auth requirement flags
770 uint8_t auth_flags = payload[0];
771
772 // Copy nonce to local buffer before freeing payload
773 // Use auth_challenge_size since that's what the server sent
774 // Note: auth_challenge_size is uint8_t (max 255), buffer is 256 bytes, so
775 // always sufficient
777 memcpy(nonce_buffer, payload + 1, ctx->crypto_ctx.auth_challenge_size);
778 const uint8_t *nonce = nonce_buffer;
779
780 log_debug("Server auth requirements: password=%s, client_key=%s",
781 (auth_flags & AUTH_REQUIRE_PASSWORD) ? "required" : "no",
782 (auth_flags & AUTH_REQUIRE_CLIENT_KEY) ? "required" : "no");
783
784 // Check if we can satisfy the server's authentication requirements
785 bool has_password = ctx->crypto_ctx.has_password;
786 bool has_client_key = (ctx->client_private_key.type == KEY_TYPE_ED25519);
787 bool password_required = (auth_flags & AUTH_REQUIRE_PASSWORD);
788 bool client_key_required = (auth_flags & AUTH_REQUIRE_CLIENT_KEY);
789
790 // Provide specific error messages based on what's missing
791 if (password_required && !has_password) {
792 if (client_key_required && !has_client_key) {
793 return SET_ERRNO(
795 "Server requires both password and client key authentication. Please "
796 "provide --password and --key to authenticate");
797 }
798 // Prompt for password interactively
799 if (ctx->defer_password_prompt) {
801 return deferred_password_error("Server requires a password");
802 }
803 char prompted_password[PASSWORD_BUFFER_SIZE];
804 if (prompt_password("Server password required - please enter password:",
805 prompted_password, sizeof(prompted_password)) != 0) {
806 return SET_ERRNO(ERROR_CRYPTO, "Failed to read password");
807 }
808
809 // Derive password key from prompted password
810 log_debug("Deriving key from prompted password");
811 crypto_result_t crypto_result =
812 crypto_derive_password_key(&ctx->crypto_ctx, prompted_password);
813 sodium_memzero(prompted_password, sizeof(prompted_password));
814
815 if (crypto_result != CRYPTO_OK) {
816 return SET_ERRNO(ERROR_CRYPTO, "Failed to derive password key: %s",
817 crypto_result_to_string(crypto_result));
818 }
819
820 // Mark that password auth is now available
821 ctx->crypto_ctx.has_password = true;
822 has_password = true; // Update flag for logic below
823 }
824
825 // Authentication response priority:
826 // NOTE: Identity verification happens during KEY_EXCHANGE phase, not
827 // AUTH_RESPONSE!
828 // 1. If server requires password → MUST send HMAC (hmac_size bytes), error if
829 // no password
830 // 2. Else if server requires identity (whitelist) → MUST send Ed25519
831 // signature (signature_size bytes), error if no key
832 // 3. Else if client has password → send HMAC (optional password auth)
833 // 4. Else if client has SSH key → send Ed25519 signature (optional identity
834 // proof)
835 // 5. Else → no authentication available
836
837 // Clean up payload before any early returns
838 if (password_required) {
839 // Server requires password - HIGHEST PRIORITY
840 // (Identity was already verified in KEY_EXCHANGE phase if whitelist is
841 // enabled)
842 if (!has_password) {
843 return SET_ERRNO(ERROR_CRYPTO,
844 "Server requires password authentication\n"
845 "Please provide --password for this server");
846 }
847
848 result =
849 send_password_auth_response(ctx, transport, nonce, "required password");
850 if (result != ASCIICHAT_OK) {
851 SET_ERRNO(ERROR_NETWORK, "Failed to send password auth response");
852 return result;
853 }
854 } else if (client_key_required) {
855 // Server requires client key (whitelist) - SECOND PRIORITY
856 if (!has_client_key) {
857 return SET_ERRNO(ERROR_CRYPTO,
858 "Server requires client key authentication (whitelist)\n"
859 "Please provide --key with your authorized Ed25519 key");
860 }
861
862 result =
863 send_key_auth_response(ctx, transport, nonce, "required client key");
864 if (result != ASCIICHAT_OK) {
865 SET_ERRNO(ERROR_NETWORK, "Failed to send key auth response");
866 return result;
867 }
868 } else if (has_password) {
869 // No server requirements, but client has password → send HMAC + client
870 // nonce (optional)
871 result =
872 send_password_auth_response(ctx, transport, nonce, "optional password");
873 if (result != ASCIICHAT_OK) {
874 SET_ERRNO(ERROR_NETWORK, "Failed to send password auth response");
875 return result;
876 }
877 } else if (has_client_key) {
878 // No server requirements, but client has SSH key → send Ed25519 signature +
879 // client nonce (optional)
880 result = send_key_auth_response(ctx, transport, nonce, "optional identity");
881 if (result != ASCIICHAT_OK) {
882 SET_ERRNO(ERROR_NETWORK, "Failed to send key auth response");
883 return result;
884 }
885 } else {
886 // No authentication method available
887 // Continue without authentication (server will decide if this is
888 // acceptable)
889 log_debug("No authentication credentials provided - continuing without "
890 "authentication");
891 }
892
894
895 return ASCIICHAT_OK;
896}
#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.
unsigned char uint8_t
const char * crypto_result_to_string(crypto_result_t result)
Convert crypto result to human-readable string.
crypto_result_t
Cryptographic operation result codes.
crypto_result_t crypto_derive_password_key(crypto_context_t *ctx, const char *password)
Derive key from password using Argon2id.
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
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_CRYPTO
@ ERROR_INVALID_PARAM
key_type_t type
Definition key_types.h:114
@ KEY_TYPE_ED25519
Definition key_types.h:61
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:565
@ AUTH_FAIL_PASSWORD_REQUIRED
Server requires password but client didn't provide one.
Definition packet.h:814
@ PACKET_TYPE_CRYPTO_HANDSHAKE_COMPLETE
Server -> Client: "encryption ready" (UNENCRYPTED).
Definition packet.h:352
@ PACKET_TYPE_CRYPTO_AUTH_FAILED
Server -> Client: "authentication failed" (UNENCRYPTED).
Definition packet.h:348
@ PACKET_TYPE_CRYPTO_AUTH_CHALLENGE
Server -> Client: {nonce[32]} (UNENCRYPTED).
Definition packet.h:344
int prompt_password(const char *prompt, char *password, size_t max_len)
Prompt the user for a password with secure input.
Definition password.c:15
#define AUTH_REQUIRE_PASSWORD
Server requires password authentication.
#define AUTH_REQUIRE_CLIENT_KEY
Server requires client key authentication (whitelist).
#define HANDSHAKE_NONCE_PACKET_CAPACITY
#define ASCII_OTEL_SCOPE(id)
Definition otel.h:102
#define PASSWORD_BUFFER_SIZE
Password input buffer size (256 bytes).
Definition sizes.h:168

References ASCII_OTEL_SCOPE, ASCIICHAT_OK, crypto_context_t::auth_challenge_size, AUTH_FAIL_PASSWORD_REQUIRED, AUTH_REQUIRE_CLIENT_KEY, AUTH_REQUIRE_PASSWORD, crypto_handshake_context_t::client_private_key, crypto_handshake_context_t::crypto_ctx, crypto_derive_password_key(), CRYPTO_HANDSHAKE_AUTHENTICATING, CRYPTO_HANDSHAKE_KEY_EXCHANGE, CRYPTO_HANDSHAKE_READY, crypto_handshake_validate_packet_size(), CRYPTO_OK, crypto_result_to_string(), crypto_handshake_context_t::defer_password_prompt, ERROR_CRYPTO, ERROR_INVALID_PARAM, ERROR_INVALID_STATE, ERROR_NETWORK, ERROR_NETWORK_PROTOCOL, crypto_context_t::handshake_complete, HANDSHAKE_NONCE_PACKET_CAPACITY, crypto_context_t::has_password, KEY_TYPE_ED25519, log_debug, PACKET_TYPE_CRYPTO_AUTH_CHALLENGE, PACKET_TYPE_CRYPTO_AUTH_FAILED, PACKET_TYPE_CRYPTO_HANDSHAKE_COMPLETE, PASSWORD_BUFFER_SIZE, crypto_handshake_context_t::password_failure, prompt_password(), SET_ERRNO, crypto_handshake_context_t::state, and private_key_t::type.

Referenced by acds_handshake_receive(), acip_security_receive(), and client_handle_auth_challenge().

◆ crypto_handshake_client_complete()

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

Client: Wait for handshake complete confirmation.

Parameters
ctxHandshake context (must be in CRYPTO_HANDSHAKE_AUTHENTICATING state)
transportACIP transport (unused, for consistency)
packet_typePacket type received (should be PACKET_TYPE_CRYPTO_SERVER_AUTH_RESP or PACKET_TYPE_CRYPTO_AUTH_FAILED)
payloadReceived packet payload
payload_lenLength of received payload
Returns
ASCIICHAT_OK on success, error code on failure

Client processes server's SERVER_AUTH_RESP or AUTH_FAILED packet. After receiving, handshake is complete and encryption is ready.

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

Definition at line 898 of file lib/crypto/handshake/client.c.

900 {
901 ASCII_OTEL_SCOPE(CRYPTO_HANDSHAKE_CLIENT_COMPLETE);
902 // Accept both KEY_EXCHANGE and AUTHENTICATING states for simple mode
903 // compatibility In simple mode, server skips AUTH_CHALLENGE and sends
904 // HANDSHAKE_COMPLETE directly
905 if (!ctx || (ctx->state != CRYPTO_HANDSHAKE_KEY_EXCHANGE &&
907 SET_ERRNO(ERROR_INVALID_STATE, "Invalid state: ctx=%p, state=%d", ctx,
908 ctx ? (int)ctx->state : -1);
909 return ERROR_INVALID_STATE;
910 }
911 if (!transport) {
912 return SET_ERRNO(ERROR_INVALID_PARAM, "transport is NULL");
913 }
914
915 // Note: Packet already received by ACIP handler
916 (void)
917 transport; // Unused parameter (this function only receives, doesn't send)
918
919 // Check packet type
920 if (packet_type == PACKET_TYPE_CRYPTO_AUTH_FAILED) {
921 // Parse the auth failure packet to get specific reasons
922 if (payload_len >= sizeof(auth_failure_packet_t)) {
923 auth_failure_packet_t *failure = (auth_failure_packet_t *)payload;
924 const uint8_t password_flags =
926 if (ctx->defer_password_prompt && failure->reason_flags &&
927 !(failure->reason_flags & ~password_flags)) {
928 ctx->password_failure = failure->reason_flags;
929 return deferred_password_error("Server rejected password");
930 }
931 NOTICE(DANGER, "AUTHENTICATION REJECTED",
932 "%s%s%s%s%sConnection rejected.",
934 ? "Incorrect password.\n"
935 : "",
937 ? "Password required: use --password.\n"
938 : "",
940 ? "Client identity required: use --key.\n"
941 : "",
943 ? "Client key is not authorized by the server.\n"
944 : "",
946 ? "Client signature verification failed.\n"
947 : "");
948 SET_ERRNO(ERROR_CRYPTO_AUTH, "Server rejected authentication:");
949
951 SET_ERRNO(ERROR_CRYPTO_AUTH, " - Incorrect password");
952 }
955 " - Server requires a password (use --password)");
956 }
959 " - Server requires a whitelisted client key (use --key "
960 "with your SSH key)");
961 }
964 " - Your client key is not in the server's whitelist");
965 }
968 " - Client signature verification failed");
969 }
970
971 // Provide helpful guidance
972 if (failure->reason_flags &
977 "Hint: Server requires BOTH correct password AND "
978 "whitelisted key");
979 } else if (failure->reason_flags & AUTH_FAIL_PASSWORD_INCORRECT) {
981 "Hint: Check your password and try again");
982 } else if (failure->reason_flags & AUTH_FAIL_CLIENT_KEY_REQUIRED) {
984 "Hint: Provide your SSH key with --key ~/.ssh/id_ed25519");
985 } else if (failure->reason_flags & AUTH_FAIL_CLIENT_KEY_REJECTED) {
986 SET_ERRNO(
988 "Hint: Your key needs to be added to the server's whitelist");
989 }
990 }
991 } else {
992 NOTICE(DANGER, "AUTHENTICATION REJECTED",
993 "Server rejected authentication (no details "
994 "provided).\nConnection rejected.");
996 "Server rejected authentication (no details provided)");
997 }
998 return SET_ERRNO(
1000 "Server authentication failed - incorrect HMAC"); // Special code for
1001 // auth failure - do
1002 // not retry
1003 }
1004
1005 // Handle no-auth flow: server sends HANDSHAKE_COMPLETE directly
1006 if (packet_type == PACKET_TYPE_CRYPTO_HANDSHAKE_COMPLETE) {
1008 ctx->crypto_ctx.handshake_complete = true;
1009 log_info("Handshake complete (no authentication required)");
1010 return ASCIICHAT_OK;
1011 }
1012
1013 // Handle with-auth flow: server sends SERVER_AUTH_RESP after authentication
1014 if (packet_type != PACKET_TYPE_CRYPTO_SERVER_AUTH_RESP) {
1016 "Expected HANDSHAKE_COMPLETE, SERVER_AUTH_RESPONSE, or "
1017 "AUTH_FAILED, got packet type %d",
1018 packet_type);
1019 }
1020
1021 // Verify server's HMAC for mutual authentication
1022 // Use ctx->crypto_ctx.hmac_size (negotiated during handshake) rather than
1023 // SERVER_AUTH_RESPONSE_SIZE constant
1024 if (payload_len != ctx->crypto_ctx.hmac_size) {
1025 return SET_ERRNO(
1027 "Invalid SERVER_AUTH_RESPONSE size: %zu bytes (expected %u)",
1028 payload_len, ctx->crypto_ctx.hmac_size);
1029 }
1030
1031 // Verify server's HMAC (binds to DH shared_secret to prevent MITM)
1033 ctx->client_challenge_nonce, payload)) {
1034 NOTICE(DANGER, "SERVER AUTHENTICATION FAILED",
1035 "The server returned an incorrect HMAC. This may indicate a "
1036 "man-in-the-middle attack.\nConnection rejected.");
1037 return SET_ERRNO(
1039 "Server authentication failed - incorrect HMAC"); // Authentication
1040 // failure - do not
1041 // retry
1042 }
1044 ctx->crypto_ctx.handshake_complete = true;
1045 log_info("Server authentication successful - mutual authentication complete");
1046
1047 return ASCIICHAT_OK;
1048}
@ ERROR_CRYPTO_AUTH
#define log_info(...)
Log an INFO message.
Definition log/log.h:578
@ 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
@ AUTH_FAIL_SIGNATURE_INVALID
Client signature verification failed (invalid signature).
Definition packet.h:822
@ 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])
#define NOTICE(severity, title,...)
Definition notice.h:86
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

References ASCII_OTEL_SCOPE, ASCIICHAT_OK, AUTH_FAIL_CLIENT_KEY_REJECTED, AUTH_FAIL_CLIENT_KEY_REQUIRED, AUTH_FAIL_PASSWORD_INCORRECT, AUTH_FAIL_PASSWORD_REQUIRED, AUTH_FAIL_SIGNATURE_INVALID, crypto_handshake_context_t::client_challenge_nonce, crypto_handshake_context_t::crypto_ctx, CRYPTO_HANDSHAKE_AUTHENTICATING, CRYPTO_HANDSHAKE_KEY_EXCHANGE, CRYPTO_HANDSHAKE_READY, crypto_verify_auth_response(), crypto_handshake_context_t::defer_password_prompt, ERROR_CRYPTO_AUTH, ERROR_INVALID_PARAM, ERROR_INVALID_STATE, ERROR_NETWORK_PROTOCOL, crypto_context_t::handshake_complete, crypto_context_t::hmac_size, log_info, NOTICE, PACKET_TYPE_CRYPTO_AUTH_FAILED, PACKET_TYPE_CRYPTO_HANDSHAKE_COMPLETE, PACKET_TYPE_CRYPTO_SERVER_AUTH_RESP, crypto_handshake_context_t::password_failure, auth_failure_packet_t::reason_flags, SET_ERRNO, and crypto_handshake_context_t::state.

Referenced by acds_handshake_receive(), acip_security_receive(), and client_handle_handshake_complete().

◆ crypto_handshake_client_key_exchange()

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

Client: Process server's public key and send our public key.

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

Client processes server's KEY_EXCHANGE_INIT packet and responds with KEY_EXCHANGE_RESP. Supports both simple and authenticated formats. Verifies server signature if present.

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

Definition at line 47 of file lib/crypto/handshake/client.c.

49 {
50 ASCII_OTEL_SCOPE(CRYPTO_HANDSHAKE_CLIENT_KEY_EXCHANGE);
51 if (!ctx || ctx->state != CRYPTO_HANDSHAKE_INIT) {
52 return SET_ERRNO(ERROR_INVALID_STATE, "Invalid state: ctx=%p, state=%d",
53 (void *)ctx, ctx ? (int)ctx->state : -1);
54 }
55 if (!transport) {
56 return SET_ERRNO(ERROR_INVALID_PARAM, "transport is NULL");
57 }
58
59 // Note: Packet already received by ACIP handler
60 int result;
61
62 // Verify packet type
63 if (packet_type != PACKET_TYPE_CRYPTO_KEY_EXCHANGE_INIT) {
65 "Expected KEY_EXCHANGE_INIT, got packet type %d",
66 packet_type);
67 }
68
69 log_debug("CLIENT_KEY_EXCHANGE: Received packet with payload_len=%zu, "
70 "kex_size=%u, auth_size=%u, sig_size=%u",
71 payload_len, ctx->crypto_ctx.public_key_size,
74
75 // Check payload size - only authenticated format supported
76 // Authenticated: public_key_size + auth_public_key_size + signature_size
77 // bytes
78 size_t expected_auth_size = ctx->crypto_ctx.public_key_size +
81
82 // Use the crypto context's public key size to ensure compatibility.
83 size_t key_size = sizeof(ctx->crypto_ctx.public_key);
84 SAFE_MALLOC_DEFER_FREE(server_ephemeral_key, key_size, uint8_t *);
85 if (!server_ephemeral_key) {
87 "Failed to allocate memory for server ephemeral key");
88 }
89 SAFE_MALLOC_DEFER_FREE(server_identity_key,
92 uint8_t *);
93
94 if (!server_identity_key || !server_signature) {
95 return SET_ERRNO(
97 "Failed to allocate memory for server identity key or signature");
98 }
99
100 // Validate packet size using session parameters
102 ctx, PACKET_TYPE_CRYPTO_KEY_EXCHANGE_INIT, payload_len);
103 if (validation_result != ASCIICHAT_OK) {
104 return validation_result;
105 }
106
107 // Check if server is using authenticated format (includes signature)
108 // Must have signature_size > 0 to distinguish from simple ephemeral-only
109 // format This covers both cases:
110 // 1. With identity key: ephemeral + identity + signature
111 // 2. Without identity key but with signature: ephemeral + 0 + signature
112 if (ctx->crypto_ctx.signature_size > 0 && payload_len == expected_auth_size) {
113 // Authenticated format:
114 // [ephemeral:public_key_size][identity:auth_public_key_size][signature:signature_size]
115 log_debug("Received authenticated KEY_EXCHANGE_INIT (%zu bytes)",
116 expected_auth_size);
117 memcpy(server_ephemeral_key, payload, ctx->crypto_ctx.public_key_size);
118 memcpy(server_identity_key, payload + ctx->crypto_ctx.public_key_size,
120 memcpy(server_signature,
121 payload + ctx->crypto_ctx.public_key_size +
124
125 // Server is using client authentication
126 ctx->server_uses_client_auth = true;
127
128 // DEBUG: Print identity key received
129 char hex_id[HEX_STRING_SIZE_32];
130 for (int i = 0; i < ED25519_PUBLIC_KEY_SIZE; i++) {
131 safe_snprintf(hex_id + i * 2, 3, "%02x", server_identity_key[i]);
132 }
133 hex_id[HEX_STRING_SIZE_32 - 1] = '\0';
134 log_debug("Received identity key: %s", hex_id);
135
136 // DEBUG: Print ephemeral key and signature
137 char hex_eph[HEX_STRING_SIZE_32];
138 for (int i = 0; i < ED25519_PUBLIC_KEY_SIZE; i++) {
139 safe_snprintf(hex_eph + i * 2, 3, "%02x", server_ephemeral_key[i]);
140 }
141 hex_eph[HEX_STRING_SIZE_32 - 1] = '\0';
142 log_debug("Received ephemeral key: %s", hex_eph);
143
144 char hex_sig[HEX_STRING_SIZE_64];
145 for (int i = 0; i < ED25519_SIGNATURE_SIZE; i++) {
146 safe_snprintf(hex_sig + i * 2, 3, "%02x", server_signature[i]);
147 }
148 hex_sig[HEX_STRING_SIZE_64 - 1] = '\0';
149 log_debug("Received signature: %s", hex_sig);
150
151 // Verify signature: server identity signed the ephemeral key
152 log_debug("Verifying server's signature over ephemeral key (already logged "
153 "above)");
154
155 // If client didn't specify --server-key, skip signature verification
156 // (client doesn't care about server identity verification)
157 if (!ctx->verify_server_key) {
158 log_info(
159 "Skipping server signature verification (no --server-key specified)");
160 NOTICE(DANGER, "UNVERIFIED SERVER IDENTITY",
161 "Connection is encrypted but server identity is NOT verified "
162 "(vulnerable to MITM)");
163 } else {
164 // Extract GPG key ID from expected_server_key if it's a GPG key
165 // (gpg:KEYID format)
166 const char *gpg_key_id = NULL;
167 if (ctx->expected_server_key[0] != '\0' &&
168 strncmp(ctx->expected_server_key, "gpg:", 4) == 0) {
169 const char *key_id_start = ctx->expected_server_key + 4;
170 size_t key_id_len = strlen(key_id_start);
171 // Accept 8, 16, or 40 character GPG key IDs (short, long, or full
172 // fingerprint)
173 if (key_id_len == 8 || key_id_len == 16 || key_id_len == 40) {
174 gpg_key_id = key_id_start;
175 log_debug("Using GPG key ID from --server-key for verification: %s",
176 gpg_key_id);
177 }
178 }
179
180 if (ed25519_verify_signature(server_identity_key, server_ephemeral_key,
182 server_signature, gpg_key_id) != 0) {
183 NOTICE(DANGER, "SERVER SIGNATURE INVALID",
184 "The server identity signature could not be verified.\n"
185 "Possible man-in-the-middle attack. Connection rejected.");
186 return SET_ERRNO(
188 "Server signature verification FAILED - rejecting connection. "
189 "This indicates: Server's identity key does not "
190 "match its ephemeral key, Potential man-in-the-middle attack, "
191 "Corrupted or malicious server");
192 }
193 log_debug("Server signature verified successfully");
194 }
195
196 // Verify server identity against a browser-provided raw key before falling
197 // back to the native file, URL, and key-list parser.
199 if (sodium_memcmp(server_identity_key, ctx->expected_server_key_bytes,
201 NOTICE(DANGER, "SERVER IDENTITY KEY MISMATCH",
202 "The server key does not match the browser verification "
203 "key.\nConnection rejected.");
205 "Server identity key does not match the active "
206 "browser verification key");
207 }
208 log_info("Server identity key verified against active browser key");
209 } else if (ctx->verify_server_key && strlen(ctx->expected_server_key) > 0) {
210 // Parse ALL expected server keys (github:/gitlab: may have multiple keys)
211 public_key_t expected_keys[MAX_CLIENTS];
212 size_t num_expected_keys = 0;
213 if (parse_public_keys(ctx->expected_server_key, expected_keys,
214 &num_expected_keys, MAX_CLIENTS) != 0 ||
215 num_expected_keys == 0) {
216 return SET_ERRNO(ERROR_CONFIG,
217 "Failed to parse expected server key: %s. Check that "
218 "--server-key value is valid (ssh-ed25519 "
219 "format, github:username, or hex)",
221 }
222
223 // Compare server's IDENTITY key against ALL expected keys (match any one)
224 // This supports users with multiple SSH keys (e.g., different machines)
225 bool key_matched = false;
226 for (size_t i = 0; i < num_expected_keys; i++) {
227 if (sodium_memcmp(server_identity_key, expected_keys[i].key,
229 key_matched = true;
230 log_debug("Server identity key matched expected key %zu/%zu", i + 1,
231 num_expected_keys);
232 break;
233 }
234 }
235
236 if (!key_matched) {
237 NOTICE(DANGER, "SERVER IDENTITY KEY MISMATCH",
238 "The server key does not match --server-key: %s.\n"
239 "Possible man-in-the-middle attack. Do not connect until the "
240 "server identity is verified.",
242 return SET_ERRNO(
244 "Server identity key mismatch - potential MITM attack! "
245 "Expected key(s) from: %s (checked %zu keys), Server presented a "
246 "different key "
247 "than specified with --server-key, DO NOT CONNECT to this "
248 "server - likely man-in-the-middle attack!",
249 ctx->expected_server_key, num_expected_keys);
250 }
251 log_info("Server identity key verified against --server-key (%zu key(s) "
252 "checked)",
253 num_expected_keys);
254 }
255
256 // Note: Server IP resolution now handled by caller (TCP transport layer)
257 // For WebSocket/WebRTC transports, server_ip should be set by the transport
258 // before handshake begins. TCP clients will use the legacy wrapper which
259 // handles this.
260 if (ctx->server_ip[0] == '\0') {
261 log_debug("Server IP not set - skipping known_hosts verification "
262 "(non-TCP transport)");
263 } else {
264 log_debug("Server IP already set: %s", ctx->server_ip);
265 }
266
267 // Check known_hosts for this server (if we have server IP and port)
268 // Check if known_hosts verification should be skipped
269 bool skip_known_hosts = false;
270 const char *env_skip =
271 platform_getenv("ASCII_CHAT_INSECURE_NO_HOST_IDENTITY_CHECK");
272 if (env_skip && strcmp(env_skip, STR_ONE) == 0) {
273 log_warn("Skipping known_hosts checking for authenticated connection "
274 "(ASCII_CHAT_INSECURE_NO_HOST_IDENTITY_CHECK=1)");
275 skip_known_hosts = true;
276 }
277#ifndef NDEBUG
278 // In debug builds, also skip for Claude Code (LLM automation can't do
279 // interactive prompts)
280 else if (platform_getenv("CLAUDECODE")) {
281 log_warn("Skipping known_hosts checking (CLAUDECODE set in debug build)");
282 skip_known_hosts = true;
283 }
284#endif
285
286 if (!ctx->addressless_transport && !skip_known_hosts &&
287 ctx->server_ip[0] != '\0' && ctx->server_port > 0) {
289 bool has_stored_key = false;
291 ctx->server_ip, ctx->server_port, server_identity_key, stored_key,
292 &has_stored_key);
293 if (known_host_result == ERROR_CRYPTO_VERIFICATION) {
294 // Key mismatch - MITM attack detected! Prompt user for confirmation
295 log_error("SECURITY: Server key does NOT match known_hosts entry!\n"
296 "This indicates a possible man-in-the-middle attack!");
298 has_stored_key ? stored_key : NULL,
299 server_identity_key)) {
300 // User declined to continue - ABORT connection for security
301
303 "SECURITY: Connection aborted - server key mismatch "
304 "(possible MITM attack)");
305 }
306 // User accepted the risk - continue with connection
307 NOTICE(DANGER, "HOST KEY CHANGE ACCEPTED",
308 "SECURITY WARNING: User accepted MITM risk - continuing with "
309 "connection");
310 } else if (known_host_result == ASCIICHAT_OK) {
311 // Unknown host (first connection) - prompt user to verify fingerprint
313 server_identity_key)) {
314 // User declined to add host - ABORT connection
315
316 return SET_ERRNO(ERROR_CRYPTO,
317 "User declined to verify unknown host");
318 }
319
320 // User accepted - add to known_hosts
321 if (add_known_host(ctx->server_ip, ctx->server_port,
322 server_identity_key) != ASCIICHAT_OK) {
323 return SET_ERRNO(
325 "CRITICAL SECURITY ERROR: Failed to create known_hosts "
326 "file! This is a security vulnerability - the "
327 "program cannot track known hosts. Please check file "
328 "permissions and ensure the program can write to: %s",
330 }
331 log_debug("Server host added to known_hosts successfully");
332 } else if (known_host_result == 1) {
333 // Key matches - connection is secure!
334 log_info(
335 "Server host key verified from known_hosts - connection secure");
336 } else {
337 // Unexpected error code from check_known_host
338
339 return SET_ERRNO(
340 known_host_result,
341 "SECURITY: known_hosts verification failed with error code %d",
342 known_host_result);
343 }
344 }
345 public_key_t identity = {.type = KEY_TYPE_ED25519};
346 memcpy(identity.key, server_identity_key, sizeof(identity.key));
348 ? "VERIFIED SERVER PUBLIC IDENTITY"
349 : "UNVERIFIED SERVER PUBLIC IDENTITY",
350 &identity);
351 } else if (payload_len == ctx->crypto_ctx.public_key_size) {
352 if (ctx->verify_server_key) {
354 "Server omitted the required identity key");
355 }
356 // Simple format: just ephemeral key (no identity key)
357 log_debug("Received simple KEY_EXCHANGE_INIT (%zu bytes) - server has no "
358 "identity key",
359 payload_len);
360 memcpy(server_ephemeral_key, payload, ctx->crypto_ctx.public_key_size);
361
362 // Clear identity key and signature for simple format
363 memset(server_identity_key, 0, ctx->crypto_ctx.auth_public_key_size);
364 memset(server_signature, 0, ctx->crypto_ctx.signature_size);
365
366 // Server is not using client authentication in simple mode
367 ctx->server_uses_client_auth = false;
368
369 log_debug("Received ephemeral key (simple format)");
370
371 if (!ctx->addressless_transport) {
372 // SECURITY: For servers without identity keys, we implement a different
373 // security model:
374 // 1. Verify IP address matches known_hosts entry
375 // 2. Always require user confirmation (no silent connections)
376 // 3. Store server fingerprint for future verification
377
378 if (ctx->server_ip[0] == '\0' || ctx->server_port <= 0) {
379 return SET_ERRNO(ERROR_CRYPTO,
380 "Server IP or port not set, cannot check known_hosts");
381 }
382
383 // Check if this server was previously connected to (IP verification)
384 bool skip_known_hosts = false;
385 asciichat_error_t known_host_result = ASCIICHAT_OK;
386 const char *env_skip_known_hosts_checking =
387 platform_getenv("ASCII_CHAT_INSECURE_NO_HOST_IDENTITY_CHECK");
388 if (env_skip_known_hosts_checking &&
389 strcmp(env_skip_known_hosts_checking, STR_ONE) == 0) {
390 log_warn(
391 "Skipping known_hosts checking. This is a security vulnerability.");
392 skip_known_hosts = true;
393 }
394#ifndef NDEBUG
395 // In debug builds, also skip for Claude Code (LLM automation can't do
396 // interactive prompts)
397 else if (platform_getenv("CLAUDECODE")) {
398 log_warn(
399 "Skipping known_hosts checking (CLAUDECODE set in debug build).");
400 skip_known_hosts = true;
401 }
402#endif
403 else {
404 known_host_result =
406 }
407
408 if (skip_known_hosts || known_host_result == 1) {
409 // Server IP is known and verified - allow connection without warnings
410 log_info("SECURITY: Server IP %s:%u is known (no-identity entry found) "
411 "- connection verified",
412 ctx->server_ip, ctx->server_port);
413 } else if (known_host_result == ASCIICHAT_OK) {
414 // Server IP is unknown - require user confirmation
415 NOTICE(DANGER, "UNVERIFIED SERVER IDENTITY",
416 "SECURITY: Unknown server IP %s:%u with no identity key\n"
417 "This connection is vulnerable to man-in-the-middle attacks\n"
418 "Anyone can intercept your connection and read your data",
419 ctx->server_ip, ctx->server_port);
420
422 ctx->server_port)) {
423 return SET_ERRNO(ERROR_CRYPTO, "User declined to connect to unknown "
424 "server without identity key");
425 }
426
427 // User accepted - add to known_hosts as no-identity entry
428 // For servers without identity keys, pass zero key to indicate
429 // no-identity
430 uint8_t zero_key[ZERO_KEY_SIZE] = {0};
431 if (add_known_host(ctx->server_ip, ctx->server_port, zero_key) !=
432 ASCIICHAT_OK) {
433 return SET_ERRNO(
435 "CRITICAL SECURITY ERROR: Failed to create known_hosts "
436 "file! This is a security vulnerability - the "
437 "program cannot track known hosts. Please check file "
438 "permissions and ensure the program can write to: %s",
440 }
441 log_debug("Server host added to known_hosts successfully");
442 } else if (known_host_result == ERROR_CRYPTO_VERIFICATION) {
443 // Server previously had identity key but now has none - potential
444 // security issue
445 NOTICE(DANGER, "SERVER IDENTITY REMOVED",
446 "SECURITY: Server previously had identity key but now has none "
447 "- potential security issue");
448
449 return SET_ERRNO(
451 "Server key configuration changed - potential security issue");
452 } else {
453 // Other error checking known_hosts (e.g., ERROR_INVALID_PARAM)
454
455 return SET_ERRNO(ERROR_CRYPTO, "Failed to verify server IP address");
456 }
457 }
458 } else {
459 return SET_ERRNO(
461 "Invalid KEY_EXCHANGE_INIT size: %zu bytes (expected %zu or "
462 "%zu). This indicates: Protocol violation "
463 "or incompatible server version, Potential man-in-the-middle "
464 "attack, Network corruption",
465 payload_len, expected_auth_size, ctx->crypto_ctx.public_key_size);
466 // retry
467 }
468
469 // Set peer's public key (EPHEMERAL X25519) - this also derives the shared
470 // secret
471 crypto_result_t crypto_result =
472 crypto_set_peer_public_key(&ctx->crypto_ctx, server_ephemeral_key);
473 if (crypto_result != CRYPTO_OK) {
474 return SET_ERRNO(
476 "Failed to set peer public key and derive shared secret: %s",
477 crypto_result_to_string(crypto_result));
478 }
479
480 // Determine if client has an identity key
481 bool client_has_identity_key =
483
484 // Send authenticated response if server has identity key
485 // (auth_public_key_size > 0) OR if server requires client authentication
486 // (require_client_auth) Note: server_uses_client_auth is set when server has
487 // identity key, but we should send authenticated response when server has
488 // identity key regardless of client auth requirement
489 bool server_has_identity = (ctx->crypto_ctx.auth_public_key_size > 0 &&
490 ctx->crypto_ctx.signature_size > 0);
491 bool server_requires_auth = server_has_identity || ctx->require_client_auth;
492
493 if (server_requires_auth || client_has_identity_key) {
494 // Send authenticated packet:
495 // [ephemeral:kex_size][identity:auth_size][signature:sig_size][gpg_key_id_len:1][gpg_key_id:0-16]
496 // Use Ed25519 sizes since client has Ed25519 key
497 size_t ed25519_pubkey_size =
498 ED25519_PUBLIC_KEY_SIZE; // Ed25519 public key is always 32 bytes
499 size_t ed25519_sig_size =
500 ED25519_SIGNATURE_SIZE; // Ed25519 signature is always 64 bytes
501 size_t response_size = ctx->crypto_ctx.public_key_size +
502 ed25519_pubkey_size + ed25519_sig_size;
503
504 // Check if client has a GPG key ID to send
505 uint8_t gpg_key_id_len = 0;
506 if (ctx->client_gpg_key_id[0] != '\0') {
507 gpg_key_id_len = (uint8_t)strlen(ctx->client_gpg_key_id);
508 if (gpg_key_id_len > 40) {
509 gpg_key_id_len = 40; // Truncate to max length (full fingerprint)
510 }
511 response_size += 1 + gpg_key_id_len; // 1 byte for length + key ID
512 } else {
513 response_size += 1; // Just the length byte (0)
514 }
515
516 SAFE_MALLOC_DEFER_FREE(key_response, response_size, uint8_t *);
517 defer(sodium_memzero(key_response, response_size));
518 size_t offset = 0;
519
520 // Copy ephemeral key
521 memcpy(key_response + offset, ctx->crypto_ctx.public_key,
522 ctx->crypto_ctx.public_key_size); // X25519 ephemeral for encryption
523 offset += ctx->crypto_ctx.public_key_size;
524
525 if (client_has_identity_key) {
526 // Client has identity key - send it with signature
527 memcpy(key_response + offset, ctx->client_private_key.public_key,
528 ed25519_pubkey_size); // Ed25519 identity
529 offset += ed25519_pubkey_size;
530
531 // Sign ephemeral key with client identity key
534 ctx->crypto_ctx.public_key_size, key_response + offset) != 0) {
535 return SET_ERRNO(ERROR_CRYPTO, "Failed to sign client ephemeral key");
536 }
537 offset += ed25519_sig_size;
538 } else {
539 // Client has no identity key - send null identity and null signature
540 memset(key_response + offset, 0, ed25519_pubkey_size); // Null identity
541 offset += ed25519_pubkey_size;
542 memset(key_response + offset, 0, ed25519_sig_size); // Null signature
543 offset += ed25519_sig_size;
544 }
545
546 // Append GPG key ID length
547 key_response[offset] = gpg_key_id_len;
548 offset += 1;
549
550 // Append GPG key ID if present
551 if (gpg_key_id_len > 0) {
552 memcpy(key_response + offset, ctx->client_gpg_key_id, gpg_key_id_len);
553 offset += gpg_key_id_len;
554 log_debug("Including client GPG key ID in KEY_EXCHANGE_RESPONSE: %.*s",
555 gpg_key_id_len, ctx->client_gpg_key_id);
556 }
557
558 result = packet_send_via_transport(transport,
560 key_response, response_size, 0);
561 if (result != 0) {
563 "Failed to send KEY_EXCHANGE_RESPONSE packet");
564 }
565
566 } else {
567 // Send X25519 encryption key only to server (no identity key)
568 // Format: [X25519 pubkey (kex_size)] = kex_size bytes total
572 if (result != 0) {
574 "Failed to send KEY_EXCHANGE_RESPONSE packet");
575 }
576 }
577
579
580 return ASCIICHAT_OK;
581}
#define SAFE_MALLOC_DEFER_FREE(name, size, cast)
const char * get_known_hosts_path(void)
Get the path to the known_hosts file.
Definition known_hosts.c:59
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).
bool prompt_unknown_host_no_identity(const char *server_ip, uint16_t port)
Interactive prompt for unknown host without identity key - returns true if user wants to continue,...
asciichat_error_t check_known_host_no_identity(const char *server_ip, uint16_t port)
Check known_hosts for servers without identity key (no-identity entries).
@ ERROR_CRYPTO_VERIFICATION
@ ERROR_MEMORY
Definition error_codes.h:55
@ ERROR_CONFIG
Definition error_codes.h:56
uint8_t key[CRYPTO_PUBLIC_KEY_SIZE]
Definition key_types.h:85
asciichat_error_t parse_public_keys(const char *input, public_key_t *keys_out, size_t *num_keys, size_t max_keys)
Parse all SSH/GPG public keys from any format (returns all keys).
Definition keys.c:474
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE]
Definition key_types.h:124
#define MAX_CLIENTS
Maximum possible clients (static array size) - actual runtime limit set by –max-clients (1-128).
#define log_warn(...)
Log a WARN message.
Definition log/log.h:591
#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
@ PACKET_TYPE_CRYPTO_KEY_EXCHANGE_RESP
Client -> Server: {client_pubkey[32]} (UNENCRYPTED).
Definition packet.h:342
#define STR_ONE
String literal: "1" (one).
bool prompt_unknown_host(const char *server_ip, uint16_t port, const uint8_t server_key[ED25519_PUBLIC_KEY_SIZE])
bool display_mitm_warning(const char *server_ip, uint16_t port, const uint8_t expected_key[ED25519_PUBLIC_KEY_SIZE], const uint8_t received_key[ED25519_PUBLIC_KEY_SIZE])
asciichat_error_t check_known_host_with_key(const char *server_ip, uint16_t port, const uint8_t server_key[ED25519_PUBLIC_KEY_SIZE], uint8_t expected_key[ED25519_PUBLIC_KEY_SIZE], bool *has_expected_key)
Definition known_hosts.c:95
asciichat_error_t add_known_host(const char *server_ip, uint16_t port, const uint8_t server_key[ED25519_PUBLIC_KEY_SIZE])
void key_identity_announce(const char *label, const public_key_t *key)
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 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 ZERO_KEY_SIZE
Zero key array size (32 bytes, used for no-identity entries).
Definition sizes.h:170
#define HEX_STRING_SIZE_64
Hex string size for 64-byte values (128 hex chars + null terminator).
Definition sizes.h:166
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
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
The normalized public identity used by ascii-chat's crypto and key-management code.
Definition key_types.h:83
const char * platform_getenv(const char *name)
Definition system.c:45

References add_known_host(), crypto_handshake_context_t::addressless_transport, ASCII_OTEL_SCOPE, ASCIICHAT_OK, crypto_context_t::auth_public_key_size, check_known_host_no_identity(), check_known_host_with_key(), crypto_handshake_context_t::client_gpg_key_id, crypto_handshake_context_t::client_private_key, crypto_handshake_context_t::crypto_ctx, CRYPTO_HANDSHAKE_INIT, CRYPTO_HANDSHAKE_KEY_EXCHANGE, crypto_handshake_validate_packet_size(), CRYPTO_OK, crypto_result_to_string(), crypto_set_peer_public_key(), display_mitm_warning(), ED25519_PUBLIC_KEY_SIZE, ed25519_sign_message(), ED25519_SIGNATURE_SIZE, ed25519_verify_signature(), ERROR_CONFIG, ERROR_CRYPTO, ERROR_CRYPTO_AUTH, ERROR_CRYPTO_VERIFICATION, ERROR_INVALID_PARAM, ERROR_INVALID_STATE, ERROR_MEMORY, ERROR_NETWORK, ERROR_NETWORK_PROTOCOL, crypto_handshake_context_t::expected_server_key, crypto_handshake_context_t::expected_server_key_bytes, crypto_handshake_context_t::expected_server_key_bytes_set, get_known_hosts_path(), HEX_STRING_SIZE_32, HEX_STRING_SIZE_64, public_key_t::key, key_identity_announce(), KEY_TYPE_ED25519, log_debug, log_error, log_info, log_warn, MAX_CLIENTS, NOTICE, packet_send_via_transport(), PACKET_TYPE_CRYPTO_KEY_EXCHANGE_INIT, PACKET_TYPE_CRYPTO_KEY_EXCHANGE_RESP, parse_public_keys(), platform_getenv(), prompt_unknown_host(), prompt_unknown_host_no_identity(), crypto_context_t::public_key, private_key_t::public_key, crypto_context_t::public_key_size, crypto_handshake_context_t::require_client_auth, SAFE_MALLOC_DEFER_FREE, crypto_handshake_context_t::server_ip, crypto_handshake_context_t::server_port, crypto_handshake_context_t::server_uses_client_auth, SET_ERRNO, crypto_context_t::signature_size, crypto_handshake_context_t::state, STR_ONE, private_key_t::type, crypto_handshake_context_t::verify_server_key, and ZERO_KEY_SIZE.

Referenced by acds_handshake_receive(), acip_security_receive(), and client_handle_key_exchange_init().