Skip to content

Commit

Permalink
Resolve #56 : Implemented async SSH driver
Browse files Browse the repository at this point in the history
  • Loading branch information
khelle committed Apr 30, 2017
1 parent 6d8498f commit ad5ad7d
Show file tree
Hide file tree
Showing 40 changed files with 3,984 additions and 9 deletions.
Empty file added .noninteractive
Empty file.
9 changes: 6 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ php:
- 7.0
- 7.1

sudo: false

install:
before_script:
- sudo apt-get update -qq
- sudo apt-get install -y -qq libssh2-1-dev libssh2-php
- pecl install -f ssh2 < .noninteractive
- php -m | grep ssh2
- composer self-update
- composer install --no-interaction --prefer-source
- echo `whoami`":1234" | sudo chpasswd

script:
- vendor/bin/phpunit -d memory_limit=1024M --coverage-text
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"ext-event": "~1.0",
"ext-libev": "*",
"ext-zmq": "*",
"ext-fileinfo": "*"
"ext-fileinfo": "*",
"ext-ssh2": "*"
},
"replace": {
"kraken-php/channel": "self.version",
Expand All @@ -53,6 +54,7 @@
"kraken-php/promise": "self.version",
"kraken-php/root": "self.version",
"kraken-php/runtime": "self.version",
"kraken-php/ssh": "self.version",
"kraken-php/stream": "self.version",
"kraken-php/supervision": "self.version",
"kraken-php/test": "self.version",
Expand Down
11 changes: 11 additions & 0 deletions src/Event/BaseEventEmitterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,15 @@ protected function attachTimesListener($pointer, $event, $limit, callable $liste
return call_user_func_array($listener, func_get_args());
};
}

/**
* Destruct method.
*/
private function destructEventEmitterTrait()
{
$this->emitterBlocked = EventEmitter::EVENTS_FORWARD;
$this->eventPointers = [];
$this->eventListeners = [];
$this->forwardListeners = [];
}
}
38 changes: 38 additions & 0 deletions src/SSH/Auth/SSH2Agent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Kraken\SSH\Auth;

use Kraken\SSH\SSH2AuthInterface;

/**
* Agent based SSH2 authentication
*/
class SSH2Agent implements SSH2AuthInterface
{
/**
* @var string
*/
protected $username;

/**
* Constructor
*
* @param string $username The authentication username
*/
public function __construct($username)
{
$this->username = $username;
}

/**
* @override
* @inheritDoc
*/
public function authenticate($conn)
{
return @ssh2_auth_agent(
$conn,
$this->username
);
}
}
76 changes: 76 additions & 0 deletions src/SSH/Auth/SSH2HostBasedFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace Kraken\SSH\Auth;

use Kraken\SSH\SSH2AuthInterface;

/**
* Host based SSH2 authentication.
*/
class SSH2HostBasedFile implements SSH2AuthInterface
{
/**
* @var string
*/
protected $username;

/**
* @var string
*/
protected $hostname;

/**
* @var string
*/
protected $publicKeyFile;

/**
* @var string
*/
protected $privateKeyFile;

/**
* @var null|string
*/
protected $passPhrase;

/**
* @var null|string
*/
protected $localUsername;

/**
* @param string $username The authentication username
* @param string $hostname The authentication hostname
* @param string $publicKeyFile The path of the public key file
* @param string $privateKeyFile The path of the private key file
* @param string $passPhrase An optional pass phrase for the key
* @param string $localUsername An optional local usernale. If omitted, the username will be used
*/
public function __construct($username, $hostname, $publicKeyFile, $privateKeyFile, $passPhrase = null, $localUsername = null)
{
$this->username = $username;
$this->hostname = $hostname;
$this->publicKeyFile = $publicKeyFile;
$this->privateKeyFile = $privateKeyFile;
$this->passPhrase = $passPhrase;
$this->localUsername = $localUsername;
}

/**
* @override
* @inheritDoc
*/
public function authenticate($conn)
{
return @ssh2_auth_hostbased_file(
$conn,
$this->username,
$this->hostname,
$this->publicKeyFile,
$this->privateKeyFile,
$this->passPhrase,
$this->localUsername
);
}
}
33 changes: 33 additions & 0 deletions src/SSH/Auth/SSH2None.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Kraken\SSH\Auth;

use Kraken\SSH\SSH2AuthInterface;

/**
* Username based SSH2 authentication.
*/
class SSH2None implements SSH2AuthInterface
{
/**
* @var string
*/
protected $username;

/**
* @param string $username The authentication username
*/
public function __construct($username)
{
$this->username = $username;
}

/**
* @override
* @inheritDoc
*/
public function authenticate($conn)
{
return true === @ssh2_auth_none($conn, $this->username);
}
}
40 changes: 40 additions & 0 deletions src/SSH/Auth/SSH2Password.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Kraken\SSH\Auth;

use Kraken\SSH\SSH2AuthInterface;

/**
* Password based SSH2 authentication
*/
class SSH2Password implements SSH2AuthInterface
{
/**
* @var string
*/
protected $username;

/**
* @var string
*/
protected $password;

/**
* @param string $username The authentication username
* @param string $password The authentication password
*/
public function __construct($username, $password)
{
$this->username = $username;
$this->password = $password;
}

/**
* @override
* @inheritDoc
*/
public function authenticate($conn)
{
return @ssh2_auth_password($conn, $this->username, $this->password);
}
}
60 changes: 60 additions & 0 deletions src/SSH/Auth/SSH2PublicKeyFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace Kraken\SSH\Auth;

use Kraken\SSH\SSH2AuthInterface;

/**
* Public key based SSH2 authentication
*/
class SSH2PublicKeyFile implements SSH2AuthInterface
{
/**
* @var string
*/
protected $username;

/**
* @var string
*/
protected $publicKeyFile;

/**
* @var string
*/
protected $privateKeyFile;

/**
* @var null|string
*/
protected $passPhrase;

/**
* @param string $username The authentication username
* @param string $publicKeyFile The path of the public key file
* @param string $privateKeyFile The path of the private key file
* @param string|null $passPhrase An optional pass phrase for the key
*/
public function __construct($username, $publicKeyFile, $privateKeyFile, $passPhrase = null)
{
$this->username = $username;
$this->publicKeyFile = $publicKeyFile;
$this->privateKeyFile = $privateKeyFile;
$this->passPhrase = $passPhrase;
}

/**
* @override
* @inheritDoc
*/
public function authenticate($conn)
{
return @ssh2_auth_pubkey_file(
$conn,
$this->username,
$this->publicKeyFile,
$this->privateKeyFile,
$this->passPhrase
);
}
}
Loading

0 comments on commit ad5ad7d

Please sign in to comment.