From 46ec3184cd1501913e8d43c7119b285ca6ed0cec Mon Sep 17 00:00:00 2001 From: lohhiiccc <96543753+lohhiiccc@users.noreply.github.com> Date: Wed, 10 Jun 2026 02:08:54 +0200 Subject: [PATCH] feat: support multiple -s strings (up to 64) --- includes/ft_ssl.h | 5 ++++- includes/internal/cli/option.h | 22 ++++++++++++++-------- includes/internal/ssl/ssl.h | 2 +- libcli | 2 +- src/cli/handlers/handle_s.c | 4 +++- src/cli/handlers/option_map.c | 6 +++--- src/ssl/run_string.c | 7 +++---- src/ssl_run.c | 6 +++--- 8 files changed, 32 insertions(+), 22 deletions(-) diff --git a/includes/ft_ssl.h b/includes/ft_ssl.h index dc1fc32..2c8b61a 100644 --- a/includes/ft_ssl.h +++ b/includes/ft_ssl.h @@ -5,11 +5,14 @@ #include #include +#define SSL_MAX_STRINGS 64 + struct ssl_config { const struct digest_algo *algo; uint8_t flags; - const char *string; + const char *strings[SSL_MAX_STRINGS]; + int nb_strings; char **files; int nb_files; }; diff --git a/includes/internal/cli/option.h b/includes/internal/cli/option.h index fd626bb..f6c1bc3 100644 --- a/includes/internal/cli/option.h +++ b/includes/internal/cli/option.h @@ -10,7 +10,8 @@ no_argument, \ cli_handle_help, \ OPT_ARG_NONE, \ - "Display this help and exit" \ + "Display this help and exit", \ + 0 \ ) \ X( \ 'V', \ @@ -18,7 +19,8 @@ no_argument, \ cli_handle_version, \ OPT_ARG_NONE, \ - "Display version information and exit" \ + "Display version information and exit", \ + 0 \ ) \ X( \ 'p', \ @@ -26,7 +28,8 @@ no_argument, \ cli_handle_p, \ OPT_ARG_NONE, \ - "Echo stdin to stdout and append checksum to output" \ + "Echo stdin to stdout and append checksum to output", \ + 0 \ ) \ X( \ 'q', \ @@ -34,7 +37,8 @@ no_argument, \ cli_handle_q, \ OPT_ARG_NONE, \ - "Quiet mode: only print the digest" \ + "Quiet mode: only print the digest", \ + 0 \ ) \ X( \ 'r', \ @@ -42,7 +46,8 @@ no_argument, \ cli_handle_r, \ OPT_ARG_NONE, \ - "Reverse the output format (digest then filename)" \ + "Reverse the output format (digest then filename)", \ + 0 \ ) \ X( \ 's', \ @@ -50,15 +55,16 @@ required_argument, \ cli_handle_s, \ OPT_ARG_STRING, \ - "Hash a string" \ + "Hash a string", \ + CLI_OPT_F_REPEATABLE \ ) #undef X -#define X(short_opt, long_opt, has_arg, handler, arg_type, desc) + 1 +#define X(short_opt, long_opt, has_arg, handler, arg_type, desc, flags) + 1 enum { FT_SSL_OPT_LEN = (0 FT_SSL_OPTION_LIST ) }; #undef X -#define X(short_opt, long_opt, has_arg, handler, arg_type, desc) \ +#define X(short_opt, long_opt, has_arg, handler, arg_type, desc, flags) \ + (1 * (has_arg == no_argument) \ + (2 * (has_arg == required_argument) \ + (3 * (has_arg == optional_argument)))) diff --git a/includes/internal/ssl/ssl.h b/includes/internal/ssl/ssl.h index d5b4722..c168d5b 100644 --- a/includes/internal/ssl/ssl.h +++ b/includes/internal/ssl/ssl.h @@ -8,7 +8,7 @@ #define MAX_DIGEST_SIZE 64 #define READ_BUFSIZE 4096 -int run_string(const struct ssl_config *config); +int run_string(const struct ssl_config *config, const char *s); int run_file(const struct ssl_config *config, const char *path); int run_stdin(const struct ssl_config *config); int digest_stream(const struct ssl_config *config, int fd, diff --git a/libcli b/libcli index 17ba957..a1b7a36 160000 --- a/libcli +++ b/libcli @@ -1 +1 @@ -Subproject commit 17ba957ed647364f8f21e43ebf2445410dc5c494 +Subproject commit a1b7a3620487d5c7b8a2178794cb8c5cb30d07f2 diff --git a/src/cli/handlers/handle_s.c b/src/cli/handlers/handle_s.c index 2e857d5..c98d683 100644 --- a/src/cli/handlers/handle_s.c +++ b/src/cli/handlers/handle_s.c @@ -6,6 +6,8 @@ cli_handle_s(const char *arg, void *config_void) { struct ssl_config *config = (struct ssl_config *)config_void; - config->string = arg; + if (config->nb_strings >= SSL_MAX_STRINGS) + return CLI_ERROR; + config->strings[config->nb_strings++] = arg; return CLI_SUCCESS; } diff --git a/src/cli/handlers/option_map.c b/src/cli/handlers/option_map.c index d25ff38..ddc149b 100644 --- a/src/cli/handlers/option_map.c +++ b/src/cli/handlers/option_map.c @@ -2,12 +2,12 @@ #include "internal/cli/option.h" #undef X -#define X(short_opt, long_opt, has_arg, handler, arg_type, desc) \ -{ short_opt, long_opt, has_arg, handler, arg_type, desc }, +#define X(short_opt, long_opt, has_arg, handler, arg_type, desc, flags) \ +{ short_opt, long_opt, has_arg, handler, arg_type, desc, flags }, const struct option_descriptor g_options[] = { FT_SSL_OPTION_LIST - {0, NULL, 0, NULL, OPT_ARG_NONE, NULL } + {0, NULL, 0, NULL, OPT_ARG_NONE, NULL, 0 } }; #undef X diff --git a/src/ssl/run_string.c b/src/ssl/run_string.c index bc1e7bd..7c7886d 100644 --- a/src/ssl/run_string.c +++ b/src/ssl/run_string.c @@ -8,17 +8,16 @@ #include "internal/ssl/ssl.h" int -run_string(const struct ssl_config *config) +run_string(const struct ssl_config *config, const char *s) { union digest_ctx ctx; uint8_t digest[MAX_DIGEST_SIZE]; char label[4096]; config->algo->init(&ctx); - config->algo->update(&ctx, (const uint8_t *)config->string, - strlen(config->string)); + config->algo->update(&ctx, (const uint8_t *)s, strlen(s)); config->algo->final(&ctx, digest); - (void)snprintf(label, sizeof(label), "\"%s\"", config->string); + (void)snprintf(label, sizeof(label), "\"%s\"", s); print_digest(config, digest, label, 1); return CLI_SUCCESS; } diff --git a/src/ssl_run.c b/src/ssl_run.c index d63d507..9ae5c3d 100644 --- a/src/ssl_run.c +++ b/src/ssl_run.c @@ -24,11 +24,11 @@ ssl_run(const struct ssl_config *config) if (CLI_SUCCESS != check_algo(config)) return CLI_ERROR; ret = CLI_SUCCESS; - has_input = (NULL != config->string || 0 < config->nb_files); + has_input = (0 < config->nb_strings || 0 < config->nb_files); if (HAS_FLAG(config->flags, FLAG_P) || !has_input) update_ret(&ret, run_stdin(config)); - if (NULL != config->string) - update_ret(&ret, run_string(config)); + for (i = 0; i < config->nb_strings; i++) + update_ret(&ret, run_string(config, config->strings[i])); for (i = 0; i < config->nb_files; i++) update_ret(&ret, run_file(config, config->files[i])); return ret;