From 6420119f1af0b0e077d957b9c35f3d9166340523 Mon Sep 17 00:00:00 2001 From: Lee Willis Date: Thu, 19 Feb 2015 21:33:49 +0000 Subject: [PATCH] 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 --- PHPCI/Helper/SshKey.php | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/PHPCI/Helper/SshKey.php b/PHPCI/Helper/SshKey.php index 47bd85bd..932686f2 100644 --- a/PHPCI/Helper/SshKey.php +++ b/PHPCI/Helper/SshKey.php @@ -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; - } }