Skip to content

KEX extension indicators are lost in libssh2_session_method_pref() #1326

Closed

Description

@malyzelenyhnus

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.

Versions:

SLES12-SP5

  • libssh2-1-1.11.0-29.9.1.x86_64 (or upstream master 4bba038)
  • openssl-1_0_0-1.0.2p-3.87.1.x86_64

OpenSUSE LEAP 15-5

  • libssh2 master branch 4bba038
  • openssl-1_1-1.1.1l-150500.17.22.1

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).

Activity

  1. willco007 commented on Mar 12, 2024

    @willco007
    Member

    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.

  2. malyzelenyhnus commented on Mar 12, 2024

    @malyzelenyhnus
    ContributorAuthor

    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.

  3. MichaelBuckley commented on Mar 12, 2024

    @MichaelBuckley
    Contributor

    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.

  4. added a commit that references this issue on Mar 28, 2024
    00e2a07
  5. added a commit that references this issue on Jul 14, 2024
    d4254ef
  6. added a commit that references this issue on Dec 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions