mirror of
https://github.com/danog/phpseclib.git
synced 2024-12-11 16:49:42 +01:00
Namespaced classes
This commit is contained in:
parent
16503848a4
commit
fddf20f89c
@ -52,45 +52,6 @@ use \phpseclib\Crypt\Random;
|
|||||||
// Used to do Diffie-Hellman key exchange and DSA/RSA signature verification.
|
// Used to do Diffie-Hellman key exchange and DSA/RSA signature verification.
|
||||||
use \phpseclib\Math\BigInteger;
|
use \phpseclib\Math\BigInteger;
|
||||||
|
|
||||||
/**#@+
|
|
||||||
* Execution Bitmap Masks
|
|
||||||
*
|
|
||||||
* @see Net_SSH2::bitmap
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
define('NET_SSH2_MASK_CONSTRUCTOR', 0x00000001);
|
|
||||||
define('NET_SSH2_MASK_CONNECTED', 0x00000002);
|
|
||||||
define('NET_SSH2_MASK_LOGIN_REQ', 0x00000004);
|
|
||||||
define('NET_SSH2_MASK_LOGIN', 0x00000008);
|
|
||||||
define('NET_SSH2_MASK_SHELL', 0x00000010);
|
|
||||||
define('NET_SSH2_MASK_WINDOW_ADJUST', 0x00000020);
|
|
||||||
/**#@-*/
|
|
||||||
|
|
||||||
/**#@+
|
|
||||||
* Channel constants
|
|
||||||
*
|
|
||||||
* RFC4254 refers not to client and server channels but rather to sender and recipient channels. we don't refer
|
|
||||||
* to them in that way because RFC4254 toggles the meaning. the client sends a SSH_MSG_CHANNEL_OPEN message with
|
|
||||||
* a sender channel and the server sends a SSH_MSG_CHANNEL_OPEN_CONFIRMATION in response, with a sender and a
|
|
||||||
* recepient channel. at first glance, you might conclude that SSH_MSG_CHANNEL_OPEN_CONFIRMATION's sender channel
|
|
||||||
* would be the same thing as SSH_MSG_CHANNEL_OPEN's sender channel, but it's not, per this snipet:
|
|
||||||
* The 'recipient channel' is the channel number given in the original
|
|
||||||
* open request, and 'sender channel' is the channel number allocated by
|
|
||||||
* the other side.
|
|
||||||
*
|
|
||||||
* @see Net_SSH2::_send_channel_packet()
|
|
||||||
* @see Net_SSH2::_get_channel_packet()
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
define('NET_SSH2_CHANNEL_EXEC', 0); // PuTTy uses 0x100
|
|
||||||
define('NET_SSH2_CHANNEL_SHELL', 1);
|
|
||||||
define('NET_SSH2_CHANNEL_SUBSYSTEM', 2);
|
|
||||||
/**#@-*/
|
|
||||||
|
|
||||||
/**#@+
|
|
||||||
* @access public
|
|
||||||
* @see Net_SSH2::getLog()
|
|
||||||
*/
|
|
||||||
/**
|
/**
|
||||||
* Pure-PHP implementation of SSHv2.
|
* Pure-PHP implementation of SSHv2.
|
||||||
*
|
*
|
||||||
@ -1896,10 +1857,10 @@ class Net_SSH2
|
|||||||
|
|
||||||
// although PHP5's get_class() preserves the case, PHP4's does not
|
// although PHP5's get_class() preserves the case, PHP4's does not
|
||||||
if (is_object($password)) {
|
if (is_object($password)) {
|
||||||
switch (strtolower(get_class($password))) {
|
switch (get_class($password)) {
|
||||||
case 'crypt_rsa':
|
case 'Crypt_RSA':
|
||||||
return $this->_privatekey_login($username, $password);
|
return $this->_privatekey_login($username, $password);
|
||||||
case 'system_ssh_agent':
|
case 'phpseclib\System\SSH\Agent':
|
||||||
return $this->_ssh_agent_login($username, $password);
|
return $this->_ssh_agent_login($username, $password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2141,7 +2102,7 @@ class Net_SSH2
|
|||||||
* Login with an ssh-agent provided key
|
* Login with an ssh-agent provided key
|
||||||
*
|
*
|
||||||
* @param String $username
|
* @param String $username
|
||||||
* @param System_SSH_Agent $agent
|
* @param \phpseclib\System\SSH\Agent $agent
|
||||||
* @return Boolean
|
* @return Boolean
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
* include 'System/SSH/Agent.php';
|
* include 'System/SSH/Agent.php';
|
||||||
* include 'Net/SSH2.php';
|
* include 'Net/SSH2.php';
|
||||||
*
|
*
|
||||||
* $agent = new System_SSH_Agent();
|
* $agent = new \phpseclib\System\SSH\Agent();
|
||||||
*
|
*
|
||||||
* $ssh = new Net_SSH2('www.domain.tld');
|
* $ssh = new Net_SSH2('www.domain.tld');
|
||||||
* if (!$ssh->login('username', $agent)) {
|
* if (!$ssh->login('username', $agent)) {
|
||||||
@ -23,7 +23,7 @@
|
|||||||
* </code>
|
* </code>
|
||||||
*
|
*
|
||||||
* @category System
|
* @category System
|
||||||
* @package System_SSH_Agent
|
* @package SSH\Agent
|
||||||
* @author Jim Wigginton <terrafrost@php.net>
|
* @author Jim Wigginton <terrafrost@php.net>
|
||||||
* @copyright 2014 Jim Wigginton
|
* @copyright 2014 Jim Wigginton
|
||||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||||
@ -31,20 +31,21 @@
|
|||||||
* @internal See http://api.libssh.org/rfc/PROTOCOL.agent
|
* @internal See http://api.libssh.org/rfc/PROTOCOL.agent
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (!class_exists('System_SSH_Agent_Identity')) {
|
namespace phpseclib\System\SSH;
|
||||||
include_once 'Agent/Identity.php';
|
|
||||||
}
|
use Crypt_RSA; //This should be removed once the Crypt package is fully namespaced
|
||||||
|
use phpseclib\System\SSH\Agent\Identity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pure-PHP ssh-agent client identity factory
|
* Pure-PHP ssh-agent client identity factory
|
||||||
*
|
*
|
||||||
* requestIdentities() method pumps out System_SSH_Agent_Identity objects
|
* requestIdentities() method pumps out \phpseclib\System\SSH\Agent\Identity objects
|
||||||
*
|
*
|
||||||
* @package System_SSH_Agent
|
* @package SSH\Agent
|
||||||
* @author Jim Wigginton <terrafrost@php.net>
|
* @author Jim Wigginton <terrafrost@php.net>
|
||||||
* @access internal
|
* @access internal
|
||||||
*/
|
*/
|
||||||
class System_SSH_Agent
|
class Agent
|
||||||
{
|
{
|
||||||
/**#@+
|
/**#@+
|
||||||
* Message numbers
|
* Message numbers
|
||||||
@ -77,7 +78,7 @@ class System_SSH_Agent
|
|||||||
/**
|
/**
|
||||||
* Default Constructor
|
* Default Constructor
|
||||||
*
|
*
|
||||||
* @return System_SSH_Agent
|
* @return \phpseclib\System\SSH\Agent
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function __construct()
|
function __construct()
|
||||||
@ -104,7 +105,7 @@ class System_SSH_Agent
|
|||||||
* Request Identities
|
* Request Identities
|
||||||
*
|
*
|
||||||
* See "2.5.2 Requesting a list of protocol 2 keys"
|
* See "2.5.2 Requesting a list of protocol 2 keys"
|
||||||
* Returns an array containing zero or more System_SSH_Agent_Identity objects
|
* Returns an array containing zero or more \phpseclib\System\SSH\Agent\Identity objects
|
||||||
*
|
*
|
||||||
* @return Array
|
* @return Array
|
||||||
* @access public
|
* @access public
|
||||||
@ -149,7 +150,7 @@ class System_SSH_Agent
|
|||||||
}
|
}
|
||||||
// resources are passed by reference by default
|
// resources are passed by reference by default
|
||||||
if (isset($key)) {
|
if (isset($key)) {
|
||||||
$identity = new System_SSH_Agent_Identity($this->fsock);
|
$identity = new Identity($this->fsock);
|
||||||
$identity->setPublicKey($key);
|
$identity->setPublicKey($key);
|
||||||
$identity->setPublicKeyBlob($key_blob);
|
$identity->setPublicKeyBlob($key_blob);
|
||||||
$identities[] = $identity;
|
$identities[] = $identity;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
* PHP versions 4 and 5
|
* PHP versions 4 and 5
|
||||||
*
|
*
|
||||||
* @category System
|
* @category System
|
||||||
* @package System_SSH_Agent
|
* @package SSH\Agent
|
||||||
* @author Jim Wigginton <terrafrost@php.net>
|
* @author Jim Wigginton <terrafrost@php.net>
|
||||||
* @copyright 2009 Jim Wigginton
|
* @copyright 2009 Jim Wigginton
|
||||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||||
@ -13,28 +13,32 @@
|
|||||||
* @internal See http://api.libssh.org/rfc/PROTOCOL.agent
|
* @internal See http://api.libssh.org/rfc/PROTOCOL.agent
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
namespace phpseclib\System\SSH\Agent;
|
||||||
|
|
||||||
|
use phpseclib\System\SSH\Agent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pure-PHP ssh-agent client identity object
|
* Pure-PHP ssh-agent client identity object
|
||||||
*
|
*
|
||||||
* Instantiation should only be performed by System_SSH_Agent class.
|
* Instantiation should only be performed by \phpseclib\System\SSH\Agent class.
|
||||||
* This could be thought of as implementing an interface that Crypt_RSA
|
* This could be thought of as implementing an interface that Crypt_RSA
|
||||||
* implements. ie. maybe a Net_SSH_Auth_PublicKey interface or something.
|
* implements. ie. maybe a Net_SSH_Auth_PublicKey interface or something.
|
||||||
* The methods in this interface would be getPublicKey, setSignatureMode
|
* The methods in this interface would be getPublicKey, setSignatureMode
|
||||||
* and sign since those are the methods phpseclib looks for to perform
|
* and sign since those are the methods phpseclib looks for to perform
|
||||||
* public key authentication.
|
* public key authentication.
|
||||||
*
|
*
|
||||||
* @package System_SSH_Agent
|
* @package SSH\Agent
|
||||||
* @author Jim Wigginton <terrafrost@php.net>
|
* @author Jim Wigginton <terrafrost@php.net>
|
||||||
* @access internal
|
* @access internal
|
||||||
*/
|
*/
|
||||||
class System_SSH_Agent_Identity
|
class Identity
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Key Object
|
* Key Object
|
||||||
*
|
*
|
||||||
* @var Crypt_RSA
|
* @var Crypt_RSA
|
||||||
* @access private
|
* @access private
|
||||||
* @see System_SSH_Agent_Identity::getPublicKey()
|
* @see \phpseclib\System\SSH\Agent\Identity::getPublicKey()
|
||||||
*/
|
*/
|
||||||
var $key;
|
var $key;
|
||||||
|
|
||||||
@ -43,7 +47,7 @@ class System_SSH_Agent_Identity
|
|||||||
*
|
*
|
||||||
* @var String
|
* @var String
|
||||||
* @access private
|
* @access private
|
||||||
* @see System_SSH_Agent_Identity::sign()
|
* @see \phpseclib\System\SSH\Agent\Identity::sign()
|
||||||
*/
|
*/
|
||||||
var $key_blob;
|
var $key_blob;
|
||||||
|
|
||||||
@ -52,7 +56,7 @@ class System_SSH_Agent_Identity
|
|||||||
*
|
*
|
||||||
* @var Resource
|
* @var Resource
|
||||||
* @access private
|
* @access private
|
||||||
* @see System_SSH_Agent_Identity::sign()
|
* @see \phpseclib\System\SSH\Agent\Identity::sign()
|
||||||
*/
|
*/
|
||||||
var $fsock;
|
var $fsock;
|
||||||
|
|
||||||
@ -60,7 +64,7 @@ class System_SSH_Agent_Identity
|
|||||||
* Default Constructor.
|
* Default Constructor.
|
||||||
*
|
*
|
||||||
* @param Resource $fsock
|
* @param Resource $fsock
|
||||||
* @return System_SSH_Agent_Identity
|
* @return \phpseclib\System\SSH\Agent\Identity
|
||||||
* @access private
|
* @access private
|
||||||
*/
|
*/
|
||||||
function __construct($fsock)
|
function __construct($fsock)
|
||||||
@ -71,7 +75,7 @@ class System_SSH_Agent_Identity
|
|||||||
/**
|
/**
|
||||||
* Set Public Key
|
* Set Public Key
|
||||||
*
|
*
|
||||||
* Called by System_SSH_Agent::requestIdentities()
|
* Called by \phpseclib\System\SSH\Agent::requestIdentities()
|
||||||
*
|
*
|
||||||
* @param Crypt_RSA $key
|
* @param Crypt_RSA $key
|
||||||
* @access private
|
* @access private
|
||||||
@ -85,7 +89,7 @@ class System_SSH_Agent_Identity
|
|||||||
/**
|
/**
|
||||||
* Set Public Key
|
* Set Public Key
|
||||||
*
|
*
|
||||||
* Called by System_SSH_Agent::requestIdentities(). The key blob could be extracted from $this->key
|
* Called by \phpseclib\System\SSH\Agent::requestIdentities(). The key blob could be extracted from $this->key
|
||||||
* but this saves a small amount of computation.
|
* but this saves a small amount of computation.
|
||||||
*
|
*
|
||||||
* @param String $key_blob
|
* @param String $key_blob
|
||||||
@ -135,7 +139,7 @@ class System_SSH_Agent_Identity
|
|||||||
function sign($message)
|
function sign($message)
|
||||||
{
|
{
|
||||||
// the last parameter (currently 0) is for flags and ssh-agent only defines one flag (for ssh-dss): SSH_AGENT_OLD_SIGNATURE
|
// the last parameter (currently 0) is for flags and ssh-agent only defines one flag (for ssh-dss): SSH_AGENT_OLD_SIGNATURE
|
||||||
$packet = pack('CNa*Na*N', System_SSH_Agent::SSH_AGENTC_SIGN_REQUEST, strlen($this->key_blob), $this->key_blob, strlen($message), $message, 0);
|
$packet = pack('CNa*Na*N', Agent::SSH_AGENTC_SIGN_REQUEST, strlen($this->key_blob), $this->key_blob, strlen($message), $message, 0);
|
||||||
$packet = pack('Na*', strlen($packet), $packet);
|
$packet = pack('Na*', strlen($packet), $packet);
|
||||||
if (strlen($packet) != fputs($this->fsock, $packet)) {
|
if (strlen($packet) != fputs($this->fsock, $packet)) {
|
||||||
user_error('Connection closed during signing');
|
user_error('Connection closed during signing');
|
||||||
@ -143,7 +147,7 @@ class System_SSH_Agent_Identity
|
|||||||
|
|
||||||
$length = current(unpack('N', fread($this->fsock, 4)));
|
$length = current(unpack('N', fread($this->fsock, 4)));
|
||||||
$type = ord(fread($this->fsock, 1));
|
$type = ord(fread($this->fsock, 1));
|
||||||
if ($type != System_SSH_Agent::SSH_AGENT_SIGN_RESPONSE) {
|
if ($type != Agent::SSH_AGENT_SIGN_RESPONSE) {
|
||||||
user_error('Unable to retreive signature');
|
user_error('Unable to retreive signature');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
use phpseclib\System\SSH\Agent;
|
||||||
|
|
||||||
class Functional_Net_SSH2AgentTest extends PhpseclibFunctionalTestCase
|
class Functional_Net_SSH2AgentTest extends PhpseclibFunctionalTestCase
|
||||||
{
|
{
|
||||||
public static function setUpBeforeClass()
|
public static function setUpBeforeClass()
|
||||||
@ -21,7 +23,7 @@ class Functional_Net_SSH2AgentTest extends PhpseclibFunctionalTestCase
|
|||||||
public function testAgentLogin()
|
public function testAgentLogin()
|
||||||
{
|
{
|
||||||
$ssh = new Net_SSH2($this->getEnv('SSH_HOSTNAME'));
|
$ssh = new Net_SSH2($this->getEnv('SSH_HOSTNAME'));
|
||||||
$agent = new System_SSH_Agent;
|
$agent = new Agent;
|
||||||
|
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
$ssh->login($this->getEnv('SSH_USERNAME'), $agent),
|
$ssh->login($this->getEnv('SSH_USERNAME'), $agent),
|
||||||
|
Loading…
Reference in New Issue
Block a user