PublicKeyFile.php (1225B)
1 <?php 2 3 namespace Ssh\Authentication; 4 5 use Ssh\Authentication; 6 7 /** 8 * Public key file authentication 9 * 10 * @author Antoine Hérault <antoine.herault@gmail.com> 11 */ 12 class PublicKeyFile implements Authentication 13 { 14 protected $username; 15 protected $publicKeyFile; 16 protected $privateKeyFile; 17 protected $passPhrase; 18 19 /** 20 * Constructor 21 * 22 * @param string $username The authentication username 23 * @param string $publicKeyFile The path of the public key file 24 * @param string $privateKeyFile The path of the private key file 25 * @param string $passPhrase An optional pass phrase for the key 26 */ 27 public function __construct($username, $publicKeyFile, $privateKeyFile, $passPhrase = null) 28 { 29 $this->username = $username; 30 $this->publicKeyFile = $publicKeyFile; 31 $this->privateKeyFile = $privateKeyFile; 32 $this->passPhrase = $passPhrase; 33 } 34 35 /** 36 * {@inheritDoc} 37 */ 38 public function authenticate($session) 39 { 40 return ssh2_auth_pubkey_file( 41 $session, 42 $this->username, 43 $this->publicKeyFile, 44 $this->privateKeyFile, 45 $this->passPhrase 46 ); 47 } 48 }