phpseclib 2.0.12 SFTP with private RSA key login failure












0















I use phpseclib to log in to an SFTP server using a RSA private key. I'm upgrading from phpseclib 1.0 on PHP 5.3 to phpseclib 2.0.12 on PHP 7.2. The old code on PHP5 works just fine, but the upgraded version fails to log in, resulting in the following error message: 1024 Connection closed prematurely in SSH2.php on line 3939. Here are the two different versions:



OLD phpseclib1.0 on PHP5.3 CODE (working):



$key = new Crypt_RSA();
$key->loadKey(file_get_contents('rsaprivate.key'));
$sftp = new Net_SFTP('urltosftpserver');
$sftp->login('username', $key)


NEW phpseclib 2.0.12 on PHP7.2 CODE (failing):



$key = new phpseclibCryptRSA();
$key->loadKey(file_get_contents(__DIR__.'/rsaprivate.key'));
$sftp = new phpseclibNetSFTP('urltosftpserver');
$sftp->_privatekey_login("username", $key);


When I look at the value of $key, they don't match in the two different versions of my code. phpseclib1.0 creates integers for value, and phpseclib2.0 creates hex numbers. When I convert the pubseclib 2.0 hex numbers to to integers, they don't match the integers created by pubseclib 1.0. But I am not sure if this has anything to do with my problem.



SNIPPLET FROM pubseclib1.0 var_dump($key):



[value] => 42318...
[is_negative] =>
[generator] => mt_rand
[precision] => -1
[bitmask] =>
[hex] =>


SNIPPLET FROM pubseclib2.0 var_dump($key):



[value] => 0x60f23...
[engine] => bcmath (OpenSSL)


I don't know it it's the RSA key that causes the problem or the _privatekey_login method.










share|improve this question


















  • 1





    Show us what $sftp->getLog() returns for both versions.

    – Martin Prikryl
    Nov 16 '18 at 12:11
















0















I use phpseclib to log in to an SFTP server using a RSA private key. I'm upgrading from phpseclib 1.0 on PHP 5.3 to phpseclib 2.0.12 on PHP 7.2. The old code on PHP5 works just fine, but the upgraded version fails to log in, resulting in the following error message: 1024 Connection closed prematurely in SSH2.php on line 3939. Here are the two different versions:



OLD phpseclib1.0 on PHP5.3 CODE (working):



$key = new Crypt_RSA();
$key->loadKey(file_get_contents('rsaprivate.key'));
$sftp = new Net_SFTP('urltosftpserver');
$sftp->login('username', $key)


NEW phpseclib 2.0.12 on PHP7.2 CODE (failing):



$key = new phpseclibCryptRSA();
$key->loadKey(file_get_contents(__DIR__.'/rsaprivate.key'));
$sftp = new phpseclibNetSFTP('urltosftpserver');
$sftp->_privatekey_login("username", $key);


When I look at the value of $key, they don't match in the two different versions of my code. phpseclib1.0 creates integers for value, and phpseclib2.0 creates hex numbers. When I convert the pubseclib 2.0 hex numbers to to integers, they don't match the integers created by pubseclib 1.0. But I am not sure if this has anything to do with my problem.



SNIPPLET FROM pubseclib1.0 var_dump($key):



[value] => 42318...
[is_negative] =>
[generator] => mt_rand
[precision] => -1
[bitmask] =>
[hex] =>


SNIPPLET FROM pubseclib2.0 var_dump($key):



[value] => 0x60f23...
[engine] => bcmath (OpenSSL)


I don't know it it's the RSA key that causes the problem or the _privatekey_login method.










share|improve this question


















  • 1





    Show us what $sftp->getLog() returns for both versions.

    – Martin Prikryl
    Nov 16 '18 at 12:11














0












0








0


1






I use phpseclib to log in to an SFTP server using a RSA private key. I'm upgrading from phpseclib 1.0 on PHP 5.3 to phpseclib 2.0.12 on PHP 7.2. The old code on PHP5 works just fine, but the upgraded version fails to log in, resulting in the following error message: 1024 Connection closed prematurely in SSH2.php on line 3939. Here are the two different versions:



OLD phpseclib1.0 on PHP5.3 CODE (working):



$key = new Crypt_RSA();
$key->loadKey(file_get_contents('rsaprivate.key'));
$sftp = new Net_SFTP('urltosftpserver');
$sftp->login('username', $key)


NEW phpseclib 2.0.12 on PHP7.2 CODE (failing):



$key = new phpseclibCryptRSA();
$key->loadKey(file_get_contents(__DIR__.'/rsaprivate.key'));
$sftp = new phpseclibNetSFTP('urltosftpserver');
$sftp->_privatekey_login("username", $key);


When I look at the value of $key, they don't match in the two different versions of my code. phpseclib1.0 creates integers for value, and phpseclib2.0 creates hex numbers. When I convert the pubseclib 2.0 hex numbers to to integers, they don't match the integers created by pubseclib 1.0. But I am not sure if this has anything to do with my problem.



SNIPPLET FROM pubseclib1.0 var_dump($key):



[value] => 42318...
[is_negative] =>
[generator] => mt_rand
[precision] => -1
[bitmask] =>
[hex] =>


SNIPPLET FROM pubseclib2.0 var_dump($key):



[value] => 0x60f23...
[engine] => bcmath (OpenSSL)


I don't know it it's the RSA key that causes the problem or the _privatekey_login method.










share|improve this question














I use phpseclib to log in to an SFTP server using a RSA private key. I'm upgrading from phpseclib 1.0 on PHP 5.3 to phpseclib 2.0.12 on PHP 7.2. The old code on PHP5 works just fine, but the upgraded version fails to log in, resulting in the following error message: 1024 Connection closed prematurely in SSH2.php on line 3939. Here are the two different versions:



OLD phpseclib1.0 on PHP5.3 CODE (working):



$key = new Crypt_RSA();
$key->loadKey(file_get_contents('rsaprivate.key'));
$sftp = new Net_SFTP('urltosftpserver');
$sftp->login('username', $key)


NEW phpseclib 2.0.12 on PHP7.2 CODE (failing):



$key = new phpseclibCryptRSA();
$key->loadKey(file_get_contents(__DIR__.'/rsaprivate.key'));
$sftp = new phpseclibNetSFTP('urltosftpserver');
$sftp->_privatekey_login("username", $key);


When I look at the value of $key, they don't match in the two different versions of my code. phpseclib1.0 creates integers for value, and phpseclib2.0 creates hex numbers. When I convert the pubseclib 2.0 hex numbers to to integers, they don't match the integers created by pubseclib 1.0. But I am not sure if this has anything to do with my problem.



SNIPPLET FROM pubseclib1.0 var_dump($key):



[value] => 42318...
[is_negative] =>
[generator] => mt_rand
[precision] => -1
[bitmask] =>
[hex] =>


SNIPPLET FROM pubseclib2.0 var_dump($key):



[value] => 0x60f23...
[engine] => bcmath (OpenSSL)


I don't know it it's the RSA key that causes the problem or the _privatekey_login method.







php sftp phpseclib






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 9:59









Andy DeveloperAndy Developer

1




1








  • 1





    Show us what $sftp->getLog() returns for both versions.

    – Martin Prikryl
    Nov 16 '18 at 12:11














  • 1





    Show us what $sftp->getLog() returns for both versions.

    – Martin Prikryl
    Nov 16 '18 at 12:11








1




1





Show us what $sftp->getLog() returns for both versions.

– Martin Prikryl
Nov 16 '18 at 12:11





Show us what $sftp->getLog() returns for both versions.

– Martin Prikryl
Nov 16 '18 at 12:11












1 Answer
1






active

oldest

votes


















1














Short Answer



From your 2.0 code:



$sftp->_privatekey_login("username", $key);


Don't do that. Do this:



$sftp->login("username", $key);


Long Answer



login calls _login, which calls _connect and _login_helper. _connect is where fsockopen is called. _login_hepler then conditionally calls _privatekey_login. By calling _privatekey_login directly you're bypassing all the steps that phpseclib normally does.



The documentation does not tell you to do this. The only way you could have even learned about that method is by looking at the source code. Per the PHPDoc comments above _privatekey_login it's clear that that method is intended to be a private method and yet you're still calling it. Indeed, it's comparable method is private in the master branch.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335420%2fphpseclib-2-0-12-sftp-with-private-rsa-key-login-failure%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Short Answer



    From your 2.0 code:



    $sftp->_privatekey_login("username", $key);


    Don't do that. Do this:



    $sftp->login("username", $key);


    Long Answer



    login calls _login, which calls _connect and _login_helper. _connect is where fsockopen is called. _login_hepler then conditionally calls _privatekey_login. By calling _privatekey_login directly you're bypassing all the steps that phpseclib normally does.



    The documentation does not tell you to do this. The only way you could have even learned about that method is by looking at the source code. Per the PHPDoc comments above _privatekey_login it's clear that that method is intended to be a private method and yet you're still calling it. Indeed, it's comparable method is private in the master branch.






    share|improve this answer




























      1














      Short Answer



      From your 2.0 code:



      $sftp->_privatekey_login("username", $key);


      Don't do that. Do this:



      $sftp->login("username", $key);


      Long Answer



      login calls _login, which calls _connect and _login_helper. _connect is where fsockopen is called. _login_hepler then conditionally calls _privatekey_login. By calling _privatekey_login directly you're bypassing all the steps that phpseclib normally does.



      The documentation does not tell you to do this. The only way you could have even learned about that method is by looking at the source code. Per the PHPDoc comments above _privatekey_login it's clear that that method is intended to be a private method and yet you're still calling it. Indeed, it's comparable method is private in the master branch.






      share|improve this answer


























        1












        1








        1







        Short Answer



        From your 2.0 code:



        $sftp->_privatekey_login("username", $key);


        Don't do that. Do this:



        $sftp->login("username", $key);


        Long Answer



        login calls _login, which calls _connect and _login_helper. _connect is where fsockopen is called. _login_hepler then conditionally calls _privatekey_login. By calling _privatekey_login directly you're bypassing all the steps that phpseclib normally does.



        The documentation does not tell you to do this. The only way you could have even learned about that method is by looking at the source code. Per the PHPDoc comments above _privatekey_login it's clear that that method is intended to be a private method and yet you're still calling it. Indeed, it's comparable method is private in the master branch.






        share|improve this answer













        Short Answer



        From your 2.0 code:



        $sftp->_privatekey_login("username", $key);


        Don't do that. Do this:



        $sftp->login("username", $key);


        Long Answer



        login calls _login, which calls _connect and _login_helper. _connect is where fsockopen is called. _login_hepler then conditionally calls _privatekey_login. By calling _privatekey_login directly you're bypassing all the steps that phpseclib normally does.



        The documentation does not tell you to do this. The only way you could have even learned about that method is by looking at the source code. Per the PHPDoc comments above _privatekey_login it's clear that that method is intended to be a private method and yet you're still calling it. Indeed, it's comparable method is private in the master branch.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 17 '18 at 0:46









        neubertneubert

        9,3881760135




        9,3881760135
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53335420%2fphpseclib-2-0-12-sftp-with-private-rsa-key-login-failure%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python