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
[libssh 1.10.1_dev] Error "Invalid MAC received" when building without HAVE_EVP_AES_128_CTR #739
Using libgit2 + libssh2 + openssl 1.1.1 compiled with mingw-w64. After upgrading from 1.10.0 to 1.10.1_dev (master branch) cloning git+ssh repos from GitHub fails with:
Error in libgit2::git_clone : failed to start SSH session: Invalid MAC received
Reverting to libssh2 1.10.1 fixes the problem, so there seems to be a regression. Afaict, the issue only appears on Windows. What recent changes could be causing this?
One thing I noticed comparing the (working) 1.10.0 build with the dev version is that the value of fullpacket_payload_len is different. In the stable branch it is always 27, but in the dev version it is much larger, I have seen 59 or 539 depending the server.
@jeroen if you revert the EVP_CipherUpdate change does it work for you? We do run tests on Windows + OpenSSL which should catch a regression in transport like this unless it's some odd interplay with mingw.
Yes after reverting the EVP_CipherUpdate change it works again. Do the tests actually connect to an ssh server? I am also surprised to see this problem only on Windows; we specifically build with gcc and openssl to get the same behaviour as on mac/linux.
If I'm reading this correctly, the API only appears to used with arcfour128 cipher which is disabled in modern OpenSSH and isn't hit with the unit tests.
Are you specifying arcfour128 explicitly? Have you reverted that entire commit, or just that one line? Assuredly the GitHub servers aren't using it by default. Could you attach a trace from a failed connection and a successful one? Thanks!
One thing that makes this difficult to debug is that the LIBSSH2_SESSION is started by libgit2, so I don't have much control over it. Is there an envvar I can set to get a trace?
I am not setting arcfour128 but perhaps libgit2 does things (though I don't see where this would be happening).
On the session you call libssh2_trace with say, these flags LIBSSH2_TRACE_KEX | LIBSSH2_TRACE_AUTH | LIBSSH2_TRACE_PUBLICKEY | LIBSSH2_TRACE_ERROR and then set a trace handler with libssh2_trace_sethandler and log the output some place.
Could you check the values for HAVE_OPAQUE_STRUCTS, LIBSSH2_WOLFSSL and LIBSSH2_OPENSSL? Maybe they aren't being defined correctly for whatever reason.
Did some more debugging, was able to reproduce the issue with some systems and not others. It turned out that on broken systems, HAVE_EVP_AES_128_CTR is not set in src/libssh2_config, probably because these have a static build of openssl.
So I guess the problem is now as follows:
autoconf is not properly detecting EVP_aes_128_ctr when openssl is only available as static library
the libssh2 fallback method for EVP_aes_128_ctr is broken
somehow this triggers a problem in EVP_CipherUpdate that wasn't there before 17c9c1f
I think you should be able to repro the issue on other systems by unsetting HAVE_EVP_AES_128_CTR in libssh2_config
I think the best solution here is to remove the option to build without HAVE_EVP_AES_128_CTR. I think all openssl versions have this function, the only reason why it is not set is that autoconf fails to detect it.
Are you overriding the location of OpenSSL and/or have you verified it's finding the correct version? If you build using CMake does it configure it correctly?
We build with autoconf, which fails the feature test for HAVE_EVP_AES_128_CTR. The reason is that a static openssl requires extra linking flags on Windows:
However, your configure script is not consulting pkg-config and assuming only libssl and libcrypto are needed. Therefore it fails the feature test for EVP_AES_128_CTR with some linking errors, even though EVP_aes_128_ctr is really there.
The resulting configuration then has OpenSSL (AES-CTR: no) like this:
I suppose the Crypto library: OpenSSL (AES-CTR: no) part means that it will use openssl but not EVP_aes_128_ctr, but this implementation somehow seems broken.
I would suggest to just remove the feature test and assume EVP_aes_128_ctr is available when openssl is used. I haven't come across a version of openssl that does not have this.
Activity
jeroen commentedon Sep 6, 2022
Did some debugging and it indeed fails here with 2 completely different mac addresses:
libssh2/src/transport.c
Lines 191 to 194 in 6c59eea
One thing I noticed comparing the (working) 1.10.0 build with the dev version is that the value of
fullpacket_payload_lenis different. In the stable branch it is always 27, but in the dev version it is much larger, I have seen 59 or 539 depending the server.jeroen commentedon Sep 6, 2022
Bisected to 17c9c1f (pr #629).
cc @haydenroche5 @bagder perhaps the change to EVP_CipherUpdate was not without side effects?
willco007 commentedon Sep 6, 2022
@jeroen if you revert the
EVP_CipherUpdatechange does it work for you? We do run tests on Windows + OpenSSL which should catch a regression in transport like this unless it's some odd interplay with mingw.jeroen commentedon Sep 6, 2022
Yes after reverting the
EVP_CipherUpdatechange it works again. Do the tests actually connect to an ssh server? I am also surprised to see this problem only on Windows; we specifically build with gcc and openssl to get the same behaviour as on mac/linux.willco007 commentedon Sep 6, 2022
If I'm reading this correctly, the API only appears to used with
arcfour128cipher which is disabled in modern OpenSSH and isn't hit with the unit tests.jeroen commentedon Sep 6, 2022
GitHub and other git servers seem to be running:
OpenSSH_8.6p1, LibreSSL 3.3.6. I wasn't able to connect to any of them using the master branch.willco007 commentedon Sep 6, 2022
Are you specifying
arcfour128explicitly? Have you reverted that entire commit, or just that one line? Assuredly the GitHub servers aren't using it by default. Could you attach a trace from a failed connection and a successful one? Thanks!jeroen commentedon Sep 6, 2022
One thing that makes this difficult to debug is that the LIBSSH2_SESSION is started by libgit2, so I don't have much control over it. Is there an envvar I can set to get a trace?
I am not setting arcfour128 but perhaps libgit2 does things (though I don't see where this would be happening).
willco007 commentedon Sep 6, 2022
On the session you call
libssh2_tracewith say, these flagsLIBSSH2_TRACE_KEX | LIBSSH2_TRACE_AUTH | LIBSSH2_TRACE_PUBLICKEY | LIBSSH2_TRACE_ERRORand then set a trace handler withlibssh2_trace_sethandlerand log the output some place.jeroen commentedon Sep 7, 2022
OK so I am testing by testing the first part of example/ssh2.c on github.com
./ssh2.exe 140.82.121.4.With the master branch I get:
And after reverting 17c9c1f we get:
willco007 commentedon Sep 7, 2022
Could you check the values for
HAVE_OPAQUE_STRUCTS,LIBSSH2_WOLFSSLandLIBSSH2_OPENSSL? Maybe they aren't being defined correctly for whatever reason.jeroen commentedon Sep 8, 2022
Did some more debugging, was able to reproduce the issue with some systems and not others. It turned out that on broken systems,
HAVE_EVP_AES_128_CTRis not set insrc/libssh2_config, probably because these have a static build of openssl.So I guess the problem is now as follows:
EVP_aes_128_ctrwhen openssl is only available as static libraryEVP_aes_128_ctris brokenEVP_CipherUpdatethat wasn't there before 17c9c1fI think you should be able to repro the issue on other systems by unsetting
HAVE_EVP_AES_128_CTRinlibssh2_configjeroen commentedon Sep 9, 2022
I think the best solution here is to remove the option to build without
HAVE_EVP_AES_128_CTR. I think all openssl versions have this function, the only reason why it is not set is that autoconf fails to detect it.willco007 commentedon Sep 9, 2022
Are you overriding the location of OpenSSL and/or have you verified it's finding the correct version? If you build using CMake does it configure it correctly?
jeroen commentedon Sep 9, 2022
We build with autoconf, which fails the feature test for
HAVE_EVP_AES_128_CTR. The reason is that a static openssl requires extra linking flags on Windows:# pkg-config --libs-only-l --static openssl -lssl -lcrypto -lws2_32 -lgdi32 -lcrypt32 -lws2_32However, your configure script is not consulting pkg-config and assuming only libssl and libcrypto are needed. Therefore it fails the feature test for
EVP_AES_128_CTRwith some linking errors, even thoughEVP_aes_128_ctris really there.The resulting configuration then has
OpenSSL (AES-CTR: no)like this:I suppose the
Crypto library: OpenSSL (AES-CTR: no)part means that it will use openssl but notEVP_aes_128_ctr, but this implementation somehow seems broken.I would suggest to just remove the feature test and assume
EVP_aes_128_ctris available when openssl is used. I haven't come across a version of openssl that does not have this.As a workaround, I now build libssh2 like so:
And that results in a working configuration with
4 remaining items
Revert usage of EVP_CipherUpdate #764 #739 (#765)
vszakats commentedon Mar 19, 2023
HAVE_EVP_AES_128_CTRdetection was fixed in 31fb886 PR #811.That said, I agree we should make this a requirement, without detection. This was available at least back in OpenSSL 1.0.2.
openssl: require v1.0.2, make HAVE_EVP_AES_128_CTR always on
openssl: require v1.0.2, make HAVE_EVP_AES_128_CTR always enabled
openssl: require v1.0.2, make HAVE_EVP_AES_128_CTR always enabled
openssl: require v1.0.2, make HAVE_EVP_AES_128_CTR always enabled
vszakats commentedon Mar 19, 2023
Opened PR to always enable this option without detection, for all build methods: #860
openssl: require `EVP_aes_128_ctr()` support
openssl: require `EVP_aes_128_ctr()` support
openssl: require `EVP_aes_128_ctr()` support
libssh2: prepare for always-on openssl EVP_aes_128_ctr [ci skip]
openssl: require `EVP_aes_128_ctr()` support
openssl: require `EVP_aes_128_ctr()` support
src: make `ssh2_xor_data()` static to WinCNG