phpseclib 2.0.12 SFTP with private RSA key login failure
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
add a comment |
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
1
Show us what$sftp->getLog()
returns for both versions.
– Martin Prikryl
Nov 16 '18 at 12:11
add a comment |
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
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
php sftp phpseclib
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 17 '18 at 0:46
neubertneubert
9,3881760135
9,3881760135
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
Show us what
$sftp->getLog()
returns for both versions.– Martin Prikryl
Nov 16 '18 at 12:11