blob: 655f34c83b57ca77eadd0f65aabccf22e4ba1ef4 [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/**
Michal Vaskoef112d72016-02-18 13:28:25 +010060 * @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 */
65void nc_client_ssh_ch_set_auth_hostkey_check_clb(int (*auth_hostkey_check)(const char *hostname, ssh_session session));
66
67/**
Michal Vasko30e2c872016-02-18 10:03:21 +010068 * @brief Set SSH Call Home password authentication callback.
69 *
Michal Vaskofdfd9dd2016-02-29 10:18:46 +010070 * @param[in] auth_password Function to call, returns the password for username\@hostname.
Michal Vasko30e2c872016-02-18 10:03:21 +010071 * If NULL, the default callback is set.
72 */
73void 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 */
82void 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 */
91void nc_client_ssh_ch_set_auth_privkey_passphrase_clb(char *(*auth_privkey_passphrase)(const char *privkey_path));
92
93/**
Michal Vasko45f298f2016-01-29 10:26:26 +010094 * @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 */
100int 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 */
109int 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 Vasko45f298f2016-01-29 10:26:26 +0100116 * @param[in] pub_key Path to the public key.
117 * @param[in] priv_key Path to the private key.
Michal Vaskof0537d82016-01-29 14:42:38 +0100118 * @return 0 on success, -1 on error.
Michal Vasko45f298f2016-01-29 10:26:26 +0100119 */
120int 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 Vasko45f298f2016-01-29 10:26:26 +0100125 * @param[in] idx Index of the keypair starting with 0.
Michal Vasko45f298f2016-01-29 10:26:26 +0100126 * @return 0 on success, -1 on error.
127 */
128int 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 */
135int 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 Vasko45f298f2016-01-29 10:26:26 +0100143 * @return 0 on success, -1 on error.
144 */
145int 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 Vasko45f298f2016-01-29 10:26:26 +0100150 * @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 */
153void 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 Vasko45f298f2016-01-29 10:26:26 +0100158 * @param[in] auth_type Authentication method to retrieve the prefrence of.
Michal Vasko45f298f2016-01-29 10:26:26 +0100159 * @return Preference of the \p auth_type.
160 */
161int16_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 */
169int nc_client_ssh_ch_set_username(const char *username);
170
Michal Vaskoe22c6732016-01-29 11:03:02 +0100171/**
172 * @brief Get client Call Home SSH username used for authentication.
173 *
174 * @return Username used.
175 */
176const char *nc_client_ssh_ch_get_username(void);
177
Radek Krejci6799a052017-05-19 14:23:23 +0200178/**@} Client-side Call Home on SSH */
179
Radek Krejci53691be2016-02-22 13:58:37 +0100180#endif /* NC_ENABLED_SSH */
Michal Vasko45f298f2016-01-29 10:26:26 +0100181
Radek Krejci53691be2016-02-22 13:58:37 +0100182#ifdef NC_ENABLED_TLS
Michal Vasko45f298f2016-01-29 10:26:26 +0100183
184/**
Radek Krejci6799a052017-05-19 14:23:23 +0200185 * @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 Vasko45f298f2016-01-29 10:26:26 +0100193 * @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 */
199int 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 */
208int 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 Vaskoe22c6732016-01-29 11:03:02 +0100213 * @param[in] client_cert Path to the file containing the client certificate.
Michal Vasko45f298f2016-01-29 10:26:26 +0100214 * @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 Vasko45f298f2016-01-29 10:26:26 +0100216 * @return 0 on success, -1 on error.
217 */
Michal Vaskoe22c6732016-01-29 11:03:02 +0100218int 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 Vaskoe22c6732016-01-29 11:03:02 +0100223 * @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 */
227void nc_client_tls_ch_get_cert_key_paths(const char **client_cert, const char **client_key);
Michal Vasko45f298f2016-01-29 10:26:26 +0100228
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 Vaskoe22c6732016-01-29 11:03:02 +0100238int 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 */
248void nc_client_tls_ch_get_trusted_ca_paths(const char **ca_file, const char **ca_dir);
Michal Vasko45f298f2016-01-29 10:26:26 +0100249
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 Vaskoe22c6732016-01-29 11:03:02 +0100257int 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 */
267void nc_client_tls_ch_get_crl_paths(const char **crl_file, const char **crl_dir);
Michal Vasko45f298f2016-01-29 10:26:26 +0100268
Radek Krejci6799a052017-05-19 14:23:23 +0200269/**@} Client-side Call Home on TLS */
270
Radek Krejci53691be2016-02-22 13:58:37 +0100271#endif /* NC_ENABLED_TLS */
Michal Vasko45f298f2016-01-29 10:26:26 +0100272
273#endif /* NC_SESSION_CLIENT_CH_H_ */