Search code examples
phpsshsftp

Use client to server MAC algorithm hmac-sha2-256 in ssh2_connect


I'm trying to connect to my SFTP server (prosftpd) but when I check its logs I find :

2018-04-19 11:00:48,303 mod_sftp/0.9.9[18488]: no shared client-to-server MAC algorithm found (client sent 'hmac-sha1,hmac-sha1-96,hmac-md5,hmac-md5-96,hmac-ripemd160,hmac-ripemd160@openssh.com', server sent 'hmac-sha2-256,hmac-sha2-512,umac-64@openssh.com')

I tried to use the "method" parameter:

ssh2_connect("my-sftp-server.com", 443, array(
    "client_to_server" => array(
      "mac" => 'hmac-sha2-256,hmac-sha2-512,umac-64@openssh.com'

But it doesn't work, it seems like this algorithm is not supported by the method ssh2_connect and on my logs I can see

client sent 'hmac-sha1,hmac-sha1-96,hmac-md5,hmac-md5-96,hmac-ripemd160,hmac-ripemd160@openssh.com'

Is there a way to install new MAC algorithm on my PHP SFTP client?


Solution

  • PHP SSH2 package uses libssh2 library.

    You need libssh2 version 1.7.0 (2016-02-23) or later for hmac-sha2-256 and hmac-sha2-512. There's no support for umac-64@openssh.com.


    Alternatively, you can use phpseclib, which supports hmac-sha2-256 ever since version 0.3.8 (2014-09-12). More recent versions support even hmac-sha2-512 and umac-64@openssh.com.