ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
https_keys.c
Go to the documentation of this file.
1
6
7/* Storage capacities in elements; text buffers include the terminating NUL. */
8#define CRYPTO_HTTPS_KEYS_IMPORT_OUTPUT_BUFFER_SIZE 2048
9#define CRYPTO_HTTPS_KEYS_KEY_IDS_COUNT 16
10#define CRYPTO_HTTPS_KEYS_LIST_OUTPUT_BUFFER_SIZE 4096
11
14#include <ascii-chat/common.h>
15#include <recast/defer.h>
18#include <libplatform/process.h>
19#include <libplatform/filesystem.h>
20#include <ascii-chat/util/url.h> // For url_parse()
22#include <string.h>
23#include <stdlib.h>
24#include <stdio.h>
25#ifndef _WIN32
26#include <unistd.h>
27#endif
28#include <fcntl.h>
29
30// =============================================================================
31// Helper Functions
32// =============================================================================
33
38static asciichat_error_t https_fetch_keys(const char *url, char **response_text, size_t *response_len) {
39 if (!url || !response_text || !response_len) {
40 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters");
42 }
43
44 // Parse URL to extract hostname and path
45 url_parts_t url_parts = {0};
46 asciichat_error_t parse_result = url_parse(url, &url_parts);
47 if (parse_result != ASCIICHAT_OK) {
48 return parse_result;
49 }
50
51 // Use https_get from http_client
52 char *response = https_get(url_parts.host, url_parts.path);
53 url_parts_destroy(&url_parts);
54
55 if (!response) {
56 SET_ERRNO(ERROR_NETWORK, "Failed to fetch from %s", url);
57 return ERROR_NETWORK;
58 }
59
60 *response_text = response;
61 *response_len = strlen(response);
62 return ASCIICHAT_OK;
63}
64
65// =============================================================================
66// URL Construction
67// =============================================================================
68
69asciichat_error_t build_github_ssh_url(const char *username, char *url_out, size_t url_size) {
70 if (!username || !url_out) {
71 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters: username=%p, url_out=%p", username, url_out);
73 }
74
75 if (url_size < 64) {
76 SET_ERRNO(ERROR_INVALID_PARAM, "URL buffer too small: %zu (minimum 64)", url_size);
78 }
79
80 // Construct GitHub SSH keys URL: https://github.com/username.keys
81 int result = safe_snprintf(url_out, url_size, "https://github.com/%s.keys", username);
82 if (result < 0 || result >= (int)url_size) {
83 SET_ERRNO(ERROR_STRING, "Failed to construct GitHub SSH URL");
84 return ERROR_STRING;
85 }
86
87 return ASCIICHAT_OK;
88}
89
90asciichat_error_t build_gitlab_ssh_url(const char *username, char *url_out, size_t url_size) {
91 if (!username || !url_out) {
92 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters: username=%p, url_out=%p", username, url_out);
94 }
95
96 if (url_size < 64) {
97 SET_ERRNO(ERROR_INVALID_PARAM, "URL buffer too small: %zu (minimum 64)", url_size);
99 }
100
101 // Construct GitLab SSH keys URL: https://gitlab.com/username.keys
102 int result = safe_snprintf(url_out, url_size, "https://gitlab.com/%s.keys", username);
103 if (result < 0 || result >= (int)url_size) {
104 SET_ERRNO(ERROR_STRING, "Failed to construct GitLab SSH URL");
105 return ERROR_STRING;
106 }
107
108 return ASCIICHAT_OK;
109}
110
111asciichat_error_t build_github_gpg_url(const char *username, char *url_out, size_t url_size) {
112 if (!username || !url_out) {
113 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters: username=%p, url_out=%p", username, url_out);
114 return ERROR_INVALID_PARAM;
115 }
116
117 if (url_size < 64) {
118 SET_ERRNO(ERROR_INVALID_PARAM, "URL buffer too small: %zu (minimum 64)", url_size);
119 return ERROR_INVALID_PARAM;
120 }
121
122 // Strip .gpg suffix if user already included it (e.g., "github:zfogg.gpg")
123 char clean_username[BUFFER_SIZE_SMALL];
124 SAFE_STRNCPY(clean_username, username, sizeof(clean_username) - 1);
125 size_t len = strlen(clean_username);
126 if (len > 4 && strcmp(clean_username + len - 4, ".gpg") == 0) {
127 clean_username[len - 4] = '\0'; // Remove .gpg suffix
128 }
129
130 // Construct GitHub GPG keys URL: https://github.com/username.gpg
131 int result = safe_snprintf(url_out, url_size, "https://github.com/%s.gpg", clean_username);
132 if (result < 0 || result >= (int)url_size) {
133 SET_ERRNO(ERROR_STRING, "Failed to construct GitHub GPG URL");
134 return ERROR_STRING;
135 }
136
137 return ASCIICHAT_OK;
138}
139
140asciichat_error_t build_gitlab_gpg_url(const char *username, char *url_out, size_t url_size) {
141 if (!username || !url_out) {
142 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters: username=%p, url_out=%p", username, url_out);
143 return ERROR_INVALID_PARAM;
144 }
145
146 if (url_size < 64) {
147 SET_ERRNO(ERROR_INVALID_PARAM, "URL buffer too small: %zu (minimum 64)", url_size);
148 return ERROR_INVALID_PARAM;
149 }
150
151 // Strip .gpg suffix if user already included it (e.g., "gitlab:zfogg.gpg")
152 char clean_username[BUFFER_SIZE_SMALL];
153 SAFE_STRNCPY(clean_username, username, sizeof(clean_username) - 1);
154 size_t len = strlen(clean_username);
155 if (len > 4 && strcmp(clean_username + len - 4, ".gpg") == 0) {
156 clean_username[len - 4] = '\0'; // Remove .gpg suffix
157 }
158
159 // Construct GitLab GPG keys URL: https://gitlab.com/username.gpg
160 int result = safe_snprintf(url_out, url_size, "https://gitlab.com/%s.gpg", clean_username);
161 if (result < 0 || result >= (int)url_size) {
162 SET_ERRNO(ERROR_STRING, "Failed to construct GitLab GPG URL");
163 return ERROR_STRING;
164 }
165
166 return ASCIICHAT_OK;
167}
168
169// =============================================================================
170// HTTPS Key Fetching Implementation
171// =============================================================================
172
173asciichat_error_t fetch_github_ssh_keys(const char *username, char ***keys_out, size_t *num_keys) {
174 if (!username || !keys_out || !num_keys) {
175 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters: username=%p, keys_out=%p, num_keys=%p", username, keys_out, num_keys);
176 return ERROR_INVALID_PARAM;
177 }
178
179 // Build the GitHub SSH keys URL
180 char url[BUFFER_SIZE_SMALL];
181 asciichat_error_t url_result = build_github_ssh_url(username, url, sizeof(url));
182 if (url_result != ASCIICHAT_OK) {
183 return url_result;
184 }
185
186 // Fetch the keys using HTTPS
187 char *response_text = NULL;
188 size_t response_len = 0;
189 asciichat_error_t fetch_result = https_fetch_keys(url, &response_text, &response_len);
190 if (fetch_result != ASCIICHAT_OK) {
191 return fetch_result;
192 }
193
194 // Parse SSH keys from the response
195 asciichat_error_t parse_result = parse_ssh_keys_from_response(response_text, response_len, keys_out, num_keys, MAX_CLIENTS);
196
197 // Clean up response text
198 SAFE_FREE(response_text);
199
200 return parse_result;
201}
202
203asciichat_error_t fetch_gitlab_ssh_keys(const char *username, char ***keys_out, size_t *num_keys) {
204 if (!username || !keys_out || !num_keys) {
205 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters: username=%p, keys_out=%p, num_keys=%p", username, keys_out, num_keys);
206 return ERROR_INVALID_PARAM;
207 }
208
209 // Build the GitLab SSH keys URL
210 char url[BUFFER_SIZE_SMALL];
211 asciichat_error_t url_result = build_gitlab_ssh_url(username, url, sizeof(url));
212 if (url_result != ASCIICHAT_OK) {
213 return url_result;
214 }
215
216 // Fetch the keys using HTTPS
217 char *response_text = NULL;
218 size_t response_len = 0;
219 asciichat_error_t fetch_result = https_fetch_keys(url, &response_text, &response_len);
220 if (fetch_result != ASCIICHAT_OK) {
221 return fetch_result;
222 }
223
224 // Parse SSH keys from the response
225 asciichat_error_t parse_result = parse_ssh_keys_from_response(response_text, response_len, keys_out, num_keys, MAX_CLIENTS);
226
227 // Clean up response text
228 SAFE_FREE(response_text);
229
230 return parse_result;
231}
232
233asciichat_error_t fetch_github_gpg_keys(const char *username, char ***keys_out, size_t *num_keys) {
234 if (!username || !keys_out || !num_keys) {
235 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters: username=%p, keys_out=%p, num_keys=%p", username, keys_out, num_keys);
236 return ERROR_INVALID_PARAM;
237 }
238
239 // Build the GitHub GPG keys URL
240 char url[BUFFER_SIZE_SMALL];
241 asciichat_error_t url_result = build_github_gpg_url(username, url, sizeof(url));
242 if (url_result != ASCIICHAT_OK) {
243 return url_result;
244 }
245
246 // Fetch the keys using HTTPS
247 char *response_text = NULL;
248 size_t response_len = 0;
249 asciichat_error_t fetch_result = https_fetch_keys(url, &response_text, &response_len);
250 if (fetch_result != ASCIICHAT_OK) {
251 return fetch_result;
252 }
253
254 // Parse GPG keys from the response
255 asciichat_error_t parse_result = parse_gpg_keys_from_response(response_text, response_len, keys_out, num_keys, MAX_CLIENTS);
256
257 // Clean up response text
258 SAFE_FREE(response_text);
259
260 return parse_result;
261}
262
263asciichat_error_t fetch_gitlab_gpg_keys(const char *username, char ***keys_out, size_t *num_keys) {
264 if (!username || !keys_out || !num_keys) {
265 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters: username=%p, keys_out=%p, num_keys=%p", username, keys_out, num_keys);
266 return ERROR_INVALID_PARAM;
267 }
268
269 // Build the GitLab GPG keys URL
270 char url[BUFFER_SIZE_SMALL];
271 asciichat_error_t url_result = build_gitlab_gpg_url(username, url, sizeof(url));
272 if (url_result != ASCIICHAT_OK) {
273 return url_result;
274 }
275
276 // Fetch the keys using HTTPS
277 char *response_text = NULL;
278 size_t response_len = 0;
279 asciichat_error_t fetch_result = https_fetch_keys(url, &response_text, &response_len);
280 if (fetch_result != ASCIICHAT_OK) {
281 return fetch_result;
282 }
283
284 // Parse GPG keys from the response
285 asciichat_error_t parse_result = parse_gpg_keys_from_response(response_text, response_len, keys_out, num_keys, MAX_CLIENTS);
286
287 // Clean up response text
288 SAFE_FREE(response_text);
289
290 return parse_result;
291}
292
293// =============================================================================
294// Key Parsing from HTTPS Responses
295// =============================================================================
296
297asciichat_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) {
298 if (!response_text || !keys_out || !num_keys) {
299 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters for SSH key parsing");
300 return ERROR_INVALID_PARAM;
301 }
302
303 *num_keys = 0;
304 *keys_out = NULL;
305
306 // Count the number of SSH keys in the response
307 size_t key_count = 0;
308 const char *line_start = response_text;
309 const char *line_end;
310
311 while ((line_end = strchr(line_start, '\n')) != NULL) {
312 size_t line_len = line_end - line_start;
313 if (line_len > 0 && line_start[0] != '\r' && line_start[0] != '\n') {
314 key_count++;
315 }
316 line_start = line_end + 1;
317 }
318
319 // Handle last line if it doesn't end with newline
320 if (line_start < response_text + response_len) {
321 key_count++;
322 }
323
324 if (key_count == 0) {
325 SET_ERRNO(ERROR_CRYPTO_KEY, "No SSH keys found in response");
326 return ERROR_CRYPTO_KEY;
327 }
328
329 if (key_count > max_keys) {
330 key_count = max_keys;
331 }
332
333 // Allocate array for key strings
334 *keys_out = SAFE_MALLOC(sizeof(char *) * key_count, char **);
335 if (!*keys_out) {
336 return SET_ERRNO(ERROR_MEMORY, "Failed to allocate SSH keys array");
337 }
338
339 // Parse each SSH key line
340 line_start = response_text;
341 size_t parsed_keys = 0;
342 defer_named(release_keys, {
343 for (size_t i = 0; i < parsed_keys; i++) {
344 SAFE_FREE((*keys_out)[i]);
345 }
346 SAFE_FREE(*keys_out);
347 *keys_out = NULL;
348 });
349
350 while (parsed_keys < key_count && (line_end = strchr(line_start, '\n')) != NULL) {
351 size_t line_len = line_end - line_start;
352
353 // Skip empty lines
354 if (line_len > 0 && line_start[0] != '\r' && line_start[0] != '\n') {
355 // Allocate space for this key line
356 (*keys_out)[parsed_keys] = SAFE_MALLOC(line_len + 1, char *);
357 if (!(*keys_out)[parsed_keys]) {
358 return SET_ERRNO(ERROR_MEMORY, "Failed to allocate SSH key string");
359 }
360
361 // Copy the key line
362 memcpy((*keys_out)[parsed_keys], line_start, line_len);
363 (*keys_out)[parsed_keys][line_len] = '\0';
364
365 parsed_keys++;
366 }
367
368 line_start = line_end + 1;
369 }
370
371 // Handle last line if it doesn't end with newline
372 if (parsed_keys < key_count && line_start < response_text + response_len) {
373 size_t line_len = (response_text + response_len) - line_start;
374 if (line_len > 0) {
375 (*keys_out)[parsed_keys] = SAFE_MALLOC(line_len + 1, char *);
376 if (!(*keys_out)[parsed_keys]) {
377 return SET_ERRNO(ERROR_MEMORY, "Failed to allocate SSH key string");
378 }
379 memcpy((*keys_out)[parsed_keys], line_start, line_len);
380 (*keys_out)[parsed_keys][line_len] = '\0';
381 parsed_keys++;
382 }
383 }
384
385 *num_keys = parsed_keys;
386 defer_cancel(release_keys);
387 return ASCIICHAT_OK;
388}
389
390asciichat_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) {
391 (void)max_keys;
392 if (!response_text || !keys_out || !num_keys) {
393 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters for GPG key parsing");
394 return ERROR_INVALID_PARAM;
395 }
396
397 *num_keys = 0;
398 *keys_out = NULL;
399
400 // Check if this looks like a GPG key (starts with -----BEGIN PGP)
401 if (strncmp(response_text, "-----BEGIN PGP", 14) != 0) {
402 SET_ERRNO(ERROR_CRYPTO_KEY, "Response does not contain a valid GPG key");
403 return ERROR_CRYPTO_KEY;
404 }
405
406 // Write armored block to temp file
407 char temp_file[PLATFORM_MAX_PATH_LENGTH];
408 int fd = -1;
409 if (platform_create_temp_file(temp_file, sizeof(temp_file), "asc_gpg_import", &fd) != 0) {
410 return SET_ERRNO(ERROR_CRYPTO_KEY, "Failed to create temp file for GPG import");
411 }
412
413#ifdef _WIN32
414 // On Windows, platform_create_temp_file returns fd=-1, need to open separately
415 fd = platform_open("https_key_temp", temp_file, O_WRONLY | O_BINARY);
416 if (fd < 0) {
417 platform_delete_temp_file(temp_file);
418 return SET_ERRNO(ERROR_CRYPTO_KEY, "Failed to open temp file for writing");
419 }
420#endif
421
422 ssize_t written = write(fd, response_text, response_len);
423 close(fd);
424
425 if (written != (ssize_t)response_len) {
426 platform_unlink(temp_file);
427 return SET_ERRNO(ERROR_CRYPTO_KEY, "Failed to write GPG key to temp file");
428 }
429
430 // Import the key using gpg --import
431 char import_cmd[BUFFER_SIZE_MEDIUM];
432 safe_snprintf(import_cmd, sizeof(import_cmd), "gpg --import '%s' 2>&1", temp_file);
433 FILE *import_fp = NULL;
434 if (platform_popen("gpg_https_import", import_cmd, "r", &import_fp) != ASCIICHAT_OK || !import_fp) {
435 platform_unlink(temp_file);
436 return SET_ERRNO(ERROR_CRYPTO_KEY, "Failed to run gpg --import");
437 }
438
440 size_t import_len = fread(import_output, 1, sizeof(import_output) - 1, import_fp);
441 import_output[import_len] = '\0';
442 platform_pclose(&import_fp);
443 platform_unlink(temp_file);
444
445 // Extract ALL key IDs from import output (format: "gpg: key KEYID: ...")
446 // GitHub often returns multiple keys in one armored block
447 const char *key_marker = "gpg: key ";
448 char key_ids[CRYPTO_HTTPS_KEYS_KEY_IDS_COUNT][GPG_KEY_ID_HEX_BUFFER_SIZE]; // Support up to 16 keys
449 size_t key_count = 0;
450
451 log_debug("GPG import output:\n%s", import_output);
452
453 char *search_pos = import_output;
454 while (key_count < 16) {
455 char *key_line = strstr(search_pos, key_marker);
456 if (!key_line)
457 break;
458
459 key_line += strlen(key_marker);
460 int i = 0;
461 while (i < 16 && key_line[i] != ':' && key_line[i] != ' ' && key_line[i] != '\n') {
462 key_ids[key_count][i] = key_line[i];
463 i++;
464 }
465 key_ids[key_count][i] = '\0';
466
467 if (i > 0) {
468 log_debug("Extracted GPG key ID #%zu: %s", key_count, key_ids[key_count]);
469 key_count++;
470 }
471 search_pos = key_line + i;
472 }
473
474 if (key_count == 0) {
475 return SET_ERRNO(ERROR_CRYPTO_KEY, "Failed to extract any key IDs from GPG import output");
476 }
477
478 log_debug("Total GPG keys extracted from import: %zu", key_count);
479
480 // Allocate array for results
481 *keys_out = SAFE_MALLOC(sizeof(char *) * key_count, char **);
482 if (!*keys_out) {
483 return SET_ERRNO(ERROR_MEMORY, "Failed to allocate GPG keys array");
484 }
485
486 // Process each key ID to get full fingerprint
487 size_t valid_keys = 0;
488 defer_named(release_keys, {
489 for (size_t i = 0; i < valid_keys; i++) {
490 SAFE_FREE((*keys_out)[i]);
491 }
492 SAFE_FREE(*keys_out);
493 *keys_out = NULL;
494 });
495 for (size_t k = 0; k < key_count; k++) {
496 // Get full fingerprint from gpg --list-keys output
497 char list_cmd[BUFFER_SIZE_SMALL];
498 safe_snprintf(list_cmd, sizeof(list_cmd), "gpg --list-keys --with-colons --fingerprint '%s' " PLATFORM_SHELL_NULL_REDIRECT, key_ids[k]);
499 FILE *list_fp = NULL;
500 if (platform_popen("gpg_https_list", list_cmd, "r", &list_fp) != ASCIICHAT_OK || !list_fp) {
501 continue; // Skip this key if we can't list it
502 }
503
505 size_t list_len = fread(list_output, 1, sizeof(list_output) - 1, list_fp);
506 list_output[list_len] = '\0';
507 platform_pclose(&list_fp);
508
509 // Check if it contains an Ed25519 key (algorithm 22)
510 if (!strstr(list_output, ":22:") && !strstr(list_output, "ed25519")) {
511 continue; // Skip non-Ed25519 keys
512 }
513
514 // Extract full 40-character fingerprint from "fpr:" line
515 // Format: fpr:::::::::FINGERPRINT:
516 // The fingerprint is field 10 (after 9 colons)
517 char fingerprint[GPG_FINGERPRINT_HEX_BUFFER_SIZE] = {0};
518 const char *fpr_marker = "\nfpr:";
519 char *fpr_line = strstr(list_output, fpr_marker);
520 if (fpr_line) {
521 fpr_line += 1; // Skip the newline
522 // Count 9 colons from the start of the line
523 int colon_count = 0;
524 while (*fpr_line && colon_count < 9) {
525 if (*fpr_line == ':')
526 colon_count++;
527 fpr_line++;
528 }
529 // Now we should be at the start of the fingerprint
530 // Extract up to 40 hex characters
531 int fpr_len = 0;
532 while (fpr_len < 40 && fpr_line[fpr_len] && fpr_line[fpr_len] != ':' && fpr_line[fpr_len] != '\n') {
533 fingerprint[fpr_len] = fpr_line[fpr_len];
534 fpr_len++;
535 }
536 fingerprint[fpr_len] = '\0';
537 }
538
539 // If fingerprint extraction failed, use the short key ID
540 if (strlen(fingerprint) == 0) {
541 log_warn("Failed to extract fingerprint for key %s, using short key ID", key_ids[k]);
542 SAFE_STRNCPY(fingerprint, key_ids[k], sizeof(fingerprint));
543 }
544
545 log_debug("Key %s -> fingerprint: %s (length: %zu)", key_ids[k], fingerprint, strlen(fingerprint));
546
547 // Allocate and store this key in gpg:KEYID format
548 size_t gpg_key_len = strlen("gpg:") + strlen(fingerprint) + 1;
549 (*keys_out)[valid_keys] = SAFE_MALLOC(gpg_key_len, char *);
550 if (!(*keys_out)[valid_keys]) {
551 return SET_ERRNO(ERROR_MEMORY, "Failed to allocate GPG key string");
552 }
553
554 safe_snprintf((*keys_out)[valid_keys], gpg_key_len, "gpg:%s", fingerprint);
555 log_debug("Added valid Ed25519 key #%zu: %s", valid_keys, (*keys_out)[valid_keys]);
556 valid_keys++;
557 }
558
559 if (valid_keys == 0) {
560 return SET_ERRNO(ERROR_CRYPTO_KEY, "No valid Ed25519 keys found in imported GPG keys");
561 }
562
563 *num_keys = valid_keys;
564 defer_cancel(release_keys);
565 return ASCIICHAT_OK;
566}
Synchronized per-thread pending error stacks and value snapshots. SET_ERRNO pushes,...
#define SET_ERRNO(code,...)
int platform_open(const char *name, const char *pathname, int flags,...)
Definition filesystem.c:65
#define BUFFER_SIZE_SMALL
Small buffer size (256 bytes).
#define BUFFER_SIZE_MEDIUM
Medium buffer size (512 bytes).
#define SAFE_STRNCPY(dst, src, size)
#define SAFE_FREE(ptr)
#define SAFE_MALLOC(size, cast)
#define PLATFORM_MAX_PATH_LENGTH
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
@ ERROR_CRYPTO_KEY
Definition error_codes.h:98
@ ERROR_NETWORK
Definition error_codes.h:76
@ ERROR_MEMORY
Definition error_codes.h:55
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_STRING
@ ERROR_INVALID_PARAM
asciichat_error_t build_github_ssh_url(const char *username, char *url_out, size_t url_size)
Construct GitHub SSH keys URL.
Definition https_keys.c:69
asciichat_error_t fetch_gitlab_gpg_keys(const char *username, char ***keys_out, size_t *num_keys)
Fetch GPG keys from GitLab using BearSSL.
Definition https_keys.c:263
asciichat_error_t build_github_gpg_url(const char *username, char *url_out, size_t url_size)
Construct GitHub GPG keys URL.
Definition https_keys.c:111
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.
Definition https_keys.c:297
asciichat_error_t fetch_github_ssh_keys(const char *username, char ***keys_out, size_t *num_keys)
Fetch SSH keys from GitHub using HTTPS.
Definition https_keys.c:173
asciichat_error_t fetch_github_gpg_keys(const char *username, char ***keys_out, size_t *num_keys)
Fetch GPG keys from GitHub using BearSSL.
Definition https_keys.c:233
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.
Definition https_keys.c:390
asciichat_error_t fetch_gitlab_ssh_keys(const char *username, char ***keys_out, size_t *num_keys)
Fetch SSH keys from GitLab using HTTPS.
Definition https_keys.c:203
asciichat_error_t build_gitlab_ssh_url(const char *username, char *url_out, size_t url_size)
Construct GitLab SSH keys URL.
Definition https_keys.c:90
asciichat_error_t build_gitlab_gpg_url(const char *username, char *url_out, size_t url_size)
Construct GitLab GPG keys URL.
Definition https_keys.c:140
#define MAX_CLIENTS
Maximum possible clients (static array size) - actual runtime limit set by –max-clients (1-128).
#define log_warn(...)
Log a WARN message.
Definition log/log.h:615
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:589
char * https_get(const char *hostname, const char *path)
Perform HTTPS GET request.
void url_parts_destroy(url_parts_t *parts)
Free parsed URL components.
Definition url.c:299
asciichat_error_t url_parse(const char *url, url_parts_t *parts_out)
Parse HTTP(S), WebSocket, and TCP URL into components.
Definition url.c:163
#define CRYPTO_HTTPS_KEYS_IMPORT_OUTPUT_BUFFER_SIZE
Definition https_keys.c:8
#define CRYPTO_HTTPS_KEYS_KEY_IDS_COUNT
Definition https_keys.c:9
#define CRYPTO_HTTPS_KEYS_LIST_OUTPUT_BUFFER_SIZE
Definition https_keys.c:10
⚙️ Common definitions, error codes, macros, and types shared throughout the application
Simple HTTPS client for fetching public keys from GitHub/GitLab.
#define GPG_FINGERPRINT_HEX_BUFFER_SIZE
Definition sizes.h:172
#define GPG_KEY_ID_HEX_BUFFER_SIZE
Definition sizes.h:174
int platform_popen(const char *name, const char *command, const char *mode, FILE **out_stream)
int platform_pclose(FILE **stream_ptr)
🔤 String Manipulation and Shell Escaping Utilities
Structure containing parsed URL components.
Definition url.h:69
char * path
Extracted path, query, and fragment (allocated if present, may be NULL).
Definition url.h:75
char * host
Canonical ASCII hostname or IP address (allocated).
Definition url.h:72
🌐 Production-Grade URL Validation and Parsing