|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
🔑 SSH key, GPG key, and key validation APIs More...
Data Structures | |
| struct | public_key_t |
| Public key structure. More... | |
| struct | private_key_t |
| Private key structure (for server –ssh-key) More... | |
Typedefs | |
| typedef struct crypto_handshake_context_t | crypto_handshake_context_t |
Variables | ||
| key_type_t | public_key_t::type | |
| uint8_t | public_key_t::key [32] | |
| char | public_key_t::comment [256] | |
| key_type_t | private_key_t::type | |
| uint8_t private_key_t::ed25519 [64] | ||
| uint8_t private_key_t::x25519 [32] | ||
| union { | ||
| uint8_t private_key_t::ed25519 [64] | ||
| uint8_t private_key_t::x25519 [32] | ||
| } | private_key_t::key | |
| bool | private_key_t::use_ssh_agent | |
| bool | private_key_t::use_gpg_agent | |
| uint8_t | private_key_t::public_key [32] | |
| char | private_key_t::key_comment [256] | |
| char | private_key_t::gpg_keygrip [64] | |
Key Type Definitions | |
| enum | key_type_t { KEY_TYPE_UNKNOWN = 0 , KEY_TYPE_ED25519 , KEY_TYPE_X25519 , KEY_TYPE_GPG } |
| Key type enumeration. More... | |
GPG Key Parsing | |
| asciichat_error_t | parse_gpg_key (const char *gpg_key_text, public_key_t *key_out) |
| Parse GPG key from armored text format. | |
| asciichat_error_t | parse_gpg_key_binary (const uint8_t *gpg_key_binary, size_t key_size, public_key_t *key_out) |
| Parse GPG key from binary format. | |
| asciichat_error_t | validate_gpg_key_format (const char *gpg_key_text) |
| Validate GPG key format and structure. | |
| asciichat_error_t | extract_ed25519_from_gpg (const char *gpg_key_text, uint8_t ed25519_pk[32]) |
| Extract Ed25519 public key from GPG key. | |
| asciichat_error_t | gpg_to_x25519_public (const char *gpg_key_text, uint8_t x25519_pk[32]) |
| Convert GPG key to X25519 for key exchange. | |
GPG Key Operations | |
| asciichat_error_t | get_gpg_fingerprint (const char *gpg_key_text, uint8_t fingerprint_out[20]) |
| Get GPG key fingerprint. | |
| asciichat_error_t | get_gpg_key_id (const char *gpg_key_text, uint8_t key_id_out[8]) |
| Get GPG key ID (short fingerprint) | |
| asciichat_error_t | check_gpg_key_expiry (const char *gpg_key_text, bool *is_expired) |
| Check if GPG key is expired. | |
GPG Key Formatting | |
| asciichat_error_t | format_gpg_key_display (const char *gpg_key_text, char *output, size_t output_size) |
| Format GPG key for display. | |
| asciichat_error_t | extract_gpg_key_comment (const char *gpg_key_text, char *comment_out, size_t comment_size) |
| Extract key comment/email from GPG key. | |
HTTPS Key Fetching | |
Fetch SSH/GPG keys from GitHub and GitLab using HTTPS (BearSSL). Requires network connectivity and valid usernames. | |
| asciichat_error_t | fetch_github_ssh_keys (const char *username, char ***keys_out, size_t *num_keys) |
| Fetch SSH keys from GitHub using HTTPS. | |
| asciichat_error_t | fetch_gitlab_ssh_keys (const char *username, char ***keys_out, size_t *num_keys) |
| Fetch SSH keys from GitLab using HTTPS. | |
| asciichat_error_t | fetch_github_gpg_keys (const char *username, char ***keys_out, size_t *num_keys) |
| Fetch GPG keys from GitHub using HTTPS. | |
| asciichat_error_t | fetch_gitlab_gpg_keys (const char *username, char ***keys_out, size_t *num_keys) |
| Fetch GPG keys from GitLab using HTTPS. | |
Key Parsing from HTTPS Responses | |
| asciichat_error_t | parse_ssh_keys_from_response (const char *response_text, size_t response_len, char ***keys_out, size_t *num_keys, size_t max_keys) |
| Parse SSH keys from HTTPS response text. | |
| asciichat_error_t | parse_gpg_keys_from_response (const char *response_text, size_t response_len, char ***keys_out, size_t *num_keys, size_t max_keys) |
| Parse GPG keys from HTTPS response text. | |
URL Construction | |
| asciichat_error_t | build_github_ssh_url (const char *username, char *url_out, size_t url_size) |
| Construct GitHub SSH keys URL. | |
| asciichat_error_t | build_gitlab_ssh_url (const char *username, char *url_out, size_t url_size) |
| Construct GitLab SSH keys URL. | |
| asciichat_error_t | build_github_gpg_url (const char *username, char *url_out, size_t url_size) |
| Construct GitHub GPG keys URL. | |
| asciichat_error_t | build_gitlab_gpg_url (const char *username, char *url_out, size_t url_size) |
| Construct GitLab GPG keys URL. | |
Public Key Parsing | |
| asciichat_error_t | parse_public_key (const char *input, public_key_t *key_out) |
| Parse SSH/GPG public key from any format (returns first key only) | |
| asciichat_error_t | parse_public_keys (const char *input, public_key_t *keys_out, size_t *num_keys, size_t max_keys) |
| Parse all SSH/GPG public keys from any format (returns all keys) | |
Private Key Parsing | |
| asciichat_error_t | parse_private_key (const char *path, private_key_t *key_out) |
| Parse SSH private key from file. | |
Key Conversion | |
| asciichat_error_t | public_key_to_x25519 (const public_key_t *key, uint8_t x25519_pk[32]) |
| Convert public key to X25519 for Diffie-Hellman key exchange. | |
| asciichat_error_t | private_key_to_x25519 (const private_key_t *key, uint8_t x25519_sk[32]) |
| Convert private key to X25519 for Diffie-Hellman key exchange. | |
Ed25519 Signing and Verification | |
| asciichat_error_t | ed25519_sign_message (const private_key_t *key, const uint8_t *message, size_t message_len, uint8_t signature[64]) |
| Sign a message with Ed25519 (uses SSH agent if available, otherwise in-memory key) | |
| asciichat_error_t | ed25519_verify_signature (const uint8_t public_key[32], const uint8_t *message, size_t message_len, const uint8_t signature[64], const char *gpg_key_id) |
| Verify an Ed25519 signature. | |
Key Fetching (GitHub/GitLab) | |
Fetch SSH/GPG keys from GitHub and GitLab using HTTPS (BearSSL). Requires network connectivity and valid usernames. | |
| asciichat_error_t | fetch_github_keys (const char *username, char ***keys_out, size_t *num_keys, bool use_gpg) |
| Fetch SSH/GPG keys from GitHub using BearSSL. | |
| asciichat_error_t | fetch_gitlab_keys (const char *username, char ***keys_out, size_t *num_keys, bool use_gpg) |
| Fetch SSH/GPG keys from GitLab using BearSSL. | |
Key Parsing | |
| asciichat_error_t | parse_keys_from_file (const char *path, public_key_t *keys, size_t *num_keys, size_t max_keys) |
| Parse SSH keys from file (supports authorized_keys and known_hosts formats) | |
Key Formatting and Utilities | |
| void | format_public_key (const public_key_t *key, char *output, size_t output_size) |
| Convert public key to display format (ssh-ed25519 or x25519 hex) | |
| asciichat_error_t | hex_decode (const char *hex, uint8_t *output, size_t output_len) |
| Decode hex string to binary (utility function for testing) | |
| asciichat_error_t | validate_ssh_key_file (const char *key_path) |
| Validate SSH key file before parsing. | |
Key Validation | |
| asciichat_error_t | validate_public_key (const public_key_t *key) |
| Validate a public key structure. | |
| asciichat_error_t | validate_private_key (const private_key_t *key) |
| Validate a private key structure. | |
| asciichat_error_t | check_key_expiry (const public_key_t *key, bool *is_expired) |
| Check if a key is expired. | |
| asciichat_error_t | validate_key_security (const char *key_path) |
| Validate key permissions and security. | |
Key Format Validation | |
| asciichat_error_t | validate_ssh_key_format (const char *key_text) |
| Validate SSH key format. | |
| asciichat_error_t | validate_x25519_key_format (const char *key_hex) |
| Validate X25519 key format. | |
Key Security Checks | |
| asciichat_error_t | check_key_strength (const public_key_t *key, bool *is_weak) |
| Check if key has weak parameters. | |
| asciichat_error_t | validate_key_permissions (const char *key_path) |
| Validate key file permissions. | |
| asciichat_error_t | check_key_patterns (const public_key_t *key, bool *has_weak_patterns) |
| Check for key reuse or weak patterns. | |
Key Comparison and Matching | |
| asciichat_error_t | compare_public_keys (const public_key_t *key1, const public_key_t *key2, bool *are_equal) |
| Compare two public keys for equality. | |
| asciichat_error_t | check_key_fingerprint (const public_key_t *key, const uint8_t *fingerprint, size_t fingerprint_len, bool *matches) |
| Check if key matches a fingerprint. | |
| asciichat_error_t | generate_key_fingerprint (const public_key_t *key, uint8_t *fingerprint_out, size_t fingerprint_size) |
| Generate key fingerprint. | |
SSH Key Parsing | |
| asciichat_error_t | parse_ssh_ed25519_line (const char *line, uint8_t ed25519_pk[32]) |
| Parse SSH Ed25519 public key from "ssh-ed25519 AAAAC3..." format. | |
| asciichat_error_t | parse_ssh_private_key (const char *key_path, private_key_t *key_out) |
| Parse SSH Ed25519 private key from file. | |
Key Conversion | |
| asciichat_error_t | ed25519_to_x25519_public (const uint8_t ed25519_pk[32], uint8_t x25519_pk[32]) |
| Convert Ed25519 public key to X25519 for key exchange. | |
| asciichat_error_t | ed25519_to_x25519_private (const uint8_t ed25519_sk[64], uint8_t x25519_sk[32]) |
| Convert Ed25519 private key to X25519 for key exchange. | |
🔑 SSH key, GPG key, and key validation APIs
SSH key, GPG key, and key validation APIs.
This module handles GPG key parsing, validation, and conversion to X25519 for key exchange operations.
This module handles fetching SSH and GPG keys from GitHub and GitLab using HTTPS requests with BearSSL for secure communication.
This header contains the core key type definitions that can be shared between the main keys.h and the specialized key modules without circular dependencies.
All keys in this system are 32 bytes - Ed25519, X25519, and GPG-derived keys. This fixed size simplifies protocol design and key management.
This header provides a unified interface for parsing SSH, GPG, and X25519 keys from various sources including files, URLs, and raw formats.
Supported input formats:
This module provides comprehensive key validation, security checks, and format verification for all supported key types.
This module handles SSH Ed25519 key parsing, validation, and conversion to X25519 for key exchange operations.
The Keys Module module provides comprehensive support for parsing, validating, and managing cryptographic keys from multiple sources and formats. It serves as the foundation for secure authentication and key exchange in ascii-chat.
Implementation: lib/crypto/keys/
Key Features:
Format: OpenSSH Ed25519 public and private keys
Public Key Format:
Private Key Format:
Supported Operations:
Example:
Format: OpenPGP armored format (PEM-style)
Key Format:
Supported Operations:
gpg --list-keys and keygripgpg --verify for deterministic Ed25519Requirements:
gpg binary must be in PATHExample:
Format: 64 hex characters or base64-encoded 32-byte key
Supported Formats:
1234567890abcdef... (64 hex chars for 32 bytes)Example:
Keys can be loaded from local files:
Public Keys:
Private Keys:
Keys can be fetched directly from GitHub or GitLab using HTTPS:
SSH Keys:
GPG Keys:
GitLab Support:
Unified Parsing:
The parse_public_key() function supports multiple input formats automatically:
All public keys are validated before use:
Validation Checks:
Private keys are validated similarly:
Validation Checks:
Private key files are checked for appropriate permissions:
Permission Recommendations:
Ed25519 keys are converted to X25519 format for Diffie-Hellman key exchange:
Public Key Conversion:
Private Key Conversion:
Conversion Details:
Lower-level conversion functions are also available:
Messages can be signed with Ed25519 private keys:
SSH Agent Support:
Signatures can be verified with Ed25519 public keys:
Security Features:
The key management module is organized into specialized submodules:
Core Modules:
keys.h: Unified key parsing interfacetypes.h: Key type definitions and structuresvalidation.h: Key validation and security functionsFormat-Specific Modules:
ssh_keys.h: SSH Ed25519 key parsinggpg_keys.h: GPG key parsing (may be disabled)https_keys.h: HTTPS key fetching from GitHub/GitLabSupport Modules:
pem_utils.h: PEM encoding/decoding utilitieshttp_client.h: BearSSL HTTPS client for key fetchingPublic Key Structure:
Private Key Structure:
Loading from file (recommended):
Loading from array:
// Verify incoming client signatures against whitelist bool is_authorized = false; for (size_t i = 0; i < num_authorized; i++) { if (ed25519_verify_signature( client_keys[i].key, // .key field (32 bytes), not .data challenge, sizeof(challenge), signature ) == ASCIICHAT_OK) { is_authorized = true; break; } }
Private Keys:
Public Keys:
In-Memory Keys:
sodium_memzero() for secure memory clearingSSH Agent:
GPG Agent:
Always Validate Keys:
Zero Key Detection:
Currently Supported:
Not Supported:
Rationale:
Current Status:
Workaround:
Unified Key Parsing:
Key Validation:
Key Conversion:
Signing and Verification:
HTTPS Key Fetching:
| typedef struct crypto_handshake_context_t crypto_handshake_context_t |
| enum key_type_t |
#include <key_types.h>
Key type enumeration.
Represents the type of cryptographic key being used. All keys are ultimately converted to X25519 for key exchange.
Definition at line 50 of file key_types.h.
| asciichat_error_t build_github_gpg_url | ( | const char * | username, |
| char * | url_out, | ||
| size_t | url_size | ||
| ) |
#include <https_keys.h>
Construct GitHub GPG keys URL.
| username | GitHub username (must not be NULL) |
| url_out | Output buffer for URL (must not be NULL) |
| url_size | Size of URL buffer (must be >= 64) |
Constructs GitHub GPG keys URL: https://github.com/username.gpg
Definition at line 116 of file https_keys.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_STRING, safe_snprintf(), SAFE_STRNCPY, and SET_ERRNO.
Referenced by fetch_github_gpg_keys().
| asciichat_error_t build_github_ssh_url | ( | const char * | username, |
| char * | url_out, | ||
| size_t | url_size | ||
| ) |
#include <https_keys.h>
Construct GitHub SSH keys URL.
| username | GitHub username (must not be NULL) |
| url_out | Output buffer for URL (must not be NULL) |
| url_size | Size of URL buffer (must be >= 64) |
Constructs GitHub SSH keys URL: https://github.com/username.keys
Definition at line 74 of file https_keys.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_STRING, safe_snprintf(), and SET_ERRNO.
Referenced by fetch_github_ssh_keys().
| asciichat_error_t build_gitlab_gpg_url | ( | const char * | username, |
| char * | url_out, | ||
| size_t | url_size | ||
| ) |
#include <https_keys.h>
Construct GitLab GPG keys URL.
| username | GitLab username (must not be NULL) |
| url_out | Output buffer for URL (must not be NULL) |
| url_size | Size of URL buffer (must be >= 64) |
Constructs GitLab GPG keys URL: https://gitlab.com/username.gpg
Definition at line 145 of file https_keys.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_STRING, safe_snprintf(), SAFE_STRNCPY, and SET_ERRNO.
Referenced by fetch_gitlab_gpg_keys().
| asciichat_error_t build_gitlab_ssh_url | ( | const char * | username, |
| char * | url_out, | ||
| size_t | url_size | ||
| ) |
#include <https_keys.h>
Construct GitLab SSH keys URL.
| username | GitLab username (must not be NULL) |
| url_out | Output buffer for URL (must not be NULL) |
| url_size | Size of URL buffer (must be >= 64) |
Constructs GitLab SSH keys URL: https://gitlab.com/username.keys
Definition at line 95 of file https_keys.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_STRING, safe_snprintf(), and SET_ERRNO.
Referenced by fetch_gitlab_ssh_keys().
| asciichat_error_t check_gpg_key_expiry | ( | const char * | gpg_key_text, |
| bool * | is_expired | ||
| ) |
#include <gpg_keys.h>
Check if GPG key is expired.
| gpg_key_text | GPG key in armored format (must not be NULL) |
| is_expired | Output: true if key is expired, false otherwise (must not be NULL) |
Checks if GPG key has expired by parsing expiration date from key structure.
Definition at line 164 of file gpg_keys.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, log_debug, log_error, log_warn, SAFE_PCLOSE, SAFE_POPEN, safe_snprintf(), and SET_ERRNO.
| asciichat_error_t check_key_expiry | ( | const public_key_t * | key, |
| bool * | is_expired | ||
| ) |
#include <keys_validation.h>
Check if a key is expired.
| key | Key to check (must not be NULL) |
| is_expired | Output: true if expired, false otherwise (must not be NULL) |
Checks if key has expired by parsing expiration date from key structure.
Definition at line 110 of file keys_validation.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, and SET_ERRNO.
| asciichat_error_t check_key_fingerprint | ( | const public_key_t * | key, |
| const uint8_t * | fingerprint, | ||
| size_t | fingerprint_len, | ||
| bool * | matches | ||
| ) |
#include <keys_validation.h>
Check if key matches a fingerprint.
| key | Key to check (must not be NULL) |
| fingerprint | Fingerprint to match against (must not be NULL) |
| fingerprint_len | Length of fingerprint (must be > 0) |
| matches | Output: true if fingerprint matches, false otherwise (must not be NULL) |
Checks if key matches a fingerprint by computing key fingerprint and comparing.
Definition at line 435 of file keys_validation.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, generate_key_fingerprint(), and SET_ERRNO.
| asciichat_error_t check_key_patterns | ( | const public_key_t * | key, |
| bool * | has_weak_patterns | ||
| ) |
#include <keys_validation.h>
Check for key reuse or weak patterns.
| key | Key to check (must not be NULL) |
| has_weak_patterns | Output: true if weak patterns found, false otherwise (must not be NULL) |
Checks key for weak patterns that could indicate security vulnerabilities. Detects keys with predictable or weak patterns.
Definition at line 320 of file keys_validation.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, public_key_t::key, and SET_ERRNO.
| asciichat_error_t check_key_strength | ( | const public_key_t * | key, |
| bool * | is_weak | ||
| ) |
#include <keys_validation.h>
Check if key has weak parameters.
| key | Key to check (must not be NULL) |
| is_weak | Output: true if weak, false otherwise (must not be NULL) |
Checks if key has weak cryptographic parameters. Detects keys with weak entropy or predictable patterns.
Definition at line 247 of file keys_validation.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, public_key_t::key, and SET_ERRNO.
| asciichat_error_t compare_public_keys | ( | const public_key_t * | key1, |
| const public_key_t * | key2, | ||
| bool * | are_equal | ||
| ) |
#include <keys_validation.h>
Compare two public keys for equality.
| key1 | First key to compare (must not be NULL) |
| key2 | Second key to compare (must not be NULL) |
| are_equal | Output: true if keys are equal, false otherwise (must not be NULL) |
Compares two public keys for equality using constant-time comparison. Compares key type and key data.
Definition at line 414 of file keys_validation.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, public_key_t::key, SET_ERRNO, and public_key_t::type.
| asciichat_error_t ed25519_sign_message | ( | const private_key_t * | key, |
| const uint8_t * | message, | ||
| size_t | message_len, | ||
| uint8_t | signature[64] | ||
| ) |
#include <keys.h>
Sign a message with Ed25519 (uses SSH agent if available, otherwise in-memory key)
Sign a message with Ed25519 private key.
| key | Private key for signing (must not be NULL) |
| message | Message to sign (must not be NULL) |
| message_len | Length of message to sign |
| signature | Output buffer for Ed25519 signature (64 bytes) |
Signs a message using Ed25519. This is the main signing function that abstracts SSH agent vs in-memory signing.
Setting use_gpg_agent=true will not work until GPG support is re-enabled.
exists but will not work until GPG support is re-enabled.
| key | Ed25519 private key (must not be NULL) |
| message | Message to sign (must not be NULL) |
| message_len | Length of message to sign |
| signature | Output buffer for Ed25519 signature (64 bytes, must not be NULL) |
Signs a message using Ed25519. Uses SSH agent if available, otherwise in-memory key.
Definition at line 1067 of file ssh_keys.c.
References ASCIICHAT_OK, private_key_t::ed25519, ERROR_CRYPTO, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, gpg_agent_connect(), gpg_agent_disconnect(), gpg_agent_sign(), private_key_t::gpg_keygrip, gpg_sign_detached_ed25519(), public_key_t::key, private_key_t::key, private_key_t::key_comment, KEY_TYPE_ED25519, log_debug, log_info, private_key_t::public_key, SET_ERRNO, ssh_agent_sign(), public_key_t::type, private_key_t::type, private_key_t::use_gpg_agent, and private_key_t::use_ssh_agent.
Referenced by crypto_handshake_client_key_exchange(), and crypto_handshake_server_start().
| asciichat_error_t ed25519_to_x25519_private | ( | const uint8_t | ed25519_sk[64], |
| uint8_t | x25519_sk[32] | ||
| ) |
#include <ssh_keys.h>
Convert Ed25519 private key to X25519 for key exchange.
| ed25519_sk | Ed25519 private key (64 bytes: seed + public, must not be NULL) |
| x25519_sk | Output buffer for X25519 private key (32 bytes, must not be NULL) |
Converts Ed25519 private key to X25519 format for Diffie-Hellman key exchange. Uses libsodium's conversion function.
Definition at line 1050 of file ssh_keys.c.
References ASCIICHAT_OK, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, and SET_ERRNO.
Referenced by private_key_to_x25519().
| asciichat_error_t ed25519_to_x25519_public | ( | const uint8_t | ed25519_pk[32], |
| uint8_t | x25519_pk[32] | ||
| ) |
#include <ssh_keys.h>
Convert Ed25519 public key to X25519 for key exchange.
| ed25519_pk | Ed25519 public key (32 bytes, must not be NULL) |
| x25519_pk | Output buffer for X25519 public key (32 bytes, must not be NULL) |
Converts Ed25519 public key to X25519 format for Diffie-Hellman key exchange. Uses libsodium's conversion function.
Definition at line 1037 of file ssh_keys.c.
References ASCIICHAT_OK, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, and SET_ERRNO.
Referenced by public_key_to_x25519().
| asciichat_error_t ed25519_verify_signature | ( | const uint8_t | public_key[32], |
| const uint8_t * | message, | ||
| size_t | message_len, | ||
| const uint8_t | signature[64], | ||
| const char * | gpg_key_id | ||
| ) |
#include <keys.h>
Verify an Ed25519 signature.
| public_key | Ed25519 public key (32 bytes) |
| message | Message that was signed (must not be NULL) |
| message_len | Length of message that was signed |
| signature | Ed25519 signature to verify (64 bytes) |
Verifies an Ed25519 signature using libsodium's verification function.
| public_key | Ed25519 public key (32 bytes, must not be NULL) |
| message | Message that was signed (must not be NULL) |
| message_len | Length of message that was signed |
| signature | Ed25519 signature to verify (64 bytes, must not be NULL) |
Verifies an Ed25519 signature using libsodium's verification function.
Definition at line 1163 of file ssh_keys.c.
References ASCIICHAT_OK, ERROR_CRYPTO, ERROR_INVALID_PARAM, gpg_verify_detached_ed25519(), log_debug, platform_getenv(), and SET_ERRNO.
Referenced by crypto_handshake_client_key_exchange(), crypto_handshake_server_auth_challenge(), and crypto_handshake_server_complete().
| asciichat_error_t extract_ed25519_from_gpg | ( | const char * | gpg_key_text, |
| uint8_t | ed25519_pk[32] | ||
| ) |
#include <gpg_keys.h>
Extract Ed25519 public key from GPG key.
| gpg_key_text | GPG key in armored format (must not be NULL) |
| ed25519_pk | Output buffer for Ed25519 public key (32 bytes, must not be NULL) |
Extracts Ed25519 public key from GPG key by parsing OpenPGP packet structure.
Definition at line 95 of file gpg_keys.c.
References ASCIICHAT_OK, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, gpg_get_public_key(), and SET_ERRNO.
Referenced by gpg_to_x25519_public(), and parse_gpg_key().
| asciichat_error_t extract_gpg_key_comment | ( | const char * | gpg_key_text, |
| char * | comment_out, | ||
| size_t | comment_size | ||
| ) |
#include <gpg_keys.h>
Extract key comment/email from GPG key.
| gpg_key_text | GPG key in armored format (must not be NULL) |
| comment_out | Output buffer for comment (must not be NULL) |
| comment_size | Size of comment buffer (must be > 0) |
Extracts comment/email from GPG key by parsing user ID packet.
Definition at line 303 of file gpg_keys.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, SAFE_STRNCPY, and SET_ERRNO.
| asciichat_error_t fetch_github_gpg_keys | ( | const char * | username, |
| char *** | keys_out, | ||
| size_t * | num_keys | ||
| ) |
#include <https_keys.h>
Fetch GPG keys from GitHub using HTTPS.
Fetch GPG keys from GitHub using BearSSL.
| username | GitHub username (must not be NULL) |
| keys_out | Output array of GPG key strings (caller must free each string and array) |
| num_keys | Output parameter for number of keys fetched |
Fetches GPG keys from GitHub: GET https://github.com/username.gpg
| username | GitHub username (must not be NULL) |
| keys_out | Output array of GPG key strings (caller must free each string and array) |
| num_keys | Output parameter for number of GPG keys fetched |
Fetches GPG keys from GitHub: GET https://github.com/username.gpg
Definition at line 242 of file https_keys.c.
References ASCIICHAT_OK, build_github_gpg_url(), ERROR_INVALID_PARAM, MAX_CLIENTS, parse_gpg_keys_from_response(), SAFE_FREE, and SET_ERRNO.
Referenced by fetch_github_keys(), and parse_public_keys().
| asciichat_error_t fetch_github_keys | ( | const char * | username, |
| char *** | keys_out, | ||
| size_t * | num_keys, | ||
| bool | use_gpg | ||
| ) |
#include <keys.h>
Fetch SSH/GPG keys from GitHub using BearSSL.
| username | GitHub username (must not be NULL) |
| keys_out | Output array of key strings (caller must free each string and array) |
| num_keys | Output parameter for number of keys fetched |
| use_gpg | True to fetch GPG keys, false to fetch SSH keys |
Fetches keys from GitHub:
c for (size_t i = 0; i < num_keys; i++) { free(keys_out[i]); } free(keys_out); Definition at line 315 of file keys.c.
References ERROR_INVALID_PARAM, fetch_github_gpg_keys(), fetch_github_ssh_keys(), and SET_ERRNO.
| asciichat_error_t fetch_github_ssh_keys | ( | const char * | username, |
| char *** | keys_out, | ||
| size_t * | num_keys | ||
| ) |
#include <https_keys.h>
Fetch SSH keys from GitHub using HTTPS.
| username | GitHub username (must not be NULL) |
| keys_out | Output array of SSH key strings (caller must free each string and array) |
| num_keys | Output parameter for number of keys fetched |
Fetches SSH keys from GitHub: GET https://github.com/username.keys
c for (size_t i = 0; i < num_keys; i++) { free(keys_out[i]); } free(keys_out); Definition at line 178 of file https_keys.c.
References ASCIICHAT_OK, build_github_ssh_url(), ERROR_INVALID_PARAM, MAX_CLIENTS, parse_ssh_keys_from_response(), SAFE_FREE, and SET_ERRNO.
Referenced by fetch_github_keys(), and parse_public_keys().
| asciichat_error_t fetch_gitlab_gpg_keys | ( | const char * | username, |
| char *** | keys_out, | ||
| size_t * | num_keys | ||
| ) |
#include <https_keys.h>
Fetch GPG keys from GitLab using HTTPS.
Fetch GPG keys from GitLab using BearSSL.
| username | GitLab username (must not be NULL) |
| keys_out | Output array of GPG key strings (caller must free each string and array) |
| num_keys | Output parameter for number of keys fetched |
Fetches GPG keys from GitLab: GET https://gitlab.com/username.gpg
| username | GitLab username (must not be NULL) |
| keys_out | Output array of GPG key strings (caller must free each string and array) |
| num_keys | Output parameter for number of GPG keys fetched |
Fetches GPG keys from GitLab: GET https://gitlab.com/username.gpg
Definition at line 274 of file https_keys.c.
References ASCIICHAT_OK, build_gitlab_gpg_url(), ERROR_INVALID_PARAM, MAX_CLIENTS, parse_gpg_keys_from_response(), SAFE_FREE, and SET_ERRNO.
Referenced by fetch_gitlab_keys(), and parse_public_keys().
| asciichat_error_t fetch_gitlab_keys | ( | const char * | username, |
| char *** | keys_out, | ||
| size_t * | num_keys, | ||
| bool | use_gpg | ||
| ) |
#include <keys.h>
Fetch SSH/GPG keys from GitLab using BearSSL.
| username | GitLab username (must not be NULL) |
| keys_out | Output array of key strings (caller must free each string and array) |
| num_keys | Output parameter for number of keys fetched |
| use_gpg | True to fetch GPG keys, false to fetch SSH keys |
Fetches keys from GitLab:
Definition at line 327 of file keys.c.
References ERROR_INVALID_PARAM, fetch_gitlab_gpg_keys(), fetch_gitlab_ssh_keys(), and SET_ERRNO.
| asciichat_error_t fetch_gitlab_ssh_keys | ( | const char * | username, |
| char *** | keys_out, | ||
| size_t * | num_keys | ||
| ) |
#include <https_keys.h>
Fetch SSH keys from GitLab using HTTPS.
| username | GitLab username (must not be NULL) |
| keys_out | Output array of SSH key strings (caller must free each string and array) |
| num_keys | Output parameter for number of keys fetched |
Fetches SSH keys from GitLab: GET https://gitlab.com/username.keys
Definition at line 210 of file https_keys.c.
References ASCIICHAT_OK, build_gitlab_ssh_url(), ERROR_INVALID_PARAM, MAX_CLIENTS, parse_ssh_keys_from_response(), SAFE_FREE, and SET_ERRNO.
Referenced by fetch_gitlab_keys(), and parse_public_keys().
| asciichat_error_t format_gpg_key_display | ( | const char * | gpg_key_text, |
| char * | output, | ||
| size_t | output_size | ||
| ) |
#include <gpg_keys.h>
Format GPG key for display.
| gpg_key_text | GPG key in armored format (must not be NULL) |
| output | Output buffer for formatted key (must not be NULL) |
| output_size | Size of output buffer (must be >= 64) |
Formats GPG key for display by extracting key ID and creating display string.
Definition at line 266 of file gpg_keys.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_STRING, get_gpg_key_id(), safe_snprintf(), SAFE_STRNCPY, and SET_ERRNO.
| void format_public_key | ( | const public_key_t * | key, |
| char * | output, | ||
| size_t | output_size | ||
| ) |
#include <keys.h>
Convert public key to display format (ssh-ed25519 or x25519 hex)
| key | Public key to format (must not be NULL) |
| output | Output buffer for formatted key string (must not be NULL) |
| output_size | Size of output buffer (must be large enough for formatted key) |
Formats public key for display:
Definition at line 387 of file keys.c.
References public_key_t::comment, public_key_t::key, KEY_TYPE_ED25519, KEY_TYPE_X25519, safe_snprintf(), and public_key_t::type.
| asciichat_error_t generate_key_fingerprint | ( | const public_key_t * | key, |
| uint8_t * | fingerprint_out, | ||
| size_t | fingerprint_size | ||
| ) |
#include <keys_validation.h>
Generate key fingerprint.
| key | Key to fingerprint (must not be NULL) |
| fingerprint_out | Output buffer for fingerprint (must not be NULL) |
| fingerprint_size | Size of fingerprint buffer (must be >= 32 for SHA-256) |
Generates key fingerprint by computing hash of key material. Typically uses SHA-256 for fingerprint generation.
Definition at line 460 of file keys_validation.c.
References ASCIICHAT_OK, ERROR_CRYPTO, ERROR_INVALID_PARAM, public_key_t::key, and SET_ERRNO.
Referenced by check_key_fingerprint().
| asciichat_error_t get_gpg_fingerprint | ( | const char * | gpg_key_text, |
| uint8_t | fingerprint_out[20] | ||
| ) |
#include <gpg_keys.h>
Get GPG key fingerprint.
| gpg_key_text | GPG key in armored format (must not be NULL) |
| fingerprint_out | Output buffer for fingerprint (20 bytes for SHA-1, must not be NULL) |
Extracts GPG key fingerprint (SHA-1 hash of key material). Used for key identification and verification.
Definition at line 137 of file gpg_keys.c.
References ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, and SET_ERRNO.
| asciichat_error_t get_gpg_key_id | ( | const char * | gpg_key_text, |
| uint8_t | key_id_out[8] | ||
| ) |
#include <gpg_keys.h>
Get GPG key ID (short fingerprint)
| gpg_key_text | GPG key in armored format (must not be NULL) |
| key_id_out | Output buffer for key ID (8 bytes, must not be NULL) |
Extracts GPG key ID (last 8 bytes of SHA-1 fingerprint). Used for key identification in short form.
Definition at line 151 of file gpg_keys.c.
References ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, and SET_ERRNO.
Referenced by format_gpg_key_display().
| asciichat_error_t gpg_to_x25519_public | ( | const char * | gpg_key_text, |
| uint8_t | x25519_pk[32] | ||
| ) |
#include <gpg_keys.h>
Convert GPG key to X25519 for key exchange.
| gpg_key_text | GPG key in armored format (must not be NULL) |
| x25519_pk | Output buffer for X25519 public key (32 bytes, must not be NULL) |
Converts GPG key to X25519 format for Diffie-Hellman key exchange. Extracts Ed25519 key and converts to X25519.
Definition at line 111 of file gpg_keys.c.
References ASCIICHAT_OK, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, extract_ed25519_from_gpg(), and SET_ERRNO.
| asciichat_error_t hex_decode | ( | const char * | hex, |
| uint8_t * | output, | ||
| size_t | output_len | ||
| ) |
#include <keys.h>
Decode hex string to binary (utility function for testing)
| hex | Hex string to decode (must not be NULL, must have even length) |
| output | Output buffer for binary data (must not be NULL) |
| output_len | Expected output length in bytes (hex string must be output_len * 2 chars) |
Decodes hex string to binary data. Utility function primarily for testing.
Definition at line 425 of file keys.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, and SET_ERRNO.
Referenced by parse_public_key().
| asciichat_error_t parse_gpg_key | ( | const char * | gpg_key_text, |
| public_key_t * | key_out | ||
| ) |
#include <gpg_keys.h>
Parse GPG key from armored text format.
Parse Ed25519 public key from PGP armored format.
| gpg_key_text | GPG key in armored format (--—BEGIN PGP PUBLIC KEY BLOCK--—, must not be NULL) |
| key_out | Output structure for parsed public key (must not be NULL) |
Parses GPG key from armored format and extracts Ed25519 public key. Converts to X25519 for key exchange.
| gpg_key_text | GPG key in armored format (must not be NULL) |
| key_out | Output structure for parsed public key (must not be NULL) |
Extracts Ed25519 public key from PGP armored format. Parses GPG key structure and converts to Ed25519/X25519 format.
Definition at line 32 of file gpg_keys.c.
References ASCIICHAT_OK, public_key_t::comment, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, extract_ed25519_from_gpg(), public_key_t::key, KEY_TYPE_GPG, safe_snprintf(), SET_ERRNO, and public_key_t::type.
Referenced by parse_public_key().
| asciichat_error_t parse_gpg_key_binary | ( | const uint8_t * | gpg_key_binary, |
| size_t | key_size, | ||
| public_key_t * | key_out | ||
| ) |
#include <gpg_keys.h>
Parse GPG key from binary format.
| gpg_key_binary | GPG key in binary format (must not be NULL) |
| key_size | Size of binary key data (must be > 0) |
| key_out | Output structure for parsed public key (must not be NULL) |
Parses GPG key from binary format (raw OpenPGP packets). Extracts Ed25519 public key and converts to X25519.
Definition at line 78 of file gpg_keys.c.
References ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, and SET_ERRNO.
| asciichat_error_t parse_gpg_keys_from_response | ( | const char * | response_text, |
| size_t | response_len, | ||
| char *** | keys_out, | ||
| size_t * | num_keys, | ||
| size_t | max_keys | ||
| ) |
#include <https_keys.h>
Parse GPG keys from HTTPS response text.
| response_text | HTTPS response containing GPG keys (must not be NULL) |
| response_len | Length of response text |
| keys_out | Output array of parsed GPG keys (must not be NULL) |
| num_keys | Output parameter for number of keys parsed (must not be NULL) |
| max_keys | Maximum number of keys to parse (must be > 0) |
Parses GPG keys from HTTPS response text (armored format). Extracts GPG key blocks and allocates memory for each key string.
Definition at line 408 of file https_keys.c.
References ASCIICHAT_OK, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, ERROR_MEMORY, log_debug, log_warn, SAFE_FREE, SAFE_MALLOC, SAFE_STRNCPY, and SET_ERRNO.
Referenced by fetch_github_gpg_keys(), and fetch_gitlab_gpg_keys().
| asciichat_error_t parse_keys_from_file | ( | const char * | path, |
| public_key_t * | keys, | ||
| size_t * | num_keys, | ||
| size_t | max_keys | ||
| ) |
#include <keys.h>
Parse SSH keys from file (supports authorized_keys and known_hosts formats)
| path | Path to key file (must not be NULL) |
| keys | Output array for parsed public keys (must not be NULL) |
| num_keys | Output parameter for number of keys parsed (must not be NULL) |
| max_keys | Maximum number of keys to parse (must be > 0) |
Parses multiple SSH keys from file. Supports:
ssh-ed25519 AAAAC3... comment format). This format is similar to authorized_keys and can contain any number of keys.File format examples:
authorized_keys format (one key per line) and known_hosts format. Also supports .pub files containing multiple key entries (one per line).Definition at line 343 of file keys.c.
References ASCIICHAT_OK, BUFFER_SIZE_LARGE, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, parse_public_key(), path_looks_like_path(), PATH_ROLE_CLIENT_KEYS, path_validate_user_path(), platform_fopen(), SAFE_FREE, and SET_ERRNO.
Referenced by parse_public_keys().
| asciichat_error_t parse_private_key | ( | const char * | path, |
| private_key_t * | key_out | ||
| ) |
#include <keys.h>
Parse SSH private key from file.
| path | Path to private key file |
| key_out | Output structure for parsed private key (must not be NULL) |
Parses private key from file. Supports:
Definition at line 108 of file keys.c.
References ASCIICHAT_OK, private_key_t::ed25519, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, gpg_get_public_key(), private_key_t::gpg_keygrip, private_key_t::key, private_key_t::key_comment, KEY_TYPE_ED25519, log_info, parse_ssh_private_key(), PATH_ROLE_KEY_PRIVATE, path_validate_user_path(), platform_strncpy(), private_key_t::public_key, SAFE_FREE, safe_snprintf(), SET_ERRNO, private_key_t::type, private_key_t::use_gpg_agent, and private_key_t::use_ssh_agent.
Referenced by client_crypto_init().
| asciichat_error_t parse_public_key | ( | const char * | input, |
| public_key_t * | key_out | ||
| ) |
#include <keys.h>
Parse SSH/GPG public key from any format (returns first key only)
| input | Key input in various formats (see below) |
| key_out | Output structure for parsed public key (must not be NULL) |
Parses public key from various input formats:
Supported formats:
gpg --export KEYID).pub file or any file containing key (reads first line)File support: When a file path is provided, the file is read and the first line is parsed as an SSH public key. Common formats:
.pub file: Standard SSH public key file (one key per file, reads first line)gpg binary in PATH and gpg-agent running.parse_public_keys() instead.parse_keys_from_file() instead.Definition at line 24 of file keys.c.
References ASCIICHAT_OK, BUFFER_SIZE_LARGE, public_key_t::comment, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, hex_decode(), public_key_t::key, KEY_TYPE_ED25519, KEY_TYPE_X25519, parse_gpg_key(), parse_public_key(), parse_public_keys(), parse_ssh_ed25519_line(), path_looks_like_path(), PATH_ROLE_KEY_PUBLIC, path_validate_user_path(), platform_fopen(), platform_strncpy(), SAFE_FREE, SET_ERRNO, and public_key_t::type.
Referenced by check_known_host(), parse_keys_from_file(), parse_public_key(), and parse_public_keys().
| asciichat_error_t parse_public_keys | ( | const char * | input, |
| public_key_t * | keys_out, | ||
| size_t * | num_keys, | ||
| size_t | max_keys | ||
| ) |
#include <keys.h>
Parse all SSH/GPG public keys from any format (returns all keys)
| input | Key input in various formats (see parse_public_key for supported formats) |
| keys_out | Output array for parsed public keys (must not be NULL) |
| num_keys | Output parameter for number of keys parsed (must not be NULL) |
| max_keys | Maximum number of keys to parse (must be > 0) |
Similar to parse_public_key(), but returns ALL keys for formats that support multiple keys:
Multiple key support:
Single key formats (behaves like parse_public_key):
This function is useful when you need to verify against ANY of a user's keys, such as when a user has multiple SSH keys for different machines on their GitHub/GitLab account.
Definition at line 187 of file keys.c.
References ASCIICHAT_OK, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, fetch_github_gpg_keys(), fetch_github_ssh_keys(), fetch_gitlab_gpg_keys(), fetch_gitlab_ssh_keys(), log_info, parse_keys_from_file(), parse_public_key(), path_looks_like_path(), SAFE_FREE, and SET_ERRNO.
Referenced by crypto_handshake_client_key_exchange(), and parse_public_key().
| asciichat_error_t parse_ssh_ed25519_line | ( | const char * | line, |
| uint8_t | ed25519_pk[32] | ||
| ) |
#include <ssh_keys.h>
Parse SSH Ed25519 public key from "ssh-ed25519 AAAAC3..." format.
| line | SSH key line to parse (must not be NULL) |
| ed25519_pk | Output buffer for Ed25519 public key (32 bytes, must not be NULL) |
Parses SSH Ed25519 public key from standard SSH public key format. Format: "ssh-ed25519 <base64_key> [comment]"
Definition at line 167 of file ssh_keys.c.
References ASCIICHAT_OK, ED25519_PUBLIC_KEY_SIZE, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, SAFE_FREE, SET_ERRNO, and SSH_KEY_HEADER_SIZE.
Referenced by parse_public_key(), and parse_ssh_private_key().
| asciichat_error_t parse_ssh_keys_from_response | ( | const char * | response_text, |
| size_t | response_len, | ||
| char *** | keys_out, | ||
| size_t * | num_keys, | ||
| size_t | max_keys | ||
| ) |
#include <https_keys.h>
Parse SSH keys from HTTPS response text.
| response_text | HTTPS response containing SSH keys (must not be NULL) |
| response_len | Length of response text |
| keys_out | Output array of parsed SSH keys (must not be NULL) |
| num_keys | Output parameter for number of keys parsed (must not be NULL) |
| max_keys | Maximum number of keys to parse (must be > 0) |
Parses SSH keys from HTTPS response text (one key per line). Extracts Ed25519 keys and allocates memory for each key string.
Definition at line 310 of file https_keys.c.
References ASCIICHAT_OK, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, ERROR_MEMORY, SAFE_FREE, SAFE_MALLOC, and SET_ERRNO.
Referenced by fetch_github_ssh_keys(), and fetch_gitlab_ssh_keys().
| asciichat_error_t parse_ssh_private_key | ( | const char * | key_path, |
| private_key_t * | key_out | ||
| ) |
#include <ssh_keys.h>
Parse SSH Ed25519 private key from file.
| key_path | Path to SSH private key file (must not be NULL) |
| key_out | Output structure for parsed private key (must not be NULL) |
Parses OpenSSH Ed25519 private key from file. Supports both encrypted and unencrypted keys.
Definition at line 218 of file ssh_keys.c.
References ASCIICHAT_OK, BUFFER_SIZE_LARGE, BUFFER_SIZE_SMALL, BUFFER_SIZE_XXLARGE, private_key_t::ed25519, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, ERROR_MEMORY, public_key_t::key, private_key_t::key, private_key_t::key_comment, KEY_TYPE_ED25519, log_debug, log_info, log_warn, parse_ssh_ed25519_line(), platform_fopen(), platform_getenv(), platform_strdup(), prompt_password_simple(), private_key_t::public_key, SAFE_FREE, SAFE_MALLOC, SAFE_REALLOC, safe_snprintf(), SAFE_STRNCPY, SET_ERRNO, ssh_agent_add_key(), ssh_agent_has_key(), public_key_t::type, private_key_t::type, private_key_t::use_ssh_agent, and validate_ssh_key_file().
Referenced by parse_private_key().
| asciichat_error_t private_key_to_x25519 | ( | const private_key_t * | key, |
| uint8_t | x25519_sk[32] | ||
| ) |
#include <keys.h>
Convert private key to X25519 for Diffie-Hellman key exchange.
| key | Private key to convert (must not be NULL) |
| x25519_sk | Output buffer for X25519 private key (32 bytes) |
Converts private key to X25519 format for key exchange:
Definition at line 292 of file keys.c.
References ASCIICHAT_OK, private_key_t::ed25519, ed25519_to_x25519_private(), ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, private_key_t::key, KEY_TYPE_ED25519, KEY_TYPE_X25519, SET_ERRNO, private_key_t::type, and private_key_t::x25519.
| asciichat_error_t public_key_to_x25519 | ( | const public_key_t * | key, |
| uint8_t | x25519_pk[32] | ||
| ) |
#include <keys.h>
Convert public key to X25519 for Diffie-Hellman key exchange.
| key | Public key to convert (must not be NULL) |
| x25519_pk | Output buffer for X25519 public key (32 bytes) |
Converts public key to X25519 format for key exchange:
Definition at line 273 of file keys.c.
References ASCIICHAT_OK, ed25519_to_x25519_public(), ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, public_key_t::key, KEY_TYPE_ED25519, KEY_TYPE_X25519, SET_ERRNO, and public_key_t::type.
| asciichat_error_t validate_gpg_key_format | ( | const char * | gpg_key_text | ) |
#include <gpg_keys.h>
Validate GPG key format and structure.
Validate GPG key format.
| gpg_key_text | GPG key text to validate (must not be NULL) |
Validates GPG key format before parsing. Checks for correct armored format and basic structure.
| key_text | GPG key text to validate (must not be NULL) |
Validates GPG key format by checking for correct armored format markers. Expects "-----BEGIN PGP PUBLIC KEY BLOCK-----" and "-----END PGP PUBLIC KEY BLOCK-----".
Definition at line 176 of file keys_validation.c.
References ASCIICHAT_OK, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, log_warn, and SET_ERRNO.
| asciichat_error_t validate_key_permissions | ( | const char * | key_path | ) |
#include <keys_validation.h>
Validate key file permissions.
| key_path | Path to key file (must not be NULL) |
Validates key file permissions by checking Unix file permissions. Ensures file has restrictive permissions (0600).
Definition at line 297 of file keys_validation.c.
References ASCIICHAT_OK, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, SET_ERRNO, and SSH_KEY_PERMISSIONS_MASK.
Referenced by validate_key_security().
| asciichat_error_t validate_key_security | ( | const char * | key_path | ) |
#include <keys_validation.h>
Validate key permissions and security.
| key_path | Path to key file (must not be NULL) |
Validates key file permissions and performs security checks. Combines permission validation with additional security checks.
Definition at line 123 of file keys_validation.c.
References ASCIICHAT_OK, ERROR_INVALID_PARAM, SET_ERRNO, and validate_key_permissions().
| asciichat_error_t validate_private_key | ( | const private_key_t * | key | ) |
#include <keys_validation.h>
Validate a private key structure.
| key | Private key to validate (must not be NULL) |
Validates private key structure by checking:
Definition at line 67 of file keys_validation.c.
References ASCIICHAT_OK, private_key_t::ed25519, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, private_key_t::key, private_key_t::key_comment, KEY_TYPE_ED25519, KEY_TYPE_UNKNOWN, KEY_TYPE_X25519, MAX_COMMENT_LEN, SET_ERRNO, and private_key_t::type.
| asciichat_error_t validate_public_key | ( | const public_key_t * | key | ) |
#include <keys_validation.h>
Validate a public key structure.
| key | Public key to validate (must not be NULL) |
Validates public key structure by checking:
Definition at line 27 of file keys_validation.c.
References ASCIICHAT_OK, public_key_t::comment, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, public_key_t::key, KEY_TYPE_ED25519, KEY_TYPE_GPG, KEY_TYPE_UNKNOWN, KEY_TYPE_X25519, MAX_COMMENT_LEN, SET_ERRNO, and public_key_t::type.
| asciichat_error_t validate_ssh_key_file | ( | const char * | key_path | ) |
#include <keys.h>
Validate SSH key file before parsing.
Validate SSH key file permissions and format.
| key_path | Path to SSH key file (must not be NULL) |
Validates SSH key file before parsing. Checks:
Definition at line 977 of file ssh_keys.c.
References ASCIICHAT_OK, BUFFER_SIZE_SMALL, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, log_error, path_looks_like_path(), PATH_ROLE_KEY_PRIVATE, path_validate_user_path(), platform_fopen(), SAFE_FREE, SET_ERRNO, and SSH_KEY_PERMISSIONS_MASK.
Referenced by client_crypto_init(), and parse_ssh_private_key().
| asciichat_error_t validate_ssh_key_format | ( | const char * | key_text | ) |
#include <keys_validation.h>
Validate SSH key format.
| key_text | SSH key text to validate (must not be NULL) |
Validates SSH key format by checking for correct format markers. Expects "ssh-ed25519 " prefix followed by base64-encoded key.
Definition at line 146 of file keys_validation.c.
References ASCIICHAT_OK, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, and SET_ERRNO.
| asciichat_error_t validate_x25519_key_format | ( | const char * | key_hex | ) |
#include <keys_validation.h>
Validate X25519 key format.
| key_hex | X25519 key in hex format (must not be NULL) |
Validates X25519 key format by checking hex string format. Expects 64 hex characters (32 bytes).
Definition at line 219 of file keys_validation.c.
References ASCIICHAT_OK, ERROR_CRYPTO_KEY, ERROR_INVALID_PARAM, and SET_ERRNO.
| char public_key_t::comment[256] |
Key comment/label (e.g., "user@hostname")
Definition at line 72 of file key_types.h.
Referenced by client_crypto_init(), crypto_handshake_server_auth_challenge(), crypto_handshake_server_complete(), format_public_key(), parse_gpg_key(), parse_public_key(), and validate_public_key().
| uint8_t private_key_t::ed25519[64] |
Ed25519 seed (32) + public key (32) = 64 bytes
Definition at line 94 of file key_types.h.
Referenced by crypto_sign_ephemeral_key(), ed25519_sign_message(), parse_private_key(), parse_ssh_private_key(), private_key_to_x25519(), ssh_agent_add_key(), and validate_private_key().
| uint8_t { ... } ::ed25519[64] |
Ed25519 seed (32) + public key (32) = 64 bytes
Definition at line 94 of file key_types.h.
| char private_key_t::gpg_keygrip[64] |
GPG keygrip (40 hex chars + null) for gpg-agent signing
Definition at line 101 of file key_types.h.
Referenced by ed25519_sign_message(), and parse_private_key().
| uint8_t public_key_t::key[32] |
Public key data (always 32 bytes)
Definition at line 71 of file key_types.h.
Referenced by check_key_patterns(), check_key_strength(), check_known_host(), client_crypto_init(), compare_public_keys(), crypto_handshake_server_auth_challenge(), crypto_handshake_server_complete(), ed25519_sign_message(), format_public_key(), generate_key_fingerprint(), parse_gpg_key(), parse_public_key(), parse_ssh_private_key(), public_key_to_x25519(), server_crypto_handshake(), ssh_agent_has_key(), ssh_agent_sign(), and validate_public_key().
| union { ... } private_key_t::key |
Private key data (union based on key type)
Referenced by crypto_sign_ephemeral_key(), ed25519_sign_message(), parse_private_key(), parse_ssh_private_key(), private_key_to_x25519(), ssh_agent_add_key(), and validate_private_key().
| char private_key_t::key_comment[256] |
SSH key comment (for agent identification)
Definition at line 100 of file key_types.h.
Referenced by client_crypto_init(), ed25519_sign_message(), parse_private_key(), parse_ssh_private_key(), and validate_private_key().
| uint8_t private_key_t::public_key[32] |
Ed25519 public key (for agent mode or verification)
Definition at line 99 of file key_types.h.
Referenced by client_crypto_init(), crypto_handshake_client_key_exchange(), crypto_handshake_server_start(), ed25519_sign_message(), parse_private_key(), parse_ssh_private_key(), server_crypto_handshake(), and server_main().
| key_type_t public_key_t::type |
Key type (Ed25519, X25519, or GPG)
Definition at line 70 of file key_types.h.
Referenced by client_crypto_handshake(), client_crypto_init(), compare_public_keys(), crypto_handshake_server_auth_challenge(), crypto_handshake_server_complete(), ed25519_sign_message(), format_public_key(), parse_gpg_key(), parse_public_key(), parse_ssh_private_key(), public_key_to_x25519(), server_crypto_handshake(), ssh_agent_sign(), and validate_public_key().
| key_type_t private_key_t::type |
Key type (Ed25519, X25519, or GPG)
Definition at line 92 of file key_types.h.
Referenced by client_crypto_init(), crypto_handshake_client_auth_response(), crypto_handshake_client_key_exchange(), crypto_handshake_server_start(), crypto_sign_ephemeral_key(), ed25519_sign_message(), parse_private_key(), parse_ssh_private_key(), private_key_to_x25519(), server_crypto_handshake(), ssh_agent_add_key(), and validate_private_key().
| bool private_key_t::use_gpg_agent |
If true, use GPG agent for signing (currently disabled)
Definition at line 98 of file key_types.h.
Referenced by ed25519_sign_message(), and parse_private_key().
| bool private_key_t::use_ssh_agent |
If true, use SSH agent for signing (key stays in agent)
Definition at line 97 of file key_types.h.
Referenced by ed25519_sign_message(), parse_private_key(), and parse_ssh_private_key().
| uint8_t private_key_t::x25519[32] |
X25519 private key (32 bytes)
Definition at line 95 of file key_types.h.
Referenced by private_key_to_x25519().
| uint8_t { ... } ::x25519[32] |
X25519 private key (32 bytes)
Definition at line 95 of file key_types.h.