|
ascii-chat 0.8.38
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 | |
| void | client_crypto_set_mode (uint8_t mode) |
| Set crypto mode for handshake (encryption + authentication) | |
| 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 441 of file src/client/crypto.c.
References buffer_pool_free(), capture_cleanup(), CONNECTION_ERROR_AUTH_FAILED, crypto_handshake_client_auth_response_socket(), crypto_handshake_client_complete_socket(), crypto_handshake_client_key_exchange_socket(), crypto_handshake_set_parameters(), g_crypto_ctx, log_lock_terminal(), log_unlock_terminal(), parse_public_keys(), platform_getenv(), platform_prompt_yes_no(), pubkey_to_hex(), receive_packet(), send_crypto_capabilities_packet(), send_packet(), and send_protocol_version_packet().
Referenced by connection_attempt_tcp(), and 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 208 of file src/client/crypto.c.
References acds_client_config_init_defaults(), acds_client_connect(), acds_client_disconnect(), acds_session_lookup(), crypto_derive_password_key(), crypto_handshake_destroy(), crypto_handshake_init(), crypto_handshake_init_with_password(), crypto_result_to_string(), discovery_keys_verify(), g_crypto_ctx, options_get(), parse_private_key(), server_connection_get_ip(), and validate_ssh_key_file().
Referenced by connection_attempt_tcp(), connection_attempt_websocket(), and server_connection_establish().
| void client_crypto_set_mode | ( | uint8_t | mode | ) |
#include <crypto.c>
Set crypto mode for handshake (encryption + authentication)
Set crypto mode for handshake (encryption + authentication)
| mode | Crypto mode bitmask (ACIP_CRYPTO_*) |
Sets the crypto mode bitmask (ACIP_CRYPTO_*) to negotiate with server. Must be called before client_crypto_init().
| mode | Crypto mode bitmask (ACIP_CRYPTO_NONE, ACIP_CRYPTO_ENCRYPT, ACIP_CRYPTO_AUTH, ACIP_CRYPTO_FULL) |
Definition at line 196 of file src/client/crypto.c.
Referenced by connection_attempt_tcp().
| void crypto_client_cleanup | ( | void | ) |
#include <crypto.c>
Cleanup crypto client resources.
Cleanup crypto client resources
Definition at line 819 of file src/client/crypto.c.
References crypto_handshake_destroy(), and g_crypto_ctx.
| 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 808 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 790 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 770 of file src/client/crypto.c.
References crypto_client_is_ready(), crypto_handshake_get_context(), and g_crypto_ctx.
Referenced by connection_attempt_tcp(), connection_attempt_websocket(), server_connection_establish(), 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 857 of file src/client/crypto.c.
References crypto_client_is_ready(), crypto_handshake_rekey_request(), g_crypto_ctx, and server_connection_get_socket().
| bool crypto_client_is_ready | ( | void | ) |
#include <crypto.c>
Check if crypto handshake is ready.
Check if crypto handshake is ready
Definition at line 755 of file src/client/crypto.c.
References crypto_handshake_is_ready(), and g_crypto_ctx.
Referenced by connection_attempt_tcp(), connection_attempt_websocket(), 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(), 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 887 of file src/client/crypto.c.
References crypto_client_is_ready(), crypto_handshake_process_rekey_request(), and g_crypto_ctx.
| 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 939 of file src/client/crypto.c.
References crypto_client_is_ready(), crypto_handshake_process_rekey_response(), and g_crypto_ctx.
| 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 961 of file src/client/crypto.c.
References crypto_client_is_ready(), crypto_handshake_rekey_complete(), g_crypto_ctx, 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 909 of file src/client/crypto.c.
References crypto_client_is_ready(), crypto_handshake_rekey_response(), g_crypto_ctx, 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 843 of file src/client/crypto.c.
References crypto_client_is_ready(), crypto_handshake_should_rekey(), and g_crypto_ctx.