public function getPuttyPrivateKey()
{
$descriptorSpec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
$pemPrivateKey = tempnam("/tmp", "SSHPEM");
@file_put_contents($pemPrivateKey, $this->privateKey);
@chmod($pemPrivateKey, 0600);
$ppkPrivateKey = tempnam("/tmp", "SSHPPK");
$keyName = $this->cloudKeyName;
if ($this->cloudLocation) {
$keyName .= ".{$this->cloudLocation}";
}
$puttygenExecPackage = '/opt/scalr-server/embedded/bin/puttygen';
$puttygenExec = is_executable($puttygenExecPackage) ? $puttygenExecPackage : 'puttygen';
$pipes = array();
$process = @proc_open("{$puttygenExec} {$pemPrivateKey} -C {$keyName} -o {$ppkPrivateKey}", $descriptorSpec, $pipes);
if (@is_resource($process)) {
@fclose($pipes[0]);
stream_get_contents($pipes[1]);
fclose($pipes[1]);
fclose($pipes[2]);
}
$retval = file_get_contents($ppkPrivateKey);
@unlink($pemPrivateKey);
@unlink($ppkPrivateKey);
return $retval;
}