Loading...
Searching...
No Matches
Client SSH
Client

Client-side settings for SSH connections. More...

Collaboration diagram for Client SSH:

## Functions

int | nc_client_ssh_add_keypair (const char *pub_key, const char *priv_key)
| Add an SSH public and private key pair to be used for client authentication.
int | nc_client_ssh_del_keypair (int idx)
| Remove an SSH public and private key pair that was used for client authentication.
void | nc_client_ssh_get_auth_interactive_clb (char *(**auth_interactive)(const char *auth_name, const char *instruction, const char *prompt, int echo, void *priv), void **priv)
| Get currently set SSH interactive authentication callback and its private data previously set by nc_client_ssh_set_auth_interactive_clb().
void | nc_client_ssh_get_auth_password_clb (char *(**auth_password)(const char *username, const char *hostname, void *priv), void **priv)
| Get currently set SSH password authentication callback and its private data previously set by nc_client_ssh_set_auth_password_clb().
int16_t | nc_client_ssh_get_auth_pref (NC_SSH_AUTH_TYPE auth_type)
| Get SSH authentication method preference.
void | nc_client_ssh_get_auth_privkey_passphrase_clb (char *(**auth_privkey_passphrase)(const char *privkey_path, void *priv), void **priv)
| Get currently set SSH publickey authentication encrypted private key passphrase callback and its private data previously set by nc_client_ssh_set_auth_privkey_passphrase_clb().
int | nc_client_ssh_get_keypair (int idx, const char **pub_key, const char **priv_key)
| Get a specific keypair set to be used for client authentication.
int | nc_client_ssh_get_keypair_count (void)
| Get the number of public an private key pairs set to be used for client authentication.
const char * | nc_client_ssh_get_username (void)
| Get client SSH username used for authentication.
void | nc_client_ssh_set_auth_interactive_clb (char *(*auth_interactive)(const char *auth_name, const char *instruction, const char *prompt, int echo, void *priv), void *priv)
| Set SSH interactive authentication callback.
void | nc_client_ssh_set_auth_password_clb (char *(*auth_password)(const char *username, const char *hostname, void *priv), void *priv)
| Set SSH password authentication callback.
void | nc_client_ssh_set_auth_pref (NC_SSH_AUTH_TYPE auth_type, int16_t pref)
| Set SSH authentication method preference.
void | nc_client_ssh_set_auth_privkey_passphrase_clb (char *(*auth_privkey_passphrase)(const char *privkey_path, void *priv), void *priv)
| Set SSH publickey authentication encrypted private key passphrase callback.
void | nc_client_ssh_set_knownhosts_mode (NC_SSH_KNOWNHOSTS_MODE mode)
| Set the behaviour of checking the host key and adding/reading entries to/from the known_hosts file.
int | nc_client_ssh_set_knownhosts_path (const char *path)
| Set the path to the known_hosts file.
int | nc_client_ssh_set_username (const char *username)
| Set client SSH username used for authentication.
struct nc_session * | nc_connect_libssh (ssh_session ssh_session, struct ly_ctx *ctx)
| Connect to the NETCONF server using the provided SSH (libssh) session.
struct nc_session * | nc_connect_ssh (const char *host, uint16_t port, struct ly_ctx *ctx)
| Connect to the NETCONF server using SSH transport (via libssh).
struct nc_session * | nc_connect_ssh_channel (struct nc_session *session, struct ly_ctx *ctx)
| Create another NETCONF session on existing SSH session using separated SSH channel.

## Detailed Description

Client-side settings for SSH connections.

## Function Documentation

## nc_client_ssh_set_knownhosts_mode()

void nc_client_ssh_set_knownhosts_mode | ( | NC_SSH_KNOWNHOSTS_MODE | mode | ) |

Set the behaviour of checking the host key and adding/reading entries to/from the known_hosts file.

The default mode is NC_SSH_KNOWNHOSTS_ASK.

Parameters

  [in] | mode | Server host key checking mode.

## nc_client_ssh_set_knownhosts_path()

int nc_client_ssh_set_knownhosts_path | ( | const char * | path | ) |

Set the path to the known_hosts file.

Repetetive calling replaces the value. If the given file doesn't exist and the process has sufficient rights, it gets created whenever the file is needed, otherwise an error occurs. If NULL is passed or the path isn't set, the default known_hosts file will be used.

Parameters

  [in] | path | Path to the known_hosts file.

Returns
  0 on success, 1 on error.

## nc_client_ssh_set_auth_password_clb()

void nc_client_ssh_set_auth_password_clb | ( | char *(*)(const char *username, const char *hostname, void *priv) | auth_password,
|  | void * | priv
| ) |  |

Set SSH password authentication callback.

Repetitive calling causes replacing of the previous callback and its private data. Caller is responsible for freeing the private data when necessary (the private data can be obtained by nc_client_ssh_get_auth_password_clb()).

Parameters

  [in] | auth_password | Function to call, returns the password for username@hostname. If NULL, the default callback is set.
  [in] | priv | Optional private data to be passed to the callback function.

## nc_client_ssh_get_auth_password_clb()

void nc_client_ssh_get_auth_password_clb | ( | char *(**)(const char *username, const char *hostname, void *priv) | auth_password,
|  | void ** | priv
| ) |  |

Get currently set SSH password authentication callback and its private data previously set by nc_client_ssh_set_auth_password_clb().

Parameters

  [out] | auth_password | Currently set callback, NULL in case of the default callback.
  [out] | priv | Currently set (optional) private data to be passed to the callback function.

## nc_client_ssh_set_auth_interactive_clb()

void nc_client_ssh_set_auth_interactive_clb | ( | char *(*)(const char *auth_name, const char *instruction, const char *prompt, int echo, void *priv) | auth_interactive,
|  | void * | priv
| ) |  |

Set SSH interactive authentication callback.

Repetitive calling causes replacing of the previous callback and its private data. Caller is responsible for freeing the private data when necessary (the private data can be obtained by nc_client_ssh_get_auth_interactive_clb()).

Parameters

  [in] | auth_interactive | Function to call for every question, returns the answer for authentication name with instruction and echoing prompt. If NULL, the default callback is set.
  [in] | priv | Optional private data to be passed to the callback function.

## nc_client_ssh_get_auth_interactive_clb()

void nc_client_ssh_get_auth_interactive_clb | ( | char *(**)(const char *auth_name, const char *instruction, const char *prompt, int echo, void *priv) | auth_interactive,
|  | void ** | priv
| ) |  |

Get currently set SSH interactive authentication callback and its private data previously set by nc_client_ssh_set_auth_interactive_clb().

Parameters

  [out] | auth_interactive | Currently set callback, NULL in case of the default callback.
  [out] | priv | Currently set (optional) private data to be passed to the callback function.

## nc_client_ssh_set_auth_privkey_passphrase_clb()

void nc_client_ssh_set_auth_privkey_passphrase_clb | ( | char *(*)(const char *privkey_path, void *priv) | auth_privkey_passphrase,
|  | void * | priv
| ) |  |

Set SSH publickey authentication encrypted private key passphrase callback.

Repetitive calling causes replacing of the previous callback and its private data. Caller is responsible for freeing the private data when necessary (the private data can be obtained by nc_client_ssh_get_auth_privkey_passphrase_clb()).

Parameters

  [in] | auth_privkey_passphrase | Function to call for every question, returns the passphrase for the specific private key.
  [in] | priv | Optional private data to be passed to the callback function.

## nc_client_ssh_get_auth_privkey_passphrase_clb()

void nc_client_ssh_get_auth_privkey_passphrase_clb | ( | char *(**)(const char *privkey_path, void *priv) | auth_privkey_passphrase,
|  | void ** | priv
| ) |  |

Get currently set SSH publickey authentication encrypted private key passphrase callback and its private data previously set by nc_client_ssh_set_auth_privkey_passphrase_clb().

Parameters

  [out] | auth_privkey_passphrase | Currently set callback, NULL in case of the default callback.
  [out] | priv | Currently set (optional) private data to be passed to the callback function.

## nc_client_ssh_add_keypair()

int nc_client_ssh_add_keypair | ( | const char * | pub_key,
|  | const char * | priv_key
| ) |  |

Add an SSH public and private key pair to be used for client authentication.

Private key can be encrypted, the passphrase will be asked for before using it.

Parameters

  [in] | pub_key | Path to the public key.
  [in] | priv_key | Path to the private key.

Returns
  0 on success, -1 on error.

## nc_client_ssh_del_keypair()

int nc_client_ssh_del_keypair | ( | int | idx | ) |

Remove an SSH public and private key pair that was used for client authentication.

Parameters

  [in] | idx | Index of the keypair starting with 0.

Returns
  0 on success, -1 on error.

## nc_client_ssh_get_keypair_count()

int nc_client_ssh_get_keypair_count | ( | void |  | ) |

Get the number of public an private key pairs set to be used for client authentication.

Returns
  Keypair count.

## nc_client_ssh_get_keypair()

int nc_client_ssh_get_keypair | ( | int | idx,
|  | const char ** | pub_key,
|  | const char ** | priv_key
| ) |  |

Get a specific keypair set to be used for client authentication.

Parameters

  [in] | idx | Index of the specific keypair.
  [out] | pub_key | Path to the public key.
  [out] | priv_key | Path to the private key.

Returns
  0 on success, -1 on error.

## nc_client_ssh_set_auth_pref()

void nc_client_ssh_set_auth_pref | ( | NC_SSH_AUTH_TYPE | auth_type,
|  | int16_t | pref
| ) |  |

Set SSH authentication method preference.

The default preference is as follows:

- interactive authentication (3)
- password authentication (2)
- public key authentication (1)

Parameters

  [in] | auth_type | Authentication method to modify the preference of.
  [in] | pref | Preference of `auth_type`. Higher number increases priority, negative values disable the method.

## nc_client_ssh_get_auth_pref()

int16_t nc_client_ssh_get_auth_pref | ( | NC_SSH_AUTH_TYPE | auth_type | ) |

Get SSH authentication method preference.

Parameters

  [in] | auth_type | Authentication method to retrieve the prefrence of.

Returns
  Preference of the `auth_type`.

## nc_client_ssh_set_username()

int nc_client_ssh_set_username | ( | const char * | username | ) |

Set client SSH username used for authentication.

Parameters

  [in] | username | Username to use.

Returns
  0 on success, -1 on error.

## nc_client_ssh_get_username()

const char * nc_client_ssh_get_username | ( | void |  | ) |

Get client SSH username used for authentication.

Returns
  Username used.

## nc_connect_ssh()

struct nc_session * nc_connect_ssh | ( | const char * | host,
|  | uint16_t | port,
|  | struct ly_ctx * | ctx
| ) |  |

Connect to the NETCONF server using SSH transport (via libssh).

SSH session is created with default options. If the caller needs to use specific SSH session properties, they are supposed to use nc_connect_libssh().

Parameters

  [in] | host | Hostname or address (both Ipv4 and IPv6 are accepted) of the target server. 'localhost' is used by default if NULL is specified.
  [in] | port | Port number of the target server. Default value 830 is used if 0 is specified.
  [in,out] | ctx | Optional custom context to use for the session. If not set, a default context is created. Any YANG modules not present in the context and supported by the server are loaded using <get-schema> (if supported) and/or by searching the searchpath (see nc_client_set_schema_searchpath()).

Returns
  Created NETCONF session object or NULL on error.

## nc_connect_libssh()

struct nc_session * nc_connect_libssh | ( | ssh_session | ssh_session,
|  | struct ly_ctx * | ctx
| ) |  |

Connect to the NETCONF server using the provided SSH (libssh) session.

SSH session can have any options set, they will not be modified. If no options were set, host 'localhost', port 22, and the username detected from the EUID is used. If socket is set and connected only the host and the username must be set/is detected. Or the `ssh_session` can already be authenticated in which case it is used directly.

Parameters

  [in] | ssh_session | libssh structure representing SSH session object. It is fully managed by the created session including freeing it.
  [in,out] | ctx | Optional custom context to use for the session. If not set, a default context is created. Any YANG modules not present in the context and supported by the server are loaded using <get-schema> (if supported) and/or by searching the searchpath (see nc_client_set_schema_searchpath()).

Returns
  Created NETCONF session object or NULL on error.

## nc_connect_ssh_channel()

struct nc_session * nc_connect_ssh_channel | ( | struct nc_session * | session,
|  | struct ly_ctx * | ctx
| ) |  |

Create another NETCONF session on existing SSH session using separated SSH channel.

Parameters

  [in] | session | Existing NETCONF session. The session has to be created on SSH transport layer using libssh - it has to be created by nc_connect_ssh(), nc_connect_libssh() or nc_connect_ssh_channel().
  [in,out] | ctx | Optional custom context to use for the session. If not set, a default context is created. Any YANG modules not present in the context and supported by the server are loaded using <get-schema> (if supported) and/or by searching the searchpath (see nc_client_set_schema_searchpath()).

Returns
  Created NETCONF session object or NULL on error.