|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
🔐 Server cryptography: per-client handshake, X25519 key exchange, and session encryption management More...
Go to the source code of this file.
Functions | |
| int | server_crypto_init (void) |
| int | server_crypto_handshake (client_info_t *client) |
| bool | crypto_server_is_ready (uint32_t client_id) |
| const crypto_context_t * | crypto_server_get_context (uint32_t client_id) |
| int | crypto_server_encrypt_packet (uint32_t client_id, const uint8_t *plaintext, size_t plaintext_len, uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_len) |
| int | crypto_server_decrypt_packet (uint32_t client_id, const uint8_t *ciphertext, size_t ciphertext_len, uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_len) |
| void | crypto_server_cleanup_client (uint32_t client_id) |
Variables | |
| bool | g_server_encryption_enabled |
| Global flag indicating if server encryption is enabled. | |
| private_key_t | g_server_private_key |
| Global server private key. | |
| public_key_t | g_client_whitelist [] |
| Global client public key whitelist. | |
| size_t | g_num_whitelisted_clients |
| Number of whitelisted clients. | |
🔐 Server cryptography: per-client handshake, X25519 key exchange, and session encryption management
The handshake follows a multi-phase protocol:
PHASE 0: PROTOCOL NEGOTIATION:
PHASE 1: KEY EXCHANGE:
PHASE 2: AUTHENTICATION:
The server supports three authentication modes:
Each client has an independent crypto context stored in client_info_t:
When client whitelist is enabled:
After handshake completion:
The server currently supports:
Handshake errors are handled gracefully:
Crypto operations are thread-safe:
The original server.c mixed cryptographic operations with connection management and packet processing, making it difficult to:
This separation provides:
Definition in file src/server/crypto.c.
| void crypto_server_cleanup_client | ( | uint32_t | client_id | ) |
Cleanup crypto resources for a specific client
| client_id | Client ID to cleanup crypto for |
Definition at line 647 of file src/server/crypto.c.
References crypto_handshake_cleanup(), client_info::crypto_handshake_ctx, client_info::crypto_initialized, find_client_by_id(), and log_debug.
| int crypto_server_decrypt_packet | ( | uint32_t | client_id, |
| const uint8_t * | ciphertext, | ||
| size_t | ciphertext_len, | ||
| uint8_t * | plaintext, | ||
| size_t | plaintext_size, | ||
| size_t * | plaintext_len | ||
| ) |
Decrypt a received packet from a specific client
| client_id | Client ID that sent the packet |
| ciphertext | Encrypted data to decrypt |
| ciphertext_len | Length of encrypted data |
| plaintext | Output buffer for decrypted data |
| plaintext_size | Size of output buffer |
| plaintext_len | Output length of decrypted data |
Definition at line 631 of file src/server/crypto.c.
References crypto_decrypt_packet_or_passthrough(), client_info::crypto_handshake_ctx, crypto_server_is_ready(), and find_client_by_id().
Referenced by process_encrypted_packet().
| int crypto_server_encrypt_packet | ( | uint32_t | client_id, |
| const uint8_t * | plaintext, | ||
| size_t | plaintext_len, | ||
| uint8_t * | ciphertext, | ||
| size_t | ciphertext_size, | ||
| size_t * | ciphertext_len | ||
| ) |
Encrypt a packet for transmission to a specific client
| client_id | Client ID to encrypt for |
| plaintext | Plaintext data to encrypt |
| plaintext_len | Length of plaintext data |
| ciphertext | Output buffer for encrypted data |
| ciphertext_size | Size of output buffer |
| ciphertext_len | Output length of encrypted data |
Definition at line 609 of file src/server/crypto.c.
References crypto_encrypt_packet_or_passthrough(), client_info::crypto_handshake_ctx, crypto_server_is_ready(), and find_client_by_id().
| const crypto_context_t * crypto_server_get_context | ( | uint32_t | client_id | ) |
Get crypto context for encryption/decryption for a specific client
| client_id | Client ID to get context for |
Definition at line 585 of file src/server/crypto.c.
References client_info::crypto_handshake_ctx, crypto_handshake_get_context(), crypto_server_is_ready(), and find_client_by_id().
Check if crypto handshake is ready for a specific client
| client_id | Client ID to check |
Definition at line 561 of file src/server/crypto.c.
References client_info::crypto_handshake_ctx, crypto_handshake_is_ready(), client_info::crypto_initialized, find_client_by_id(), and GET_OPTION.
Referenced by crypto_server_decrypt_packet(), crypto_server_encrypt_packet(), crypto_server_get_context(), and process_encrypted_packet().
| int server_crypto_handshake | ( | client_info_t * | client | ) |
Perform crypto handshake with client
| client | Client info structure |
Definition at line 184 of file src/server/crypto.c.
References ASCIICHAT_OK, AUTH_ALGO_ED25519, AUTH_ALGO_NONE, crypto_parameters_packet_t::auth_public_key_size, buffer_pool_free(), CIPHER_ALGO_XSALSA20_POLY1305, client_info::client_id, client_info::client_state_mutex, crypto_handshake_context_t::client_whitelist, protocol_version_packet_t::compression_algorithms, protocol_version_packet_t::compression_threshold, client_info::crypto_handshake_ctx, crypto_handshake_init(), crypto_handshake_init_with_password(), CRYPTO_HANDSHAKE_READY, crypto_handshake_server_auth_challenge(), crypto_handshake_server_complete(), crypto_handshake_server_start(), crypto_handshake_set_parameters(), CRYPTO_HMAC_SIZE, client_info::crypto_initialized, CRYPTO_MAC_SIZE, CRYPTO_NONCE_SIZE, CRYPTO_PUBLIC_KEY_SIZE, ED25519_PUBLIC_KEY_SIZE, ED25519_SIGNATURE_SIZE, ERROR_CRYPTO, ERROR_CRYPTO_AUTH, ERROR_CRYPTO_HANDSHAKE, ERROR_CRYPTO_VERIFICATION, ERROR_NETWORK, ERROR_NETWORK_PROTOCOL, FATAL, protocol_version_packet_t::feature_flags, g_client_whitelist, g_num_whitelisted_clients, g_server_encryption_enabled, g_server_private_key, GET_OPTION, crypto_parameters_packet_t::hmac_size, HOST_TO_NET_U16, INVALID_SOCKET_VALUE, KEX_ALGO_X25519, crypto_parameters_packet_t::kex_public_key_size, public_key_t::key, KEY_TYPE_ED25519, log_debug, LOG_ERRNO_IF_SET, log_error, log_info, log_info_client, crypto_parameters_packet_t::mac_size, mutex_lock, mutex_unlock, NET_TO_HOST_U16, crypto_parameters_packet_t::nonce_size, crypto_handshake_context_t::num_whitelisted_clients, options_get(), PACKET_TYPE_CRYPTO_CAPABILITIES, PACKET_TYPE_PROTOCOL_VERSION, options_state::password, client_info::pending_packet_length, client_info::pending_packet_payload, client_info::pending_packet_type, protocol_version_packet_t::protocol_revision, protocol_version_packet_t::protocol_version, private_key_t::public_key, receive_packet(), 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, send_crypto_parameters_packet(), send_protocol_version_packet(), crypto_handshake_context_t::server_private_key, crypto_handshake_context_t::server_public_key, SET_ERRNO, crypto_parameters_packet_t::shared_secret_size, crypto_parameters_packet_t::signature_size, client_info::socket, START_TIMER, crypto_handshake_context_t::state, STOP_TIMER, STOP_TIMER_AND_LOG, crypto_capabilities_packet_t::supported_auth_algorithms, crypto_capabilities_packet_t::supported_cipher_algorithms, crypto_capabilities_packet_t::supported_kex_algorithms, protocol_version_packet_t::supports_encryption, public_key_t::type, private_key_t::type, and crypto_parameters_packet_t::verification_enabled.
| int server_crypto_init | ( | void | ) |
Initialize server crypto system (global initialization)
Definition at line 167 of file src/server/crypto.c.
References GET_OPTION, and log_info.