blob: c94b42df716e6e14c28ac533f9a7376397e4a90e [file] [log] [blame]
Michal Vasko45f298f2016-01-29 10:26:26 +01001/**
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 Krejci9b81f5b2016-02-24 13:14:49 +01008 * 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 Vaskoafd416b2016-02-25 14:51:46 +010011 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +010012 * https://opensource.org/licenses/BSD-3-Clause
Michal Vasko45f298f2016-01-29 10:26:26 +010013 */
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 Krejci53691be2016-02-22 13:58:37 +010024#if defined(NC_ENABLED_SSH) || defined(NC_ENABLED_TLS)
Michal Vasko45f298f2016-01-29 10:26:26 +010025
26/**
Radek Krejci6799a052017-05-19 14:23:23 +020027 * @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 Vasko45f298f2016-01-29 10:26:26 +010035 * @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 Vaskof0537d82016-01-29 14:42:38 +010041 * @return 1 on success, 0 on timeout, -1 on error.
Michal Vasko45f298f2016-01-29 10:26:26 +010042 */
43int nc_accept_callhome(int timeout, struct ly_ctx *ctx, struct nc_session **session);
44
Radek Krejci6799a052017-05-19 14:23:23 +020045/**@} Client-side Call Home */
46
Radek Krejci53691be2016-02-22 13:58:37 +010047#endif /* NC_ENABLED_SSH || NC_ENABLED_TLS */
Michal Vasko45f298f2016-01-29 10:26:26 +010048
Radek Krejci53691be2016-02-22 13:58:37 +010049#ifdef NC_ENABLED_SSH
Michal Vasko45f298f2016-01-29 10:26:26 +010050
51/**
Radek Krejci6799a052017-05-19 14:23:23 +020052 * @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/**
Radek Krejci90a84a22017-05-25 13:53:00 +020060 * @brief Set SSH Call Home authentication hostkey check (knownhosts) callback.
61 *
62 * Repetitive calling causes replacing of the previous callback and its private data. Caller is responsible for
63 * freeing the private data when necessary (the private data can be obtained by
64 * nc_client_ssh_ch_get_auth_hostkey_check_clb()).
Michal Vaskoef112d72016-02-18 13:28:25 +010065 *
66 * @param[in] auth_hostkey_check Function to call, returns 0 on success, non-zero in error.
67 * If NULL, the default callback is set.
Radek Krejci90a84a22017-05-25 13:53:00 +020068 * @param[in] priv Optional private data to be passed to the callback function.
Michal Vaskoef112d72016-02-18 13:28:25 +010069 */
Radek Krejci90a84a22017-05-25 13:53:00 +020070void nc_client_ssh_ch_set_auth_hostkey_check_clb(int (*auth_hostkey_check)(const char *hostname, ssh_session session, void *priv),
71 void *priv);
Michal Vaskoef112d72016-02-18 13:28:25 +010072
73/**
Radek Krejci90a84a22017-05-25 13:53:00 +020074 * @brief Get currently set SSH Call Home authentication hostkey check (knownhosts) callback and its private data
75 * previously set by nc_client_ssh_ch_set_auth_hostkey_check_clb().
76 *
77 * @param[out] auth_hostkey_check Currently set callback, NULL in case of the default callback.
78 * @param[out] priv Currently set (optional) private data to be passed to the callback function.
79 */
80void nc_client_ssh_ch_get_auth_hostkey_check_clb(int (**auth_hostkey_check)(const char *hostname, ssh_session session, void *priv),
81 void **priv);
82/**
Michal Vasko30e2c872016-02-18 10:03:21 +010083 * @brief Set SSH Call Home password authentication callback.
84 *
Radek Krejci90a84a22017-05-25 13:53:00 +020085 * Repetitive calling causes replacing of the previous callback and its private data. Caller is responsible for
86 * freeing the private data when necessary (the private data can be obtained by
87 * nc_client_ssh_ch_get_auth_password_clb()).
88 *
Michal Vaskofdfd9dd2016-02-29 10:18:46 +010089 * @param[in] auth_password Function to call, returns the password for username\@hostname.
Michal Vasko30e2c872016-02-18 10:03:21 +010090 * If NULL, the default callback is set.
Radek Krejci90a84a22017-05-25 13:53:00 +020091 * @param[in] priv Optional private data to be passed to the callback function.
Michal Vasko30e2c872016-02-18 10:03:21 +010092 */
Radek Krejci90a84a22017-05-25 13:53:00 +020093void nc_client_ssh_ch_set_auth_password_clb(char *(*auth_password)(const char *username, const char *hostname, void *priv),
94 void *priv);
95
96/**
97 * @brief Get currently set SSH Call Home password authentication callback and its private data
98 * previously set by nc_client_ssh_ch_set_auth_password_clb().
99 *
100 * @param[out] auth_password Currently set callback, NULL in case of the default callback.
101 * @param[out] priv Currently set (optional) private data to be passed to the callback function.
102 */
103void nc_client_ssh_ch_get_auth_password_clb(char *(**auth_password)(const char *username, const char *hostname, void *priv),
104 void **priv);
Michal Vasko30e2c872016-02-18 10:03:21 +0100105
106/**
107 * @brief Set SSH Call Home interactive authentication callback.
108 *
Radek Krejci90a84a22017-05-25 13:53:00 +0200109 * Repetitive calling causes replacing of the previous callback and its private data. Caller is responsible for
110 * freeing the private data when necessary (the private data can be obtained by
111 * nc_client_ssh_ch_get_auth_interactive_clb()).
112 *
Michal Vasko30e2c872016-02-18 10:03:21 +0100113 * @param[in] auth_interactive Function to call for every question, returns the answer for
114 * authentication name with instruction and echoing prompt.
115 * If NULL, the default callback is set.
Radek Krejci90a84a22017-05-25 13:53:00 +0200116 * @param[in] priv Optional private data to be passed to the callback function.
Michal Vasko30e2c872016-02-18 10:03:21 +0100117 */
118void nc_client_ssh_ch_set_auth_interactive_clb(char *(*auth_interactive)(const char *auth_name, const char *instruction,
Radek Krejci90a84a22017-05-25 13:53:00 +0200119 const char *prompt, int echo, void *priv),
120 void *priv);
121
122/**
123 * @brief Get currently set SSH Call Home interactive authentication callback and its private data
124 * previously set by nc_client_ssh_ch_set_auth_interactive_clb().
125 *
126 * @param[out] auth_interactive Currently set callback, NULL in case of the default callback.
127 * @param[out] priv Currently set (optional) private data to be passed to the callback function.
128 */
129void nc_client_ssh_ch_get_auth_interactive_clb(char *(**auth_interactive)(const char *auth_name, const char *instruction,
130 const char *prompt, int echo, void *priv),
131 void **priv);
Michal Vasko30e2c872016-02-18 10:03:21 +0100132
133/**
134 * @brief Set SSH Call Home publickey authentication encrypted private key passphrase callback.
135 *
Radek Krejci90a84a22017-05-25 13:53:00 +0200136 * Repetitive calling causes replacing of the previous callback and its private data. Caller is responsible for
137 * freeing the private data when necessary (the private data can be obtained by
138 * nc_client_ssh_ch_get_auth_privkey_passphrase_clb()).
139 *
Michal Vasko30e2c872016-02-18 10:03:21 +0100140 * @param[in] auth_privkey_passphrase Function to call for every question, returns
141 * the passphrase for the specific private key.
Radek Krejci90a84a22017-05-25 13:53:00 +0200142 * @param[in] priv Optional private data to be passed to the callback function.
Michal Vasko30e2c872016-02-18 10:03:21 +0100143 */
Radek Krejci90a84a22017-05-25 13:53:00 +0200144void nc_client_ssh_ch_set_auth_privkey_passphrase_clb(char *(*auth_privkey_passphrase)(const char *privkey_path, void *priv),
145 void *priv);
146
147/**
148 * @brief Get currently set SSH Call Home publickey authentication encrypted private key passphrase callback and its
149 * private data previously set by nc_client_ssh_ch_set_auth_privkey_passphrase_clb().
150 *
151 * @param[out] auth_privkey_passphrase Currently set callback, NULL in case of the default callback.
152 * @param[out] priv Currently set (optional) private data to be passed to the callback function.
153 */
154void nc_client_ssh_ch_get_auth_privkey_passphrase_clb(char *(**auth_privkey_passphrase)(const char *privkey_path, void *priv),
155 void **priv);
Michal Vasko30e2c872016-02-18 10:03:21 +0100156
157/**
Michal Vasko45f298f2016-01-29 10:26:26 +0100158 * @brief Add a new client bind and start listening on it for SSH Call Home connections.
159 *
160 * @param[in] address IP address to bind to.
161 * @param[in] port Port to bind to.
162 * @return 0 on success, -1 on error.
163 */
164int nc_client_ssh_ch_add_bind_listen(const char *address, uint16_t port);
165
166/**
167 * @brief Remove an SSH listening client bind.
168 *
169 * @param[in] address IP address the socket was bound to. NULL matches all.
170 * @param[in] port Port the socket was bound to. 0 matches all.
171 * @return 0 on success, -1 on not found.
172 */
173int nc_client_ssh_ch_del_bind(const char *address, uint16_t port);
174
175/**
176 * @brief Add an SSH public and private key pair to be used for Call Home client authentication.
177 *
178 * Private key can be encrypted, the passphrase will be asked for before using it.
179 *
Michal Vasko45f298f2016-01-29 10:26:26 +0100180 * @param[in] pub_key Path to the public key.
181 * @param[in] priv_key Path to the private key.
Michal Vaskof0537d82016-01-29 14:42:38 +0100182 * @return 0 on success, -1 on error.
Michal Vasko45f298f2016-01-29 10:26:26 +0100183 */
184int nc_client_ssh_ch_add_keypair(const char *pub_key, const char *priv_key);
185
186/**
187 * @brief Remove an SSH public and private key pair that was used for Call Home client authentication.
188 *
Michal Vasko45f298f2016-01-29 10:26:26 +0100189 * @param[in] idx Index of the keypair starting with 0.
Michal Vasko45f298f2016-01-29 10:26:26 +0100190 * @return 0 on success, -1 on error.
191 */
192int nc_client_ssh_ch_del_keypair(int idx);
193
194/**
195 * @brief Get the number of public an private key pairs set to be used for Call Home client authentication.
196 *
197 * @return Keypair count.
198 */
199int nc_client_ssh_ch_get_keypair_count(void);
200
201/**
202 * @brief Get a specific keypair set to be used for Call Home client authentication.
203 *
204 * @param[in] idx Index of the specific keypair.
205 * @param[out] pub_key Path to the public key.
206 * @param[out] priv_key Path to the private key.
Michal Vasko45f298f2016-01-29 10:26:26 +0100207 * @return 0 on success, -1 on error.
208 */
209int nc_client_ssh_ch_get_keypair(int idx, const char **pub_key, const char **priv_key);
210
211/**
212 * @brief Set SSH Call Home authentication method preference.
213 *
Radek Krejci62aa0642017-05-25 16:33:49 +0200214 * The default preference is as follows:
215 * - public key authentication (3)
216 * - password authentication (2)
217 * - interactive authentication (1)
218 *
219 * @param[in] auth_type Authentication method to modify the preference of.
220 * @param[in] pref Preference of \p auth_type. Higher number increases priority, negative values disable the method.
Michal Vasko45f298f2016-01-29 10:26:26 +0100221 */
222void nc_client_ssh_ch_set_auth_pref(NC_SSH_AUTH_TYPE auth_type, int16_t pref);
223
224/**
225 * @brief Get SSH Call Home authentication method preference.
226 *
Michal Vasko45f298f2016-01-29 10:26:26 +0100227 * @param[in] auth_type Authentication method to retrieve the prefrence of.
Michal Vasko45f298f2016-01-29 10:26:26 +0100228 * @return Preference of the \p auth_type.
229 */
230int16_t nc_client_ssh_ch_get_auth_pref(NC_SSH_AUTH_TYPE auth_type);
231
232/**
233 * @brief Set client Call Home SSH username used for authentication.
234 *
235 * @param[in] username Username to use.
236 * @return 0 on success, -1 on error.
237 */
238int nc_client_ssh_ch_set_username(const char *username);
239
Michal Vaskoe22c6732016-01-29 11:03:02 +0100240/**
241 * @brief Get client Call Home SSH username used for authentication.
242 *
243 * @return Username used.
244 */
245const char *nc_client_ssh_ch_get_username(void);
246
Radek Krejci6799a052017-05-19 14:23:23 +0200247/**@} Client-side Call Home on SSH */
248
Radek Krejci53691be2016-02-22 13:58:37 +0100249#endif /* NC_ENABLED_SSH */
Michal Vasko45f298f2016-01-29 10:26:26 +0100250
Radek Krejci53691be2016-02-22 13:58:37 +0100251#ifdef NC_ENABLED_TLS
Michal Vasko45f298f2016-01-29 10:26:26 +0100252
253/**
Radek Krejci6799a052017-05-19 14:23:23 +0200254 * @defgroup client_ch_tls Client-side Call Home on TLS
255 * @ingroup client_ch
256 *
257 * @brief TLS settings for the Call Home functionality
258 * @{
259 */
260
261/**
Michal Vasko45f298f2016-01-29 10:26:26 +0100262 * @brief Add a new client bind and start listening on it for TLS Call Home connections.
263 *
264 * @param[in] address IP address to bind to.
265 * @param[in] port Port to bind to.
266 * @return 0 on success, -1 on error.
267 */
268int nc_client_tls_ch_add_bind_listen(const char *address, uint16_t port);
269
270/**
271 * @brief Remove a TLS listening client bind.
272 *
273 * @param[in] address IP address the socket was bound to. NULL matches all.
274 * @param[in] port Port the socket was bound to. 0 matches all.
275 * @return 0 on success, -1 on not found.
276 */
277int nc_client_tls_ch_del_bind(const char *address, uint16_t port);
278
279/**
280 * @brief Set client Call Home authentication identity - a certificate and a private key.
281 *
Michal Vaskoe22c6732016-01-29 11:03:02 +0100282 * @param[in] client_cert Path to the file containing the client certificate.
Michal Vasko45f298f2016-01-29 10:26:26 +0100283 * @param[in] client_key Path to the file containing the private key for the \p client_cert.
284 * If NULL, key is expected to be stored with \p client_cert.
Michal Vasko45f298f2016-01-29 10:26:26 +0100285 * @return 0 on success, -1 on error.
286 */
Michal Vaskoe22c6732016-01-29 11:03:02 +0100287int nc_client_tls_ch_set_cert_key_paths(const char *client_cert, const char *client_key);
288
289/**
290 * @brief Get client Call Home authentication identity - a certificate and a private key.
291 *
Michal Vaskoe22c6732016-01-29 11:03:02 +0100292 * @param[out] client_cert Path to the file containing the client certificate. Can be NULL.
293 * @param[out] client_key Path to the file containing the private key for the \p client_cert.
294 * Can be NULL.
295 */
296void nc_client_tls_ch_get_cert_key_paths(const char **client_cert, const char **client_key);
Michal Vasko45f298f2016-01-29 10:26:26 +0100297
298/**
299 * @brief Set client Call Home trusted CA certificates.
300 *
301 * @param[in] ca_file Location of the CA certificate file used to verify server certificates.
302 * For more info, see the documentation for SSL_CTX_load_verify_locations() from OpenSSL.
303 * @param[in] ca_dir Location of the CA certificates directory used to verify the server certificates.
304 * For more info, see the documentation for SSL_CTX_load_verify_locations() from OpenSSL.
305 * @return 0 on success, -1 on error.
306 */
Michal Vaskoe22c6732016-01-29 11:03:02 +0100307int nc_client_tls_ch_set_trusted_ca_paths(const char *ca_file, const char *ca_dir);
308
309/**
310 * @brief Get client Call Home trusted CA certificates.
311 *
312 * @param[out] ca_file Location of the CA certificate file used to verify server certificates.
313 * Can be NULL.
314 * @param[out] ca_dir Location of the CA certificates directory used to verify the server certificates.
315 * Can be NULL.
316 */
317void nc_client_tls_ch_get_trusted_ca_paths(const char **ca_file, const char **ca_dir);
Michal Vasko45f298f2016-01-29 10:26:26 +0100318
319/**
320 * @brief Set client Call Home Certificate Revocation Lists.
321 *
322 * @param[in] crl_file Location of the CRL certificate file used to check for revocated certificates.
323 * @param[in] crl_dir Location of the CRL certificate directory used to check for revocated certificates.
324 * @return 0 on success, -1 on error.
325 */
Michal Vaskoe22c6732016-01-29 11:03:02 +0100326int nc_client_tls_ch_set_crl_paths(const char *crl_file, const char *crl_dir);
327
328/**
329 * @brief Get client Call Home Certificate Revocation Lists.
330 *
331 * @param[out] crl_file Location of the CRL certificate file used to check for revocated certificates.
332 * Can be NULL.
333 * @param[out] crl_dir Location of the CRL certificate directory used to check for revocated certificates.
334 * Can be NULL.
335 */
336void nc_client_tls_ch_get_crl_paths(const char **crl_file, const char **crl_dir);
Michal Vasko45f298f2016-01-29 10:26:26 +0100337
Radek Krejci6799a052017-05-19 14:23:23 +0200338/**@} Client-side Call Home on TLS */
339
Radek Krejci53691be2016-02-22 13:58:37 +0100340#endif /* NC_ENABLED_TLS */
Michal Vasko45f298f2016-01-29 10:26:26 +0100341
342#endif /* NC_SESSION_CLIENT_CH_H_ */