HostBasedFile.php (1538B)
1 <?php 2 3 namespace Ssh\Authentication; 4 5 use Ssh\Authentication; 6 7 /** 8 * Host based file authentication 9 * 10 * @author Antoine Hérault <antoine.herault@gmail.com> 11 */ 12 class HostBasedFile implements Authentication 13 { 14 protected $username; 15 protected $hostname; 16 protected $publicKeyFile; 17 protected $privateKeyFile; 18 protected $passPhrase; 19 protected $localUsername; 20 21 /** 22 * Constructor 23 * 24 * @param string $username 25 * @param string $hostname 26 * @param string $publicKeyFile 27 * @param string $privateKeyFile 28 * @param string $passPhrase An optional pass phrase for the key 29 * @param string $localUsername An optional local usernale. If omitted, 30 * the username will be used 31 */ 32 public function __construct($username, $hostname, $publicKeyFile, $privateKeyFile, $passPhrase = null, $localUsername = null) 33 { 34 $this->username = $username; 35 $this->hostname = $hostname; 36 $this->publicKeyFile = $publicKeyFile; 37 $this->privateKeyFile = $privateKeyFile; 38 $this->passPhrase = $passPhrase; 39 $this->localUsername = $localUsername; 40 } 41 42 /** 43 * {@inheritDoc} 44 */ 45 public function authenticate($session) 46 { 47 return ssh2_auth_hostbased_file( 48 $session, 49 $this->username, 50 $this->hostname, 51 $this->publicKeyFile, 52 $this->privateKeyFile, 53 $this->passPhrase, 54 $this->localUsername 55 ); 56 } 57 }