@@ -2003,7 +2003,9 @@ nc_accept_ssh_session(struct nc_session *session, struct nc_server_ssh_opts *opt
20032003 goto cleanup ;
20042004 }
20052005 if (opts -> encryption_algs ) {
2006- if (ssh_bind_options_set (sbind , SSH_BIND_OPTIONS_CIPHERS_S_C , opts -> encryption_algs )) {
2006+ /* both client->server and server->client directions set for the same reason as for MAC algorithms below */
2007+ if (ssh_bind_options_set (sbind , SSH_BIND_OPTIONS_CIPHERS_S_C , opts -> encryption_algs ) ||
2008+ ssh_bind_options_set (sbind , SSH_BIND_OPTIONS_CIPHERS_C_S , opts -> encryption_algs )) {
20072009 ERR (session , "Failed to set encryption algorithms (%s)." , ssh_get_error (sbind ));
20082010 rc = -1 ;
20092011 goto cleanup ;
@@ -2015,7 +2017,14 @@ nc_accept_ssh_session(struct nc_session *session, struct nc_server_ssh_opts *opt
20152017 goto cleanup ;
20162018 }
20172019 if (opts -> mac_algs ) {
2018- if (ssh_bind_options_set (sbind , SSH_BIND_OPTIONS_HMAC_S_C , opts -> mac_algs )) {
2020+ /* * SSH negotiates MAC algorithms independently for each direction (Client->Server
2021+ * and Server->Client). We must explicitly apply the configured algorithms to
2022+ * both directions to ensure consistent security and avoid falling back to
2023+ * libssh defaults for the unspecified direction.
2024+ * Ref: https://github.com/CESNET/libnetconf2/issues/523
2025+ */
2026+ if (ssh_bind_options_set (sbind , SSH_BIND_OPTIONS_HMAC_S_C , opts -> mac_algs ) ||
2027+ ssh_bind_options_set (sbind , SSH_BIND_OPTIONS_HMAC_C_S , opts -> mac_algs )) {
20192028 ERR (session , "Failed to set MAC algorithms (%s)." , ssh_get_error (sbind ));
20202029 rc = -1 ;
20212030 goto cleanup ;
0 commit comments