Skip to content

Implement HMAC -SHA-2 EtM #582

Closed

Description

@bk2204

Describe the bug
libssh2 does not implement the [email protected] or [email protected] algorithms.

To Reproduce
Attempt to connect to a server supporting only those algorithms as MACs and notice it fails.

Expected behavior
libssh2 should connect to servers offering only HMAC-SHA-2 encrypt-then-MAC cipher suites.

Version (please complete the following information):
Should be all systems using the latest master. I don't see any instances of etm in the codebase at all.

Additional context
This came up because I'm aware of a Git server implementation running in FIPS mode which allows only [email protected] (which doesn't need a MAC) or aes256-ctr as ciphers and [email protected] and [email protected] as MACs. (I can't mention names at the moment.) libgit2 uses libssh2, and libgit2 is unable to connect to this implementation.

My needs could also be met by implementing [email protected], but I suspect the HMAC-SHA2 EtM algorithms is going to be easier.

I'm not interested in [email protected] or [email protected] because I'd like to see SHA-1 die a fiery death as soon as possible, so this report does not ask for them to be implemented (and I would prefer if they were not).

Activity

  1. willco007 commented on Apr 28, 2021

    @willco007
    Member

    I have ETM working on my private branch but as I've noted before, it's a bit of a hack. Specifically _libssh2_transport_read needs to support ETM and also further down the road chacha20 needs to decrypt the full packet to get the size which also further complicates this function. It should probably branch to helper functions based on the type of payload it's working on. I just haven't had the time to do all this work on main.

  2. bk2204 commented on Apr 28, 2021

    @bk2204
    ContributorAuthor

    I do want to be clear, since I'm not writing the code, I have no timeline for this being implemented or expectation that it will be; this is merely to track that somebody would like these implementations, so if some generous person wanted to do that, it's known. So I'm delighted that you already have this working at all and am happy to wait (or, maybe in the future, contribute if that's desired and I have sufficient time).

  3. stale commented on Aug 28, 2021

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  4. SuperSandro2000 commented on Aug 28, 2021

    @SuperSandro2000

    Bump

  5. palmin commented on Nov 5, 2021

    @palmin
    Contributor

    Would you like some assistance with this issue, @willco007 ?

    My strategy to support encode-then-mac is to add a new field to _LIBSSH2_MAC_METHOD and use this field in transport:fullpacket() and transport:_libssh2_transport_send() to decide whether the hash is checked/calculated before or after encoding.

    I haven't tried this and your mention of chacha20 makes me think there are subtleties I do not understand.

    If you like I could bring the work from your private branch into main such that you would only need to review my changes minimising the time spent by you.

    Otherwise I will move forward with my strategy and hope it leads to something useful.

  6. willco007 commented on Nov 5, 2021

    @willco007
    Member

    @palmin, That's generally how I've implemented it. When using etm the size field of the packet isn't encrypted and it requires the full packet to be present before encrypting/decrypting it. ETM also has some padding bytes that need to be dealt with. This behavior is not what _libssh2_transport_read() expects (it works on blocks at a time) so in my branch there is a lot of if etm, else... I felt like that wasn't clean enough for a PR so I've held it back. chacha20 further complicates things by encrypting the size field and adding a tag to each packet. If this is something we want to do, I can post my code some place and we can factor it into a way clean enough for a PR.

  7. palmin commented on Nov 5, 2021

    @palmin
    Contributor

    @willco007 I would like to try this and I hope we can do this in a way that doesn’t require a lot of your time as I suspect that I have more hours for libssh2 at the moment.

  8. palmin commented on Dec 25, 2021

    @palmin
    Contributor

    I have been working on something in PR #655 / 63805b9 and would love to get feedback.

    When reading packets in etm mode the encryption is postponed until the entire packet is read, which allows skipping decryption if message authentication code is wrong. This is mentioned in the OpenSSH 7.2 release notes as a way to avoid timming attacks.

    Decryption when reading in etm mode is done in transport.c:fullpacket() and the packet is passed to transport.c:_libssh2_packet_add even when MAC fails and the packet payload is not decrypted which feels pretty weird. Perhaps the packet should be decrypted even when MAC fails if session->macerror is set.

  9. stale commented on Apr 28, 2022

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

  10. added a commit that references this issue on Apr 21, 2023
    0048f30
  11. added a commit that references this issue on Jul 14, 2024
    d379592
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions