diff options
author | Ryo Nakamura <upa@haeena.net> | 2024-04-29 18:03:41 +0900 |
---|---|---|
committer | Ryo Nakamura <upa@haeena.net> | 2024-04-29 18:03:41 +0900 |
commit | ab6649f29e7a24e02a5c363a17a79601607930aa (patch) | |
tree | 58b06494b5b9cede91933f9bef0293c068d27587 | |
parent | 7c5314ea11b636ff1790d543c9b45ba5ade04e12 (diff) |
add available ciphers and hmacs on help print (#20)
-rw-r--r-- | include/mscp.h | 11 | ||||
-rw-r--r-- | patch/libssh-0.10.6-2-g6f1b1e76.patch | 74 | ||||
-rw-r--r-- | src/main.c | 20 | ||||
-rw-r--r-- | src/ssh.c | 10 |
4 files changed, 105 insertions, 10 deletions
diff --git a/include/mscp.h b/include/mscp.h index 8519f23..6444463 100644 --- a/include/mscp.h +++ b/include/mscp.h @@ -294,4 +294,15 @@ enum { }; +/** + * @brief Return available ciphers. + */ +const char **mscp_ssh_ciphers(void); + +/** + * @brief Return available hmacs. + */ + const char **mscp_ssh_hmacs(void); + + #endif /* _MSCP_H_ */ diff --git a/patch/libssh-0.10.6-2-g6f1b1e76.patch b/patch/libssh-0.10.6-2-g6f1b1e76.patch index 8db9213..bdca411 100644 --- a/patch/libssh-0.10.6-2-g6f1b1e76.patch +++ b/patch/libssh-0.10.6-2-g6f1b1e76.patch @@ -37,7 +37,7 @@ index 1fce7b76..b64d1455 100644 int ssh_buffer_validate_length(struct ssh_buffer_struct *buffer, size_t len); diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h -index 669a0a96..da5b4099 100644 +index 669a0a96..26b20f3f 100644 --- a/include/libssh/libssh.h +++ b/include/libssh/libssh.h @@ -368,6 +368,7 @@ enum ssh_options_e { @@ -64,12 +64,15 @@ index 669a0a96..da5b4099 100644 LIBSSH_API void ssh_buffer_free(ssh_buffer buffer); #define SSH_BUFFER_FREE(x) \ do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0) -@@ -843,6 +846,8 @@ LIBSSH_API void *ssh_buffer_get(ssh_buffer buffer); +@@ -843,6 +846,11 @@ LIBSSH_API void *ssh_buffer_get(ssh_buffer buffer); LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer); LIBSSH_API int ssh_session_set_disconnect_message(ssh_session session, const char *message); +typedef ssize_t (*ssh_add_func) (void *ptr, size_t max_bytes, void *userdata); + ++LIBSSH_API const char **ssh_ciphers(void); ++LIBSSH_API const char **ssh_hmacs(void); ++ #ifndef LIBSSH_LEGACY_0_4 #include "libssh/legacy.h" #endif @@ -299,6 +302,60 @@ index 15cae644..02ef43b4 100644 errno = 0; rc = connect(s, itr->ai_addr, itr->ai_addrlen); if (rc == -1 && (errno != 0) && (errno != EINPROGRESS)) { +diff --git a/src/misc.c b/src/misc.c +index 7081f12a..e3879fe4 100644 +--- a/src/misc.c ++++ b/src/misc.c +@@ -71,6 +71,8 @@ + #include "libssh/priv.h" + #include "libssh/misc.h" + #include "libssh/session.h" ++#include "libssh/wrapper.h" ++#include "libssh/crypto.h" + + #ifdef HAVE_LIBGCRYPT + #define GCRYPT_STRING "/gnutls" +@@ -2074,4 +2076,40 @@ int ssh_check_hostname_syntax(const char *hostname) + return SSH_OK; + } + ++/** ++ * @brief Return supported cipher names ++ * @return The list of cipher names. ++ */ ++const char **ssh_ciphers(void) ++{ ++ struct ssh_cipher_struct *tab=ssh_get_ciphertab(); ++ static const char *ciphers[32]; ++ int n; ++ ++ memset(ciphers, 0, sizeof(*ciphers)); ++ ++ for (n = 0; tab[n].name != NULL; n++) { ++ ciphers[n] = tab[n].name; ++ } ++ return ciphers; ++} ++ ++/** ++ * @brief Return supported hmac names ++ * @return The list of hmac names. ++ */ ++const char **ssh_hmacs(void) ++{ ++ struct ssh_hmac_struct *tab=ssh_get_hmactab(); ++ static const char *hmacs[32]; ++ int n; ++ ++ memset(hmacs, 0, sizeof(*hmacs)); ++ ++ for (n = 0; tab[n].name != NULL; n++) { ++ hmacs[n] = tab[n].name; ++ } ++ return hmacs; ++} ++ + /** @} */ diff --git a/src/options.c b/src/options.c index b3ecffe1..8de24ed6 100644 --- a/src/options.c @@ -392,10 +449,10 @@ index 8c509699..307388e5 100644 session->opts.flags = SSH_OPT_FLAG_PASSWORD_AUTH | SSH_OPT_FLAG_PUBKEY_AUTH | diff --git a/src/sftp.c b/src/sftp.c -index e01012a8..3b86c3c6 100644 +index e01012a8..702623a0 100644 --- a/src/sftp.c +++ b/src/sftp.c -@@ -2228,6 +2228,135 @@ ssize_t sftp_write(sftp_file file, const void *buf, size_t count) { +@@ -2228,6 +2228,132 @@ ssize_t sftp_write(sftp_file file, const void *buf, size_t count) { return -1; /* not reached */ } @@ -434,8 +491,7 @@ index e01012a8..3b86c3c6 100644 + + buffer = ssh_buffer_new_size(buf_sz, HEADROOM); + if (buffer == NULL) { -+ ssh_set_error(sftp->session, SSH_FATAL, -+ "ssh_buffer_new_size failed: Out of Memory"); ++ ssh_set_error_oom(sftp->session); + return -1; + } + @@ -449,16 +505,14 @@ index e01012a8..3b86c3c6 100644 + count); /* len of datastring */ + + if (rc != SSH_OK){ -+ ssh_set_error(sftp->session, SSH_FATAL, -+ "ssh_buffer_pack failed: Out of Memory"); ++ ssh_set_error_oom(sftp->session); + ssh_buffer_free(buffer); + return SSH_ERROR; + } + + actual = ssh_buffer_add_func(buffer, f, count, userdata); + if (actual < 0){ -+ ssh_set_error(sftp->session, SSH_FATAL, -+ "ssh_buffer_add_func failed: %s", strerror(errno)); ++ ssh_set_error_oom(sftp->session); + ssh_buffer_free(buffer); + return SSH_ERROR; + } @@ -75,6 +75,26 @@ void usage(bool print_help) " -N enable Nagle's algorithm (default disabled)\n" " -h print this help\n" "\n"); + + const char **ciphers = mscp_ssh_ciphers(); + const char **hmacs = mscp_ssh_hmacs(); + int n; + + printf("Available ciphers: "); + for (n = 0; ciphers[n] != NULL; n++) { + printf("%s", ciphers[n]); + if (ciphers[n + 1]) + printf(", "); + } + printf("\n\n"); + + printf("Available hmacs: "); + for (n = 0; hmacs[n] != NULL; n++) { + printf("%s", hmacs[n]); + if (hmacs[n + 1]) + printf(", "); + } + printf("\n\n"); } char *strip_brackets(char *s) @@ -407,3 +407,13 @@ void ssh_sftp_close(sftp_session sftp) ssh_disconnect(ssh); ssh_free(ssh); } + +const char **mscp_ssh_ciphers(void) +{ + return ssh_ciphers(); +} + +const char **mscp_ssh_hmacs(void) +{ + return ssh_hmacs(); +} |