Skip to content

phpseclib\Crypt\RSA::loadKey result not checked #84

@ben-challis

Description

@ben-challis

Currently League\Flysystem\Sftp\SftpAdapter::getPrivateKey() does not check the bool result of RSA::loadKey() where false indicates error.

public function getPrivateKey()
{
if ("---" !== substr($this->privateKey, 0, 3) && is_file($this->privateKey)) {
$this->privateKey = file_get_contents($this->privateKey);
}
$key = new RSA();
if ($password = $this->getPassword()) {
$key->setPassword($password);
}
$key->loadKey($this->privateKey);
return $key;

I hit this due to phpseclib/phpseclib#1372 where by regular OpenSSH generated keys wouldn't load when generated with recent versions.

Is it fair to say that this should be detected and a LogicException raised to ease identification of the problem? At present you end up with the general "Could not login ..." exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions