Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file session_client_ch.h |
| 3 | * \author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * \brief libnetconf2 Call Home session client manipulation |
| 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
Michal Vasko | afd416b | 2016-02-25 14:51:46 +0100 | [diff] [blame] | 11 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 12 | * https://opensource.org/licenses/BSD-3-Clause |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #ifndef NC_SESSION_CLIENT_CH_H_ |
| 16 | #define NC_SESSION_CLIENT_CH_H_ |
| 17 | |
| 18 | #include <libyang/libyang.h> |
| 19 | |
| 20 | #include "session.h" |
| 21 | #include "netconf.h" |
| 22 | #include "messages_client.h" |
| 23 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 24 | #if defined(NC_ENABLED_SSH) || defined(NC_ENABLED_TLS) |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 25 | |
| 26 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame^] | 27 | * @defgroup client_ch Client-side Call Home |
| 28 | * @ingroup client |
| 29 | * |
| 30 | * @brief Call Home functionality for client-side applications. |
| 31 | * @{ |
| 32 | */ |
| 33 | |
| 34 | /** |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 35 | * @brief Accept a Call Home connection on any of the listening binds. |
| 36 | * |
| 37 | * @param[in] timeout Timeout for receiving a new connection in milliseconds, 0 for |
| 38 | * non-blocking call, -1 for infinite waiting. |
| 39 | * @param[in] ctx Session context to use. Can be NULL. |
| 40 | * @param[out] session New session. |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 41 | * @return 1 on success, 0 on timeout, -1 on error. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 42 | */ |
| 43 | int nc_accept_callhome(int timeout, struct ly_ctx *ctx, struct nc_session **session); |
| 44 | |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame^] | 45 | /**@} Client-side Call Home */ |
| 46 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 47 | #endif /* NC_ENABLED_SSH || NC_ENABLED_TLS */ |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 48 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 49 | #ifdef NC_ENABLED_SSH |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 50 | |
| 51 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame^] | 52 | * @defgroup client_ch_ssh Client-side Call Home on SSH |
| 53 | * @ingroup client_ch |
| 54 | * |
| 55 | * @brief SSH settings for the Call Home functionality |
| 56 | * @{ |
| 57 | */ |
| 58 | |
| 59 | /** |
Michal Vasko | ef112d7 | 2016-02-18 13:28:25 +0100 | [diff] [blame] | 60 | * @brief Set SSH CALL Home authentication hostkey check (knownhosts) callback. |
| 61 | * |
| 62 | * @param[in] auth_hostkey_check Function to call, returns 0 on success, non-zero in error. |
| 63 | * If NULL, the default callback is set. |
| 64 | */ |
| 65 | void nc_client_ssh_ch_set_auth_hostkey_check_clb(int (*auth_hostkey_check)(const char *hostname, ssh_session session)); |
| 66 | |
| 67 | /** |
Michal Vasko | 30e2c87 | 2016-02-18 10:03:21 +0100 | [diff] [blame] | 68 | * @brief Set SSH Call Home password authentication callback. |
| 69 | * |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 70 | * @param[in] auth_password Function to call, returns the password for username\@hostname. |
Michal Vasko | 30e2c87 | 2016-02-18 10:03:21 +0100 | [diff] [blame] | 71 | * If NULL, the default callback is set. |
| 72 | */ |
| 73 | void nc_client_ssh_ch_set_auth_password_clb(char *(*auth_password)(const char *username, const char *hostname)); |
| 74 | |
| 75 | /** |
| 76 | * @brief Set SSH Call Home interactive authentication callback. |
| 77 | * |
| 78 | * @param[in] auth_interactive Function to call for every question, returns the answer for |
| 79 | * authentication name with instruction and echoing prompt. |
| 80 | * If NULL, the default callback is set. |
| 81 | */ |
| 82 | void nc_client_ssh_ch_set_auth_interactive_clb(char *(*auth_interactive)(const char *auth_name, const char *instruction, |
| 83 | const char *prompt, int echo)); |
| 84 | |
| 85 | /** |
| 86 | * @brief Set SSH Call Home publickey authentication encrypted private key passphrase callback. |
| 87 | * |
| 88 | * @param[in] auth_privkey_passphrase Function to call for every question, returns |
| 89 | * the passphrase for the specific private key. |
| 90 | */ |
| 91 | void nc_client_ssh_ch_set_auth_privkey_passphrase_clb(char *(*auth_privkey_passphrase)(const char *privkey_path)); |
| 92 | |
| 93 | /** |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 94 | * @brief Add a new client bind and start listening on it for SSH Call Home connections. |
| 95 | * |
| 96 | * @param[in] address IP address to bind to. |
| 97 | * @param[in] port Port to bind to. |
| 98 | * @return 0 on success, -1 on error. |
| 99 | */ |
| 100 | int nc_client_ssh_ch_add_bind_listen(const char *address, uint16_t port); |
| 101 | |
| 102 | /** |
| 103 | * @brief Remove an SSH listening client bind. |
| 104 | * |
| 105 | * @param[in] address IP address the socket was bound to. NULL matches all. |
| 106 | * @param[in] port Port the socket was bound to. 0 matches all. |
| 107 | * @return 0 on success, -1 on not found. |
| 108 | */ |
| 109 | int nc_client_ssh_ch_del_bind(const char *address, uint16_t port); |
| 110 | |
| 111 | /** |
| 112 | * @brief Add an SSH public and private key pair to be used for Call Home client authentication. |
| 113 | * |
| 114 | * Private key can be encrypted, the passphrase will be asked for before using it. |
| 115 | * |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 116 | * @param[in] pub_key Path to the public key. |
| 117 | * @param[in] priv_key Path to the private key. |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 118 | * @return 0 on success, -1 on error. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 119 | */ |
| 120 | int nc_client_ssh_ch_add_keypair(const char *pub_key, const char *priv_key); |
| 121 | |
| 122 | /** |
| 123 | * @brief Remove an SSH public and private key pair that was used for Call Home client authentication. |
| 124 | * |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 125 | * @param[in] idx Index of the keypair starting with 0. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 126 | * @return 0 on success, -1 on error. |
| 127 | */ |
| 128 | int nc_client_ssh_ch_del_keypair(int idx); |
| 129 | |
| 130 | /** |
| 131 | * @brief Get the number of public an private key pairs set to be used for Call Home client authentication. |
| 132 | * |
| 133 | * @return Keypair count. |
| 134 | */ |
| 135 | int nc_client_ssh_ch_get_keypair_count(void); |
| 136 | |
| 137 | /** |
| 138 | * @brief Get a specific keypair set to be used for Call Home client authentication. |
| 139 | * |
| 140 | * @param[in] idx Index of the specific keypair. |
| 141 | * @param[out] pub_key Path to the public key. |
| 142 | * @param[out] priv_key Path to the private key. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 143 | * @return 0 on success, -1 on error. |
| 144 | */ |
| 145 | int nc_client_ssh_ch_get_keypair(int idx, const char **pub_key, const char **priv_key); |
| 146 | |
| 147 | /** |
| 148 | * @brief Set SSH Call Home authentication method preference. |
| 149 | * |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 150 | * @param[in] auth_type Authentication method to modify the prefrence of. |
| 151 | * @param[in] pref Preference of \p auth_type. Negative values disable the method. |
| 152 | */ |
| 153 | void nc_client_ssh_ch_set_auth_pref(NC_SSH_AUTH_TYPE auth_type, int16_t pref); |
| 154 | |
| 155 | /** |
| 156 | * @brief Get SSH Call Home authentication method preference. |
| 157 | * |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 158 | * @param[in] auth_type Authentication method to retrieve the prefrence of. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 159 | * @return Preference of the \p auth_type. |
| 160 | */ |
| 161 | int16_t nc_client_ssh_ch_get_auth_pref(NC_SSH_AUTH_TYPE auth_type); |
| 162 | |
| 163 | /** |
| 164 | * @brief Set client Call Home SSH username used for authentication. |
| 165 | * |
| 166 | * @param[in] username Username to use. |
| 167 | * @return 0 on success, -1 on error. |
| 168 | */ |
| 169 | int nc_client_ssh_ch_set_username(const char *username); |
| 170 | |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 171 | /** |
| 172 | * @brief Get client Call Home SSH username used for authentication. |
| 173 | * |
| 174 | * @return Username used. |
| 175 | */ |
| 176 | const char *nc_client_ssh_ch_get_username(void); |
| 177 | |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame^] | 178 | /**@} Client-side Call Home on SSH */ |
| 179 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 180 | #endif /* NC_ENABLED_SSH */ |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 181 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 182 | #ifdef NC_ENABLED_TLS |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 183 | |
| 184 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame^] | 185 | * @defgroup client_ch_tls Client-side Call Home on TLS |
| 186 | * @ingroup client_ch |
| 187 | * |
| 188 | * @brief TLS settings for the Call Home functionality |
| 189 | * @{ |
| 190 | */ |
| 191 | |
| 192 | /** |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 193 | * @brief Add a new client bind and start listening on it for TLS Call Home connections. |
| 194 | * |
| 195 | * @param[in] address IP address to bind to. |
| 196 | * @param[in] port Port to bind to. |
| 197 | * @return 0 on success, -1 on error. |
| 198 | */ |
| 199 | int nc_client_tls_ch_add_bind_listen(const char *address, uint16_t port); |
| 200 | |
| 201 | /** |
| 202 | * @brief Remove a TLS listening client bind. |
| 203 | * |
| 204 | * @param[in] address IP address the socket was bound to. NULL matches all. |
| 205 | * @param[in] port Port the socket was bound to. 0 matches all. |
| 206 | * @return 0 on success, -1 on not found. |
| 207 | */ |
| 208 | int nc_client_tls_ch_del_bind(const char *address, uint16_t port); |
| 209 | |
| 210 | /** |
| 211 | * @brief Set client Call Home authentication identity - a certificate and a private key. |
| 212 | * |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 213 | * @param[in] client_cert Path to the file containing the client certificate. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 214 | * @param[in] client_key Path to the file containing the private key for the \p client_cert. |
| 215 | * If NULL, key is expected to be stored with \p client_cert. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 216 | * @return 0 on success, -1 on error. |
| 217 | */ |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 218 | int nc_client_tls_ch_set_cert_key_paths(const char *client_cert, const char *client_key); |
| 219 | |
| 220 | /** |
| 221 | * @brief Get client Call Home authentication identity - a certificate and a private key. |
| 222 | * |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 223 | * @param[out] client_cert Path to the file containing the client certificate. Can be NULL. |
| 224 | * @param[out] client_key Path to the file containing the private key for the \p client_cert. |
| 225 | * Can be NULL. |
| 226 | */ |
| 227 | void nc_client_tls_ch_get_cert_key_paths(const char **client_cert, const char **client_key); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 228 | |
| 229 | /** |
| 230 | * @brief Set client Call Home trusted CA certificates. |
| 231 | * |
| 232 | * @param[in] ca_file Location of the CA certificate file used to verify server certificates. |
| 233 | * For more info, see the documentation for SSL_CTX_load_verify_locations() from OpenSSL. |
| 234 | * @param[in] ca_dir Location of the CA certificates directory used to verify the server certificates. |
| 235 | * For more info, see the documentation for SSL_CTX_load_verify_locations() from OpenSSL. |
| 236 | * @return 0 on success, -1 on error. |
| 237 | */ |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 238 | int nc_client_tls_ch_set_trusted_ca_paths(const char *ca_file, const char *ca_dir); |
| 239 | |
| 240 | /** |
| 241 | * @brief Get client Call Home trusted CA certificates. |
| 242 | * |
| 243 | * @param[out] ca_file Location of the CA certificate file used to verify server certificates. |
| 244 | * Can be NULL. |
| 245 | * @param[out] ca_dir Location of the CA certificates directory used to verify the server certificates. |
| 246 | * Can be NULL. |
| 247 | */ |
| 248 | void nc_client_tls_ch_get_trusted_ca_paths(const char **ca_file, const char **ca_dir); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 249 | |
| 250 | /** |
| 251 | * @brief Set client Call Home Certificate Revocation Lists. |
| 252 | * |
| 253 | * @param[in] crl_file Location of the CRL certificate file used to check for revocated certificates. |
| 254 | * @param[in] crl_dir Location of the CRL certificate directory used to check for revocated certificates. |
| 255 | * @return 0 on success, -1 on error. |
| 256 | */ |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 257 | int nc_client_tls_ch_set_crl_paths(const char *crl_file, const char *crl_dir); |
| 258 | |
| 259 | /** |
| 260 | * @brief Get client Call Home Certificate Revocation Lists. |
| 261 | * |
| 262 | * @param[out] crl_file Location of the CRL certificate file used to check for revocated certificates. |
| 263 | * Can be NULL. |
| 264 | * @param[out] crl_dir Location of the CRL certificate directory used to check for revocated certificates. |
| 265 | * Can be NULL. |
| 266 | */ |
| 267 | void nc_client_tls_ch_get_crl_paths(const char **crl_file, const char **crl_dir); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 268 | |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame^] | 269 | /**@} Client-side Call Home on TLS */ |
| 270 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 271 | #endif /* NC_ENABLED_TLS */ |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 272 | |
| 273 | #endif /* NC_SESSION_CLIENT_CH_H_ */ |