Make SSH key generation more robust.
Do not try and predict whether we will be able to create a key. Instead try and create one and capture failure if it happens. Closes #803
This commit is contained in:
parent
c669fd0797
commit
99446b56f5
|
@ -39,9 +39,9 @@ class SshKey
|
|||
|
||||
$return = array('private_key' => '', 'public_key' => '');
|
||||
|
||||
if ($this->canGenerateKeys()) {
|
||||
shell_exec('ssh-keygen -q -t rsa -b 2048 -f '.$keyFile.' -N "" -C "deploy@phpci"');
|
||||
$output = @shell_exec('ssh-keygen -t rsa -b 2048 -f '.$keyFile.' -N "" -C "deploy@phpci"');
|
||||
|
||||
if (!empty($output)) {
|
||||
$pub = file_get_contents($keyFile . '.pub');
|
||||
$prv = file_get_contents($keyFile);
|
||||
|
||||
|
@ -56,16 +56,4 @@ class SshKey
|
|||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether or not we can generate keys, by quietly test running ssh-keygen.
|
||||
* @return bool
|
||||
*/
|
||||
public function canGenerateKeys()
|
||||
{
|
||||
$keygen = @shell_exec('ssh-keygen --help');
|
||||
$canGenerateKeys = !empty($keygen);
|
||||
|
||||
return $canGenerateKeys;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue