Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hitting error -44 "Unable to ask for ssh-userauth service" with mbedtls #793

Open
green-nsk opened this issue Feb 6, 2023 · 9 comments
Open
Labels

Comments

@green-nsk
Copy link

Describe the bug

When downloading from SFTP via libcurl, I am hitting error code -44 with description "Unable to ask for ssh-userauth service". This happens for one particular SFTP server, and others work fine.

To Reproduce

I think it has to do with server using aes256-cbc algorithm. As I have no control over the server, I'm trying to verify that assumption by changing advertised set of Ciphers on my side.

Expected behavior

I would like it to work :-D

Version (please complete the following information):

  • OS and version: Julia 1.8.5 running on Ubuntu Linux 22.04
  • libssh2 version: 1.10.0
  • crypto backend: MbedTLS

Additional context

It seems to fail to send encrypt the message before sending it. Relevant code here and here.

I have found a similar issue here which was resolved by fixing how openssl functions called here. I assume this might be a similar issue with mbedtls, but I'd be hard pressed to find out exactly what's wrong.

@willco007
Copy link
Member

There is one place -44 is returned and that is from LIBSSH2_ERROR_ENCRYPT in transport.c. That is from the crypt call which seems to be failing when using the mbedtls engine based on your report. You'll need to do some digging to see why it's failing.

@dfandrich
Copy link
Contributor

I'm adding some end-to-end data transfer tests in PR#807 and the CI tests are showing all the following crypt methods failing with this error for MbedTLS:

The following tests FAILED:
	 13 - test_read_3des-cbc (Failed)
	 14 - test_read_aes128-cbc (Failed)
	 16 - test_read_aes192-cbc (Failed)
	 18 - test_read_aes256-cbc (Failed)
	 20 - test_read_rijndael-cbc (Failed)

@vszakats
Copy link
Member

vszakats commented Mar 4, 2023

@green-nsk Is this happening with mbedTLS 2.x or 3.x?

@green-nsk
Copy link
Author

@vszakats it's 2.28.0 (built-in Julia one)

@zocterminal
Copy link

I believe I have a similar (related) issue, also with a server over which I have no control.
This is a windows build with openssl, version libssh2 1.10 which works fine in any other regard.

When the client (libssh2) requests the userauth service the reply packet is apparently mangled.

In session.c at libssh2_NB_state_sent4 it calls
_libssh2_packet_require ()
which goes to
_libssh2_transport_read()
which errors out with
LIBSSH2_ERROR_OUT_OF_BOUNDARY (-41)
with a packet length of 878809339.

The server works fine with OpenSSH (I debugged down there and it gets a reasonable packet).

It's a server from a large transport company, so I guess I could share the name for debugging or do some other debugging tasks myself.

@zocterminal
Copy link

Upon further debugging, it appears that the remote server does not like the random padding (or libssh2 is doing something wrong with the random pad).

Not sure what is going wrong there exactly (my understanding of the protocol at that level is woefully inadequate), but the "ssh-userauth" request is the first that is encrypted outgoing packet and the reply is the first encrypted received packet. With random padding enabled, it seems the two sides get out of sync (differing on the sent packet), so the received packet is decrypted incorrectly.

The "fun" thing is, at least as far as I can tell, is that RANDOM_PADDING isn't set in the libssh2 itself. But in my case the source picked up the definition from a windows header (WinCrypt.h) so I'd say it got accidentally enabled.

I'll file that as a bug separately and let the upper echelons decide if that was intended or not.

@vszakats
Copy link
Member

@Markus-Schmidt: can you confirm that patch #921 fixed this issue?

@zocterminal
Copy link

@vszakats: It does fix my version of the issue, but I'm not sure if it the same issue the original poster @green-nsk had.

(I had initially thought these may be similar issues, so I first posted here, before opening another bug #921 after further debugging).

But I guess the question here is more if the patch fixes the original reporter's @green-nsk issue (for example he mentions an Ubuntu in his report, so he may be affected by something else).

@vszakats
Copy link
Member

vszakats commented Apr 15, 2023

Thanks @Markus-Schmidt.

Our CI still fails, so there seems to be something else at play here: https://github.com/libssh2/libssh2/actions/runs/4709502488/jobs/8352601338?pr=969#step:7:1091

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants