ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
Cryptographic Operations

🔐 Client-side cryptographic handshake and key management

🔐 Client-side cryptographic handshake and key management

Cryptographic Operations

Overview

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

Handshake Process

int client_crypto_handshake(socket_t socket)
{
// Perform client-side handshake
crypto_handshake_result_t result =
perform_crypto_handshake_client(socket, &handshake_ctx,
opt_server_key, server_ip, opt_client_key);
switch (result) {
case HANDSHAKE_SUCCESS:
log_info("Secure connection established");
g_crypto_ctx = handshake_ctx.crypto_ctx;
g_crypto_ready = true;
return 0;
case HANDSHAKE_WARNING_NO_CLIENT_AUTH:
log_warn("Server not verifying client identity");
g_crypto_ctx = handshake_ctx.crypto_ctx;
g_crypto_ready = true;
case HANDSHAKE_ERROR_AUTH_FAILED:
log_error("Client authentication failed - wrong client key?");
return CONNECTION_ERROR_AUTH_FAILED; // No retry
case HANDSHAKE_ERROR_HOST_KEY_FAILED:
log_error("Server host key verification failed");
default:
log_error("Handshake failed");
return CONNECTION_ERROR_GENERIC; // Allow retry
}
}
#define log_warn(...)
Log a WARN message.
Definition log/log.h:615
#define log_error(...)
Log an ERROR message.
Definition log/log.h:628
#define log_info(...)
Log an INFO message.
Definition log/log.h:602
int socket_t
@ CONNECTION_ERROR_GENERIC
Generic error (retry allowed).
@ CONNECTION_ERROR_HOST_KEY_FAILED
Host key verification failed (no retry).
@ CONNECTION_ERROR_AUTH_FAILED
Authentication failure (no retry).
@ CONNECTION_WARNING_NO_CLIENT_AUTH
Server not using client verification (warning).
Cryptographic handshake context structure.

Key Management

Client Keys (--client-key):

  • Ed25519 SSH private keys for client authentication
  • Loaded from filesystem or SSH agent
  • Password support via $ASCII_CHAT_KEY_PASSWORD

Server Keys (--server-key):

  • Ed25519 SSH public keys for server verification
  • Can be loaded from:
    • Filesystem path (~/.ssh/server_id_ed25519.pub)
    • GitHub URL (github:username)
    • GitLab URL (gitlab:username)
  • Verified against known_hosts file
Note
Native Decryption: Encrypted SSH keys are decrypted natively using bcrypt_pbkdf (from libsodium-bcrypt-pbkdf) + BearSSL AES-256-CTR. No external tools required. Alternatively, use $SSH_AUTH_SOCK (ssh-agent) for password-free authentication.

Known Hosts Verification

TOFU (Trust On First Use):

  • First connection: Record server public key by IP
  • Subsequent connections: Verify key matches recorded value
  • Key mismatch: Connection rejected (possible MITM attack)

Known hosts file: ~/.ascii-chat/known_hosts

See also
src/client/crypto.c
src/client/crypto.h
lib/crypto/handshake.h
lib/crypto/keys/keys.h
Client Overview