ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
known_hosts.c File Reference

📜 SSH known_hosts file parser for host key verification and trust management More...

Go to the source code of this file.

Functions

asciichat_error_t check_known_host (const char *server_ip, uint16_t port, const uint8_t server_key[32])
 Check if server key is in known_hosts.
 
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)
 
asciichat_error_t add_known_host (const char *server_ip, uint16_t port, const uint8_t server_key[32])
 Add server to known_hosts.
 
asciichat_error_t remove_known_host (const char *server_ip, uint16_t port)
 Remove server from known_hosts.
 
void compute_key_fingerprint (const uint8_t key[ED25519_PUBLIC_KEY_SIZE], char fingerprint[CRYPTO_HEX_KEY_SIZE_NULL])
 
bool prompt_unknown_host (const char *server_ip, uint16_t port, const uint8_t server_key[32])
 Interactive prompt for unknown host - returns true if user wants to add, false to abort.
 
bool display_mitm_warning (const char *server_ip, uint16_t port, const uint8_t expected_key[32], const uint8_t received_key[32])
 Display MITM warning with key comparison and prompt user for confirmation.
 
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, false to abort.
 
void known_hosts_cleanup (void)
 Cleanup function to free cached known_hosts path.
 
Known Hosts Management
const char * get_known_hosts_path (void)
 Get the path to the known_hosts file.
 

Detailed Description

📜 SSH known_hosts file parser for host key verification and trust management

Definition in file known_hosts.c.

Function Documentation

◆ compute_key_fingerprint()

void compute_key_fingerprint ( const uint8_t  key[ED25519_PUBLIC_KEY_SIZE],
char  fingerprint[CRYPTO_HEX_KEY_SIZE_NULL] 
)

Definition at line 536 of file known_hosts.c.

536 {
538 crypto_hash_sha256(hash, key, ED25519_PUBLIC_KEY_SIZE);
539
540 // Build hex string byte by byte to avoid buffer overflow issues
541 for (int i = 0; i < HMAC_SHA256_SIZE; i++) {
542 uint8_t byte = hash[i];
543 fingerprint[i * 2] = "0123456789abcdef"[byte >> 4]; // High nibble
544 fingerprint[i * 2 + 1] = "0123456789abcdef"[byte & 0xf]; // Low nibble
545 }
546 fingerprint[CRYPTO_HEX_KEY_SIZE] = '\0';
547}
unsigned char uint8_t
Definition common.h:56
#define CRYPTO_HEX_KEY_SIZE
Hex string size for 32-byte key (64 hex characters)
#define HMAC_SHA256_SIZE
HMAC-SHA256 output size in bytes.
#define ED25519_PUBLIC_KEY_SIZE
Ed25519 public key size in bytes.

References CRYPTO_HEX_KEY_SIZE, ED25519_PUBLIC_KEY_SIZE, and HMAC_SHA256_SIZE.

Referenced by display_mitm_warning(), and prompt_unknown_host().