|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
🔐 Client-side cryptographic handshake and key management More...
Files | |
| file | crypto.c |
| 🔐 Client cryptography: handshake integration, X25519 key exchange, and per-session encryption | |
| file | crypto.h |
| ascii-chat Client Cryptography Handler Interface | |
Functions | |
| int | client_crypto_init (void) |
| Initialize client crypto handshake. | |
| int | client_crypto_handshake (socket_t socket) |
| Perform crypto handshake with server. | |
| bool | crypto_client_is_ready (void) |
| Check if crypto handshake is ready. | |
| const crypto_context_t * | crypto_client_get_context (void) |
| Get crypto context for encryption/decryption. | |
| int | crypto_client_encrypt_packet (const uint8_t *plaintext, size_t plaintext_len, uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_len) |
| Encrypt a packet for transmission. | |
| int | crypto_client_decrypt_packet (const uint8_t *ciphertext, size_t ciphertext_len, uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_len) |
| Decrypt a received packet. | |
| void | crypto_client_cleanup (void) |
| Cleanup crypto client resources. | |
| bool | crypto_client_should_rekey (void) |
| Check if session rekeying should be triggered. | |
| int | crypto_client_initiate_rekey (void) |
| Initiate session rekeying (client-initiated) | |
| int | crypto_client_process_rekey_request (const uint8_t *packet, size_t packet_len) |
| Process received REKEY_REQUEST packet from server. | |
| int | crypto_client_send_rekey_response (void) |
| Send REKEY_RESPONSE packet to server. | |
| int | crypto_client_process_rekey_response (const uint8_t *packet, size_t packet_len) |
| Process received REKEY_RESPONSE packet from server. | |
| int | crypto_client_send_rekey_complete (void) |
| Send REKEY_COMPLETE packet to server and commit to new key. | |
🔐 Client-side cryptographic handshake and key management
The client crypto subsystem coordinates the cryptographic handshake with the server, loads client and server keys, verifies host identity, and manages the encryption context for secure communication.
Implementation: src/client/crypto.c, src/client/crypto.h
Client Keys (--client-key):
$ASCII_CHAT_KEY_PASSWORDServer Keys (--server-key):
~/.ssh/server_id_ed25519.pub)github:username)gitlab:username)$SSH_AUTH_SOCK (ssh-agent) for password-free authentication.TOFU (Trust On First Use):
Known hosts file: ~/.ascii-chat/known_hosts
| int client_crypto_handshake | ( | socket_t | socket | ) |
#include <crypto.c>
Perform crypto handshake with server.
Perform crypto handshake with server
| socket | Connected socket to server |
Executes the complete cryptographic handshake protocol with the server, including protocol negotiation, key exchange, and authentication.
| socket | Connected socket to server |
Definition at line 399 of file src/client/crypto.c.
References ASCIICHAT_OK, AUTH_ALGO_ED25519, AUTH_ALGO_NONE, crypto_parameters_packet_t::auth_public_key_size, buffer_pool_free(), capture_cleanup(), CIPHER_ALGO_XSALSA20_POLY1305, crypto_handshake_context_t::client_public_key, protocol_version_packet_t::compression_algorithms, protocol_version_packet_t::compression_threshold, CONNECTION_ERROR_AUTH_FAILED, crypto_handshake_client_auth_response(), crypto_handshake_client_complete(), crypto_handshake_client_key_exchange(), CRYPTO_HANDSHAKE_READY, crypto_handshake_set_parameters(), FATAL, protocol_version_packet_t::feature_flags, g_crypto_ctx, GET_OPTION, HOST_TO_NET_U16, KEX_ALGO_X25519, crypto_parameters_packet_t::kex_public_key_size, KEY_TYPE_ED25519, log_debug, log_error, log_info, log_lock_terminal(), log_plain, log_unlock_terminal(), log_warn, NET_TO_HOST_U16, PACKET_TYPE_CRYPTO_PARAMETERS, PACKET_TYPE_PROTOCOL_VERSION, platform_getenv(), platform_is_interactive(), platform_prompt_yes_no(), crypto_capabilities_packet_t::preferred_auth, crypto_capabilities_packet_t::preferred_cipher, crypto_capabilities_packet_t::preferred_kex, protocol_version_packet_t::protocol_revision, protocol_version_packet_t::protocol_version, receive_packet(), crypto_handshake_context_t::require_client_auth, crypto_capabilities_packet_t::requires_verification, crypto_parameters_packet_t::selected_auth, crypto_parameters_packet_t::selected_cipher, crypto_parameters_packet_t::selected_kex, send_crypto_capabilities_packet(), send_protocol_version_packet(), crypto_handshake_context_t::server_uses_client_auth, crypto_parameters_packet_t::shared_secret_size, crypto_parameters_packet_t::signature_size, 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, and crypto_parameters_packet_t::verification_enabled.
Referenced by server_connection_establish().
| int client_crypto_init | ( | void | ) |
#include <crypto.c>
Initialize client crypto handshake.
Initialize client crypto handshake
Sets up the client-side cryptographic context with authentication credentials. Supports SSH key, password, and passwordless modes.
Definition at line 194 of file src/client/crypto.c.
References acds_client_config_init_defaults(), acds_client_connect(), acds_client_disconnect(), acds_session_lookup(), options_state::address, ASCIICHAT_OK, crypto_handshake_context_t::client_gpg_key_id, crypto_handshake_context_t::client_private_key, crypto_handshake_context_t::client_public_key, public_key_t::comment, crypto_handshake_context_t::crypto_ctx, crypto_derive_password_key(), crypto_handshake_cleanup(), crypto_handshake_init(), crypto_handshake_init_with_password(), CRYPTO_OK, crypto_result_to_string(), ED25519_PUBLIC_KEY_SIZE, options_state::encrypt_key, crypto_handshake_context_t::expected_server_key, FATAL, acds_session_lookup_result_t::found, g_crypto_ctx, GET_OPTION, crypto_context_t::has_password, acds_session_lookup_result_t::host_pubkey, public_key_t::key, private_key_t::key_comment, KEY_TYPE_ED25519, log_debug, log_error, log_info, log_warn, options_get(), parse_private_key(), options_state::password, options_state::port, private_key_t::public_key, SAFE_SNPRINTF, SAFE_STRNCPY, acds_client_config_t::server_address, server_connection_get_ip(), crypto_handshake_context_t::server_hostname, crypto_handshake_context_t::server_ip, options_state::server_key, crypto_handshake_context_t::server_port, acds_client_config_t::server_port, strtoint_safe(), acds_client_config_t::timeout_ms, public_key_t::type, private_key_t::type, validate_ssh_key_file(), and crypto_handshake_context_t::verify_server_key.
Referenced by server_connection_establish().
| void crypto_client_cleanup | ( | void | ) |
#include <crypto.c>
Cleanup crypto client resources.
Cleanup crypto client resources
Definition at line 728 of file src/client/crypto.c.
References crypto_handshake_cleanup(), g_crypto_ctx, and log_debug.
| int crypto_client_decrypt_packet | ( | const uint8_t * | ciphertext, |
| size_t | ciphertext_len, | ||
| uint8_t * | plaintext, | ||
| size_t | plaintext_size, | ||
| size_t * | plaintext_len | ||
| ) |
#include <crypto.c>
Decrypt a received packet.
Decrypt a received 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 |
| 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 717 of file src/client/crypto.c.
References crypto_client_is_ready(), crypto_decrypt_packet_or_passthrough(), and g_crypto_ctx.
| int crypto_client_encrypt_packet | ( | const uint8_t * | plaintext, |
| size_t | plaintext_len, | ||
| uint8_t * | ciphertext, | ||
| size_t | ciphertext_size, | ||
| size_t * | ciphertext_len | ||
| ) |
#include <crypto.c>
Encrypt a packet for transmission.
Encrypt a packet for transmission
| 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 |
| 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 699 of file src/client/crypto.c.
References crypto_client_is_ready(), crypto_encrypt_packet_or_passthrough(), and g_crypto_ctx.
| const crypto_context_t * crypto_client_get_context | ( | void | ) |
#include <crypto.c>
Get crypto context for encryption/decryption.
Get crypto context for encryption/decryption
Definition at line 679 of file src/client/crypto.c.
References crypto_client_is_ready(), crypto_handshake_get_context(), and g_crypto_ctx.
Referenced by server_connection_establish(), threaded_send_audio_batch_packet(), and threaded_send_client_join_packet().
| int crypto_client_initiate_rekey | ( | void | ) |
#include <crypto.c>
Initiate session rekeying (client-initiated)
Initiate session rekeying (client-initiated)
Definition at line 761 of file src/client/crypto.c.
References ASCIICHAT_OK, crypto_client_is_ready(), crypto_handshake_rekey_request(), g_crypto_ctx, INVALID_SOCKET_VALUE, log_error, and server_connection_get_socket().
Referenced by __attribute__().
| bool crypto_client_is_ready | ( | void | ) |
#include <crypto.c>
Check if crypto handshake is ready.
Check if crypto handshake is ready
Definition at line 664 of file src/client/crypto.c.
References crypto_handshake_is_ready(), g_crypto_ctx, and GET_OPTION.
Referenced by crypto_client_decrypt_packet(), crypto_client_encrypt_packet(), crypto_client_get_context(), crypto_client_initiate_rekey(), crypto_client_process_rekey_request(), crypto_client_process_rekey_response(), crypto_client_send_rekey_complete(), crypto_client_send_rekey_response(), crypto_client_should_rekey(), server_connection_establish(), threaded_send_audio_batch_packet(), and threaded_send_client_join_packet().
| int crypto_client_process_rekey_request | ( | const uint8_t * | packet, |
| size_t | packet_len | ||
| ) |
#include <crypto.c>
Process received REKEY_REQUEST packet from server.
Process received REKEY_REQUEST packet from server
| packet | Packet data |
| packet_len | Packet length |
| packet | Packet data |
| packet_len | Packet length |
Definition at line 791 of file src/client/crypto.c.
References ASCIICHAT_OK, crypto_client_is_ready(), crypto_handshake_process_rekey_request(), g_crypto_ctx, and log_error.
| int crypto_client_process_rekey_response | ( | const uint8_t * | packet, |
| size_t | packet_len | ||
| ) |
#include <crypto.c>
Process received REKEY_RESPONSE packet from server.
Process received REKEY_RESPONSE packet from server
| packet | Packet data |
| packet_len | Packet length |
| packet | Packet data |
| packet_len | Packet length |
Definition at line 843 of file src/client/crypto.c.
References ASCIICHAT_OK, crypto_client_is_ready(), crypto_handshake_process_rekey_response(), g_crypto_ctx, and log_error.
| int crypto_client_send_rekey_complete | ( | void | ) |
#include <crypto.c>
Send REKEY_COMPLETE packet to server and commit to new key.
Send REKEY_COMPLETE packet to server and commit to new key
Definition at line 865 of file src/client/crypto.c.
References ASCIICHAT_OK, crypto_client_is_ready(), crypto_handshake_rekey_complete(), g_crypto_ctx, INVALID_SOCKET_VALUE, log_error, and server_connection_get_socket().
| int crypto_client_send_rekey_response | ( | void | ) |
#include <crypto.c>
Send REKEY_RESPONSE packet to server.
Send REKEY_RESPONSE packet to server
Definition at line 813 of file src/client/crypto.c.
References ASCIICHAT_OK, crypto_client_is_ready(), crypto_handshake_rekey_response(), g_crypto_ctx, INVALID_SOCKET_VALUE, log_error, and server_connection_get_socket().
| bool crypto_client_should_rekey | ( | void | ) |
#include <crypto.c>
Check if session rekeying should be triggered.
Check if session rekeying should be triggered
Definition at line 747 of file src/client/crypto.c.
References crypto_client_is_ready(), crypto_handshake_should_rekey(), and g_crypto_ctx.
Referenced by __attribute__().