blob: 5f8dab745f0214d726e4de99a669ebcfad6b2a13 [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 *
Michal Vaskofdfd9dd2016-02-29 10:18:46 +010052 * @param[in] auth_password Function to call, returns the password for username\@hostname.
Michal Vasko30e2c872016-02-18 10:03:21 +010053 * 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 *
Michal Vasko45f298f2016-01-29 10:26:26 +010098 * @param[in] pub_key Path to the public key.
99 * @param[in] priv_key Path to the private key.
Michal Vaskof0537d82016-01-29 14:42:38 +0100100 * @return 0 on success, -1 on error.
Michal Vasko45f298f2016-01-29 10:26:26 +0100101 */
102int nc_client_ssh_ch_add_keypair(const char *pub_key, const char *priv_key);
103
104/**
105 * @brief Remove an SSH public and private key pair that was used for Call Home client authentication.
106 *
Michal Vasko45f298f2016-01-29 10:26:26 +0100107 * @param[in] idx Index of the keypair starting with 0.
Michal Vasko45f298f2016-01-29 10:26:26 +0100108 * @return 0 on success, -1 on error.
109 */
110int nc_client_ssh_ch_del_keypair(int idx);
111
112/**
113 * @brief Get the number of public an private key pairs set to be used for Call Home client authentication.
114 *
115 * @return Keypair count.
116 */
117int nc_client_ssh_ch_get_keypair_count(void);
118
119/**
120 * @brief Get a specific keypair set to be used for Call Home client authentication.
121 *
122 * @param[in] idx Index of the specific keypair.
123 * @param[out] pub_key Path to the public key.
124 * @param[out] priv_key Path to the private key.
Michal Vasko45f298f2016-01-29 10:26:26 +0100125 * @return 0 on success, -1 on error.
126 */
127int nc_client_ssh_ch_get_keypair(int idx, const char **pub_key, const char **priv_key);
128
129/**
130 * @brief Set SSH Call Home authentication method preference.
131 *
Michal Vasko45f298f2016-01-29 10:26:26 +0100132 * @param[in] auth_type Authentication method to modify the prefrence of.
133 * @param[in] pref Preference of \p auth_type. Negative values disable the method.
134 */
135void nc_client_ssh_ch_set_auth_pref(NC_SSH_AUTH_TYPE auth_type, int16_t pref);
136
137/**
138 * @brief Get SSH Call Home authentication method preference.
139 *
Michal Vasko45f298f2016-01-29 10:26:26 +0100140 * @param[in] auth_type Authentication method to retrieve the prefrence of.
Michal Vasko45f298f2016-01-29 10:26:26 +0100141 * @return Preference of the \p auth_type.
142 */
143int16_t nc_client_ssh_ch_get_auth_pref(NC_SSH_AUTH_TYPE auth_type);
144
145/**
146 * @brief Set client Call Home SSH username used for authentication.
147 *
148 * @param[in] username Username to use.
149 * @return 0 on success, -1 on error.
150 */
151int nc_client_ssh_ch_set_username(const char *username);
152
Michal Vaskoe22c6732016-01-29 11:03:02 +0100153/**
154 * @brief Get client Call Home SSH username used for authentication.
155 *
156 * @return Username used.
157 */
158const char *nc_client_ssh_ch_get_username(void);
159
Radek Krejci53691be2016-02-22 13:58:37 +0100160#endif /* NC_ENABLED_SSH */
Michal Vasko45f298f2016-01-29 10:26:26 +0100161
Radek Krejci53691be2016-02-22 13:58:37 +0100162#ifdef NC_ENABLED_TLS
Michal Vasko45f298f2016-01-29 10:26:26 +0100163
164/**
165 * @brief Add a new client bind and start listening on it for TLS Call Home connections.
166 *
167 * @param[in] address IP address to bind to.
168 * @param[in] port Port to bind to.
169 * @return 0 on success, -1 on error.
170 */
171int nc_client_tls_ch_add_bind_listen(const char *address, uint16_t port);
172
173/**
174 * @brief Remove a TLS listening client bind.
175 *
176 * @param[in] address IP address the socket was bound to. NULL matches all.
177 * @param[in] port Port the socket was bound to. 0 matches all.
178 * @return 0 on success, -1 on not found.
179 */
180int nc_client_tls_ch_del_bind(const char *address, uint16_t port);
181
182/**
183 * @brief Set client Call Home authentication identity - a certificate and a private key.
184 *
Michal Vaskoe22c6732016-01-29 11:03:02 +0100185 * @param[in] client_cert Path to the file containing the client certificate.
Michal Vasko45f298f2016-01-29 10:26:26 +0100186 * @param[in] client_key Path to the file containing the private key for the \p client_cert.
187 * If NULL, key is expected to be stored with \p client_cert.
Michal Vasko45f298f2016-01-29 10:26:26 +0100188 * @return 0 on success, -1 on error.
189 */
Michal Vaskoe22c6732016-01-29 11:03:02 +0100190int nc_client_tls_ch_set_cert_key_paths(const char *client_cert, const char *client_key);
191
192/**
193 * @brief Get client Call Home authentication identity - a certificate and a private key.
194 *
Michal Vaskoe22c6732016-01-29 11:03:02 +0100195 * @param[out] client_cert Path to the file containing the client certificate. Can be NULL.
196 * @param[out] client_key Path to the file containing the private key for the \p client_cert.
197 * Can be NULL.
198 */
199void nc_client_tls_ch_get_cert_key_paths(const char **client_cert, const char **client_key);
Michal Vasko45f298f2016-01-29 10:26:26 +0100200
201/**
202 * @brief Set client Call Home trusted CA certificates.
203 *
204 * @param[in] ca_file Location of the CA certificate file used to verify server certificates.
205 * For more info, see the documentation for SSL_CTX_load_verify_locations() from OpenSSL.
206 * @param[in] ca_dir Location of the CA certificates directory used to verify the server certificates.
207 * For more info, see the documentation for SSL_CTX_load_verify_locations() from OpenSSL.
208 * @return 0 on success, -1 on error.
209 */
Michal Vaskoe22c6732016-01-29 11:03:02 +0100210int nc_client_tls_ch_set_trusted_ca_paths(const char *ca_file, const char *ca_dir);
211
212/**
213 * @brief Get client Call Home trusted CA certificates.
214 *
215 * @param[out] ca_file Location of the CA certificate file used to verify server certificates.
216 * Can be NULL.
217 * @param[out] ca_dir Location of the CA certificates directory used to verify the server certificates.
218 * Can be NULL.
219 */
220void nc_client_tls_ch_get_trusted_ca_paths(const char **ca_file, const char **ca_dir);
Michal Vasko45f298f2016-01-29 10:26:26 +0100221
222/**
223 * @brief Set client Call Home Certificate Revocation Lists.
224 *
225 * @param[in] crl_file Location of the CRL certificate file used to check for revocated certificates.
226 * @param[in] crl_dir Location of the CRL certificate directory used to check for revocated certificates.
227 * @return 0 on success, -1 on error.
228 */
Michal Vaskoe22c6732016-01-29 11:03:02 +0100229int nc_client_tls_ch_set_crl_paths(const char *crl_file, const char *crl_dir);
230
231/**
232 * @brief Get client Call Home Certificate Revocation Lists.
233 *
234 * @param[out] crl_file Location of the CRL certificate file used to check for revocated certificates.
235 * Can be NULL.
236 * @param[out] crl_dir Location of the CRL certificate directory used to check for revocated certificates.
237 * Can be NULL.
238 */
239void nc_client_tls_ch_get_crl_paths(const char **crl_file, const char **crl_dir);
Michal Vasko45f298f2016-01-29 10:26:26 +0100240
Radek Krejci53691be2016-02-22 13:58:37 +0100241#endif /* NC_ENABLED_TLS */
Michal Vasko45f298f2016-01-29 10:26:26 +0100242
243#endif /* NC_SESSION_CLIENT_CH_H_ */