libssh
0.11.0
The SSH library
|
Functions | |
int | ssh_connect (ssh_session session) |
Connect to the ssh server. | |
char * | ssh_get_issue_banner (ssh_session session) |
Get the issue banner from the server. | |
int | ssh_get_openssh_version (ssh_session session) |
Get the version of the OpenSSH server, if it is not an OpenSSH server then 0 will be returned. | |
int | ssh_request_no_more_sessions (ssh_session session) |
Most SSH connections will only ever request a single session, but an attacker may abuse a running ssh client to surreptitiously open additional sessions under their control. OpenSSH provides a global request "no-more-sessions@openssh.com" to mitigate this attack. | |
int | ssh_session_set_disconnect_message (ssh_session session, const char *message) |
Add disconnect message when ssh_session is disconnected To add a disconnect message to give peer a better hint. | |
void | ssh_disconnect (ssh_session session) |
Disconnect from a session (client or server). | |
const char * | ssh_copyright (void) |
Copyright information. | |
int | ssh_select (ssh_channel *channels, ssh_channel *outchannels, socket_t maxfd, fd_set *readfds, struct timeval *timeout) |
A wrapper for the select syscall. | |
bool | ssh_dh_is_known_group (bignum modulus, bignum generator) |
ssh_key | ssh_dh_get_current_server_publickey (ssh_session session) |
int | ssh_dh_get_current_server_publickey_blob (ssh_session session, ssh_string *pubkey_blob) |
ssh_key | ssh_dh_get_next_server_publickey (ssh_session session) |
int | ssh_dh_get_next_server_publickey_blob (ssh_session session, ssh_string *pubkey_blob) |
char * | ssh_get_fingerprint_hash (enum ssh_publickey_hash_type type, unsigned char *hash, size_t len) |
Get a hash as a human-readable hex- or base64-string. | |
void | ssh_print_hash (enum ssh_publickey_hash_type type, unsigned char *hash, size_t len) |
Print a hash as a human-readable hex- or base64-string. | |
int | ssh_is_server_known (ssh_session session) |
This function is deprecated. | |
char * | ssh_dump_knownhost (ssh_session session) |
This function is deprecated. | |
int | ssh_write_knownhost (ssh_session session) |
This function is deprecated. | |
void | ssh_knownhosts_entry_free (struct ssh_knownhosts_entry *entry) |
Free an allocated ssh_knownhosts_entry. | |
struct ssh_list * | ssh_known_hosts_get_algorithms (ssh_session session) |
char * | ssh_known_hosts_get_algorithms_names (ssh_session session) |
int | ssh_known_hosts_parse_line (const char *hostname, const char *line, struct ssh_knownhosts_entry **entry) |
Parse a line from a known_hosts entry into a structure. | |
enum ssh_known_hosts_e | ssh_session_has_known_hosts_entry (ssh_session session) |
Check if the set hostname and port match an entry in known_hosts. | |
int | ssh_session_export_known_hosts_entry (ssh_session session, char **pentry_string) |
Export the current session information to a known_hosts string. | |
int | ssh_session_update_known_hosts (ssh_session session) |
Adds the currently connected server to the user known_hosts file. | |
enum ssh_known_hosts_e | ssh_session_get_known_hosts_entry (ssh_session session, struct ssh_knownhosts_entry **pentry) |
Get the known_hosts entry for the currently connected session. | |
enum ssh_known_hosts_e | ssh_session_get_known_hosts_entry_file (ssh_session session, const char *filename, struct ssh_knownhosts_entry **pentry) |
Get the known_hosts entry for the current connected session from the given known_hosts file. | |
enum ssh_known_hosts_e | ssh_session_is_known_server (ssh_session session) |
Check if the servers public key for the connected session is known. | |
int | ssh_options_copy (ssh_session src, ssh_session *dest) |
Duplicate the options of a session structure. | |
int | ssh_options_set_algo (ssh_session session, enum ssh_kex_types_e algo, const char *list, char **place) |
int | ssh_options_set (ssh_session session, enum ssh_options_e type, const void *value) |
This function can set all possible ssh options. | |
char * | ssh_options_get_algo (ssh_session session, enum ssh_kex_types_e algo) |
This function returns the current algorithms used for algorithm negotiation. It is either libssh default, option manually set or option read from configuration file. | |
int | ssh_options_get_port (ssh_session session, unsigned int *port_target) |
This function can get ssh the ssh port. It must only be used on a valid ssh session. This function is useful when the session options have been automatically inferred from the environment or configuration files and one. | |
int | ssh_options_get (ssh_session session, enum ssh_options_e type, char **value) |
This function can get ssh options, it does not support all options provided for ssh options set, but mostly those which a user-space program may care about having trusted the ssh driver to infer these values from underlying configuration files. It operates only on those SSH_OPTIONS_* which return char*. If you wish to receive the port then please use ssh_options_get_port() which returns an unsigned int. | |
int | ssh_options_getopt (ssh_session session, int *argcptr, char **argv) |
Parse command line arguments. | |
int | ssh_options_parse_config (ssh_session session, const char *filename) |
Parse the ssh config file. | |
int | ssh_options_apply (ssh_session session) |
ssh_session | ssh_new (void) |
Create a new ssh session. | |
void | ssh_free (ssh_session session) |
Deallocate a SSH session handle. | |
const char * | ssh_get_clientbanner (ssh_session session) |
get the client banner | |
const char * | ssh_get_serverbanner (ssh_session session) |
get the server banner | |
const char * | ssh_get_kex_algo (ssh_session session) |
get the name of the current key exchange algorithm. | |
const char * | ssh_get_cipher_in (ssh_session session) |
get the name of the input cipher for the given session. | |
const char * | ssh_get_cipher_out (ssh_session session) |
get the name of the output cipher for the given session. | |
const char * | ssh_get_hmac_in (ssh_session session) |
get the name of the input HMAC algorithm for the given session. | |
const char * | ssh_get_hmac_out (ssh_session session) |
get the name of the output HMAC algorithm for the given session. | |
void | ssh_session_socket_close (ssh_session session) |
void | ssh_silent_disconnect (ssh_session session) |
Disconnect impolitely from a remote host by closing the socket. | |
void | ssh_set_blocking (ssh_session session, int blocking) |
Set the session in blocking/nonblocking mode. | |
int | ssh_is_blocking (ssh_session session) |
Return the blocking mode of libssh. | |
int | ssh_blocking_flush (ssh_session session, int timeout) |
Blocking flush of the outgoing buffer. | |
int | ssh_is_connected (ssh_session session) |
Check if we are connected. | |
socket_t | ssh_get_fd (ssh_session session) |
Get the fd of a connection. | |
void | ssh_set_fd_toread (ssh_session session) |
Tell the session it has data to read on the file descriptor without blocking. | |
void | ssh_set_fd_towrite (ssh_session session) |
Tell the session it may write to the file descriptor without blocking. | |
void | ssh_set_fd_except (ssh_session session) |
Tell the session it has an exception to catch on the file descriptor. | |
int | ssh_handle_packets (ssh_session session, int timeout) |
int | ssh_handle_packets_termination (ssh_session session, int timeout, ssh_termination_function fct, void *user) |
int | ssh_get_status (ssh_session session) |
Get session status. | |
int | ssh_get_poll_flags (ssh_session session) |
Get poll flags for an external mainloop. | |
const char * | ssh_get_disconnect_message (ssh_session session) |
Get the disconnect message from the server. | |
int | ssh_get_version (ssh_session session) |
Get the protocol version of the session. | |
void | ssh_socket_exception_callback (int code, int errno_code, void *user) |
int | ssh_send_ignore (ssh_session session, const char *data) |
Send a message that should be ignored. | |
int | ssh_send_debug (ssh_session session, const char *message, int always_display) |
Send a debug message. | |
void | ssh_set_counters (ssh_session session, ssh_counter scounter, ssh_counter rcounter) |
Set the session data counters. | |
int | ssh_get_pubkey_hash (ssh_session session, unsigned char **hash) |
void | ssh_clean_pubkey_hash (unsigned char **hash) |
Deallocate the hash obtained by ssh_get_pubkey_hash. | |
int | ssh_get_server_publickey (ssh_session session, ssh_key *key) |
Get the server public key from a session. | |
int | ssh_get_publickey (ssh_session session, ssh_key *key) |
int | ssh_get_publickey_hash (const ssh_key key, enum ssh_publickey_hash_type type, unsigned char **hash, size_t *hlen) |
Allocates a buffer with the hash of the public key. | |
Functions that manage a session.
int ssh_blocking_flush | ( | ssh_session | session, |
int | timeout ) |
Blocking flush of the outgoing buffer.
[in] | session | The SSH session |
[in] | timeout | Set an upper limit on the time for which this function will block, in milliseconds. Specifying -1 means an infinite timeout. This parameter is passed to the poll() function. |
void ssh_clean_pubkey_hash | ( | unsigned char ** | hash | ) |
Deallocate the hash obtained by ssh_get_pubkey_hash.
This is required under Microsoft platform as this library might use a different C library than your software, hence a different heap.
[in] | hash | The buffer to deallocate. |
int ssh_connect | ( | ssh_session | session | ) |
Connect to the ssh server.
[in] | session | The ssh session to connect. |
const char * ssh_copyright | ( | void | ) |
Copyright information.
Returns copyright information
void ssh_disconnect | ( | ssh_session | session | ) |
Disconnect from a session (client or server).
The session can then be reused to open a new session.
[in] | session | The SSH session to use. |
char * ssh_dump_knownhost | ( | ssh_session | session | ) |
This function is deprecated.
void ssh_free | ( | ssh_session | session | ) |
Deallocate a SSH session handle.
[in] | session | The SSH session to free. |
const char * ssh_get_cipher_in | ( | ssh_session | session | ) |
get the name of the input cipher for the given session.
[in] | session | The SSH session. |
const char * ssh_get_cipher_out | ( | ssh_session | session | ) |
get the name of the output cipher for the given session.
[in] | session | The SSH session. |
const char * ssh_get_clientbanner | ( | ssh_session | session | ) |
get the client banner
[in] | session | The SSH session |
const char * ssh_get_disconnect_message | ( | ssh_session | session | ) |
Get the disconnect message from the server.
[in] | session | The ssh session to use. |
socket_t ssh_get_fd | ( | ssh_session | session | ) |
Get the fd of a connection.
In case you'd need the file descriptor of the connection to the server/client.
[in] | session | The ssh session to use. |
char * ssh_get_fingerprint_hash | ( | enum ssh_publickey_hash_type | type, |
unsigned char * | hash, | ||
size_t | len ) |
Get a hash as a human-readable hex- or base64-string.
This gets an allocated fingerprint hash. If it is a SHA sum, it will return an unpadded base64 string. If it is a MD5 sum, it will return a hex string. Either way, the output is prepended by the hash-type.
type | Which sort of hash is given, use SSH_PUBLICKEY_HASH_SHA256 or better. |
hash | The hash to be converted to fingerprint. |
len | Length of the buffer to convert. |
const char * ssh_get_hmac_in | ( | ssh_session | session | ) |
get the name of the input HMAC algorithm for the given session.
[in] | session | The SSH session. |
const char * ssh_get_hmac_out | ( | ssh_session | session | ) |
get the name of the output HMAC algorithm for the given session.
[in] | session | The SSH session. |
char * ssh_get_issue_banner | ( | ssh_session | session | ) |
Get the issue banner from the server.
This is the banner showing a disclaimer to users who log in, typically their right or the fact that they will be monitored.
[in] | session | The SSH session to use. |
const char * ssh_get_kex_algo | ( | ssh_session | session | ) |
get the name of the current key exchange algorithm.
[in] | session | The SSH session |
int ssh_get_openssh_version | ( | ssh_session | session | ) |
Get the version of the OpenSSH server, if it is not an OpenSSH server then 0 will be returned.
You can use the SSH_VERSION_INT macro to compare version numbers.
[in] | session | The SSH session to use. |
int ssh_get_poll_flags | ( | ssh_session | session | ) |
Get poll flags for an external mainloop.
session | The ssh session to use. |
int ssh_get_pubkey_hash | ( | ssh_session | session, |
unsigned char ** | hash ) |
int ssh_get_publickey | ( | ssh_session | session, |
ssh_key * | key ) |
int ssh_get_publickey_hash | ( | const ssh_key | key, |
enum ssh_publickey_hash_type | type, | ||
unsigned char ** | hash, | ||
size_t * | hlen ) |
Allocates a buffer with the hash of the public key.
This function allows you to get a hash of the public key. You can then print this hash in a human-readable form to the user so that he is able to verify it. Use ssh_get_hexa() or ssh_print_hash() to display it.
[in] | key | The public key to create the hash for. |
[in] | type | The type of the hash you want. |
[out] | hash | A pointer to store the allocated buffer. It can be freed using ssh_clean_pubkey_hash(). |
[in] | hlen | The length of the hash. |
int ssh_get_server_publickey | ( | ssh_session | session, |
ssh_key * | key ) |
Get the server public key from a session.
[in] | session | The session to get the key from. |
[out] | key | A pointer to store the allocated key. You need to free the key using ssh_key_free(). |
const char * ssh_get_serverbanner | ( | ssh_session | session | ) |
get the server banner
[in] | session | The SSH session |
int ssh_get_status | ( | ssh_session | session | ) |
Get session status.
session | The ssh session to use. |
int ssh_get_version | ( | ssh_session | session | ) |
Get the protocol version of the session.
session | The ssh session to use. |
int ssh_is_blocking | ( | ssh_session | session | ) |
Return the blocking mode of libssh.
[in] | session | The SSH session |
int ssh_is_connected | ( | ssh_session | session | ) |
Check if we are connected.
[in] | session | The session to check if it is connected. |
int ssh_is_server_known | ( | ssh_session | session | ) |
This function is deprecated.
int ssh_known_hosts_parse_line | ( | const char * | hostname, |
const char * | line, | ||
struct ssh_knownhosts_entry ** | entry ) |
Parse a line from a known_hosts entry into a structure.
This parses a known_hosts entry into a structure with the key in a libssh consumeable form. You can use the PKI key function to further work with it.
[in] | hostname | The hostname to match the line to |
[in] | line | The line to compare and parse if we have a hostname match. |
[in] | entry | A pointer to store the allocated known_hosts entry structure. The user needs to free the memory using SSH_KNOWNHOSTS_ENTRY_FREE(). |
void ssh_knownhosts_entry_free | ( | struct ssh_knownhosts_entry * | entry | ) |
Free an allocated ssh_knownhosts_entry.
Use SSH_KNOWNHOSTS_ENTRY_FREE() to set the pointer to NULL.
[in] | entry | The entry to free. |
ssh_session ssh_new | ( | void | ) |
Create a new ssh session.
int ssh_options_copy | ( | ssh_session | src, |
ssh_session * | dest ) |
Duplicate the options of a session structure.
If you make several sessions with the same options this is useful. You cannot use twice the same option structure in ssh_connect.
src | The session to use to copy the options. |
dest | A pointer to store the allocated session with duplicated options. You have to free the memory using ssh_free() |
int ssh_options_get | ( | ssh_session | session, |
enum ssh_options_e | type, | ||
char ** | value ) |
This function can get ssh options, it does not support all options provided for ssh options set, but mostly those which a user-space program may care about having trusted the ssh driver to infer these values from underlying configuration files. It operates only on those SSH_OPTIONS_* which return char*. If you wish to receive the port then please use ssh_options_get_port() which returns an unsigned int.
session | An allocated SSH session structure. |
type | The option type to get. This could be one of the following: |
value | The value to get into. As a char**, space will be allocated by the function for the value, it is your responsibility to free the memory using ssh_string_free_char(). |
char * ssh_options_get_algo | ( | ssh_session | session, |
enum ssh_kex_types_e | algo ) |
This function returns the current algorithms used for algorithm negotiation. It is either libssh default, option manually set or option read from configuration file.
This function will return NULL on error
session | An allocated SSH session structure. |
algo | One of the ssh_kex_types_e values. |
int ssh_options_get_port | ( | ssh_session | session, |
unsigned int * | port_target ) |
This function can get ssh the ssh port. It must only be used on a valid ssh session. This function is useful when the session options have been automatically inferred from the environment or configuration files and one.
session | An allocated SSH session structure. |
port_target | An unsigned integer into which the port will be set from the ssh session. |
int ssh_options_getopt | ( | ssh_session | session, |
int * | argcptr, | ||
char ** | argv ) |
Parse command line arguments.
This is a helper for your application to generate the appropriate options from the command line arguments.
The argv array and argc value are changed so that the parsed arguments won't appear anymore in them.
The single arguments (without switches) are not parsed. thus, myssh -l user localhost
The command won't set the hostname value of options to localhost.
session | The session to configure. |
argcptr | The pointer to the argument count. |
argv | The arguments list pointer. |
int ssh_options_parse_config | ( | ssh_session | session, |
const char * | filename ) |
Parse the ssh config file.
This should be the last call of all options, it may overwrite options which are already set. It requires that the host name is already set with ssh_options_set(SSH_OPTIONS_HOST).
session | SSH session handle |
filename | The options file to use, if NULL the default ~/.ssh/config and /etc/ssh/ssh_config will be used. |
int ssh_options_set | ( | ssh_session | session, |
enum ssh_options_e | type, | ||
const void * | value ) |
This function can set all possible ssh options.
session | An allocated SSH session structure. |
type | The option type to set. This could be one of the following: |
SSH_OPTIONS_PROXYJUMP: Set the comma separated jump hosts in order to connect to server (const char *). Set to "none" to disable. Example: "alice@127.0.0.1:5555,bob@127.0.0.2"
If environment variable OPENSSH_PROXYJUMP is set to 1 then proxyjump will be handled by the OpenSSH binary.
SSH_OPTIONS_CONTROL_MASTER Set the option to enable the sharing of multiple sessions over a single network connection using connection multiplexing (int).
The possible options are among the following:
The default is SSH_CONTROL_MASTER_NO.
value | The value to set. This is a generic pointer and the datatype which is used should be set according to the type set. |
void ssh_print_hash | ( | enum ssh_publickey_hash_type | type, |
unsigned char * | hash, | ||
size_t | len ) |
Print a hash as a human-readable hex- or base64-string.
This prints an unpadded base64 strings for SHA sums and hex strings for MD5 sum. Either way, the output is prepended by the hash-type.
type | Which sort of hash is given. Use SSH_PUBLICKEY_HASH_SHA256 or better. |
hash | The hash to be converted to fingerprint. |
len | Length of the buffer to convert. |
int ssh_request_no_more_sessions | ( | ssh_session | session | ) |
Most SSH connections will only ever request a single session, but an attacker may abuse a running ssh client to surreptitiously open additional sessions under their control. OpenSSH provides a global request "no-more-sessions@openssh.com" to mitigate this attack.
[in] | session | The SSH session to use. |
int ssh_select | ( | ssh_channel * | channels, |
ssh_channel * | outchannels, | ||
socket_t | maxfd, | ||
fd_set * | readfds, | ||
struct timeval * | timeout ) |
A wrapper for the select syscall.
This function acts more or less like the select(2) syscall.
There is no support for writing or exceptions.
[in] | channels | Arrays of channels pointers terminated by a NULL. It is never rewritten. |
[out] | outchannels | Arrays of the same size as "channels", there is no need to initialize it. |
[in] | maxfd | Maximum +1 file descriptor from readfds. |
[in] | readfds | A fd_set of file descriptors to be select'ed for reading. |
[in] | timeout | The timeout in milliseconds. |
int ssh_send_debug | ( | ssh_session | session, |
const char * | message, | ||
int | always_display ) |
Send a debug message.
[in] | session | The SSH session |
[in] | message | Data to be sent |
[in] | always_display | Message SHOULD be displayed by the server. It SHOULD NOT be displayed unless debugging information has been explicitly requested. |
int ssh_send_ignore | ( | ssh_session | session, |
const char * | data ) |
Send a message that should be ignored.
[in] | session | The SSH session |
[in] | data | Data to be sent |
int ssh_session_export_known_hosts_entry | ( | ssh_session | session, |
char ** | pentry_string ) |
Export the current session information to a known_hosts string.
This exports the current information of a session which is connected so a ssh server into an entry line which can be added to a known_hosts file.
[in] | session | The session with information to export. |
[in] | pentry_string | A pointer to a string to store the allocated line of the entry. The user must free it using ssh_string_free_char(). |
enum ssh_known_hosts_e ssh_session_get_known_hosts_entry | ( | ssh_session | session, |
struct ssh_knownhosts_entry ** | pentry ) |
Get the known_hosts entry for the currently connected session.
[in] | session | The session to validate. |
[in] | pentry | A pointer to store the allocated known hosts entry. |
enum ssh_known_hosts_e ssh_session_get_known_hosts_entry_file | ( | ssh_session | session, |
const char * | filename, | ||
struct ssh_knownhosts_entry ** | pentry ) |
Get the known_hosts entry for the current connected session from the given known_hosts file.
[in] | session | The session to validate. |
[in] | filename | The filename to parse. |
[in] | pentry | A pointer to store the allocated known hosts entry. |
enum ssh_known_hosts_e ssh_session_has_known_hosts_entry | ( | ssh_session | session | ) |
Check if the set hostname and port match an entry in known_hosts.
This check if the set hostname and port have an entry in the known_hosts file. You need to set at least the hostname using ssh_options_set().
[in] | session | The session with the values set to check. |
enum ssh_known_hosts_e ssh_session_is_known_server | ( | ssh_session | session | ) |
Check if the servers public key for the connected session is known.
This checks if we already know the public key of the server we want to connect to. This allows to detect if there is a MITM attach going on of if there have been changes on the server we don't know about.
[in] | session | The SSH to validate. |
int ssh_session_set_disconnect_message | ( | ssh_session | session, |
const char * | message ) |
Add disconnect message when ssh_session is disconnected To add a disconnect message to give peer a better hint.
session | The SSH session to use. |
message | The message to send after the session is disconnected. If no message is passed then a default message i.e "Bye Bye" will be sent. |
int ssh_session_update_known_hosts | ( | ssh_session | session | ) |
Adds the currently connected server to the user known_hosts file.
This adds the currently connected server to the known_hosts file by appending a new line at the end. The global known_hosts file is considered read-only so it is not touched by this function.
[in] | session | The session to use to write the entry. |
void ssh_set_blocking | ( | ssh_session | session, |
int | blocking ) |
Set the session in blocking/nonblocking mode.
[in] | session | The ssh session to change. |
[in] | blocking | Zero for nonblocking mode. |
void ssh_set_counters | ( | ssh_session | session, |
ssh_counter | scounter, | ||
ssh_counter | rcounter ) |
Set the session data counters.
This function sets the counter structures to be used to calculate data which comes in and goes out through the session at different levels.
[in] | session | The SSH session. |
[in] | scounter | Counter for byte data handled by the session sockets. |
[in] | rcounter | Counter for byte and packet data handled by the session, prior compression and SSH overhead. |
void ssh_set_fd_except | ( | ssh_session | session | ) |
Tell the session it has an exception to catch on the file descriptor.
[in] | session | The ssh session to use. |
void ssh_set_fd_toread | ( | ssh_session | session | ) |
Tell the session it has data to read on the file descriptor without blocking.
[in] | session | The ssh session to use. |
void ssh_set_fd_towrite | ( | ssh_session | session | ) |
Tell the session it may write to the file descriptor without blocking.
[in] | session | The ssh session to use. |
void ssh_silent_disconnect | ( | ssh_session | session | ) |
Disconnect impolitely from a remote host by closing the socket.
Suitable if you forked and want to destroy this session.
[in] | session | The SSH session to disconnect. |
int ssh_write_knownhost | ( | ssh_session | session | ) |
This function is deprecated.