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
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).
Reacted by Daniel Perez, Ian Hattendorf, WSLUser and Viktor Szakats
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.
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).
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.
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.
@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.
@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.
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.
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.
Activity
willco007 commentedon Apr 28, 2021
I have ETM working on my private branch but as I've noted before, it's a bit of a hack. Specifically
_libssh2_transport_readneeds to support ETM and also further down the roadchacha20needs 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.bk2204 commentedon Apr 28, 2021
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).
stale commentedon Aug 28, 2021
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.
SuperSandro2000 commentedon Aug 28, 2021
Bump
palmin commentedon Nov 5, 2021
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_METHODand use this field intransport:fullpacket()andtransport:_libssh2_transport_send()to decide whether the hash is checked/calculated before or after encoding.I haven't tried this and your mention of
chacha20makes 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.
willco007 commentedon Nov 5, 2021
@palmin, That's generally how I've implemented it. When using
etmthe 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.chacha20further 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.palmin commentedon Nov 5, 2021
@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.
palmin commentedon Dec 25, 2021
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 totransport.c:_libssh2_packet_addeven when MAC fails and the packet payload is not decrypted which feels pretty weird. Perhaps the packet should be decrypted even when MAC fails ifsession->macerroris set.stale commentedon Apr 28, 2022
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.
support encrypt-then-mac (etm) MACs (#987)
support encrypt-then-mac (etm) MACs (libssh2#987)