You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
KEX extension indicators are lost in libssh2_session_method_pref() #1326
Describe the bug
Default list of preferred KEX methods contains also extension indicators "ext-info-c" and "[email protected]".
If new list is configured using libssh2_session_method_pref() function these indicators are not preserved unless the caller
explicitly includes them in input *prefs argument.
This can cause mismatched result of handshake - remote side disables the extensions because libssh2 does not announce them
while libssh2 enables them according to peer's announcement.
To Reproduce
Set valid list of KEX methods before libssh2_session_handshake() that does not explicitly include "ext-info-c" and "[email protected]" pseudo-methods.
Enable debug logging and connect to a server supporting these extensions. Check if both sides are using them.
Expected behavior
libssh2 based client announce available KEX extensions and both sides have enabled them after handshake.
Additional context
I found this issue when mismatching strict-kex setup after kex init caused failed connection with error:
[libssh2] 0.524957 Failure Event: -43 - Failed to get response to ssh-userauth request
Failure establishing SSH session: -43
However that depends on negotiated ciphers - with different configuration was the connection established but with different strict-kex setup on both sides.
IMO this bug can disable recent fix for Terrapin Attack (CVE-2023-48795).
I'm not sure how "ext-info" works but strict-kex can't be turned off by removing the pseudo algorithm from that list.
It only disables the announcement sent to remote peer.
Whether kex_strict is used is decided only by presence of "[email protected]" in message from remote side. libssh2 never checks whether it sent the client's strict-key announcement or whether it was removed.
Therefore it causes the mismatch - libssh2 expect that strict-kex support was negotiated because it was announced by remote peer. Remote peer disables it because it got no strict-kex announcement from libssh2.
BTW, your approach would require modification of every app using libssh2 to append the strict-kex pseudo-alg to every method_pref call to be protected from Terrapin attack.
Chiming in as the person who wrote the original implementation of the terrapin mitigation code for libssh2. I think this is a legitimate issue after all.
Originally, I was concerned that not giving users a way to remove the indicator from the KEX list would cause problems with some older, non-OpenSSH servers. We've seen the occasional server that just doesn't allow connections if the KEX list (or similar) isn't exactly what it expects from the client. So I wanted a way to allow users to specify, though their ~/.ssh/config file, a KEX list exactly as their server needed it.
Yes, this would mean every client would have to manually append the indicators if they wanted to enforce them. But in my mind, it should have been up to the user whether to turn these on or off, and thus, up to the user whether or not they want to mitigate terrapin.
But since I always set session->kex_strict based on whether or not the indicator is in the server list, without checking the client, @malyzelenyhnus is correct that removing the indicator does not turn off strict checking. Given my original intent, that would be the real bug.
However ,while looking into this further, however, it appears that OpenSSH always appends the indicators, no matter what. We should probably follow OpenSSH's lead. I feel a bit bad for our tech support colleagues who will have to field complaints from people using old, bespoke servers, but the fact that those users won't be able to connect with OpenSSH clients either should provide them some cover.
Activity
willco007 commentedon Mar 12, 2024
I believe this is by design. There needs to be a way to turn them off. If you want them on, add them to the list you pass in to method_pref.
malyzelenyhnus commentedon Mar 12, 2024
I'm not sure how "ext-info" works but strict-kex can't be turned off by removing the pseudo algorithm from that list.
It only disables the announcement sent to remote peer.
Whether kex_strict is used is decided only by presence of "[email protected]" in message from remote side. libssh2 never checks whether it sent the client's strict-key announcement or whether it was removed.
Therefore it causes the mismatch - libssh2 expect that strict-kex support was negotiated because it was announced by remote peer. Remote peer disables it because it got no strict-kex announcement from libssh2.
BTW, your approach would require modification of every app using libssh2 to append the strict-kex pseudo-alg to every method_pref call to be protected from Terrapin attack.
MichaelBuckley commentedon Mar 12, 2024
Chiming in as the person who wrote the original implementation of the terrapin mitigation code for libssh2. I think this is a legitimate issue after all.
Originally, I was concerned that not giving users a way to remove the indicator from the KEX list would cause problems with some older, non-OpenSSH servers. We've seen the occasional server that just doesn't allow connections if the KEX list (or similar) isn't exactly what it expects from the client. So I wanted a way to allow users to specify, though their ~/.ssh/config file, a KEX list exactly as their server needed it.
Yes, this would mean every client would have to manually append the indicators if they wanted to enforce them. But in my mind, it should have been up to the user whether to turn these on or off, and thus, up to the user whether or not they want to mitigate terrapin.
But since I always set session->kex_strict based on whether or not the indicator is in the server list, without checking the client, @malyzelenyhnus is correct that removing the indicator does not turn off strict checking. Given my original intent, that would be the real bug.
However ,while looking into this further, however, it appears that OpenSSH always appends the indicators, no matter what. We should probably follow OpenSSH's lead. I feel a bit bad for our tech support colleagues who will have to field complaints from people using old, bespoke servers, but the fact that those users won't be able to connect with OpenSSH clients either should provide them some cover.
kex: always add extension indicators to kex_algorithms (#1327)
kex: always add extension indicators to kex_algorithms (libssh2#1327)
libssh2: upgrade 1.11.0 -> 1.11.1
libssh2: upgrade 1.11.0 -> 1.11.1
libssh2: upgrade 1.11.0 -> 1.11.1
libssh2: upgrade 1.11.0 -> 1.11.1
libssh2: upgrade 1.11.0 -> 1.11.1
libssh2: upgrade 1.11.0 -> 1.11.1
libssh2: upgrade 1.11.0 -> 1.11.1
libssh2: upgrade 1.11.0 -> 1.11.1
libssh2: upgrade 1.11.0 -> 1.11.1