At least one byte needs to be present for successful C / b decodes
Hello, Sometimes we see this in our error logs when trying to login to some random servers we're using the last phpseclib 3 version
$this->sftp->login($this->server->username, $password)
"class": "LengthException",
"message": "At least one byte needs to be present for successful C / b decodes",
"files" : "/var/dms/vendor/phpseclib/phpseclib/phpseclib/Common/Functions/Strings.php:92",
"trace": [
"/var/dms/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php:2245",
"/var/dms/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php:2109",
"/var/dms/vendor/phpseclib/phpseclib/phpseclib/Net/SSH2.php:2084",
"/var/dms/vendor/phpseclib/phpseclib/phpseclib/Net/SFTP.php:441",
...
]
If the server isn't sending any bytes then the server isn't sending any bytes and idk that there's anything phpseclib can do about that.
But maybe the logs will provide more insight. Like maybe the server is sending an error message that's being picked up by filter() before it gets to that point.
Can you post the SSH logs? You can get them by doing define('NET_SSH2_LOGGING', 2) at the top and then echo $ssh->getLog() after the error.
Thanks!
Hi, Unfortunately i couldn't produce this bug locally in our servers, but it still occur in production server so i have no clue why it happening thanks!
I've upgraded to v3 and it started occurring as well. Don't know why yet tho. Had similar issue with v2 (#1426) but that was fixed and no longer the case.
I've upgraded to v3 and it started occurring as well. Don't know why yet tho. Had similar issue with v2 (#1426) but that was fixed and no longer the case.
Can you post the SSH logs? You can get them by doing define('NET_SSH2_LOGGING', 2) at the top and echo $ssh->getLog() after the error. Since it's v3 you might actually need to do it in a try / catch block.
Thanks!
@terrafrost I have the log, can I send it to you somewhere privately?
@simPod - got the file. I'll try to take a look in the next few days.
Thanks!
I'm also seeing this issue. I hope it's okay to email you the log.
any update ?
I never quite figured out the problem. It usually works, but if the server takes too long to respond, then I may get the issue I asked you about.
@terrafrost asked me for another log though I have not get to it yet.
reopening the issue
@malohtie / @insiderinside (and really @ just anyone having this issue)... get me logs! You can get them by doing define('NET_SSH2_LOGGING', 2) at the top and then echo $ssh->getLog() after the error.
Without logs, asking me for help is rather like asking some why their computer crashed. The reasons why a computer crashed are endless as are the reasons that this error could occur.
Ultimately, the server sends packets to phpseclib and phpseclib decrypts and then decodes them. If the server just decided to send the letter a repeated over and over again a bunch of times there's 99.999% chance that'd cause things to break. If the server sent over a malformed packet that'd cause things to break as well. Maybe the server doesn't implement the SSH / SFTP protocol very well. Or maybe there's a very specific packet that phpseclib isn't decoding correctly. In any event, the possibilities are endless and I really can't do much without the logs, so please, provide the logs.
Thank you.
@terrafrost In my case the issue is happening systematically, i'm able to connect with sftp command and many other clients, below the log output:
Thanks
@gadz82 - By systematically do you mean consistently?
Anyway, altho the logs are helpful, a stack trace would also be helpful. Altho if I had to guess I'd guess... assuming you're using 3.0.13 I'm guessing the stack trace would include line 2447 of SSH2.php?
I'm not seeing any evidence of a timeout in the logs.
Would you be able to get me access to the server? Maybe you could email the hostname (and port if it's not 22) to me at [email protected]? idk if an actual account on the server would be needed - your logs show the password being sent but not the server response so it's unclear if a valid username / password is needed to reproduce the issue.
Also, doing sudo /usr/sbin/sshd -ddd -p2222 might yield some useful info (eg. the most verbose debug mode OpenSSH has available)
We had the very same exception with the apple school manager sftp server (upload.appleschoolcontent.com) when we accidentally used a username starting with a space character, i.e. " username" instead of "username".
@franzrosenkohl - can you get me the logs? You can get them by doing define('NET_SSH2_LOGGING', 2) at the top and then echo $ssh->getLog() after the error.
Without logs, asking me for help is rather like asking some why their computer crashed. The reasons why a computer crashed are endless as are the reasons that this error could occur.
Thanks!
We had a similar issue, however ours was a persistent error of At least one byte needs to be present for successful C / b decodes. And I wanted to share the solution for anyone else that finds this page looking for help.
Essentially, to get this to work on our servers, we had to ensure that the private key we used for authentication had its permission set using chmod 600 nameofkey.pem.
It's been a little while since we first encountered this, and I'm not sure if this is something I found in the phpseclib docs or other recommendations, but I can report that it worked for our use case and allowed us to connect to to Azure Blob Storage sFTP successfully. As always this is only possible due to the hard work of the phpseclib team.