diff --git a/backport-Fix-a-memcmp-errors-in-code-that-was-changed-from-me.patch b/backport-Fix-a-memcmp-errors-in-code-that-was-changed-from-me.patch deleted file mode 100644 index 4cd4931062b1df4a13c4645c8a5fcd2d6827092a..0000000000000000000000000000000000000000 --- a/backport-Fix-a-memcmp-errors-in-code-that-was-changed-from-me.patch +++ /dev/null @@ -1,41 +0,0 @@ -From 13ad7b2f5cd67e0dc843098ce19ce8b208368c29 Mon Sep 17 00:00:00 2001 -From: Michael Buckley -Date: Thu, 6 Jan 2022 13:56:22 -0800 -Subject: [PATCH] Fix a memcmp errors in code that was changed from memmem to - memcmp (#656) - -Notes: -Fixed supported algo prefs list check when upgrading rsa keys - -Credit: Michael Buckley -Conflict:NA -Reference:https://github.com/libssh2/commit/13ad7b2f5cd67e0dc843098ce19ce8b208368c29 ---- - src/userauth.c | 4 ++-- - 1 file changed, 2 insertions(+), 2 deletions(-) - -diff --git a/src/userauth.c b/src/userauth.c -index 988dc17..29f58ba 100644 ---- a/src/userauth.c -+++ b/src/userauth.c -@@ -1147,7 +1147,7 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session, - f = strchr(a, ','); - f_len = f ? (f - a) : (int) strlen(a); - -- if(f_len == p_len && memcmp(a, s, p_len)) { -+ if(f_len == p_len && memcmp(a, s, p_len) == 0) { - - if(i != filtered_algs) { - memcpy(i, ",", 1); -@@ -1185,7 +1185,7 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session, - f = strchr(a, ','); - f_len = f ? (f - a) : (int) strlen(a); - -- if(f_len == p_len && memcmp(a, s, p_len)) { -+ if(f_len == p_len && memcmp(a, s, p_len) == 0) { - /* found a match, upgrade key method */ - match = s; - match_len = p_len; --- -2.23.0 - diff --git a/backport-Legacy-Agent-support-for-rsa2-key-upgrading-downgrad.patch b/backport-Legacy-Agent-support-for-rsa2-key-upgrading-downgrad.patch deleted file mode 100644 index b1a0837111d4c27c6657dde81ad70c6b71752bd0..0000000000000000000000000000000000000000 --- a/backport-Legacy-Agent-support-for-rsa2-key-upgrading-downgrad.patch +++ /dev/null @@ -1,172 +0,0 @@ -From de7a74aff24c47b2f2e9815f0a98598195d602e4 Mon Sep 17 00:00:00 2001 -From: Will Cosgrove -Date: Fri, 14 Jan 2022 11:55:18 -0800 -Subject: [PATCH] Legacy Agent support for rsa2 key upgrading/downgrading #659 - (#662) - -Files: libssh2.h, agent.c, userauth.c - -Notes: -Part 2 of the fix for #659. This adds rsa key downgrading for agents that don't support sha2 upgrading. It also adds better trace output for debugging/logging around key upgrading. - -Credit: -Will Cosgrove (signed off by Michael Buckley) - -Conflict:NA -Reference:https://github.com/libssh2/commit/de7a74aff24c47b2f2e9815f0a98598195d602e4 ---- - include/libssh2.h | 1 + - src/agent.c | 27 +++++++++++++++++++++++++++ - src/userauth.c | 43 ++++++++++++++++++++++++++++++++++--------- - 3 files changed, 62 insertions(+), 9 deletions(-) - -diff --git a/include/libssh2.h b/include/libssh2.h -index 20ba548..15dda6f 100644 ---- a/include/libssh2.h -+++ b/include/libssh2.h -@@ -508,5 +508,6 @@ typedef struct _LIBSSH2_POLLFD { - #define LIBSSH2_ERROR_KEYFILE_AUTH_FAILED -48 - #define LIBSSH2_ERROR_RANDGEN -49 -+#define LIBSSH2_ERROR_ALGO_UNSUPPORTED -51 - - /* this is a define to provide the old (<= 1.2.7) name */ - #define LIBSSH2_ERROR_BANNER_NONE LIBSSH2_ERROR_BANNER_RECV -diff --git a/src/agent.c b/src/agent.c -index bce7175..4ed79ac 100644 ---- a/src/agent.c -+++ b/src/agent.c -@@ -379,6 +379,7 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, - ssize_t method_len; - unsigned char *s; - int rc; -+ unsigned char *method_name = NULL; - uint32_t sign_flags = 0; - - /* Create a request to sign the data */ -@@ -465,8 +466,28 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, - rc = LIBSSH2_ERROR_AGENT_PROTOCOL; - goto error; - } -+ -+ /* method name */ -+ method_name = LIBSSH2_ALLOC(session, method_len); -+ if(!method_name) { -+ rc = LIBSSH2_ERROR_ALLOC; -+ goto error; -+ } -+ memcpy(method_name, s, method_len); - s += method_len; - -+ /* check to see if we match requested */ -+ if((size_t)method_len != session->userauth_pblc_method_len || -+ memcmp(method_name, session->userauth_pblc_method, method_len)) { -+ _libssh2_debug(session, -+ LIBSSH2_TRACE_KEX, -+ "Agent sign method %.*s", -+ method_len, method_name); -+ -+ rc = LIBSSH2_ERROR_ALGO_UNSUPPORTED; -+ goto error; -+ } -+ - /* Read the signature */ - len -= 4; - if(len < 0) { -@@ -489,12 +510,18 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, - memcpy(*sig, s, *sig_len); - - error: -+ -+ if(method_name) -+ LIBSSH2_FREE(session, method_name); -+ - LIBSSH2_FREE(session, transctx->request); - transctx->request = NULL; - - LIBSSH2_FREE(session, transctx->response); - transctx->response = NULL; - -+ transctx->state = agent_NB_state_init; -+ - return _libssh2_error(session, rc, "agent sign failure"); - } - -diff --git a/src/userauth.c b/src/userauth.c -index 84285bf..59b76ca 100644 ---- a/src/userauth.c -+++ b/src/userauth.c -@@ -1283,9 +1283,6 @@ _libssh2_key_sign_algorithm(LIBSSH2_SESSION *session, - if(key_method) { - memcpy(*key_method, match, match_len); - *key_method_len = match_len; -- -- _libssh2_debug(session, LIBSSH2_TRACE_KEX, -- "Signing using %.*s", match_len, match); - } - else { - *key_method_len = 0; -@@ -1321,6 +1318,10 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, - }; - int rc; - unsigned char *s; -+ int auth_attempts = 0; -+ -+ retry_auth: -+ auth_attempts++; - - if(session->userauth_pblc_state == libssh2_NB_state_idle) { - -@@ -1364,13 +1365,26 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, - session->userauth_pblc_method_len); - } - -- /* upgrade key key signing algo needed */ -- rc = _libssh2_key_sign_algorithm(session, -- &session->userauth_pblc_method, -- &session->userauth_pblc_method_len); -+ /* upgrade key signing algo if it is supported and -+ * it is our first auth attempt, otherwise fallback to -+ * the key default algo */ -+ if(auth_attempts == 1) { -+ rc = _libssh2_key_sign_algorithm(session, -+ &session->userauth_pblc_method, -+ &session->userauth_pblc_method_len); - -- if(rc) -- return rc; -+ if(rc) -+ return rc; -+ } -+ -+ if(session->userauth_pblc_method_len && -+ session->userauth_pblc_method) { -+ _libssh2_debug(session, -+ LIBSSH2_TRACE_KEX, -+ "Signing using %.*s", -+ session->userauth_pblc_method_len, -+ session->userauth_pblc_method); -+ } - - /* - * 45 = packet_type(1) + username_len(4) + servicename_len(4) + -@@ -1528,6 +1542,17 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, - return _libssh2_error(session, LIBSSH2_ERROR_EAGAIN, - "Would block"); - } -+ else if(rc == LIBSSH2_ERROR_ALGO_UNSUPPORTED && auth_attempts == 1) { -+ /* try again with the default key algo */ -+ LIBSSH2_FREE(session, session->userauth_pblc_method); -+ session->userauth_pblc_method = NULL; -+ LIBSSH2_FREE(session, session->userauth_pblc_packet); -+ session->userauth_pblc_packet = NULL; -+ session->userauth_pblc_state = libssh2_NB_state_idle; -+ -+ rc = LIBSSH2_ERROR_NONE; -+ goto retry_auth; -+ } - else if(rc) { - LIBSSH2_FREE(session, session->userauth_pblc_method); - session->userauth_pblc_method = NULL; --- -2.23.0 - diff --git a/backport-NULL-terminate-server_sign_algorithms-string-669.patch b/backport-NULL-terminate-server_sign_algorithms-string-669.patch deleted file mode 100644 index b3d38573450ace4af5d74fcff8a6bf4bcd50a09e..0000000000000000000000000000000000000000 --- a/backport-NULL-terminate-server_sign_algorithms-string-669.patch +++ /dev/null @@ -1,58 +0,0 @@ -From 2a2aaed3b6c3c1dc25e35e11afcfb23f88a18510 Mon Sep 17 00:00:00 2001 -From: tihmstar -Date: Thu, 3 Feb 2022 19:11:36 +0100 -Subject: [PATCH] NULL terminate server_sign_algorithms string (#669) - -files: packet.c, libssh2_priv.h - -notes: -* Fix heap buffer overflow in _libssh2_key_sign_algorithm - -When allocating `session->server_sign_algorithms` which is a `char*` is is important to also allocate space for the string-terminating null byte at the end and make sure the string is actually null terminated. - -Without this fix, the `strchr()` call inside the `_libssh2_key_sign_algorithm` (line 1219) function will try to parse the string and go out of buffer on the last invocation. - -Credit: tihmstar -Co-authored-by: Will Cosgrove - -Conflict:NA -Reference:https://github.com/libssh2/commit/2a2aaed3b6c3c1dc25e35e11afcfb23f88a18510 ---- - src/libssh2_priv.h | 1 - - src/packet.c | 4 ++-- - 2 files changed, 2 insertions(+), 3 deletions(-) - -diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h -index f218a83..be16ad2 100644 ---- a/src/libssh2_priv.h -+++ b/src/libssh2_priv.h -@@ -642,7 +642,6 @@ struct _LIBSSH2_SESSION - - /* public key algorithms accepted as comma separated list */ - char *server_sign_algorithms; -- size_t server_sign_algorithms_len; - - /* key signing algorithm preferences -- NULL yields server order */ - char *sign_algo_prefs; -diff --git a/src/packet.c b/src/packet.c -index 686be5c..c3756a8 100644 ---- a/src/packet.c -+++ b/src/packet.c -@@ -665,12 +665,12 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, - - session->server_sign_algorithms = - LIBSSH2_ALLOC(session, -- value_len); -+ value_len + 1); - - if(session->server_sign_algorithms) { -- session->server_sign_algorithms_len = value_len; - memcpy(session->server_sign_algorithms, - value, value_len); -+ session->server_sign_algorithms[value_len] = '\0'; - } - else { - rc = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, --- -2.23.0 - diff --git a/backport-RSA-SHA2-256-512-key-upgrade-support-RFC-8332.patch b/backport-RSA-SHA2-256-512-key-upgrade-support-RFC-8332.patch deleted file mode 100644 index ccb5d3f9ac85b1479427fa1d8c59ce67c600298f..0000000000000000000000000000000000000000 --- a/backport-RSA-SHA2-256-512-key-upgrade-support-RFC-8332.patch +++ /dev/null @@ -1,1025 +0,0 @@ -From 64a555d6f5aafed504a10e5b756e85c91b1d56ce Mon Sep 17 00:00:00 2001 -From: Will Cosgrove -Date: Thu, 6 Jan 2022 09:50:58 -0800 -Subject: [PATCH] RSA SHA2 256/512 key upgrade support RFC 8332 #536 (#626) - -Notes: -* Host Key RSA 256/512 support #536 -* Client side key hash upgrading for RFC 8332 -* Support for server-sig-algs, ext-info-c server messages -* Customizing preferred server-sig-algs via the preference LIBSSH2_METHOD_SIGN_ALGO - -Credit: Anders Borum, Will Cosgrove ---- - docs/HACKING-CRYPTO | 37 ++++++++ - docs/libssh2_session_methods.3 | 7 +- - include/libssh2.h | 1 + - src/crypto.h | 32 +++++++ - src/hostkey.c | 198 ++++++++++++++++++++++++++++++++++++++++- - src/kex.c | 22 +++++ - src/libgcrypt.c | 18 ++++ - src/libgcrypt.h | 1 + - src/libssh2_priv.h | 8 ++ - src/mbedtls.c | 19 ++++ - src/mbedtls.h | 1 + - src/openssl.c | 94 +++++++++++++++++-- - src/openssl.h | 2 + - src/packet.c | 69 ++++++++++++++ - src/userauth.c | 159 +++++++++++++++++++++++++++++++-- - src/wincng.c | 18 ++++ - src/wincng.h | 1 + - 19 files changed, 685 insertions(+), 21 deletions(-) - -diff --git a/docs/HACKING-CRYPTO b/docs/HACKING-CRYPTO -index ca94772..85d813a 100644 ---- a/docs/HACKING-CRYPTO -+++ b/docs/HACKING-CRYPTO -@@ -637,6 +637,32 @@ Note: this procedure is not used if macro _libssh2_rsa_sha1_signv() is defined. - void _libssh2_rsa_free(libssh2_rsa_ctx *rsactx); - Releases the RSA computation context at rsactx. - -+LIBSSH2_RSA_SHA2 -+#define as 1 if the crypto library supports RSA SHA2 256/512, else 0. -+If defined as 0, the rest of this section can be omitted. -+ -+int _libssh2_rsa_sha2_sign(LIBSSH2_SESSION * session, -+ libssh2_rsa_ctx * rsactx, -+ const unsigned char *hash, -+ size_t hash_len, -+ unsigned char **signature, -+ size_t *signature_len); -+RSA signs the (hash, hashlen) SHA-2 hash bytes based on hash length and stores -+the allocated signature at (signature, signature_len). -+Signature buffer must be allocated from the given session. -+Returns 0 if OK, else -1. -+This procedure is already prototyped in crypto.h. -+Note: this procedure is not used if macro _libssh2_rsa_sha1_signv() is defined. -+ -+int _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsa, -+ size_t hash_len, -+ const unsigned char *sig, -+ unsigned long sig_len, -+ const unsigned char *m, unsigned long m_len); -+Verify (sig, sig_len) signature of (m, m_len) using an SHA-2 hash based on -+hash length and the RSA context. -+Return 0 if OK, else -1. -+This procedure is already prototyped in crypto.h. - - 7.2) DSA - LIBSSH2_DSA -@@ -900,3 +926,14 @@ If this is not needed, it should be defined as an empty macro. - int _libssh2_random(unsigned char *buf, int len); - Store len random bytes at buf. - Returns 0 if OK, else -1. -+ -+const char * _libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, -+ unsigned char *key_method, -+ size_t key_method_len); -+ -+This function is for implementing key hash upgrading as defined in RFC 8332. -+ -+Based on the incoming key_method value, this function will return a -+list of supported algorithms that can upgrade the original key method algorithm -+as a comma seperated list, if there is no upgrade option this function should -+return NULL. -diff --git a/docs/libssh2_session_methods.3 b/docs/libssh2_session_methods.3 -index cc4f6d4..0e7f79f 100644 ---- a/docs/libssh2_session_methods.3 -+++ b/docs/libssh2_session_methods.3 -@@ -1,4 +1,4 @@ --.TH libssh2_session_methods 3 "1 Jun 2007" "libssh2 0.15" "libssh2 manual" -+.TH libssh2_session_methods 3 "8 Nov 2021" "libssh2 1.11" "libssh2 manual" - .SH NAME - libssh2_session_methods - return the currently active algorithms - .SH SYNOPSIS -@@ -8,13 +8,14 @@ const char * - libssh2_session_methods(LIBSSH2_SESSION *session, int method_type); - - .SH DESCRIPTION --\fIsession\fP - Session instance as returned by -+\fIsession\fP - Session instance as returned by - .BR libssh2_session_init_ex(3) - - \fImethod_type\fP - one of the method type constants: LIBSSH2_METHOD_KEX, - LIBSSH2_METHOD_HOSTKEY, LIBSSH2_METHOD_CRYPT_CS, LIBSSH2_METHOD_CRYPT_SC, - LIBSSH2_METHOD_MAC_CS, LIBSSH2_METHOD_MAC_SC, LIBSSH2_METHOD_COMP_CS, --LIBSSH2_METHOD_COMP_SC, LIBSSH2_METHOD_LANG_CS, LIBSSH2_METHOD_LANG_SC. -+LIBSSH2_METHOD_COMP_SC, LIBSSH2_METHOD_LANG_CS, LIBSSH2_METHOD_LANG_SC, -+LIBSSH2_METHOD_SIGN_ALGO. - - Returns the actual method negotiated for a particular transport parameter. - .SH RETURN VALUE -diff --git a/include/libssh2.h b/include/libssh2.h -index d064b31..b9ae809 100644 ---- a/include/libssh2.h -+++ b/include/libssh2.h -@@ -356,6 +356,7 @@ typedef struct _LIBSSH2_USERAUTH_KBDINT_RESPONSE - #define LIBSSH2_METHOD_COMP_SC 7 - #define LIBSSH2_METHOD_LANG_CS 8 - #define LIBSSH2_METHOD_LANG_SC 9 -+#define LIBSSH2_METHOD_SIGN_ALGO 10 - - /* flags */ - #define LIBSSH2_FLAG_SIGPIPE 1 -diff --git a/src/crypto.h b/src/crypto.h -index f512d60..809aef7 100644 ---- a/src/crypto.h -+++ b/src/crypto.h -@@ -93,6 +93,19 @@ int _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, - size_t hash_len, - unsigned char **signature, - size_t *signature_len); -+#if LIBSSH2_RSA_SHA2 -+int _libssh2_rsa_sha2_sign(LIBSSH2_SESSION * session, -+ libssh2_rsa_ctx * rsactx, -+ const unsigned char *hash, -+ size_t hash_len, -+ unsigned char **signature, -+ size_t *signature_len); -+int _libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsa, -+ size_t hash_len, -+ const unsigned char *sig, -+ unsigned long sig_len, -+ const unsigned char *m, unsigned long m_len); -+#endif - int _libssh2_rsa_new_private_frommemory(libssh2_rsa_ctx ** rsa, - LIBSSH2_SESSION * session, - const char *filedata, -@@ -245,4 +258,23 @@ int _libssh2_pub_priv_keyfilememory(LIBSSH2_SESSION *session, - size_t privatekeydata_len, - const char *passphrase); - -+ -+/** -+ * @function _libssh2_supported_key_sign_algorithms -+ * @abstract Returns supported algorithms used for upgrading public -+ * key signing RFC 8332 -+ * @discussion Based on the incoming key_method value, this function -+ * will return supported algorithms that can upgrade the key method -+ * @related _libssh2_key_sign_algorithm() -+ * @param key_method current key method, usually the default key sig method -+ * @param key_method_len length of the key method buffer -+ * @result comma seperated list of supported upgrade options per RFC 8332, if -+ * there is no upgrade option return NULL -+ */ -+ -+const char * -+_libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, -+ unsigned char *key_method, -+ size_t key_method_len); -+ - #endif /* __LIBSSH2_CRYPTO_H */ -diff --git a/src/hostkey.c b/src/hostkey.c -index c0e2c63..f005d90 100644 ---- a/src/hostkey.c -+++ b/src/hostkey.c -@@ -64,8 +64,8 @@ hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session, - void **abstract) - { - libssh2_rsa_ctx *rsactx; -- unsigned char *e, *n; -- size_t e_len, n_len; -+ unsigned char *e, *n, *type; -+ size_t e_len, n_len, type_len; - struct string_buf buf; - - if(*abstract) { -@@ -83,8 +83,27 @@ hostkey_method_ssh_rsa_init(LIBSSH2_SESSION * session, - buf.dataptr = buf.data; - buf.len = hostkey_data_len; - -- if(_libssh2_match_string(&buf, "ssh-rsa")) -+ if(_libssh2_get_string(&buf, &type, &type_len)) { - return -1; -+ } -+ -+ /* we accept one of 3 header types */ -+ if(type_len == 7 && strncmp("ssh-rsa", (char *)type, 7) == 0) { -+ /* ssh-rsa */ -+ } -+#if LIBSSH2_RSA_SHA2 -+ else if(type_len == 12 && strncmp("rsa-sha2-256", (char *)type, 12) == 0) { -+ /* rsa-sha2-256 */ -+ } -+ else if(type_len == 12 && strncmp("rsa-sha2-512", (char *)type, 12) == 0) { -+ /* rsa-sha2-512 */ -+ } -+#endif -+ else { -+ _libssh2_debug(session, LIBSSH2_TRACE_ERROR, -+ "unexpected rsa type: %.*s", type_len, type); -+ return -1; -+ } - - if(_libssh2_get_string(&buf, &e, &e_len)) - return -1; -@@ -228,6 +247,146 @@ hostkey_method_ssh_rsa_signv(LIBSSH2_SESSION * session, - } - - /* -+ * hostkey_method_ssh_rsa_sha2_256_sig_verify -+ * -+ * Verify signature created by remote -+ */ -+#if LIBSSH2_RSA_SHA2 -+ -+static int -+hostkey_method_ssh_rsa_sha2_256_sig_verify(LIBSSH2_SESSION * session, -+ const unsigned char *sig, -+ size_t sig_len, -+ const unsigned char *m, -+ size_t m_len, void **abstract) -+{ -+ libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract); -+ (void) session; -+ -+ /* Skip past keyname_len(4) + keyname(12){"rsa-sha2-256"} + -+ signature_len(4) */ -+ if(sig_len < 20) -+ return -1; -+ -+ sig += 20; -+ sig_len -= 20; -+ return _libssh2_rsa_sha2_verify(rsactx, SHA256_DIGEST_LENGTH, sig, sig_len, -+ m, m_len); -+} -+ -+/* -+ * hostkey_method_ssh_rsa_sha2_256_signv -+ * -+ * Construct a signature from an array of vectors -+ */ -+ -+static int -+hostkey_method_ssh_rsa_sha2_256_signv(LIBSSH2_SESSION * session, -+ unsigned char **signature, -+ size_t *signature_len, -+ int veccount, -+ const struct iovec datavec[], -+ void **abstract) -+{ -+ libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract); -+ -+#ifdef _libssh2_rsa_sha2_256_signv -+ return _libssh2_rsa_sha2_256_signv(session, signature, signature_len, -+ veccount, datavec, rsactx); -+#else -+ int ret; -+ int i; -+ unsigned char hash[SHA256_DIGEST_LENGTH]; -+ libssh2_sha256_ctx ctx; -+ -+ libssh2_sha256_init(&ctx); -+ for(i = 0; i < veccount; i++) { -+ libssh2_sha256_update(ctx, datavec[i].iov_base, datavec[i].iov_len); -+ } -+ libssh2_sha256_final(ctx, hash); -+ -+ ret = _libssh2_rsa_sha2_sign(session, rsactx, hash, SHA256_DIGEST_LENGTH, -+ signature, signature_len); -+ if(ret) { -+ return -1; -+ } -+ -+ return 0; -+#endif -+} -+ -+/* -+ * hostkey_method_ssh_rsa_sha2_512_sig_verify -+ * -+ * Verify signature created by remote -+ */ -+ -+static int -+hostkey_method_ssh_rsa_sha2_512_sig_verify(LIBSSH2_SESSION * session, -+ const unsigned char *sig, -+ size_t sig_len, -+ const unsigned char *m, -+ size_t m_len, void **abstract) -+{ -+ libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract); -+ (void) session; -+ -+ /* Skip past keyname_len(4) + keyname(12){"rsa-sha2-512"} + -+ signature_len(4) */ -+ if(sig_len < 20) -+ return -1; -+ -+ sig += 20; -+ sig_len -= 20; -+ return _libssh2_rsa_sha2_verify(rsactx, SHA512_DIGEST_LENGTH, sig, -+ sig_len, m, m_len); -+} -+ -+ -+/* -+ * hostkey_method_ssh_rsa_sha2_512_signv -+ * -+ * Construct a signature from an array of vectors -+ */ -+static int -+hostkey_method_ssh_rsa_sha2_512_signv(LIBSSH2_SESSION * session, -+ unsigned char **signature, -+ size_t *signature_len, -+ int veccount, -+ const struct iovec datavec[], -+ void **abstract) -+{ -+ libssh2_rsa_ctx *rsactx = (libssh2_rsa_ctx *) (*abstract); -+ -+#ifdef _libssh2_rsa_sha2_512_signv -+ return _libssh2_rsa_sha2_512_signv(session, signature, signature_len, -+ veccount, datavec, rsactx); -+#else -+ int ret; -+ int i; -+ unsigned char hash[SHA512_DIGEST_LENGTH]; -+ libssh2_sha512_ctx ctx; -+ -+ libssh2_sha512_init(&ctx); -+ for(i = 0; i < veccount; i++) { -+ libssh2_sha512_update(ctx, datavec[i].iov_base, datavec[i].iov_len); -+ } -+ libssh2_sha512_final(ctx, hash); -+ -+ ret = _libssh2_rsa_sha2_sign(session, rsactx, hash, SHA512_DIGEST_LENGTH, -+ signature, signature_len); -+ if(ret) { -+ return -1; -+ } -+ -+ return 0; -+#endif -+} -+ -+#endif /* LIBSSH2_RSA_SHA2 */ -+ -+ -+/* - * hostkey_method_ssh_rsa_dtor - * - * Shutdown the hostkey -@@ -260,6 +419,35 @@ static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa = { - NULL, /* encrypt */ - hostkey_method_ssh_rsa_dtor, - }; -+ -+#if LIBSSH2_RSA_SHA2 -+ -+static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa_sha2_256 = { -+ "rsa-sha2-256", -+ SHA256_DIGEST_LENGTH, -+ hostkey_method_ssh_rsa_init, -+ hostkey_method_ssh_rsa_initPEM, -+ hostkey_method_ssh_rsa_initPEMFromMemory, -+ hostkey_method_ssh_rsa_sha2_256_sig_verify, -+ hostkey_method_ssh_rsa_sha2_256_signv, -+ NULL, /* encrypt */ -+ hostkey_method_ssh_rsa_dtor, -+}; -+ -+static const LIBSSH2_HOSTKEY_METHOD hostkey_method_ssh_rsa_sha2_512 = { -+ "rsa-sha2-512", -+ SHA512_DIGEST_LENGTH, -+ hostkey_method_ssh_rsa_init, -+ hostkey_method_ssh_rsa_initPEM, -+ hostkey_method_ssh_rsa_initPEMFromMemory, -+ hostkey_method_ssh_rsa_sha2_512_sig_verify, -+ hostkey_method_ssh_rsa_sha2_512_signv, -+ NULL, /* encrypt */ -+ hostkey_method_ssh_rsa_dtor, -+}; -+ -+#endif /* LIBSSH2_RSA_SHA2 */ -+ - #endif /* LIBSSH2_RSA */ - - #if LIBSSH2_DSA -@@ -1041,6 +1229,10 @@ static const LIBSSH2_HOSTKEY_METHOD *hostkey_methods[] = { - &hostkey_method_ssh_ed25519, - #endif - #if LIBSSH2_RSA -+#if LIBSSH2_RSA_SHA2 -+ &hostkey_method_ssh_rsa_sha2_512, -+ &hostkey_method_ssh_rsa_sha2_256, -+#endif /* LIBSSH2_RSA_SHA2 */ - &hostkey_method_ssh_rsa, - #endif /* LIBSSH2_RSA */ - #if LIBSSH2_DSA -diff --git a/src/kex.c b/src/kex.c -index c300ecb..8f02808 100644 ---- a/src/kex.c -+++ b/src/kex.c -@@ -3026,6 +3026,17 @@ kex_method_ssh_curve25519_sha256 = { - }; - #endif - -+/* this kex method signals that client can receive extensions -+ * as described in https://datatracker.ietf.org/doc/html/rfc8308 -+*/ -+ -+static const LIBSSH2_KEX_METHOD -+kex_method_extension_negotiation = { -+ "ext-info-c", -+ NULL, -+ 0, -+}; -+ - static const LIBSSH2_KEX_METHOD *libssh2_kex_methods[] = { - #if LIBSSH2_ED25519 - &kex_method_ssh_curve25519_sha256, -@@ -3043,6 +3054,7 @@ static const LIBSSH2_KEX_METHOD *libssh2_kex_methods[] = { - &kex_method_diffie_helman_group14_sha1, - &kex_method_diffie_helman_group1_sha1, - &kex_method_diffie_helman_group_exchange_sha1, -+ &kex_method_extension_negotiation, - NULL - }; - -@@ -3978,6 +3990,11 @@ libssh2_session_method_pref(LIBSSH2_SESSION * session, int method_type, - mlist = NULL; - break; - -+ case LIBSSH2_METHOD_SIGN_ALGO: -+ prefvar = &session->sign_algo_prefs; -+ mlist = NULL; -+ break; -+ - default: - return _libssh2_error(session, LIBSSH2_ERROR_INVAL, - "Invalid parameter specified for method_type"); -@@ -4073,6 +4090,11 @@ LIBSSH2_API int libssh2_session_supported_algs(LIBSSH2_SESSION* session, - _libssh2_comp_methods(session); - break; - -+ case LIBSSH2_METHOD_SIGN_ALGO: -+ /* no built-in supported list due to backend support */ -+ mlist = NULL; -+ break; -+ - default: - return _libssh2_error(session, LIBSSH2_ERROR_METHOD_NOT_SUPPORTED, - "Unknown method type"); -diff --git a/src/libgcrypt.c b/src/libgcrypt.c -index 0aff176..f6e9b64 100644 ---- a/src/libgcrypt.c -+++ b/src/libgcrypt.c -@@ -664,4 +664,22 @@ _libssh2_dh_dtor(_libssh2_dh_ctx *dhctx) - *dhctx = NULL; - } - -+/* _libssh2_supported_key_sign_algorithms -+ * -+ * Return supported key hash algo upgrades, see crypto.h -+ * -+ */ -+ -+const char * -+_libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, -+ unsigned char *key_method, -+ size_t key_method_len) -+{ -+ (void)session; -+ (void)key_method; -+ (void)key_method_len; -+ -+ return NULL; -+} -+ - #endif /* LIBSSH2_LIBGCRYPT */ -diff --git a/src/libgcrypt.h b/src/libgcrypt.h -index 298c65e..95876b9 100644 ---- a/src/libgcrypt.h -+++ b/src/libgcrypt.h -@@ -55,6 +55,7 @@ - #define LIBSSH2_3DES 1 - - #define LIBSSH2_RSA 1 -+#define LIBSSH2_RSA_SHA2 0 - #define LIBSSH2_DSA 1 - #define LIBSSH2_ECDSA 0 - #define LIBSSH2_ED25519 0 -diff --git a/src/libssh2_priv.h b/src/libssh2_priv.h -index da488b7..aff791e 100644 ---- a/src/libssh2_priv.h -+++ b/src/libssh2_priv.h -@@ -640,6 +640,13 @@ struct _LIBSSH2_SESSION - unsigned char server_hostkey_sha256[SHA256_DIGEST_LENGTH]; - int server_hostkey_sha256_valid; - -+ /* public key algorithms accepted as comma separated list */ -+ char *server_sign_algorithms; -+ size_t server_sign_algorithms_len; -+ -+ /* key signing algorithm preferences -- NULL yields server order */ -+ char *sign_algo_prefs; -+ - /* (remote as source of data -- packet_read ) */ - libssh2_endpoint_data remote; - -@@ -1006,6 +1013,7 @@ _libssh2_debug(LIBSSH2_SESSION * session, int context, const char *format, ...) - #define SSH_MSG_DEBUG 4 - #define SSH_MSG_SERVICE_REQUEST 5 - #define SSH_MSG_SERVICE_ACCEPT 6 -+#define SSH_MSG_EXT_INFO 7 - - #define SSH_MSG_KEXINIT 20 - #define SSH_MSG_NEWKEYS 21 -diff --git a/src/mbedtls.c b/src/mbedtls.c -index 4629ce4..dc76ef5 100644 ---- a/src/mbedtls.c -+++ b/src/mbedtls.c -@@ -1247,5 +1247,24 @@ _libssh2_mbedtls_ecdsa_free(libssh2_ecdsa_ctx *ctx) - mbedtls_free(ctx); - } - -+ -+/* _libssh2_supported_key_sign_algorithms -+ * -+ * Return supported key hash algo upgrades, see crypto.h -+ * -+ */ -+ -+const char * -+_libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, -+ unsigned char *key_method, -+ size_t key_method_len) -+{ -+ (void)session; -+ (void)key_method; -+ (void)key_method_len; -+ -+ return NULL; -+} -+ - #endif /* LIBSSH2_ECDSA */ - #endif /* LIBSSH2_MBEDTLS */ -diff --git a/src/mbedtls.h b/src/mbedtls.h -index 671932c..0450113 100644 ---- a/src/mbedtls.h -+++ b/src/mbedtls.h -@@ -71,6 +71,7 @@ - #define LIBSSH2_3DES 1 - - #define LIBSSH2_RSA 1 -+#define LIBSSH2_RSA_SHA2 0 - #define LIBSSH2_DSA 0 - #ifdef MBEDTLS_ECDSA_C - # define LIBSSH2_ECDSA 1 -diff --git a/src/openssl.c b/src/openssl.c -index 7a6810f..72a85b3 100644 ---- a/src/openssl.c -+++ b/src/openssl.c -@@ -154,21 +154,57 @@ _libssh2_rsa_new(libssh2_rsa_ctx ** rsa, - } - - int --_libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsactx, -+_libssh2_rsa_sha2_verify(libssh2_rsa_ctx * rsactx, -+ size_t hash_len, - const unsigned char *sig, - unsigned long sig_len, - const unsigned char *m, unsigned long m_len) - { -- unsigned char hash[SHA_DIGEST_LENGTH]; - int ret; -+ int nid_type; -+ unsigned char *hash = malloc(hash_len); -+ if(hash == NULL) -+ return -1; -+ -+ if(hash_len == SHA_DIGEST_LENGTH) { -+ nid_type = NID_sha1; -+ ret = _libssh2_sha1(m, m_len, hash); -+ } -+ else if(hash_len == SHA256_DIGEST_LENGTH) { -+ nid_type = NID_sha256; -+ ret = _libssh2_sha256(m, m_len, hash); -+ -+ } -+ else if(hash_len == SHA512_DIGEST_LENGTH) { -+ nid_type = NID_sha512; -+ ret = _libssh2_sha512(m, m_len, hash); -+ } -+ else -+ ret = -1; /* unsupported digest */ - -- if(_libssh2_sha1(m, m_len, hash)) -+ if(ret != 0) { -+ free(hash); - return -1; /* failure */ -- ret = RSA_verify(NID_sha1, hash, SHA_DIGEST_LENGTH, -+ } -+ -+ ret = RSA_verify(nid_type, hash, hash_len, - (unsigned char *) sig, sig_len, rsactx); -+ -+ free(hash); -+ - return (ret == 1) ? 0 : -1; - } - -+int -+_libssh2_rsa_sha1_verify(libssh2_rsa_ctx * rsactx, -+ const unsigned char *sig, -+ unsigned long sig_len, -+ const unsigned char *m, unsigned long m_len) -+{ -+ return _libssh2_rsa_sha2_verify(rsactx, SHA_DIGEST_LENGTH, sig, sig_len, m, -+ m_len); -+} -+ - #if LIBSSH2_DSA - int - _libssh2_dsa_new(libssh2_dsa_ctx ** dsactx, -@@ -1876,7 +1912,7 @@ _libssh2_ed25519_new_public(libssh2_ed25519_ctx ** ed_ctx, - - - int --_libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, -+_libssh2_rsa_sha2_sign(LIBSSH2_SESSION * session, - libssh2_rsa_ctx * rsactx, - const unsigned char *hash, - size_t hash_len, -@@ -1893,7 +1929,17 @@ _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, - return -1; - } - -- ret = RSA_sign(NID_sha1, hash, hash_len, sig, &sig_len, rsactx); -+ if(hash_len == SHA_DIGEST_LENGTH) -+ ret = RSA_sign(NID_sha1, hash, hash_len, sig, &sig_len, rsactx); -+ else if(hash_len == SHA256_DIGEST_LENGTH) -+ ret = RSA_sign(NID_sha256, hash, hash_len, sig, &sig_len, rsactx); -+ else if(hash_len == SHA512_DIGEST_LENGTH) -+ ret = RSA_sign(NID_sha512, hash, hash_len, sig, &sig_len, rsactx); -+ else { -+ _libssh2_error(session, LIBSSH2_ERROR_PROTO, -+ "Unsupported hash digest length"); -+ ret = -1; -+ } - - if(!ret) { - LIBSSH2_FREE(session, sig); -@@ -1906,6 +1952,19 @@ _libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, - return 0; - } - -+ -+int -+_libssh2_rsa_sha1_sign(LIBSSH2_SESSION * session, -+ libssh2_rsa_ctx * rsactx, -+ const unsigned char *hash, -+ size_t hash_len, -+ unsigned char **signature, size_t *signature_len) -+{ -+ return _libssh2_rsa_sha2_sign(session, rsactx, hash, hash_len, -+ signature, signature_len); -+} -+ -+ - #if LIBSSH2_DSA - int - _libssh2_dsa_sha1_sign(libssh2_dsa_ctx * dsactx, -@@ -3283,4 +3342,27 @@ _libssh2_dh_dtor(_libssh2_dh_ctx *dhctx) - *dhctx = NULL; - } - -+/* _libssh2_supported_key_sign_algorithms -+ * -+ * Return supported key hash algo upgrades, see crypto.h -+ * -+ */ -+ -+const char * -+_libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, -+ unsigned char *key_method, -+ size_t key_method_len) -+{ -+ (void)session; -+ -+#if LIBSSH2_RSA_SHA2 -+ if(key_method_len == 7 && -+ memcmp(key_method, "ssh-rsa", key_method_len) == 0) { -+ return "rsa-sha2-512,rsa-sha2-256,ssh-rsa"; -+ } -+#endif -+ -+ return NULL; -+} -+ - #endif /* LIBSSH2_OPENSSL */ -diff --git a/src/openssl.h b/src/openssl.h -index 658b040..2a002b4 100644 ---- a/src/openssl.h -+++ b/src/openssl.h -@@ -64,8 +64,10 @@ - - #ifdef OPENSSL_NO_RSA - # define LIBSSH2_RSA 0 -+# define LIBSSH2_RSA_SHA2 0 - #else - # define LIBSSH2_RSA 1 -+# define LIBSSH2_RSA_SHA2 1 - #endif - - #ifdef OPENSSL_NO_DSA -diff --git a/src/packet.c b/src/packet.c -index 04937d6..686be5c 100644 ---- a/src/packet.c -+++ b/src/packet.c -@@ -616,6 +616,75 @@ _libssh2_packet_add(LIBSSH2_SESSION * session, unsigned char *data, - return 0; - - /* -+ byte SSH_MSG_EXT_INFO -+ uint32 nr-extensions -+ [repeat "nr-extensions" times] -+ string extension-name [RFC8308] -+ string extension-value (binary) -+ */ -+ -+ case SSH_MSG_EXT_INFO: -+ if(datalen >= 5) { -+ uint32_t nr_extensions = 0; -+ struct string_buf buf; -+ buf.data = (unsigned char *)data; -+ buf.dataptr = buf.data; -+ buf.len = datalen; -+ buf.dataptr += 1; /* advance past type */ -+ -+ if(_libssh2_get_u32(&buf, &nr_extensions) != 0) { -+ rc = _libssh2_error(session, LIBSSH2_ERROR_PROTO, -+ "Invalid extension info received"); -+ } -+ -+ while(rc == 0 && nr_extensions > 0) { -+ -+ size_t name_len = 0; -+ size_t value_len = 0; -+ unsigned char *name = NULL; -+ unsigned char *value = NULL; -+ -+ nr_extensions -= 1; -+ -+ _libssh2_get_string(&buf, &name, &name_len); -+ _libssh2_get_string(&buf, &value, &value_len); -+ -+ if(name != NULL && value != NULL) { -+ _libssh2_debug(session, -+ LIBSSH2_TRACE_KEX, -+ "Server to Client extension %.*s: %.*s", -+ name_len, name, value_len, value); -+ } -+ -+ if(name_len == 15 && -+ memcmp(name, "server-sig-algs", 15) == 0) { -+ if(session->server_sign_algorithms) { -+ LIBSSH2_FREE(session, -+ session->server_sign_algorithms); -+ } -+ -+ session->server_sign_algorithms = -+ LIBSSH2_ALLOC(session, -+ value_len); -+ -+ if(session->server_sign_algorithms) { -+ session->server_sign_algorithms_len = value_len; -+ memcpy(session->server_sign_algorithms, -+ value, value_len); -+ } -+ else { -+ rc = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, -+ "memory for server sign algo"); -+ } -+ } -+ } -+ } -+ -+ LIBSSH2_FREE(session, data); -+ session->packAdd_state = libssh2_NB_state_idle; -+ return rc; -+ -+ /* - byte SSH_MSG_GLOBAL_REQUEST - string request name in US-ASCII only - boolean want reply -diff --git a/src/userauth.c b/src/userauth.c -index 4442eee..988dc17 100644 ---- a/src/userauth.c -+++ b/src/userauth.c -@@ -1086,6 +1086,148 @@ static int plain_method_len(const char *method, size_t method_len) - return method_len; - } - -+/** -+ * @function _libssh2_key_sign_algorithm -+ * @abstract Upgrades the algorithm used for public key signing RFC 8332 -+ * @discussion Based on the incoming key_method value, this function -+ * will upgrade the key method input based on user preferences, -+ * server support algos and crypto backend support -+ * @related _libssh2_supported_key_sign_algorithms() -+ * @param key_method current key method, usually the default key sig method -+ * @param key_method_len length of the key method buffer -+ * @result error code or zero on success -+ */ -+ -+static int -+_libssh2_key_sign_algorithm(LIBSSH2_SESSION *session, -+ unsigned char **key_method, -+ size_t *key_method_len) -+{ -+ const char *s = NULL; -+ const char *a = NULL; -+ const char *match = NULL; -+ const char *p = NULL; -+ const char *f = NULL; -+ char *i = NULL; -+ int p_len = 0; -+ int f_len = 0; -+ int rc = 0; -+ int match_len = 0; -+ char *filtered_algs = NULL; -+ -+ const char *supported_algs = -+ _libssh2_supported_key_sign_algorithms(session, -+ *key_method, -+ *key_method_len); -+ -+ if(supported_algs == NULL || session->server_sign_algorithms == NULL) { -+ /* no upgrading key algorithm supported, do nothing */ -+ return LIBSSH2_ERROR_NONE; -+ } -+ -+ filtered_algs = LIBSSH2_ALLOC(session, strlen(supported_algs) + 1); -+ if(!filtered_algs) { -+ rc = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, -+ "Unable to allocate filtered algs"); -+ return rc; -+ } -+ -+ s = session->server_sign_algorithms; -+ i = filtered_algs; -+ -+ /* this walks the server algo list and the supported algo list and creates -+ a filtered list that includes matches */ -+ -+ while(s && *s) { -+ p = strchr(s, ','); -+ p_len = p ? (p - s) : (int) strlen(s); -+ a = supported_algs; -+ -+ while(a && *a) { -+ f = strchr(a, ','); -+ f_len = f ? (f - a) : (int) strlen(a); -+ -+ if(f_len == p_len && memcmp(a, s, p_len)) { -+ -+ if(i != filtered_algs) { -+ memcpy(i, ",", 1); -+ i += 1; -+ } -+ -+ memcpy(i, s, p_len); -+ i += p_len; -+ } -+ -+ a = f ? (f + 1) : NULL; -+ } -+ -+ s = p ? (p + 1) : NULL; -+ } -+ -+ filtered_algs[i - filtered_algs] = '\0'; -+ -+ if(session->sign_algo_prefs) { -+ s = session->sign_algo_prefs; -+ } -+ else { -+ s = supported_algs; -+ } -+ -+ /* now that we have the possible supported algos, match based on the prefs -+ or what is supported by the crypto backend, look for a match */ -+ -+ while(s && *s && !match) { -+ p = strchr(s, ','); -+ p_len = p ? (p - s) : (int) strlen(s); -+ a = filtered_algs; -+ -+ while(a && *a && !match) { -+ f = strchr(a, ','); -+ f_len = f ? (f - a) : (int) strlen(a); -+ -+ if(f_len == p_len && memcmp(a, s, p_len)) { -+ /* found a match, upgrade key method */ -+ match = s; -+ match_len = p_len; -+ } -+ else { -+ a = f ? (f + 1) : NULL; -+ } -+ } -+ -+ s = p ? (p + 1) : NULL; -+ } -+ -+ if(match != NULL) { -+ if(*key_method) -+ LIBSSH2_FREE(session, *key_method); -+ -+ *key_method = LIBSSH2_ALLOC(session, match_len); -+ if(key_method) { -+ memcpy(*key_method, match, match_len); -+ *key_method_len = match_len; -+ -+ _libssh2_debug(session, LIBSSH2_TRACE_KEX, -+ "Signing using %.*s", match_len, match); -+ } -+ else { -+ *key_method_len = 0; -+ rc = _libssh2_error(session, LIBSSH2_ERROR_ALLOC, -+ "Unable to allocate key method upgrade"); -+ } -+ } -+ else { -+ /* no match was found */ -+ rc = _libssh2_error(session, LIBSSH2_ERROR_METHOD_NONE, -+ "No signing signature matched"); -+ } -+ -+ if(filtered_algs) -+ LIBSSH2_FREE(session, filtered_algs); -+ -+ return rc; -+} -+ - int - _libssh2_userauth_publickey(LIBSSH2_SESSION *session, - const char *username, -@@ -1144,15 +1286,14 @@ _libssh2_userauth_publickey(LIBSSH2_SESSION *session, - memcpy(session->userauth_pblc_method, pubkeydata + 4, - session->userauth_pblc_method_len); - } -- /* -- * The length of the method name read from plaintext prefix in the -- * file must match length embedded in the key. -- * TODO: The data should match too but we don't check that. Should we? -- */ -- else if(session->userauth_pblc_method_len != -- _libssh2_ntohu32(pubkeydata)) -- return _libssh2_error(session, LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED, -- "Invalid public key"); -+ -+ /* upgrade key key signing algo needed */ -+ rc = _libssh2_key_sign_algorithm(session, -+ &session->userauth_pblc_method, -+ &session->userauth_pblc_method_len); -+ -+ if(rc) -+ return rc; - - /* - * 45 = packet_type(1) + username_len(4) + servicename_len(4) + -diff --git a/src/wincng.c b/src/wincng.c -index 9ae8dde..58e2251 100644 ---- a/src/wincng.c -+++ b/src/wincng.c -@@ -2591,4 +2591,22 @@ fb: - return _libssh2_wincng_bignum_mod_exp(secret, f, dhctx->bn, p); - } - -+/* _libssh2_supported_key_sign_algorithms -+ * -+ * Return supported key hash algo upgrades, see crypto.h -+ * -+ */ -+ -+const char * -+_libssh2_supported_key_sign_algorithms(LIBSSH2_SESSION *session, -+ unsigned char *key_method, -+ size_t key_method_len) -+{ -+ (void)session; -+ (void)key_method; -+ (void)key_method_len; -+ -+ return NULL; -+} -+ - #endif /* LIBSSH2_WINCNG */ -diff --git a/src/wincng.h b/src/wincng.h -index eaf6f90..538cc43 100644 ---- a/src/wincng.h -+++ b/src/wincng.h -@@ -63,6 +63,7 @@ - #define LIBSSH2_3DES 1 - - #define LIBSSH2_RSA 1 -+#define LIBSSH2_RSA_SHA2 0 - #define LIBSSH2_DSA 1 - #define LIBSSH2_ECDSA 0 - #define LIBSSH2_ED25519 0 --- -1.8.3.1 - diff --git a/backport-Skip-leading-r-and-n-characters-in-banner_receive-76.patch b/backport-Skip-leading-r-and-n-characters-in-banner_receive-76.patch deleted file mode 100644 index 15ed7a8ff2f775944d469d4f10b8ff2d66dc697f..0000000000000000000000000000000000000000 --- a/backport-Skip-leading-r-and-n-characters-in-banner_receive-76.patch +++ /dev/null @@ -1,33 +0,0 @@ -From 821d50dad313b53fb2782f26aec1f52f1be34fc0 Mon Sep 17 00:00:00 2001 -From: Michael Buckley -Date: Wed, 9 Nov 2022 15:56:22 -0800 -Subject: [PATCH] Skip leading \r and \n characters in banner_receive() (#769) - -Fixes #768 - -Credit: -Michael Buckley -Conflict:NA -Reference:https://github.com/libssh2/commit/821d50dad313b53fb2782f26aec1f52f1be34fc0 ---- - src/session.c | 4 ++++ - 1 file changed, 4 insertions(+) - -diff --git a/src/session.c b/src/session.c -index 3549152..235ab95 100644 ---- a/src/session.c -+++ b/src/session.c -@@ -147,6 +147,10 @@ banner_receive(LIBSSH2_SESSION * session) - return LIBSSH2_ERROR_SOCKET_DISCONNECT; - } - -+ if((c == '\r' || c == '\n') && banner_len == 0) { -+ continue; -+ } -+ - if(c == '\0') { - /* NULLs are not allowed in SSH banners */ - session->banner_TxRx_state = libssh2_NB_state_idle; --- -2.23.0 - diff --git a/backport-Support-rsa-sha2-agent-flags.patch b/backport-Support-rsa-sha2-agent-flags.patch deleted file mode 100644 index 2837cffa4ac14c515a242055cbb81018596cccb5..0000000000000000000000000000000000000000 --- a/backport-Support-rsa-sha2-agent-flags.patch +++ /dev/null @@ -1,63 +0,0 @@ -From 50a1262772fd9cdbdd8f747958e42ef480aecb2b Mon Sep 17 00:00:00 2001 -From: Ian Hattendorf -Date: Thu, 13 Jan 2022 16:05:53 -0700 -Subject: [PATCH] Support rsa-sha2 agent flags (#661) - -File: agent.c -Notes: implements rsa-sha2 flags used to tell the agent which signing algo to use. - https://tools.ietf.org/id/draft-miller-ssh-agent-01.html#rfc.section.4.5.1 - -Credit: -Ian Hattendorf -Conflict:NA -Reference:https://github.com/libssh2/commit/50a1262772fd9cdbdd8f747958e42ef480aecb2b ---- - src/agent.c | 18 +++++++++++++++++- - 1 file changed, 17 insertions(+), 1 deletion(-) - -diff --git a/src/agent.c b/src/agent.c -index a526c77..bce7175 100644 ---- a/src/agent.c -+++ b/src/agent.c -@@ -94,6 +94,10 @@ - #define SSH_AGENT_CONSTRAIN_LIFETIME 1 - #define SSH_AGENT_CONSTRAIN_CONFIRM 2 - -+/* Signature request methods */ -+#define SSH_AGENT_RSA_SHA2_256 2 -+#define SSH_AGENT_RSA_SHA2_512 4 -+ - #ifdef PF_UNIX - static int - agent_connect_unix(LIBSSH2_AGENT *agent) -@@ -375,6 +379,7 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, - ssize_t method_len; - unsigned char *s; - int rc; -+ uint32_t sign_flags = 0; - - /* Create a request to sign the data */ - if(transctx->state == agent_NB_state_init) { -@@ -391,7 +396,18 @@ agent_sign(LIBSSH2_SESSION *session, unsigned char **sig, size_t *sig_len, - _libssh2_store_str(&s, (const char *)data, data_len); - - /* flags */ -- _libssh2_store_u32(&s, 0); -+ if(session->userauth_pblc_method_len > 0 && -+ session->userauth_pblc_method) { -+ if(session->userauth_pblc_method_len == 12 && -+ !memcmp(session->userauth_pblc_method, "rsa-sha2-512", 12)) { -+ sign_flags = SSH_AGENT_RSA_SHA2_512; -+ } -+ else if(session->userauth_pblc_method_len == 12 && -+ !memcmp(session->userauth_pblc_method, "rsa-sha2-256", 12)) { -+ sign_flags = SSH_AGENT_RSA_SHA2_256; -+ } -+ } -+ _libssh2_store_u32(&s, sign_flags); - - transctx->request_len = s - transctx->request; - transctx->send_recv_total = 0; --- -2.23.0 - diff --git a/backport-free-RSA2-related-memory-664.patch b/backport-free-RSA2-related-memory-664.patch deleted file mode 100644 index 3f0230bac55db065141ed4cea14b2cdc6f7fe247..0000000000000000000000000000000000000000 --- a/backport-free-RSA2-related-memory-664.patch +++ /dev/null @@ -1,32 +0,0 @@ -From 30fc410b972e6dec87c248c0fedbff28cfa18f17 Mon Sep 17 00:00:00 2001 -From: Will Cosgrove -Date: Tue, 18 Jan 2022 11:28:13 -0800 -Subject: [PATCH] free RSA2 related memory (#664) - -Free `server_sign_algorithms` and `sign_algo_prefs`. -Conflict:NA -Reference:https://github.com/libssh2/commit/30fc410b972e6dec87c248c0fedbff28cfa18f17 ---- - src/session.c | 6 ++++++ - 1 file changed, 6 insertions(+) - -diff --git a/src/session.c b/src/session.c -index 0de5ab3..ae6132c 100644 ---- a/src/session.c -+++ b/src/session.c -@@ -981,6 +981,12 @@ session_free(LIBSSH2_SESSION *session) - if(session->remote.lang_prefs) { - LIBSSH2_FREE(session, session->remote.lang_prefs); - } -+ if(session->server_sign_algorithms) { -+ LIBSSH2_FREE(session, session->server_sign_algorithms); -+ } -+ if(session->sign_algo_prefs) { -+ LIBSSH2_FREE(session, session->sign_algo_prefs); -+ } - - /* - * Make sure all memory used in the state variables are free --- -2.23.0 - diff --git a/backport-misc-libssh2_copy_string-avoid-malloc-zero-bytes.patch b/backport-misc-libssh2_copy_string-avoid-malloc-zero-bytes.patch deleted file mode 100644 index 371aab6a8e4e57859e0c6b512fdb0f81c01dd3df..0000000000000000000000000000000000000000 --- a/backport-misc-libssh2_copy_string-avoid-malloc-zero-bytes.patch +++ /dev/null @@ -1,33 +0,0 @@ -From: https://github.com/libssh2/libssh2/commit/e7e1312b0cbfa643e2f8bf5f2036ce5147ed797d -From: bagder -Date: 21 Mar 2022 10:11 -0800 -Subject: misc/libssh2_copy_string: avoid malloc zero bytes #686 - -Notes: -* Avoid the inconsistent malloc return code for malloc(0) - ---- libssh2-1.10.0/src/misc.c 2019-09-13 14:39:11.000000000 +0800 -+++ libssh2-1.10.0/src/misc.c 2022-09-29 18:27:13.604424483 +0800 -@@ -794,12 +794,18 @@ - return -1; - } - -- *outbuf = LIBSSH2_ALLOC(session, str_len); -- if(*outbuf) { -- memcpy(*outbuf, str, str_len); -+ if(str_len) { -+ *outbuf = LIBSSH2_ALLOC(session, str_len); -+ if(*outbuf) { -+ memcpy(*outbuf, str, str_len); -+ } -+ else { -+ return -1; -+ } - } - else { -- return -1; -+ *outlen = 0; -+ *outbuf = NULL; - } - - if(outlen) diff --git a/libssh2-1.10.0.tar.gz b/libssh2-1.10.0.tar.gz deleted file mode 100644 index 675581d990ecaf32f5c078542b66efe956255393..0000000000000000000000000000000000000000 Binary files a/libssh2-1.10.0.tar.gz and /dev/null differ diff --git a/libssh2-1.11.0.tar.gz b/libssh2-1.11.0.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..a2a60461915f588ad6b0653d77cf49f64750be3a Binary files /dev/null and b/libssh2-1.11.0.tar.gz differ diff --git a/libssh2.spec b/libssh2.spec index 05343959c3f979daa2354d8e7c653b6c041421dc..8fe0073a58af3ce0be4de14258e4aded18ab2fd6 100644 --- a/libssh2.spec +++ b/libssh2.spec @@ -1,23 +1,13 @@ Name: libssh2 -Version: 1.10.0 -Release: 6 +Version: 1.11.0 +Release: 1 Summary: A library implementing the SSH2 protocol License: BSD URL: https://www.libssh2.org/ Source0: https://libssh2.org/download/libssh2-%{version}.tar.gz -Patch0: backport-RSA-SHA2-256-512-key-upgrade-support-RFC-8332.patch -Patch1: backport-misc-libssh2_copy_string-avoid-malloc-zero-bytes.patch -Patch2: sftp-Prevent-files-from-being-skipped-if-the-output.patch -Patch3: backport-Support-rsa-sha2-agent-flags.patch -Patch4: backport-Fix-a-memcmp-errors-in-code-that-was-changed-from-me.patch -Patch5: backport-Legacy-Agent-support-for-rsa2-key-upgrading-downgrad.patch -Patch6: backport-free-RSA2-related-memory-664.patch -Patch7: backport-NULL-terminate-server_sign_algorithms-string-669.patch -Patch8: backport-Skip-leading-r-and-n-characters-in-banner_receive-76.patch - BuildRequires: coreutils findutils /usr/bin/man zlib-devel -BuildRequires: gcc make sed openssl-devel > 1:1.0.1 openssh-server +BuildRequires: gcc make sed openssl-devel > 1:1.0.2 openssh-server BuildRequires: glibc-langpack-en groff %description @@ -39,10 +29,10 @@ developing applications that use libssh2. %prep %autosetup -n %{name}-%{version} -p1 -sed -i s/4711/47%{__isa_bits}/ tests/ssh2.{c,sh} +sed -i s/4711/47%{?__isa_bits}/ tests/{openssh_fixture.c,test_ssh{2.c,d.test}} %build -%configure --disable-silent-rules --enable-shared +%configure --disable-silent-rules --enable-shared --disable-docker-tests %make_build %install @@ -90,17 +80,23 @@ LC_ALL=en_US.UTF-8 make -C tests check %files help %defattr(-,root,root) -%doc docs/BINDINGS docs/HACKING docs/TODO NEWS +%doc docs/BINDINGS.md docs/HACKING.md docs/TODO NEWS %{_mandir}/man3/libssh2_*.3* %changelog -* Tue Mar 28 2023 renmingshuai - 1.10.0-6 +* Mon Aug 7 2023 renmingshuai - 1.11.0-1 +- Type:requirement +- ID:NA +- SUG:NA +- DESC:update to 1.11.0 + +* Tue Mar 28 2023 renmingshuai - 1.10.0-6 - Type:bugfix - ID:NA - SUG:NA - DESC:backport some upstream patches -* Thu Feb 16 2023 renmingshuai - 1.10.0-5 +* Thu Feb 16 2023 renmingshuai - 1.10.0-5 - Type:bugfix - ID:NA - SUG:NA diff --git a/sftp-Prevent-files-from-being-skipped-if-the-output.patch b/sftp-Prevent-files-from-being-skipped-if-the-output.patch deleted file mode 100644 index b8ce89cc98351fba2f17fe43771c945029ad965a..0000000000000000000000000000000000000000 --- a/sftp-Prevent-files-from-being-skipped-if-the-output.patch +++ /dev/null @@ -1,43 +0,0 @@ -From bd9c65d68c4152ba0726f5588b4b611410972fbc Mon Sep 17 00:00:00 2001 -From: Gabriel Smith -Date: Fri, 23 Sep 2022 13:03:56 -0400 -Subject: [PATCH] sftp: Prevent files from being skipped if the output buffer - is too small (#746) - -Notes: -LIBSSH2_ERROR_BUFFER_TOO_SMALL is returned if the buffer is too small -to contain a returned directory entry. On this condition we jump to the -label `end`. At this point the number of names left is decremented -despite no name being returned. - -As suggested in #714, this commit moves the error label after the -decrement of `names_left`. - -Fixes #714 - -Credit: -Co-authored-by: Gabriel Smith ---- - src/sftp.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/src/sftp.c b/src/sftp.c -index b1a5352..2df918a 100644 ---- a/src/sftp.c -+++ b/src/sftp.c -@@ -1852,11 +1852,11 @@ static ssize_t sftp_readdir(LIBSSH2_SFTP_HANDLE *handle, char *buffer, - - handle->u.dir.next_name = (char *) s; - handle->u.dir.names_packet_len = names_packet_len; -- end: - - if((--handle->u.dir.names_left) == 0) - LIBSSH2_FREE(session, handle->u.dir.names_packet); - -+ end: - _libssh2_debug(session, LIBSSH2_TRACE_SFTP, - "libssh2_sftp_readdir_ex() return %d", - filename_len); --- -2.25.1 -