ne7ssh_connection Class Reference

#include <ne7ssh_connection.h>

Collaboration diagram for ne7ssh_connection:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 ne7ssh_connection ()
 ~ne7ssh_connection ()
int connectWithPassword (uint32 channelID, const char *host, uint32 port, const char *username, const char *password, bool shell=true, int timeout=0)
int connectWithKey (uint32 channelID, const char *host, uint32 port, const char *username, const char *privKeyFileName, bool shell=true, int timeout=0)
SOCKET getSocket ()
void handleData ()
void sendData (const char *data)
void setChannelNo (int channelID)
int getChannelNo ()
bool data2Send ()
void sendData ()
bool sendCmd (const char *cmd)
bool sendClose ()
bool isOpen ()
bool isConnected ()
Botan::SecureVector
< Botan::byte > & 
getReceived ()
bool getCmdComplete ()
bool isCmdClosed ()
bool isRemoteShell ()
bool isCmdRunning ()
Ne7sshSftpstartSftp ()
bool isSftpActive ()

Private Member Functions

bool checkRemoteVersion ()
bool sendLocalVersion ()
bool requestService (const char *service)
bool authWithPassword (const char *username, const char *password)
bool authWithKey (const char *username, const char *privKeyFileName)

Private Attributes

SOCKET sock
int thisChannel
ne7ssh_cryptcrypto
ne7ssh_transporttransport
ne7ssh_sessionsession
ne7ssh_channelchannel
Ne7sshSftpsftp
Ne7ssh_Mutex mut
bool connected
bool cmdRunning
bool cmdClosed


Detailed Description

Author:
Andrew Useckas

Constructor & Destructor Documentation

ne7ssh_connection::ne7ssh_connection (  ) 

ne7ssh_connection class constructor.

ne7ssh_connection::~ne7ssh_connection (  ) 

ne7ssh_connection class destructor.


Member Function Documentation

bool ne7ssh_connection::authWithKey ( const char *  username,
const char *  privKeyFileName 
) [private]

Sends a test message to check if "publickey" authentication is allowed fo specified user. If succesfull proceeds wtih generating a signature and sending real authentication packet of "publickey" type.

Parameters:
username Username used for authentication.
privKeyFileName Full path to file containing private key to be used in authentication.
Returns:
True if authentication was successful, otherwise false is returned.

References ne7ssh_string::addChar(), ne7ssh_string::addString(), ne7ssh_string::addVector(), ne7ssh_string::addVectorField(), ne7ssh_string::clear(), ne7ssh::errors(), ne7ssh_keys::generateSignature(), ne7ssh_string::getByte(), ne7ssh_keys::getKeyAlgo(), ne7ssh_keys::getKeyPairFromFile(), ne7ssh_transport::getPacket(), ne7ssh_keys::getPublicKeyBlob(), ne7ssh_session::getSessionID(), ne7ssh_session::getSshChannel(), ne7ssh_string::getString(), Ne7sshError::push(), ne7ssh_transport::sendPacket(), ne7ssh_string::value(), and ne7ssh_transport::waitForPacket().

Referenced by connectWithKey().

bool ne7ssh_connection::authWithPassword ( const char *  username,
const char *  password 
) [private]

Sends an authentication request of "password" type. Waits for packet 'USERAUTH_SUCESS'.

Parameters:
username Username used for authentication.
password Password used for authentication.
Returns:
True if authentication was successful, otherwise false is returned.

References ne7ssh_string::addChar(), ne7ssh_string::addString(), ne7ssh_string::clear(), ne7ssh::errors(), ne7ssh_string::getByte(), ne7ssh_transport::getPacket(), ne7ssh_string::getString(), Ne7sshError::push(), ne7ssh_transport::sendPacket(), ne7ssh_string::value(), and ne7ssh_transport::waitForPacket().

Referenced by connectWithPassword().

bool ne7ssh_connection::checkRemoteVersion (  )  [private]

Checks if remote side is returning a correctly formated SSH version string, and makes sure that version 2 of SSH protocol is supported by the remote side.

Returns:
False if version string is malformed, or version 2 is not supported, otherwise true is returned.

References ne7ssh::errors(), ne7ssh_session::getSshChannel(), Ne7sshError::push(), ne7ssh_transport::receive(), and ne7ssh_session::setRemoteVersion().

Referenced by connectWithKey(), and connectWithPassword().

int ne7ssh_connection::connectWithKey ( uint32  channelID,
const char *  host,
uint32  port,
const char *  username,
const char *  privKeyFileName,
bool  shell = true,
int  timeout = 0 
)

Connects to a remote host using SSH protocol version 2, with publickey based authentication.

Parameters:
channelID ID assigned to the new channel.
host Hostname / IP of the remote host.
port Connection port.
username Username to use in the authentication.
privKeyFileName Full path to file containing private key to be used in authentication.
shell Set this to true if you wish to launch the shell on the remote end. By default set to true.
timeout Timeout for the connection procedure, in seconds.
Returns:
A newly assigned channel ID, or -1 if connection failed.

References authWithKey(), checkRemoteVersion(), ne7ssh_transport::establish(), ne7ssh_channel::getShell(), ne7ssh_kex::handleInit(), ne7ssh_kex::handleKexDHReply(), ne7ssh_channel::open(), requestService(), ne7ssh_kex::sendInit(), ne7ssh_kex::sendKexDHInit(), ne7ssh_kex::sendKexNewKeys(), sendLocalVersion(), and ne7ssh_session::setSshChannel().

Referenced by ne7ssh::connectWithKey().

int ne7ssh_connection::connectWithPassword ( uint32  channelID,
const char *  host,
uint32  port,
const char *  username,
const char *  password,
bool  shell = true,
int  timeout = 0 
)

Connects to a remote host using SSH protocol version 2, with password based authentication.

Parameters:
channelID ID of the new channel.
host Hostname / IP of the remote host.
port Connection port.
username Username to use in the authentication.
password Password to use in the authentication.
shell Set this to true if you wish to launch the shell on the remote end. By default set to true.
timeout Timeout for the connection procedure, in seconds.
Returns:
A newly assigned channel ID, or -1 if connection failed.

References authWithPassword(), checkRemoteVersion(), ne7ssh_transport::establish(), ne7ssh_channel::getShell(), ne7ssh_kex::handleInit(), ne7ssh_kex::handleKexDHReply(), ne7ssh_channel::open(), requestService(), ne7ssh_kex::sendInit(), ne7ssh_kex::sendKexDHInit(), ne7ssh_kex::sendKexNewKeys(), sendLocalVersion(), and ne7ssh_session::setSshChannel().

Referenced by ne7ssh::connectWithPassword().

bool ne7ssh_connection::data2Send (  )  [inline]

Checks for the data in the send buffer.

Returns:
True is there is data to send, otherwise false.

References ne7ssh_channel::data2Send().

int ne7ssh_connection::getChannelNo (  )  [inline]

Retrieves the current SSH channel.

Returns:
Returns SSH channel or -1 if not connected.

bool ne7ssh_connection::getCmdComplete (  )  [inline]

When executing a single command with ne7ssh::sendCmd this command is used to determine when remote side finishes the xecution.

Returns:
True if execution of the command is complete. Otherwise false.

References ne7ssh_channel::getCmdComplete().

Referenced by sendClose().

Botan::SecureVector<Botan::byte>& ne7ssh_connection::getReceived (  )  [inline]

Retrieves the last received packet.

Returns:
A reference to a buffer containing the last received packet.

References ne7ssh_channel::getReceived().

Referenced by ne7ssh::getReceivedSize(), ne7ssh::read(), and ne7ssh::readBinary().

SOCKET ne7ssh_connection::getSocket (  )  [inline]

Retrieves the tcp socket number.

Returns:
Socket, or -1 if not connected.

void ne7ssh_connection::handleData (  ) 

When new data arrives, and is available for reading, this function is called from selectThread to handle it.

References ne7ssh_channel::receive().

Referenced by ne7ssh::selectThread().

bool ne7ssh_connection::isCmdClosed (  )  [inline]

When executing a single command with ne7ssh::sendCmd this command is used to determine when the user requested a close() on the channel.

Returns:
True if the user requested to close the channel. Otherwise false.

bool ne7ssh_connection::isCmdRunning (  )  [inline]

Checks if current connection is executing a single command, without a shell.

Returns:
True if a single command is running. Otherwise false.

bool ne7ssh_connection::isConnected (  )  [inline]

Checks if process is connected and authenticated to the remote side.

Returns:
True if connected, otherwise false is returned.

bool ne7ssh_connection::isOpen (  )  [inline]

Checks if channel is open.

Returns:
True if channel is open, otherwise false is returned.

References ne7ssh_channel::isOpen().

bool ne7ssh_connection::isRemoteShell (  )  [inline]

Determines if the shell has been spawned on the remote side.

Returns:
True if the shell has been spawned. Otherwise false.

References ne7ssh_channel::isRemoteShell().

bool ne7ssh_connection::isSftpActive (  ) 

Checks if SFTP subsystem is active on the current connection.

Returns:
True if SFTP subsystem is active, otherwise false.

Referenced by sendClose().

bool ne7ssh_connection::requestService ( const char *  service  )  [private]

Sends an SSH service request, waits for 'SERVICE_ACCEPT' packet.

Parameters:
service pointer to a string containing the requested SSH service. For example "ssh-userauth".
Returns:
True If SERVICE_ACCEPT packet was received, otherwise false is returned.

References ne7ssh_string::addChar(), ne7ssh_string::addString(), ne7ssh::errors(), ne7ssh_session::getSshChannel(), Ne7sshError::push(), ne7ssh_transport::sendPacket(), ne7ssh_string::value(), and ne7ssh_transport::waitForPacket().

Referenced by connectWithKey(), and connectWithPassword().

bool ne7ssh_connection::sendClose (  ) 

This function is used to close the current connection.

First closes the channel, and then the connection itself.

Returns:
True, if packet sent successfully, otherwise false is returned.

References getCmdComplete(), ne7ssh_channel::isOpen(), isSftpActive(), and ne7ssh_channel::sendClose().

Referenced by ne7ssh::close().

bool ne7ssh_connection::sendCmd ( const char *  cmd  ) 

Parameters:
cmd 
Returns:

References ne7ssh_channel::execCmd().

Referenced by ne7ssh::sendCmd().

void ne7ssh_connection::sendData (  )  [inline]

Sends the content of the buffer.,

Usually used after data2Send returns true, executed by selectThread.

References ne7ssh_channel::sendAll().

void ne7ssh_connection::sendData ( const char *  data  ) 

This function is used to write commands to the buffer, later to be sent to the remote site for execution.

Parameters:
data Pointer to a string, containing command to be written to the buffer.

References ne7ssh_channel::write().

Referenced by ne7ssh::selectThread(), and ne7ssh::send().

bool ne7ssh_connection::sendLocalVersion (  )  [private]

Sends local version string.

Returns:
Returns false is there any communication errors occur, otherwise true is returned.

References ne7ssh_transport::send(), and ne7ssh_session::setLocalVersion().

Referenced by connectWithKey(), and connectWithPassword().

void ne7ssh_connection::setChannelNo ( int  channelID  )  [inline]

Sets the current SSH channel number.

Referenced by ne7ssh::connectWithKey(), and ne7ssh::connectWithPassword().

Ne7sshSftp * ne7ssh_connection::startSftp (  ) 

Starts a new sftp subsystem.

Returns:
Returns a pointer to the newly started Ne7sshSftp instance.

References ne7ssh::errors(), ne7ssh_session::getSshChannel(), Ne7sshSftp::init(), ne7ssh_channel::isRemoteShell(), and Ne7sshError::push().

Referenced by ne7ssh::initSftp().


The documentation for this class was generated from the following files:

Generated on Tue May 5 14:10:42 2009 for ne7ssh.kdevelop by  doxygen 1.5.9