blob: e8c508ba95758d4a07c492a0718896774cba57ce [file] [log] [blame]
Michal Vasko45f298f2016-01-29 10:26:26 +01001/**
Michal Vaskoc446a382021-06-18 08:54:05 +02002 * @file session_server_ch.h
3 * @author Michal Vasko <mvasko@cesnet.cz>
4 * @brief libnetconf2 Call Home session server manipulation
Michal Vasko45f298f2016-01-29 10:26:26 +01005 *
Michal Vasko95ea9ff2021-11-09 12:29:14 +01006 * @copyright
Michal Vaskoc446a382021-06-18 08:54:05 +02007 * Copyright (c) 2015 - 2021 CESNET, z.s.p.o.
Michal Vasko45f298f2016-01-29 10:26:26 +01008 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +01009 * This source code is licensed under BSD 3-Clause License (the "License").
10 * You may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
Michal Vaskoafd416b2016-02-25 14:51:46 +010012 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +010013 * https://opensource.org/licenses/BSD-3-Clause
Michal Vasko45f298f2016-01-29 10:26:26 +010014 */
15
16#ifndef NC_SESSION_SERVER_CH_H_
17#define NC_SESSION_SERVER_CH_H_
18
Michal Vaskoc09730e2019-01-17 10:07:26 +010019#ifdef __cplusplus
20extern "C" {
21#endif
22
Michal Vasko45f298f2016-01-29 10:26:26 +010023#include <libyang/libyang.h>
Michal Vaskob83a3fa2021-05-26 09:53:42 +020024#include <stdint.h>
Michal Vasko45f298f2016-01-29 10:26:26 +010025
Michal Vasko45f298f2016-01-29 10:26:26 +010026#include "netconf.h"
Michal Vaskob83a3fa2021-05-26 09:53:42 +020027#include "session.h"
Michal Vasko45f298f2016-01-29 10:26:26 +010028
Michal Vaskob83a3fa2021-05-26 09:53:42 +020029#if defined (NC_ENABLED_SSH) || defined (NC_ENABLED_TLS)
Michal Vasko45f298f2016-01-29 10:26:26 +010030
31/**
Radek Krejci6799a052017-05-19 14:23:23 +020032 * @defgroup server_ch Server-side Call Home
33 * @ingroup server
34 *
35 * @brief Call Home functionality for server-side applications.
36 * @{
37 */
38
39/**
Michal Vasko2e6defd2016-10-07 15:48:15 +020040 * @brief Add a new Call Home client.
Michal Vasko45f298f2016-01-29 10:26:26 +010041 *
Michal Vasko2e6defd2016-10-07 15:48:15 +020042 * @param[in] name Arbitrary unique client name.
Michal Vasko2e6defd2016-10-07 15:48:15 +020043 * @return 0 on success, -1 on error.
Michal Vasko45f298f2016-01-29 10:26:26 +010044 */
Michal Vaskoadf30f02019-06-24 09:34:47 +020045int nc_server_ch_add_client(const char *name);
Michal Vasko2e6defd2016-10-07 15:48:15 +020046
47/**
48 * @brief Drop any connections, stop connecting and remove a client.
49 *
50 * @param[in] name Client name. NULL matches all the clients.
51 * @return 0 on success, -1 on not finding any match.
52 */
Michal Vaskoadf30f02019-06-24 09:34:47 +020053int nc_server_ch_del_client(const char *name);
Michal Vasko2e6defd2016-10-07 15:48:15 +020054
55/**
Michal Vaskofb1724b2020-01-31 11:02:00 +010056 * @brief Check if a Call Home client exists.
57 *
58 * @param[in] name Client name.
59 * @return 0 if does not exists, non-zero otherwise.
60 */
61int nc_server_ch_is_client(const char *name);
62
63/**
Michal Vasko2e6defd2016-10-07 15:48:15 +020064 * @brief Add a new Call Home client endpoint.
65 *
66 * @param[in] client_name Existing client name.
67 * @param[in] endpt_name Arbitrary unique (within the client) endpoint name.
Michal Vaskoadf30f02019-06-24 09:34:47 +020068 * @param[in] ti Transport protocol to use.
Michal Vasko2e6defd2016-10-07 15:48:15 +020069 * @return 0 on success, -1 on error.
70 */
Michal Vaskoadf30f02019-06-24 09:34:47 +020071int nc_server_ch_client_add_endpt(const char *client_name, const char *endpt_name, NC_TRANSPORT_IMPL ti);
Michal Vasko2e6defd2016-10-07 15:48:15 +020072
73/**
74 * @brief Remove a Call Home client endpoint.
75 *
76 * @param[in] client_name Existing client name.
Michal Vaskoc446a382021-06-18 08:54:05 +020077 * @param[in] endpt_name Existing endpoint of @p client_name. NULL matches all endpoints.
Michal Vaskoadf30f02019-06-24 09:34:47 +020078 * @param[in] ti Client transport protocol. NULL matches any protocol.
Michal Vaskoc446a382021-06-18 08:54:05 +020079 * Redundant to set if @p endpt_name is set, client names are
Michal Vaskoadf30f02019-06-24 09:34:47 +020080 * unique disregarding their protocol.
Michal Vasko2e6defd2016-10-07 15:48:15 +020081 * @return 0 on success, -1 on error.
82 */
Michal Vaskoadf30f02019-06-24 09:34:47 +020083int nc_server_ch_client_del_endpt(const char *client_name, const char *endpt_name, NC_TRANSPORT_IMPL ti);
Michal Vasko2e6defd2016-10-07 15:48:15 +020084
85/**
Michal Vaskofb1724b2020-01-31 11:02:00 +010086 * @brief Check if an endpoint of a Call Home client exists.
87 *
88 * @param[in] client_name Client name.
89 * @param[in] endpt_name Endpoint name.
90 * @return 0 if does not exists, non-zero otherwise.
91 */
92int nc_server_ch_client_is_endpt(const char *client_name, const char *endpt_name);
93
94/**
Michal Vasko2e6defd2016-10-07 15:48:15 +020095 * @brief Change Call Home client endpoint listening address.
96 *
97 * On error the previous listening socket (if any) is left untouched.
98 *
99 * @param[in] client_name Existing Call Home client name.
Michal Vaskoc446a382021-06-18 08:54:05 +0200100 * @param[in] endpt_name Existing endpoint name of @p client_name.
Michal Vasko2e6defd2016-10-07 15:48:15 +0200101 * @param[in] address New listening address.
102 * @return 0 on success, -1 on error.
103 */
104int nc_server_ch_client_endpt_set_address(const char *client_name, const char *endpt_name, const char *address);
105
106/**
107 * @brief Change Call Home client endpoint listening port.
108 *
109 * On error the previous listening socket (if any) is left untouched.
110 *
111 * @param[in] client_name Existing Call Home client name.
Michal Vaskoc446a382021-06-18 08:54:05 +0200112 * @param[in] endpt_name Existing endpoint name of @p client_name.
Michal Vasko2e6defd2016-10-07 15:48:15 +0200113 * @param[in] port New listening port.
114 * @return 0 on success, -1 on error.
115 */
116int nc_server_ch_client_endpt_set_port(const char *client_name, const char *endpt_name, uint16_t port);
117
118/**
Michal Vaskoe49a15f2019-05-27 14:18:36 +0200119 * @brief Change Call Home client endpoint keepalives state. Affects only new connections.
120 *
121 * @param[in] client_name Existing Call Home client name.
Michal Vaskoc446a382021-06-18 08:54:05 +0200122 * @param[in] endpt_name Existing endpoint name of @p client_name.
Michal Vaskoe49a15f2019-05-27 14:18:36 +0200123 * @param[in] enable Whether to enable or disable keepalives.
124 * @return 0 on success, -1 on error.
125 */
126int nc_server_ch_client_endpt_enable_keepalives(const char *client_name, const char *endpt_name, int enable);
127
128/**
129 * @brief Change Call Home client endpoint keepalives parameters. Affects only new connections.
130 *
131 * @param[in] client_name Existing Call Home client name.
Michal Vaskoc446a382021-06-18 08:54:05 +0200132 * @param[in] endpt_name Existing endpoint name of @p client_name.
Michal Vaskoe49a15f2019-05-27 14:18:36 +0200133 * @param[in] idle_time Keepalive idle time in seconds, 1 by default, -1 to keep previous value.
134 * @param[in] max_probes Keepalive max probes sent, 10 by default, -1 to keep previous value.
135 * @param[in] probe_interval Keepalive probe interval in seconds, 5 by default, -1 to keep previous value.
136 * @return 0 on success, -1 on error.
137 */
138int nc_server_ch_client_endpt_set_keepalives(const char *client_name, const char *endpt_name, int idle_time,
139 int max_probes, int probe_interval);
140
141/**
Michal Vasko2e6defd2016-10-07 15:48:15 +0200142 * @brief Set Call Home client connection type.
143 *
144 * @param[in] client_name Existing Call Home client name.
145 * @param[in] conn_type Call Home connection type.
146 * @return 0 on success, -1 on error.
147 */
148int nc_server_ch_client_set_conn_type(const char *client_name, NC_CH_CONN_TYPE conn_type);
149
150/**
Michal Vaskoe49a15f2019-05-27 14:18:36 +0200151 * @brief Set Call Home client periodic connection period for reconnecting.
Michal Vasko2e6defd2016-10-07 15:48:15 +0200152 *
153 * @param[in] client_name Existing Call Home client name.
Michal Vaskoe49a15f2019-05-27 14:18:36 +0200154 * @param[in] period Call Home periodic connection period in minutes.
Michal Vasko2e6defd2016-10-07 15:48:15 +0200155 * @return 0 on success, -1 on error.
156 */
Michal Vaskoe49a15f2019-05-27 14:18:36 +0200157int nc_server_ch_client_periodic_set_period(const char *client_name, uint16_t period);
Michal Vasko2e6defd2016-10-07 15:48:15 +0200158
159/**
Michal Vaskoe49a15f2019-05-27 14:18:36 +0200160 * @brief Set Call Home client periodic connection period anchor time.
Michal Vasko2e6defd2016-10-07 15:48:15 +0200161 *
162 * @param[in] client_name Existing Call Home client name.
Michal Vaskoe49a15f2019-05-27 14:18:36 +0200163 * @param[in] anchor_time Call Home periodic connection anchor time for the period.
Michal Vasko2e6defd2016-10-07 15:48:15 +0200164 * @return 0 on success, -1 on error.
165 */
Michal Vaskoe49a15f2019-05-27 14:18:36 +0200166int nc_server_ch_client_periodic_set_anchor_time(const char *client_name, time_t anchor_time);
Michal Vasko2e6defd2016-10-07 15:48:15 +0200167
168/**
169 * @brief Set Call Home client periodic connection idle timeout.
170 *
171 * @param[in] client_name Existing Call Home client name.
172 * @param[in] idle_timeout Call Home periodic idle timeout.
173 * @return 0 on success, -1 on error.
174 */
Michal Vaskoe49a15f2019-05-27 14:18:36 +0200175int nc_server_ch_client_periodic_set_idle_timeout(const char *client_name, uint16_t idle_timeout);
Michal Vasko2e6defd2016-10-07 15:48:15 +0200176
177/**
178 * @brief Set Call Home client start-with policy.
179 *
180 * @param[in] client_name Existing Call Home client name.
181 * @param[in] start_with Call Home client start-with.
182 * @return 0 on success, -1 on error.
183 */
184int nc_server_ch_client_set_start_with(const char *client_name, NC_CH_START_WITH start_with);
185
186/**
187 * @brief Set Call Home client overall max attempts.
188 *
189 * @param[in] client_name Existing Call Home client name.
Michal Vasko50d2a5c2017-02-14 10:29:49 +0100190 * @param[in] max_attempts Call Home overall max reconnect attempts.
Michal Vasko2e6defd2016-10-07 15:48:15 +0200191 * @return 0 on success, -1 on error.
192 */
193int nc_server_ch_client_set_max_attempts(const char *client_name, uint8_t max_attempts);
194
195/**
Michal Vasko93224072021-11-09 12:14:28 +0100196 * @brief Callback for getting a locked context for new Call Home sessions.
197 *
198 * @param[in] cb_data Arbitrary ctx callback data.
199 * @return Context for the session to use during its lifetime;
200 * @return NULL on error and session fails to be created.
201 */
202typedef const struct ly_ctx *(*nc_server_ch_session_acquire_ctx_cb)(void *cb_data);
203
204/**
205 * @brief Callback for releasing a locked context for Call Home sessions.
206 *
207 * @param[in] cb_data Arbitrary ctx callback data.
208 */
209typedef void (*nc_server_ch_session_release_ctx_cb)(void *cb_data);
210
211/**
212 * @brief Callback for new Call Home sessions.
213 *
214 * @param[in] client_name Name of the CH client which established the session.
215 * @param[in] new_session New established CH session, the pointer is internally discarded afterwards.
216 * @return 0 on success;
217 * @return non-zero on error and @p new_session is freed.
218 */
219typedef int (*nc_server_ch_new_session_cb)(const char *client_name, struct nc_session *new_session);
220
221/**
222 * @brief Dispatch a thread connecting to a listening NETCONF client and creating Call Home sessions.
Michal Vasko2e6defd2016-10-07 15:48:15 +0200223 *
224 * @param[in] client_name Existing client name.
Michal Vasko93224072021-11-09 12:14:28 +0100225 * @param[in] acquire_ctx_cb Callback for acquiring new session context.
226 * @param[in] release_ctx_cb Callback for releasing session context.
227 * @param[in] ctx_cb_data Arbitrary user data passed to @p acquire_ctx_cb and @p release_ctx_cb.
228 * @param[in] new_session_cb Callback called for every established session on the client.
Michal Vasko2e6defd2016-10-07 15:48:15 +0200229 * @return 0 if the thread was successfully created, -1 on error.
230 */
Michal Vasko93224072021-11-09 12:14:28 +0100231int nc_connect_ch_client_dispatch(const char *client_name, nc_server_ch_session_acquire_ctx_cb acquire_ctx_cb,
232 nc_server_ch_session_release_ctx_cb release_ctx_cb, void *ctx_cb_data, nc_server_ch_new_session_cb new_session_cb);
Michal Vasko2e6defd2016-10-07 15:48:15 +0200233
Radek Krejci6799a052017-05-19 14:23:23 +0200234/** @} Server-side Call Home */
235
Michal Vasko2e6defd2016-10-07 15:48:15 +0200236#endif /* NC_ENABLED_SSH || NC_ENABLED_TLS */
237
238#ifdef NC_ENABLED_SSH
Michal Vasko45f298f2016-01-29 10:26:26 +0100239
240/**
Radek Krejci6799a052017-05-19 14:23:23 +0200241 * @defgroup server_ch_ssh Server-side Call Home on SSH
242 * @ingroup server_ch
243 *
244 * @brief SSH settings for the Call Home functionality
245 * @{
246 */
247
248/**
Michal Vasko4c1fb492017-01-30 14:31:07 +0100249 * @brief Add Call Home SSH host keys the server will identify itself with. Only the name is set, the key itself
250 * wil be retrieved using a callback.
Michal Vaskoe2713da2016-08-22 16:06:40 +0200251 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200252 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200253 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko4c1fb492017-01-30 14:31:07 +0100254 * @param[in] name Arbitrary name of the host key.
Michal Vasko7d255882017-02-09 13:35:08 +0100255 * @param[in] idx Optional index where to add the key. -1 adds at the end.
Michal Vaskoe2713da2016-08-22 16:06:40 +0200256 * @return 0 on success, -1 on error.
257 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200258int nc_server_ssh_ch_client_endpt_add_hostkey(const char *client_name, const char *endpt_name, const char *name, int16_t idx);
Michal Vaskoe2713da2016-08-22 16:06:40 +0200259
260/**
261 * @brief Delete Call Home SSH host keys. Their order is preserved.
Michal Vasko45f298f2016-01-29 10:26:26 +0100262 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200263 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200264 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vaskoc446a382021-06-18 08:54:05 +0200265 * @param[in] name Name of the host key. NULL matches all the keys, but if @p idx != -1 then this must be NULL.
266 * @param[in] idx Index of the hostkey. -1 matches all indices, but if @p name != NULL then this must be -1.
Michal Vasko45f298f2016-01-29 10:26:26 +0100267 * @return 0 on success, -1 on error.
268 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200269int nc_server_ssh_ch_client_endpt_del_hostkey(const char *client_name, const char *endpt_name, const char *name, int16_t idx);
Michal Vasko45f298f2016-01-29 10:26:26 +0100270
271/**
Michal Vaskofbfe8b62017-02-14 10:22:30 +0100272 * @brief Move Call Home SSH host key.
273 *
Michal Vasko50d2a5c2017-02-14 10:29:49 +0100274 * @param[in] client_name Exisitng Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200275 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vaskofbfe8b62017-02-14 10:22:30 +0100276 * @param[in] key_mov Name of the host key that will be moved.
Michal Vaskoc446a382021-06-18 08:54:05 +0200277 * @param[in] key_after Name of the key that will preceed @p key_mov. NULL if @p key_mov is to be moved at the beginning.
Michal Vaskofbfe8b62017-02-14 10:22:30 +0100278 * @return 0 in success, -1 on error.
279 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200280int nc_server_ssh_ch_client_endpt_mov_hostkey(const char *client_name, const char *endpt_name, const char *key_mov,
281 const char *key_after);
Michal Vaskofbfe8b62017-02-14 10:22:30 +0100282
283/**
Michal Vasko45f298f2016-01-29 10:26:26 +0100284 * @brief Set accepted Call Home SSH authentication methods. All (publickey, password, interactive)
Michal Vaskof0537d82016-01-29 14:42:38 +0100285 * are supported by default.
Michal Vasko45f298f2016-01-29 10:26:26 +0100286 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200287 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200288 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko45f298f2016-01-29 10:26:26 +0100289 * @param[in] auth_methods Accepted authentication methods bit field of NC_SSH_AUTH_TYPE.
290 * @return 0 on success, -1 on error.
291 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200292int nc_server_ssh_ch_client_endpt_set_auth_methods(const char *client_name, const char *endpt_name, int auth_methods);
Michal Vasko45f298f2016-01-29 10:26:26 +0100293
294/**
Michal Vaskoddce1212019-05-24 09:58:49 +0200295 * @brief Get accepted Call Home SSH authentication methods.
296 *
297 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200298 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vaskoddce1212019-05-24 09:58:49 +0200299 * @return Accepted authentication methods bit field of NC_SSH_AUTH_TYPE.
300 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200301int nc_server_ssh_ch_client_endpt_get_auth_methods(const char *client_name, const char *endpt_name);
Michal Vaskoddce1212019-05-24 09:58:49 +0200302
303/**
Michal Vasko45f298f2016-01-29 10:26:26 +0100304 * @brief Set Call Home SSH authentication attempts of every client. 3 by default.
305 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200306 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200307 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko45f298f2016-01-29 10:26:26 +0100308 * @param[in] auth_attempts Failed authentication attempts before a client is dropped.
309 * @return 0 on success, -1 on error.
310 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200311int nc_server_ssh_ch_client_endpt_set_auth_attempts(const char *client_name, const char *endpt_name, uint16_t auth_attempts);
Michal Vasko45f298f2016-01-29 10:26:26 +0100312
313/**
Michal Vaskocbad4c52019-06-27 16:30:35 +0200314 * @brief Set Call Home SSH authentication timeout. 30 seconds by default.
Michal Vasko45f298f2016-01-29 10:26:26 +0100315 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200316 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200317 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko45f298f2016-01-29 10:26:26 +0100318 * @param[in] auth_timeout Number of seconds before an unauthenticated client is dropped.
319 * @return 0 on success, -1 on error.
320 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200321int nc_server_ssh_ch_client_endpt_set_auth_timeout(const char *client_name, const char *endpt_name, uint16_t auth_timeout);
Michal Vasko45f298f2016-01-29 10:26:26 +0100322
Radek Krejci6799a052017-05-19 14:23:23 +0200323/** @} Server-side Call Home on SSH */
324
Radek Krejci53691be2016-02-22 13:58:37 +0100325#endif /* NC_ENABLED_SSH */
Michal Vasko45f298f2016-01-29 10:26:26 +0100326
Radek Krejci53691be2016-02-22 13:58:37 +0100327#ifdef NC_ENABLED_TLS
Michal Vasko45f298f2016-01-29 10:26:26 +0100328
329/**
Radek Krejci6799a052017-05-19 14:23:23 +0200330 * @defgroup server_ch_tls Server-side Call Home on TLS
331 * @ingroup server_ch
332 *
333 * @brief TLS settings for the Call Home functionality
334 * @{
335 */
336
337/**
Michal Vasko4c1fb492017-01-30 14:31:07 +0100338 * @brief Set the server Call Home TLS certificate. Only the name is set, the certificate itself
339 * wil be retrieved using a callback.
Michal Vasko45f298f2016-01-29 10:26:26 +0100340 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200341 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200342 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko4c1fb492017-01-30 14:31:07 +0100343 * @param[in] name Arbitrary certificate name.
Michal Vasko45f298f2016-01-29 10:26:26 +0100344 * @return 0 on success, -1 on error.
345 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200346int nc_server_tls_ch_client_endpt_set_server_cert(const char *client_name, const char *endpt_name, const char *name);
Michal Vasko45f298f2016-01-29 10:26:26 +0100347
348/**
Michal Vasko4c1fb492017-01-30 14:31:07 +0100349 * @brief Add a Call Home trusted certificate list. Can be both a CA or a client one.
Michal Vasko45f298f2016-01-29 10:26:26 +0100350 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200351 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200352 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko4c1fb492017-01-30 14:31:07 +0100353 * @param[in] name Arbitary name identifying this certificate list.
Michal Vasko45f298f2016-01-29 10:26:26 +0100354 * @return 0 on success, -1 on error.
355 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200356int nc_server_tls_ch_client_endpt_add_trusted_cert_list(const char *client_name, const char *endpt_name, const char *name);
Michal Vasko45f298f2016-01-29 10:26:26 +0100357
358/**
Michal Vasko4c1fb492017-01-30 14:31:07 +0100359 * @brief Remove a set Call Home trusted certificate list. CRLs and CTN entries are not affected.
Michal Vasko45f298f2016-01-29 10:26:26 +0100360 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200361 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200362 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko4c1fb492017-01-30 14:31:07 +0100363 * @param[in] name Name of the certificate list to delete. NULL deletes all the lists.
364 * @return 0 on success, -1 on not found.
Michal Vasko45f298f2016-01-29 10:26:26 +0100365 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200366int nc_server_tls_ch_client_endpt_del_trusted_cert_list(const char *client_name, const char *endpt_name, const char *name);
Michal Vasko45f298f2016-01-29 10:26:26 +0100367
368/**
369 * @brief Set trusted Call Home Certificate Authority certificate locations. There
Michal Vaskof0537d82016-01-29 14:42:38 +0100370 * can only be one file and one directory, they are replaced if already set.
Michal Vasko45f298f2016-01-29 10:26:26 +0100371 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200372 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200373 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vaskob34b3e82016-02-26 15:04:58 +0100374 * @param[in] ca_file Path to a trusted CA cert store file in PEM format.
375 * Can be NULL.
376 * @param[in] ca_dir Path to a trusted CA cert store hashed directory
377 * (c_rehash utility can be used to create hashes)
378 * with PEM files. Can be NULL.
Michal Vasko45f298f2016-01-29 10:26:26 +0100379 * @return 0 on success, -1 on error.
380 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200381int nc_server_tls_ch_client_endpt_set_trusted_ca_paths(const char *client_name, const char *endpt_name, const char *ca_file,
382 const char *ca_dir);
Michal Vasko45f298f2016-01-29 10:26:26 +0100383
384/**
Michal Vasko45f298f2016-01-29 10:26:26 +0100385 * @brief Set Call Home Certificate Revocation List locations. There can only be
Michal Vaskof0537d82016-01-29 14:42:38 +0100386 * one file and one directory, they are replaced if already set.
Michal Vasko45f298f2016-01-29 10:26:26 +0100387 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200388 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200389 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vaskob34b3e82016-02-26 15:04:58 +0100390 * @param[in] crl_file Path to a CRL store file in PEM format. Can be NULL.
391 * @param[in] crl_dir Path to a CRL store hashed directory (c_rehash utility
392 * can be used to create hashes) with PEM files. Can be NULL.
Michal Vasko45f298f2016-01-29 10:26:26 +0100393 * @return 0 on success, -1 on error.
394 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200395int nc_server_tls_ch_client_endpt_set_crl_paths(const char *client_name, const char *endpt_name, const char *crl_file,
396 const char *crl_dir);
Michal Vasko45f298f2016-01-29 10:26:26 +0100397
398/**
399 * @brief Destroy and clean Call Home CRLs. Call Home certificates, private keys,
Michal Vaskof0537d82016-01-29 14:42:38 +0100400 * and CTN entries are not affected.
Michal Vasko2e6defd2016-10-07 15:48:15 +0200401 *
402 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200403 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko45f298f2016-01-29 10:26:26 +0100404 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200405void nc_server_tls_ch_client_endpt_clear_crls(const char *client_name, const char *endpt_name);
Michal Vasko45f298f2016-01-29 10:26:26 +0100406
407/**
Michal Vasko3cf4aaa2017-02-01 15:03:36 +0100408 * @brief Add a cert-to-name entry.
Michal Vasko45f298f2016-01-29 10:26:26 +0100409 *
Michal Vaskoc446a382021-06-18 08:54:05 +0200410 * It is possible to add an entry step-by-step, specifying first only @p ip and in later calls
411 * @p fingerprint, @p map_type, and optionally @p name spearately.
Michal Vasko3cf4aaa2017-02-01 15:03:36 +0100412 *
Michal Vasko50d2a5c2017-02-14 10:29:49 +0100413 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200414 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko3cf4aaa2017-02-01 15:03:36 +0100415 * @param[in] id Priority of the entry. It must be unique. If already exists, the entry with this id
416 * is modified.
417 * @param[in] fingerprint Matching certificate fingerprint. If NULL, kept temporarily unset.
418 * @param[in] map_type Type of username-certificate mapping. If 0, kept temporarily unset.
Michal Vaskoc446a382021-06-18 08:54:05 +0200419 * @param[in] name Specific username used only if @p map_type == NC_TLS_CTN_SPECIFED.
Michal Vasko45f298f2016-01-29 10:26:26 +0100420 * @return 0 on success, -1 on error.
421 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200422int nc_server_tls_ch_client_endpt_add_ctn(const char *client_name, const char *endpt_name, uint32_t id,
423 const char *fingerprint, NC_TLS_CTN_MAPTYPE map_type, const char *name);
Michal Vasko45f298f2016-01-29 10:26:26 +0100424
425/**
Michal Vasko58c22a22016-11-23 13:49:53 +0100426 * @brief Remove a Call Home cert-to-name entry.
Michal Vasko45f298f2016-01-29 10:26:26 +0100427 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200428 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200429 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko45f298f2016-01-29 10:26:26 +0100430 * @param[in] id Priority of the entry. -1 matches all the priorities.
431 * @param[in] fingerprint Fingerprint fo the entry. NULL matches all the fingerprints.
432 * @param[in] map_type Mapping type of the entry. 0 matches all the mapping types.
433 * @param[in] name Specific username for the entry. NULL matches all the usernames.
434 * @return 0 on success, -1 on not finding any match.
435 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200436int nc_server_tls_ch_client_endpt_del_ctn(const char *client_name, const char *endpt_name, int64_t id,
437 const char *fingerprint, NC_TLS_CTN_MAPTYPE map_type, const char *name);
Michal Vasko45f298f2016-01-29 10:26:26 +0100438
Michal Vaskodf5e6af2016-11-23 13:50:56 +0100439/**
440 * @brief Get a Call Home cert-to-name entry.
441 *
442 * If a parameter is NULL, it is ignored. If its dereferenced value is NULL,
443 * it is filled and returned. If the value is set, it is used as a filter.
444 * Returns first matching entry.
445 *
446 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200447 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vaskodf5e6af2016-11-23 13:50:56 +0100448 * @param[in,out] id Priority of the entry.
449 * @param[in,out] fingerprint Fingerprint fo the entry.
450 * @param[in,out] map_type Mapping type of the entry.
451 * @param[in,out] name Specific username for the entry.
452 * @return 0 on success, -1 on not finding any match.
453 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200454int nc_server_tls_ch_client_endpt_get_ctn(const char *client_name, const char *endpt_name, uint32_t *id, char **fingerprint,
455 NC_TLS_CTN_MAPTYPE *map_type, char **name);
Michal Vaskodf5e6af2016-11-23 13:50:56 +0100456
Radek Krejci6799a052017-05-19 14:23:23 +0200457/** @} Server-side Call Home on TLS */
458
Radek Krejci53691be2016-02-22 13:58:37 +0100459#endif /* NC_ENABLED_TLS */
Michal Vasko45f298f2016-01-29 10:26:26 +0100460
Michal Vaskoc09730e2019-01-17 10:07:26 +0100461#ifdef __cplusplus
462}
463#endif
464
Michal Vasko45f298f2016-01-29 10:26:26 +0100465#endif /* NC_SESSION_SERVER_CH_H_ */