Exemple #1
0
 public function testAddKey()
 {
     $key = SshPrivateKey::fromFile("{$this->keysDir}/id_nopass_rsa");
     $agent = new SshAgent();
     // Agent is not running so not possible to add a key to it
     $this->assertFalse($agent->addKey($key));
     $agent->start();
     $this->assertTrue($agent->addKey($key));
 }
Exemple #2
0
 public function addKey(SshPrivateKey $key)
 {
     if (!$this->isRunning()) {
         // No point in trying to add a key to an agent that is not running
         // so abort early
         return false;
     }
     // Save the key to a temporary file
     $tmpKey = tempnam(sys_get_temp_dir(), 'codeaken_sshagent_');
     file_put_contents($tmpKey, $key->getKeyData(SshKey::FORMAT_PKCS8));
     $sshAdd = new Process("ssh-add {$tmpKey}", null, ['SSH_AUTH_SOCK' => $this->getSocket()], $key->getPassword() . "\n");
     $sshAdd->setPty(true);
     $sshAdd->run();
     if (!$sshAdd->isSuccessful()) {
         unlink($tmpKey);
         return false;
     }
     unlink($tmpKey);
     return true;
 }
Exemple #3
0
 public function testPrivateKeyGetPassword()
 {
     // Private key without a password
     $key = SshPrivateKey::fromFile("{$this->keysDir}/id_nopass_rsa");
     $this->assertFalse($key->hasPassword());
     $this->assertEquals('', $key->getPassword());
     // Private key with password
     $key = SshPrivateKey::fromFile("{$this->keysDir}/id_pass_rsa", 'abc123');
     $this->assertTrue($key->hasPassword());
     $this->assertEquals('abc123', $key->getPassword());
 }