blob: 39ccc4f8af59f72a33244a9de6a738596394f89e [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/**
27 * @brief Accept a Call Home connection on any of the listening binds.
28 *
29 * @param[in] timeout Timeout for receiving a new connection in milliseconds, 0 for
30 * non-blocking call, -1 for infinite waiting.
31 * @param[in] ctx Session context to use. Can be NULL.
32 * @param[out] session New session.
Michal Vaskof0537d82016-01-29 14:42:38 +010033 * @return 1 on success, 0 on timeout, -1 on error.
Michal Vasko45f298f2016-01-29 10:26:26 +010034 */
35int nc_accept_callhome(int timeout, struct ly_ctx *ctx, struct nc_session **session);
36
Radek Krejci53691be2016-02-22 13:58:37 +010037#endif /* NC_ENABLED_SSH || NC_ENABLED_TLS */
Michal Vasko45f298f2016-01-29 10:26:26 +010038
Radek Krejci53691be2016-02-22 13:58:37 +010039#ifdef NC_ENABLED_SSH
Michal Vasko45f298f2016-01-29 10:26:26 +010040
41/**
Michal Vaskoef112d72016-02-18 13:28:25 +010042 * @brief Set SSH CALL Home authentication hostkey check (knownhosts) callback.
43 *
44 * @param[in] auth_hostkey_check Function to call, returns 0 on success, non-zero in error.
45 * If NULL, the default callback is set.
46 */
47void nc_client_ssh_ch_set_auth_hostkey_check_clb(int (*auth_hostkey_check)(const char *hostname, ssh_session session));
48
49/**
Michal Vasko30e2c872016-02-18 10:03:21 +010050 * @brief Set SSH Call Home password authentication callback.
51 *
52 * @param[in] auth_password Function to call, returns the password for username@hostname.
53 * If NULL, the default callback is set.
54 */
55void nc_client_ssh_ch_set_auth_password_clb(char *(*auth_password)(const char *username, const char *hostname));
56
57/**
58 * @brief Set SSH Call Home interactive authentication callback.
59 *
60 * @param[in] auth_interactive Function to call for every question, returns the answer for
61 * authentication name with instruction and echoing prompt.
62 * If NULL, the default callback is set.
63 */
64void nc_client_ssh_ch_set_auth_interactive_clb(char *(*auth_interactive)(const char *auth_name, const char *instruction,
65 const char *prompt, int echo));
66
67/**
68 * @brief Set SSH Call Home publickey authentication encrypted private key passphrase callback.
69 *
70 * @param[in] auth_privkey_passphrase Function to call for every question, returns
71 * the passphrase for the specific private key.
72 */
73void nc_client_ssh_ch_set_auth_privkey_passphrase_clb(char *(*auth_privkey_passphrase)(const char *privkey_path));
74
75/**
Michal Vasko45f298f2016-01-29 10:26:26 +010076 * @brief Add a new client bind and start listening on it for SSH Call Home connections.
77 *
78 * @param[in] address IP address to bind to.
79 * @param[in] port Port to bind to.
80 * @return 0 on success, -1 on error.
81 */
82int nc_client_ssh_ch_add_bind_listen(const char *address, uint16_t port);
83
84/**
85 * @brief Remove an SSH listening client bind.
86 *
87 * @param[in] address IP address the socket was bound to. NULL matches all.
88 * @param[in] port Port the socket was bound to. 0 matches all.
89 * @return 0 on success, -1 on not found.
90 */
91int nc_client_ssh_ch_del_bind(const char *address, uint16_t port);
92
93/**
94 * @brief Add an SSH public and private key pair to be used for Call Home client authentication.
95 *
96 * Private key can be encrypted, the passphrase will be asked for before using it.
97 *
98 * Function is provided only via nc_client.h header file and only when libnetconf2 is compiled with libssh support.
99 *
100 * @param[in] pub_key Path to the public key.
101 * @param[in] priv_key Path to the private key.
Michal Vaskof0537d82016-01-29 14:42:38 +0100102 * @return 0 on success, -1 on error.
Michal Vasko45f298f2016-01-29 10:26:26 +0100103 */
104int nc_client_ssh_ch_add_keypair(const char *pub_key, const char *priv_key);
105
106/**
107 * @brief Remove an SSH public and private key pair that was used for Call Home client authentication.
108 *
109 * Function is provided only via nc_client.h header file and only when libnetconf2 is compiled with libssh support.
110 *
111 * @param[in] idx Index of the keypair starting with 0.
Michal Vasko45f298f2016-01-29 10:26:26 +0100112 * @return 0 on success, -1 on error.
113 */
114int nc_client_ssh_ch_del_keypair(int idx);
115
116/**
117 * @brief Get the number of public an private key pairs set to be used for Call Home client authentication.
118 *
119 * @return Keypair count.
120 */
121int nc_client_ssh_ch_get_keypair_count(void);
122
123/**
124 * @brief Get a specific keypair set to be used for Call Home client authentication.
125 *
126 * @param[in] idx Index of the specific keypair.
127 * @param[out] pub_key Path to the public key.
128 * @param[out] priv_key Path to the private key.
Michal Vasko45f298f2016-01-29 10:26:26 +0100129 * @return 0 on success, -1 on error.
130 */
131int nc_client_ssh_ch_get_keypair(int idx, const char **pub_key, const char **priv_key);
132
133/**
134 * @brief Set SSH Call Home authentication method preference.
135 *
136 * Function is provided only via nc_client.h header file and only when libnetconf2 is compiled with libssh support.
137 *
138 * @param[in] auth_type Authentication method to modify the prefrence of.
139 * @param[in] pref Preference of \p auth_type. Negative values disable the method.
140 */
141void nc_client_ssh_ch_set_auth_pref(NC_SSH_AUTH_TYPE auth_type, int16_t pref);
142
143/**
144 * @brief Get SSH Call Home authentication method preference.
145 *
146 * Function is provided only via nc_client.h header file and only when libnetconf2 is compiled with libssh support.
147 *
148 * @param[in] auth_type Authentication method to retrieve the prefrence of.
Michal Vasko45f298f2016-01-29 10:26:26 +0100149 * @return Preference of the \p auth_type.
150 */
151int16_t nc_client_ssh_ch_get_auth_pref(NC_SSH_AUTH_TYPE auth_type);
152
153/**
154 * @brief Set client Call Home SSH username used for authentication.
155 *
156 * @param[in] username Username to use.
157 * @return 0 on success, -1 on error.
158 */
159int nc_client_ssh_ch_set_username(const char *username);
160
Michal Vaskoe22c6732016-01-29 11:03:02 +0100161/**
162 * @brief Get client Call Home SSH username used for authentication.
163 *
164 * @return Username used.
165 */
166const char *nc_client_ssh_ch_get_username(void);
167
Radek Krejci53691be2016-02-22 13:58:37 +0100168#endif /* NC_ENABLED_SSH */
Michal Vasko45f298f2016-01-29 10:26:26 +0100169
Radek Krejci53691be2016-02-22 13:58:37 +0100170#ifdef NC_ENABLED_TLS
Michal Vasko45f298f2016-01-29 10:26:26 +0100171
172/**
173 * @brief Add a new client bind and start listening on it for TLS Call Home connections.
174 *
175 * @param[in] address IP address to bind to.
176 * @param[in] port Port to bind to.
177 * @return 0 on success, -1 on error.
178 */
179int nc_client_tls_ch_add_bind_listen(const char *address, uint16_t port);
180
181/**
182 * @brief Remove a TLS listening client bind.
183 *
184 * @param[in] address IP address the socket was bound to. NULL matches all.
185 * @param[in] port Port the socket was bound to. 0 matches all.
186 * @return 0 on success, -1 on not found.
187 */
188int nc_client_tls_ch_del_bind(const char *address, uint16_t port);
189
190/**
191 * @brief Set client Call Home authentication identity - a certificate and a private key.
192 *
193 * Function is provided only via nc_client.h header file and only when libnetconf2 is compiled with TLS support.
194 *
Michal Vaskoe22c6732016-01-29 11:03:02 +0100195 * @param[in] client_cert Path to the file containing the client certificate.
Michal Vasko45f298f2016-01-29 10:26:26 +0100196 * @param[in] client_key Path to the file containing the private key for the \p client_cert.
197 * If NULL, key is expected to be stored with \p client_cert.
Michal Vasko45f298f2016-01-29 10:26:26 +0100198 * @return 0 on success, -1 on error.
199 */
Michal Vaskoe22c6732016-01-29 11:03:02 +0100200int nc_client_tls_ch_set_cert_key_paths(const char *client_cert, const char *client_key);
201
202/**
203 * @brief Get client Call Home authentication identity - a certificate and a private key.
204 *
205 * Function is provided only via nc_client.h header file and only when libnetconf2 is compiled with TLS support.
206 *
207 * @param[out] client_cert Path to the file containing the client certificate. Can be NULL.
208 * @param[out] client_key Path to the file containing the private key for the \p client_cert.
209 * Can be NULL.
210 */
211void nc_client_tls_ch_get_cert_key_paths(const char **client_cert, const char **client_key);
Michal Vasko45f298f2016-01-29 10:26:26 +0100212
213/**
214 * @brief Set client Call Home trusted CA certificates.
215 *
216 * @param[in] ca_file Location of the CA certificate file used to verify server certificates.
217 * For more info, see the documentation for SSL_CTX_load_verify_locations() from OpenSSL.
218 * @param[in] ca_dir Location of the CA certificates directory used to verify the server certificates.
219 * For more info, see the documentation for SSL_CTX_load_verify_locations() from OpenSSL.
220 * @return 0 on success, -1 on error.
221 */
Michal Vaskoe22c6732016-01-29 11:03:02 +0100222int nc_client_tls_ch_set_trusted_ca_paths(const char *ca_file, const char *ca_dir);
223
224/**
225 * @brief Get client Call Home trusted CA certificates.
226 *
227 * @param[out] ca_file Location of the CA certificate file used to verify server certificates.
228 * Can be NULL.
229 * @param[out] ca_dir Location of the CA certificates directory used to verify the server certificates.
230 * Can be NULL.
231 */
232void nc_client_tls_ch_get_trusted_ca_paths(const char **ca_file, const char **ca_dir);
Michal Vasko45f298f2016-01-29 10:26:26 +0100233
234/**
235 * @brief Set client Call Home Certificate Revocation Lists.
236 *
237 * @param[in] crl_file Location of the CRL certificate file used to check for revocated certificates.
238 * @param[in] crl_dir Location of the CRL certificate directory used to check for revocated certificates.
239 * @return 0 on success, -1 on error.
240 */
Michal Vaskoe22c6732016-01-29 11:03:02 +0100241int nc_client_tls_ch_set_crl_paths(const char *crl_file, const char *crl_dir);
242
243/**
244 * @brief Get client Call Home Certificate Revocation Lists.
245 *
246 * @param[out] crl_file Location of the CRL certificate file used to check for revocated certificates.
247 * Can be NULL.
248 * @param[out] crl_dir Location of the CRL certificate directory used to check for revocated certificates.
249 * Can be NULL.
250 */
251void nc_client_tls_ch_get_crl_paths(const char **crl_file, const char **crl_dir);
Michal Vasko45f298f2016-01-29 10:26:26 +0100252
Radek Krejci53691be2016-02-22 13:58:37 +0100253#endif /* NC_ENABLED_TLS */
Michal Vasko45f298f2016-01-29 10:26:26 +0100254
255#endif /* NC_SESSION_CLIENT_CH_H_ */