#include <ne7ssh.h>

Public Member Functions | |
| ne7ssh () | |
| ~ne7ssh () | |
| int | connectWithPassword (const char *host, const int port, const char *username, const char *password, bool shell=true, const int timeout=0) |
| int | connectWithKey (const char *host, const int port, const char *username, const char *privKeyFileName, bool shell=true, const int timeout=0) |
| connStruct * | getConnetions () |
| bool | send (const char *data, int channel) |
| bool | sendCmd (const char *cmd, int channel, int timeout) |
| bool | close (int channel) |
| void | setCount (uint32 count) |
| const char * | read (int channel, bool do_lock=true) |
| void * | readBinary (int channel) |
| int | getReceivedSize (int channel, bool do_lock=true) |
| bool | waitFor (int channel, const char *str, uint32 timeout=0) |
| void | setOptions (const char *prefCipher, const char *prefHmac) |
| bool | generateKeyPair (const char *type, const char *fqdn, const char *privKeyFileName, const char *pubKeyFileName, uint16 keySize=0) |
| bool | initSftp (Ne7SftpSubsystem &_sftp, int channel) |
Static Public Member Functions | |
| static Ne7sshError * | errors () |
| static bool | isSelectActive () |
| static void | selectDead () |
Static Public Attributes | |
| static const char * | SSH_VERSION = "SSH-2.0-NetSieben_1.3.1" |
| static const char * | KEX_ALGORITHMS = "diffie-hellman-group1-sha1,diffie-hellman-group14-sha1" |
| static const char * | HOSTKEY_ALGORITHMS = "ssh-dss,ssh-rsa" |
| static const char * | MAC_ALGORITHMS = "hmac-md5,hmac-sha1,none" |
| static const char * | CIPHER_ALGORITHMS = "aes256-cbc,aes192-cbc,twofish-cbc,twofish256-cbc,blowfish-cbc,3des-cbc,aes128-cbc,cast128-cbc" |
| static const char * | COMPRESSION_ALGORITHMS = "none" |
| static char * | PREFERED_CIPHER = 0 |
| static char * | PREFERED_MAC = 0 |
Private Member Functions | |
| uint32 | getChannelNo () |
Static Private Member Functions | |
| static void * | selectThread (void *) |
| static bool | lock () |
| static bool | unlock () |
Private Attributes | |
| Botan::LibraryInitializer * | init |
| ne7ssh_connection ** | connections |
| uint32 | conCount |
| connStruct | allConns |
| ne7ssh_thread_t | select_thread |
| bool | connected |
Static Private Attributes | |
| static Ne7ssh_Mutex | mut |
| static bool | running = false |
| static bool | selectActive = true |
| static Ne7sshError * | errs = NULL |
| ne7ssh::ne7ssh | ( | ) |
Default constructor. Used to allocate required memory, as well as initializing cryptographic routines.
References connStruct::conns, connStruct::count, Ne7sshError::push(), and selectThread().
| bool ne7ssh::close | ( | int | channel | ) |
Closes specified channel.
| channel | Channel to close. |
References Ne7sshError::deleteChannel(), getChannelNo(), lock(), Ne7sshError::push(), ne7ssh_connection::sendClose(), and unlock().
Referenced by ~ne7ssh().
| int ne7ssh::connectWithKey | ( | const char * | host, | |
| const int | port, | |||
| const char * | username, | |||
| const char * | privKeyFileName, | |||
| bool | shell = true, |
|||
| const int | timeout = 0 | |||
| ) |
Connect to remote host using SSH2 protocol, with publickey authentication.
Reads private key from a file specified, and uses it to authenticate to remote host. Remote side must have public key from the key pair for authentication to succeed.
| host | Hostname or IP to connect to. | |
| port | Port to connect to. | |
| username | Username to use in authentication. | |
| privKeyFileName | Full path to file containing private key 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. |
References ne7ssh_connection::connectWithKey(), connStruct::conns, connStruct::count, errors(), getChannelNo(), lock(), Ne7sshError::push(), ne7ssh_connection::setChannelNo(), and unlock().
| int ne7ssh::connectWithPassword | ( | const char * | host, | |
| const int | port, | |||
| const char * | username, | |||
| const char * | password, | |||
| bool | shell = true, |
|||
| const int | timeout = 0 | |||
| ) |
Connect to remote host using SSH2 protocol, with password authentication.
| host | Hostname or IP to connect to. | |
| port | Port to connect to. | |
| username | Username to use in authentication. | |
| password | Password to use 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. |
References ne7ssh_connection::connectWithPassword(), connStruct::conns, connStruct::count, errors(), getChannelNo(), lock(), Ne7sshError::push(), ne7ssh_connection::setChannelNo(), and unlock().
| SSH_EXPORT Ne7sshError * ne7ssh::errors | ( | ) | [static] |
This method returns a pointer to the current Error collection.
Referenced by ne7ssh_string::addFile(), ne7ssh_connection::authWithKey(), ne7ssh_connection::authWithPassword(), Ne7sshSftp::cd(), ne7ssh_connection::checkRemoteVersion(), Ne7sshSftp::chmod(), Ne7sshSftp::chown(), Ne7sshSftp::closeFile(), ne7ssh_crypt::compute_key(), ne7ssh_crypt::computeH(), connectWithKey(), connectWithPassword(), Ne7SftpSubsystem::errorNotInited(), ne7ssh_transport::establish(), ne7ssh_channel::execCmd(), ne7ssh_keys::generateDSAKeys(), ne7ssh_keys::generateDSASignature(), ne7ssh_keys::generateRSAKeys(), ne7ssh_keys::generateRSASignature(), Ne7sshSftp::get(), ne7ssh_crypt::getCryptAlgo(), ne7ssh_keys::getDSAKeys(), Ne7sshSftp::getFileAttrs(), Ne7sshSftp::getFileHandle(), Ne7sshSftp::getFileSize(), Ne7sshSftp::getFileStats(), Ne7sshSftp::getFStat(), ne7ssh_crypt::getHashAlgo(), ne7ssh_crypt::getHmacAlgo(), ne7ssh_crypt::getKexPublic(), ne7ssh_keys::getKeyPairFromFile(), ne7ssh_crypt::getMacKeyLen(), ne7ssh_keys::getRSAKeys(), Ne7sshSftp::handleData(), ne7ssh_channel::handleData(), ne7ssh_channel::handleDisconnect(), ne7ssh_channel::handleEof(), ne7ssh_channel::handleExtendedData(), ne7ssh_kex::handleInit(), ne7ssh_channel::handleReceived(), ne7ssh_channel::handleRequest(), Ne7sshSftp::handleSftpData(), Ne7sshSftp::handleStatus(), Ne7sshSftp::handleVersion(), Ne7sshSftp::isType(), Ne7sshError::lock(), Ne7sshSftp::ls(), Ne7sshSftp::mkdir(), Ne7sshSftp::mv(), ne7ssh_crypt::negotiatedCmprsC2s(), ne7ssh_crypt::negotiatedCmprsS2c(), ne7ssh_crypt::negotiatedCryptoC2s(), ne7ssh_crypt::negotiatedCryptoS2c(), ne7ssh_crypt::negotiatedHostkey(), ne7ssh_crypt::negotiatedKex(), ne7ssh_crypt::negotiatedMacC2s(), ne7ssh_crypt::negotiatedMacS2c(), ne7ssh_transport::NoBlock(), ne7ssh_channel::open(), Ne7sshSftp::openDir(), Ne7sshSftp::openFile(), Ne7sshSftp::put(), Ne7sshSftp::readFile(), ne7ssh_transport::receive(), Ne7sshSftp::receiveWindowAdjust(), ne7ssh_connection::requestService(), Ne7sshSftp::rm(), Ne7sshSftp::rmdir(), ne7ssh_transport::send(), ne7ssh_kex::sendInit(), ne7ssh_kex::sendKexDHInit(), ne7ssh_kex::sendKexNewKeys(), ne7ssh_transport::sendPacket(), ne7ssh_connection::startSftp(), Ne7sshError::unlock(), ne7ssh_crypt::verifySig(), ne7ssh_transport::waitForPacket(), and Ne7sshSftp::writeFile().
| bool ne7ssh::generateKeyPair | ( | const char * | type, | |
| const char * | fqdn, | |||
| const char * | privKeyFileName, | |||
| const char * | pubKeyFileName, | |||
| uint16 | keySize = 0 | |||
| ) |
Generate key pair.
| type | String specifying key type. Currently "dsa" and "rsa" are supported. | |
| fqdn | User id. Usually an Email. For example "test@netsieben.com" | |
| privKeyFileName | Full path to a file where generated private key should be written. | |
| pubKeyFileName | Full path to a file where generated public key should be written. | |
| keySize | Desired key size in bits. If not specified will default to 2048. |
References ne7ssh_keys::generateDSAKeys(), ne7ssh_keys::generateRSAKeys(), and Ne7sshError::push().
| uint32 ne7ssh::getChannelNo | ( | ) | [private] |
Returns the number of active channel.
References Ne7sshError::push().
Referenced by close(), connectWithKey(), connectWithPassword(), getReceivedSize(), initSftp(), read(), readBinary(), send(), and sendCmd().
| connStruct* ne7ssh::getConnetions | ( | ) | [inline] |
Retrieves a pointer to all current connections.
For internal use only.
Referenced by selectThread().
| int ne7ssh::getReceivedSize | ( | int | channel, | |
| bool | do_lock = true | |||
| ) |
Returns the size of all data read. Used to read buffer passed 0x0.
| channel | Channel number which buffer size to check. |
References getChannelNo(), ne7ssh_connection::getReceived(), lock(), and unlock().
Referenced by waitFor().
| bool ne7ssh::initSftp | ( | Ne7SftpSubsystem & | _sftp, | |
| int | channel | |||
| ) |
This method is used to initialize a new SFTP subsystem.
| _sftp | Reference to SFTP subsystem to be initialized. | |
| channel | Channel ID returned by one of the connect methods. |
References getChannelNo(), lock(), Ne7sshError::push(), ne7ssh_connection::startSftp(), and unlock().
| bool ne7ssh::lock | ( | ) | [static, private] |
Lock the mutex.
References Ne7sshError::push().
Referenced by close(), connectWithKey(), connectWithPassword(), getReceivedSize(), initSftp(), read(), readBinary(), selectThread(), send(), sendCmd(), waitFor(), and ~ne7ssh().
| const char * ne7ssh::read | ( | int | channel, | |
| bool | do_lock = true | |||
| ) |
Reads all data from receiving buffer on specified channel.
| channel | Channel to read data on. |
References getChannelNo(), ne7ssh_connection::getReceived(), lock(), Ne7sshError::push(), and unlock().
Referenced by waitFor().
| void * ne7ssh::readBinary | ( | int | channel | ) |
Reads all data from receiving buffer on specified channel. Returns pointer to void. Together with getReceivedSize and sendCmd can be used to read remote files.
| channel | Channel to read data on. |
References getChannelNo(), ne7ssh_connection::getReceived(), lock(), Ne7sshError::push(), and unlock().
| void * ne7ssh::selectThread | ( | void * | initData | ) | [static, private] |
Send / Receive thread.
For Internal use only
References connStruct::conns, getConnetions(), ne7ssh_connection::handleData(), lock(), Ne7sshError::push(), ne7ssh_connection::sendData(), setCount(), and unlock().
Referenced by ne7ssh().
| bool ne7ssh::send | ( | const char * | data, | |
| int | channel | |||
| ) |
Retreives count of current connections
For internal use only.
| data | Pointer to the command string to send to a channel. | |
| channel | Channel to send data on. |
References getChannelNo(), lock(), Ne7sshError::push(), ne7ssh_connection::sendData(), and unlock().
| bool ne7ssh::sendCmd | ( | const char * | cmd, | |
| int | channel, | |||
| int | timeout | |||
| ) |
Can be used to send a single command and disconnect, similiar behavior to openssh when one appends a command to the end of ssh command.
| cmd | Remote command to execute. Can be used to read files on unix with 'cat [filename]'. | |
| channel | Channel to send the command. | |
| timeout | How long to wait before giving up. |
References getChannelNo(), lock(), Ne7sshError::push(), ne7ssh_connection::sendCmd(), and unlock().
| void ne7ssh::setCount | ( | uint32 | count | ) | [inline] |
Sets connection count.
For internal use only.
| count | Integer to set connection count. |
Referenced by selectThread().
| void ne7ssh::setOptions | ( | const char * | prefCipher, | |
| const char * | prefHmac | |||
| ) |
Sets prefered cipher and hmac algorithms.
This function as to be executed before connection functions, just after initialization of ne7ssh class.
| prefCipher | prefered cipher algorithm string representation. Possible cipher algorithms are aes256-cbc, twofish-cbc, twofish256-cbc, blowfish-cbc, 3des-cbc, aes128-cbc, cast128-cbc. | |
| prefHmac | preferede hmac algorithm string representation. Possible hmac algorithms are hmac-md5, hmac-sha1, none. |
| bool ne7ssh::unlock | ( | ) | [static, private] |
Unlock the mutext.
References Ne7sshError::push().
Referenced by close(), connectWithKey(), connectWithPassword(), getReceivedSize(), initSftp(), read(), readBinary(), selectThread(), send(), sendCmd(), waitFor(), and ~ne7ssh().
| bool ne7ssh::waitFor | ( | int | channel, | |
| const char * | str, | |||
| uint32 | timeout = 0 | |||
| ) |
Wait until receiving buffer contains a string passed in str, or until the function timeouts as specified in timeout.
| channel | Channel to wait on. | |
| str | String to wait for. | |
| timeout | Timeout in seconds. |
References getReceivedSize(), lock(), Ne7sshError::push(), read(), and unlock().
1.5.9