blob: f1b1b041cbce64f41f16278af06bb31a1407af66 [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>
roman3f9b65c2023-06-05 14:26:58 +020025#include <time.h>
Michal Vasko45f298f2016-01-29 10:26:26 +010026
Michal Vasko45f298f2016-01-29 10:26:26 +010027#include "netconf.h"
Michal Vaskob83a3fa2021-05-26 09:53:42 +020028#include "session.h"
Michal Vasko45f298f2016-01-29 10:26:26 +010029
roman2eab4742023-06-06 10:00:26 +020030#ifdef NC_ENABLED_SSH_TLS
Michal Vasko45f298f2016-01-29 10:26:26 +010031
32/**
Radek Krejci6799a052017-05-19 14:23:23 +020033 * @defgroup server_ch Server-side Call Home
34 * @ingroup server
35 *
36 * @brief Call Home functionality for server-side applications.
37 * @{
38 */
39
40/**
Michal Vasko2e6defd2016-10-07 15:48:15 +020041 * @brief Add a new Call Home client.
Michal Vasko45f298f2016-01-29 10:26:26 +010042 *
Michal Vasko2e6defd2016-10-07 15:48:15 +020043 * @param[in] name Arbitrary unique client name.
Michal Vasko2e6defd2016-10-07 15:48:15 +020044 * @return 0 on success, -1 on error.
Michal Vasko45f298f2016-01-29 10:26:26 +010045 */
Michal Vaskoadf30f02019-06-24 09:34:47 +020046int nc_server_ch_add_client(const char *name);
Michal Vasko2e6defd2016-10-07 15:48:15 +020047
48/**
49 * @brief Drop any connections, stop connecting and remove a client.
50 *
51 * @param[in] name Client name. NULL matches all the clients.
52 * @return 0 on success, -1 on not finding any match.
53 */
Michal Vaskoadf30f02019-06-24 09:34:47 +020054int nc_server_ch_del_client(const char *name);
Michal Vasko2e6defd2016-10-07 15:48:15 +020055
56/**
Michal Vaskofb1724b2020-01-31 11:02:00 +010057 * @brief Check if a Call Home client exists.
58 *
59 * @param[in] name Client name.
60 * @return 0 if does not exists, non-zero otherwise.
61 */
62int nc_server_ch_is_client(const char *name);
63
64/**
Michal Vasko2e6defd2016-10-07 15:48:15 +020065 * @brief Add a new Call Home client endpoint.
66 *
67 * @param[in] client_name Existing client name.
68 * @param[in] endpt_name Arbitrary unique (within the client) endpoint name.
Michal Vaskoadf30f02019-06-24 09:34:47 +020069 * @param[in] ti Transport protocol to use.
Michal Vasko2e6defd2016-10-07 15:48:15 +020070 * @return 0 on success, -1 on error.
71 */
Michal Vaskoadf30f02019-06-24 09:34:47 +020072int 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 +020073
74/**
75 * @brief Remove a Call Home client endpoint.
76 *
77 * @param[in] client_name Existing client name.
Michal Vaskoc446a382021-06-18 08:54:05 +020078 * @param[in] endpt_name Existing endpoint of @p client_name. NULL matches all endpoints.
Michal Vaskoadf30f02019-06-24 09:34:47 +020079 * @param[in] ti Client transport protocol. NULL matches any protocol.
Michal Vaskoc446a382021-06-18 08:54:05 +020080 * Redundant to set if @p endpt_name is set, client names are
Michal Vaskoadf30f02019-06-24 09:34:47 +020081 * unique disregarding their protocol.
Michal Vasko2e6defd2016-10-07 15:48:15 +020082 * @return 0 on success, -1 on error.
83 */
Michal Vaskoadf30f02019-06-24 09:34:47 +020084int 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 +020085
86/**
Michal Vaskofb1724b2020-01-31 11:02:00 +010087 * @brief Check if an endpoint of a Call Home client exists.
88 *
89 * @param[in] client_name Client name.
90 * @param[in] endpt_name Endpoint name.
91 * @return 0 if does not exists, non-zero otherwise.
92 */
93int nc_server_ch_client_is_endpt(const char *client_name, const char *endpt_name);
94
95/**
Michal Vasko2e6defd2016-10-07 15:48:15 +020096 * @brief Change Call Home client endpoint listening address.
97 *
98 * On error the previous listening socket (if any) is left untouched.
99 *
100 * @param[in] client_name Existing Call Home client name.
Michal Vaskoc446a382021-06-18 08:54:05 +0200101 * @param[in] endpt_name Existing endpoint name of @p client_name.
Michal Vasko2e6defd2016-10-07 15:48:15 +0200102 * @param[in] address New listening address.
103 * @return 0 on success, -1 on error.
104 */
105int nc_server_ch_client_endpt_set_address(const char *client_name, const char *endpt_name, const char *address);
106
107/**
108 * @brief Change Call Home client endpoint listening port.
109 *
110 * On error the previous listening socket (if any) is left untouched.
111 *
112 * @param[in] client_name Existing Call Home client name.
Michal Vaskoc446a382021-06-18 08:54:05 +0200113 * @param[in] endpt_name Existing endpoint name of @p client_name.
Michal Vasko2e6defd2016-10-07 15:48:15 +0200114 * @param[in] port New listening port.
115 * @return 0 on success, -1 on error.
116 */
117int nc_server_ch_client_endpt_set_port(const char *client_name, const char *endpt_name, uint16_t port);
118
119/**
Michal Vaskoe49a15f2019-05-27 14:18:36 +0200120 * @brief Change Call Home client endpoint keepalives state. Affects only new connections.
121 *
122 * @param[in] client_name Existing Call Home client name.
Michal Vaskoc446a382021-06-18 08:54:05 +0200123 * @param[in] endpt_name Existing endpoint name of @p client_name.
Michal Vaskoe49a15f2019-05-27 14:18:36 +0200124 * @param[in] enable Whether to enable or disable keepalives.
125 * @return 0 on success, -1 on error.
126 */
127int nc_server_ch_client_endpt_enable_keepalives(const char *client_name, const char *endpt_name, int enable);
128
129/**
130 * @brief Change Call Home client endpoint keepalives parameters. Affects only new connections.
131 *
132 * @param[in] client_name Existing Call Home client name.
Michal Vaskoc446a382021-06-18 08:54:05 +0200133 * @param[in] endpt_name Existing endpoint name of @p client_name.
Michal Vaskoe49a15f2019-05-27 14:18:36 +0200134 * @param[in] idle_time Keepalive idle time in seconds, 1 by default, -1 to keep previous value.
135 * @param[in] max_probes Keepalive max probes sent, 10 by default, -1 to keep previous value.
136 * @param[in] probe_interval Keepalive probe interval in seconds, 5 by default, -1 to keep previous value.
137 * @return 0 on success, -1 on error.
138 */
139int nc_server_ch_client_endpt_set_keepalives(const char *client_name, const char *endpt_name, int idle_time,
140 int max_probes, int probe_interval);
141
142/**
Michal Vasko2e6defd2016-10-07 15:48:15 +0200143 * @brief Set Call Home client start-with policy.
144 *
145 * @param[in] client_name Existing Call Home client name.
146 * @param[in] start_with Call Home client start-with.
147 * @return 0 on success, -1 on error.
148 */
149int nc_server_ch_client_set_start_with(const char *client_name, NC_CH_START_WITH start_with);
150
151/**
152 * @brief Set Call Home client overall max attempts.
153 *
154 * @param[in] client_name Existing Call Home client name.
Michal Vasko50d2a5c2017-02-14 10:29:49 +0100155 * @param[in] max_attempts Call Home overall max reconnect attempts.
Michal Vasko2e6defd2016-10-07 15:48:15 +0200156 * @return 0 on success, -1 on error.
157 */
158int nc_server_ch_client_set_max_attempts(const char *client_name, uint8_t max_attempts);
159
160/**
Michal Vasko93224072021-11-09 12:14:28 +0100161 * @brief Callback for getting a locked context for new Call Home sessions.
162 *
163 * @param[in] cb_data Arbitrary ctx callback data.
164 * @return Context for the session to use during its lifetime;
165 * @return NULL on error and session fails to be created.
166 */
167typedef const struct ly_ctx *(*nc_server_ch_session_acquire_ctx_cb)(void *cb_data);
168
169/**
170 * @brief Callback for releasing a locked context for Call Home sessions.
171 *
172 * @param[in] cb_data Arbitrary ctx callback data.
173 */
174typedef void (*nc_server_ch_session_release_ctx_cb)(void *cb_data);
175
176/**
177 * @brief Callback for new Call Home sessions.
178 *
179 * @param[in] client_name Name of the CH client which established the session.
180 * @param[in] new_session New established CH session, the pointer is internally discarded afterwards.
181 * @return 0 on success;
182 * @return non-zero on error and @p new_session is freed.
183 */
roman5cbb6532023-06-22 12:53:17 +0200184typedef int (*nc_server_ch_new_session_cb)(const char *client_name, struct nc_session *new_session, void *user_data);
Michal Vasko93224072021-11-09 12:14:28 +0100185
186/**
187 * @brief Dispatch a thread connecting to a listening NETCONF client and creating Call Home sessions.
Michal Vasko2e6defd2016-10-07 15:48:15 +0200188 *
189 * @param[in] client_name Existing client name.
Michal Vasko93224072021-11-09 12:14:28 +0100190 * @param[in] acquire_ctx_cb Callback for acquiring new session context.
191 * @param[in] release_ctx_cb Callback for releasing session context.
192 * @param[in] ctx_cb_data Arbitrary user data passed to @p acquire_ctx_cb and @p release_ctx_cb.
193 * @param[in] new_session_cb Callback called for every established session on the client.
roman5cbb6532023-06-22 12:53:17 +0200194 * @param[in] new_session_cb_data Arbitrary user data passed to @p new_session_cb.
Michal Vasko2e6defd2016-10-07 15:48:15 +0200195 * @return 0 if the thread was successfully created, -1 on error.
196 */
Michal Vasko93224072021-11-09 12:14:28 +0100197int nc_connect_ch_client_dispatch(const char *client_name, nc_server_ch_session_acquire_ctx_cb acquire_ctx_cb,
roman5cbb6532023-06-22 12:53:17 +0200198 nc_server_ch_session_release_ctx_cb release_ctx_cb, void *ctx_cb_data, nc_server_ch_new_session_cb new_session_cb,
199 void *new_session_cb_data);
Michal Vasko2e6defd2016-10-07 15:48:15 +0200200
Radek Krejci6799a052017-05-19 14:23:23 +0200201/** @} Server-side Call Home */
202
Michal Vasko45f298f2016-01-29 10:26:26 +0100203/**
Radek Krejci6799a052017-05-19 14:23:23 +0200204 * @defgroup server_ch_ssh Server-side Call Home on SSH
205 * @ingroup server_ch
206 *
207 * @brief SSH settings for the Call Home functionality
208 * @{
209 */
210
211/**
Michal Vasko4c1fb492017-01-30 14:31:07 +0100212 * @brief Add Call Home SSH host keys the server will identify itself with. Only the name is set, the key itself
213 * wil be retrieved using a callback.
Michal Vaskoe2713da2016-08-22 16:06:40 +0200214 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200215 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200216 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko4c1fb492017-01-30 14:31:07 +0100217 * @param[in] name Arbitrary name of the host key.
Michal Vasko7d255882017-02-09 13:35:08 +0100218 * @param[in] idx Optional index where to add the key. -1 adds at the end.
Michal Vaskoe2713da2016-08-22 16:06:40 +0200219 * @return 0 on success, -1 on error.
220 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200221int 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 +0200222
223/**
224 * @brief Delete Call Home SSH host keys. Their order is preserved.
Michal Vasko45f298f2016-01-29 10:26:26 +0100225 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200226 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200227 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vaskoc446a382021-06-18 08:54:05 +0200228 * @param[in] name Name of the host key. NULL matches all the keys, but if @p idx != -1 then this must be NULL.
229 * @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 +0100230 * @return 0 on success, -1 on error.
231 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200232int 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 +0100233
234/**
Michal Vaskofbfe8b62017-02-14 10:22:30 +0100235 * @brief Move Call Home SSH host key.
236 *
Michal Vasko50d2a5c2017-02-14 10:29:49 +0100237 * @param[in] client_name Exisitng Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200238 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vaskofbfe8b62017-02-14 10:22:30 +0100239 * @param[in] key_mov Name of the host key that will be moved.
Michal Vaskoc446a382021-06-18 08:54:05 +0200240 * @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 +0100241 * @return 0 in success, -1 on error.
242 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200243int nc_server_ssh_ch_client_endpt_mov_hostkey(const char *client_name, const char *endpt_name, const char *key_mov,
244 const char *key_after);
Michal Vaskofbfe8b62017-02-14 10:22:30 +0100245
246/**
Michal Vasko45f298f2016-01-29 10:26:26 +0100247 * @brief Set accepted Call Home SSH authentication methods. All (publickey, password, interactive)
Michal Vaskof0537d82016-01-29 14:42:38 +0100248 * are supported by default.
Michal Vasko45f298f2016-01-29 10:26:26 +0100249 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200250 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200251 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko45f298f2016-01-29 10:26:26 +0100252 * @param[in] auth_methods Accepted authentication methods bit field of NC_SSH_AUTH_TYPE.
253 * @return 0 on success, -1 on error.
254 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200255int 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 +0100256
257/**
Michal Vaskoddce1212019-05-24 09:58:49 +0200258 * @brief Get accepted Call Home SSH authentication methods.
259 *
260 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200261 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vaskoddce1212019-05-24 09:58:49 +0200262 * @return Accepted authentication methods bit field of NC_SSH_AUTH_TYPE.
263 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200264int nc_server_ssh_ch_client_endpt_get_auth_methods(const char *client_name, const char *endpt_name);
Michal Vaskoddce1212019-05-24 09:58:49 +0200265
266/**
Michal Vasko45f298f2016-01-29 10:26:26 +0100267 * @brief Set Call Home SSH authentication attempts of every client. 3 by default.
268 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200269 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200270 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko45f298f2016-01-29 10:26:26 +0100271 * @param[in] auth_attempts Failed authentication attempts before a client is dropped.
272 * @return 0 on success, -1 on error.
273 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200274int 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 +0100275
276/**
Michal Vaskocbad4c52019-06-27 16:30:35 +0200277 * @brief Set Call Home SSH authentication timeout. 30 seconds by default.
Michal Vasko45f298f2016-01-29 10:26:26 +0100278 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200279 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200280 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko45f298f2016-01-29 10:26:26 +0100281 * @param[in] auth_timeout Number of seconds before an unauthenticated client is dropped.
282 * @return 0 on success, -1 on error.
283 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200284int 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 +0100285
Radek Krejci6799a052017-05-19 14:23:23 +0200286/** @} Server-side Call Home on SSH */
287
Michal Vasko45f298f2016-01-29 10:26:26 +0100288/**
Radek Krejci6799a052017-05-19 14:23:23 +0200289 * @defgroup server_ch_tls Server-side Call Home on TLS
290 * @ingroup server_ch
291 *
292 * @brief TLS settings for the Call Home functionality
293 * @{
294 */
295
296/**
Michal Vasko4c1fb492017-01-30 14:31:07 +0100297 * @brief Set the server Call Home TLS certificate. Only the name is set, the certificate itself
298 * wil be retrieved using a callback.
Michal Vasko45f298f2016-01-29 10:26:26 +0100299 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200300 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200301 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko4c1fb492017-01-30 14:31:07 +0100302 * @param[in] name Arbitrary certificate name.
Michal Vasko45f298f2016-01-29 10:26:26 +0100303 * @return 0 on success, -1 on error.
304 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200305int 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 +0100306
307/**
Michal Vasko4c1fb492017-01-30 14:31:07 +0100308 * @brief Add a Call Home trusted certificate list. Can be both a CA or a client one.
Michal Vasko45f298f2016-01-29 10:26:26 +0100309 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200310 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200311 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko4c1fb492017-01-30 14:31:07 +0100312 * @param[in] name Arbitary name identifying this certificate list.
Michal Vasko45f298f2016-01-29 10:26:26 +0100313 * @return 0 on success, -1 on error.
314 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200315int 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 +0100316
317/**
Michal Vasko4c1fb492017-01-30 14:31:07 +0100318 * @brief Remove a set Call Home trusted certificate list. CRLs and CTN entries are not affected.
Michal Vasko45f298f2016-01-29 10:26:26 +0100319 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200320 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200321 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko4c1fb492017-01-30 14:31:07 +0100322 * @param[in] name Name of the certificate list to delete. NULL deletes all the lists.
323 * @return 0 on success, -1 on not found.
Michal Vasko45f298f2016-01-29 10:26:26 +0100324 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200325int 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 +0100326
327/**
328 * @brief Set trusted Call Home Certificate Authority certificate locations. There
Michal Vaskof0537d82016-01-29 14:42:38 +0100329 * can only be one file and one directory, they are replaced if already set.
Michal Vasko45f298f2016-01-29 10:26:26 +0100330 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200331 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200332 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vaskob34b3e82016-02-26 15:04:58 +0100333 * @param[in] ca_file Path to a trusted CA cert store file in PEM format.
334 * Can be NULL.
335 * @param[in] ca_dir Path to a trusted CA cert store hashed directory
336 * (c_rehash utility can be used to create hashes)
337 * with PEM files. Can be NULL.
Michal Vasko45f298f2016-01-29 10:26:26 +0100338 * @return 0 on success, -1 on error.
339 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200340int nc_server_tls_ch_client_endpt_set_trusted_ca_paths(const char *client_name, const char *endpt_name, const char *ca_file,
341 const char *ca_dir);
Michal Vasko45f298f2016-01-29 10:26:26 +0100342
343/**
Michal Vasko45f298f2016-01-29 10:26:26 +0100344 * @brief Set Call Home Certificate Revocation List locations. There can only be
Michal Vaskof0537d82016-01-29 14:42:38 +0100345 * one file and one directory, they are replaced if already set.
Michal Vasko45f298f2016-01-29 10:26:26 +0100346 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200347 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200348 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vaskob34b3e82016-02-26 15:04:58 +0100349 * @param[in] crl_file Path to a CRL store file in PEM format. Can be NULL.
350 * @param[in] crl_dir Path to a CRL store hashed directory (c_rehash utility
351 * can be used to create hashes) with PEM files. Can be NULL.
Michal Vasko45f298f2016-01-29 10:26:26 +0100352 * @return 0 on success, -1 on error.
353 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200354int nc_server_tls_ch_client_endpt_set_crl_paths(const char *client_name, const char *endpt_name, const char *crl_file,
355 const char *crl_dir);
Michal Vasko45f298f2016-01-29 10:26:26 +0100356
357/**
358 * @brief Destroy and clean Call Home CRLs. Call Home certificates, private keys,
Michal Vaskof0537d82016-01-29 14:42:38 +0100359 * and CTN entries are not affected.
Michal Vasko2e6defd2016-10-07 15:48:15 +0200360 *
361 * @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 Vasko45f298f2016-01-29 10:26:26 +0100363 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200364void nc_server_tls_ch_client_endpt_clear_crls(const char *client_name, const char *endpt_name);
Michal Vasko45f298f2016-01-29 10:26:26 +0100365
366/**
Michal Vasko3cf4aaa2017-02-01 15:03:36 +0100367 * @brief Add a cert-to-name entry.
Michal Vasko45f298f2016-01-29 10:26:26 +0100368 *
Michal Vaskoc446a382021-06-18 08:54:05 +0200369 * It is possible to add an entry step-by-step, specifying first only @p ip and in later calls
370 * @p fingerprint, @p map_type, and optionally @p name spearately.
Michal Vasko3cf4aaa2017-02-01 15:03:36 +0100371 *
Michal Vasko50d2a5c2017-02-14 10:29:49 +0100372 * @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 Vasko3cf4aaa2017-02-01 15:03:36 +0100374 * @param[in] id Priority of the entry. It must be unique. If already exists, the entry with this id
375 * is modified.
376 * @param[in] fingerprint Matching certificate fingerprint. If NULL, kept temporarily unset.
377 * @param[in] map_type Type of username-certificate mapping. If 0, kept temporarily unset.
Michal Vaskoc446a382021-06-18 08:54:05 +0200378 * @param[in] name Specific username used only if @p map_type == NC_TLS_CTN_SPECIFED.
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_add_ctn(const char *client_name, const char *endpt_name, uint32_t id,
382 const char *fingerprint, NC_TLS_CTN_MAPTYPE map_type, const char *name);
Michal Vasko45f298f2016-01-29 10:26:26 +0100383
384/**
Michal Vasko58c22a22016-11-23 13:49:53 +0100385 * @brief Remove a Call Home cert-to-name entry.
Michal Vasko45f298f2016-01-29 10:26:26 +0100386 *
Michal Vasko2e6defd2016-10-07 15:48:15 +0200387 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200388 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vasko45f298f2016-01-29 10:26:26 +0100389 * @param[in] id Priority of the entry. -1 matches all the priorities.
390 * @param[in] fingerprint Fingerprint fo the entry. NULL matches all the fingerprints.
391 * @param[in] map_type Mapping type of the entry. 0 matches all the mapping types.
392 * @param[in] name Specific username for the entry. NULL matches all the usernames.
393 * @return 0 on success, -1 on not finding any match.
394 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200395int nc_server_tls_ch_client_endpt_del_ctn(const char *client_name, const char *endpt_name, int64_t id,
396 const char *fingerprint, NC_TLS_CTN_MAPTYPE map_type, const char *name);
Michal Vasko45f298f2016-01-29 10:26:26 +0100397
Michal Vaskodf5e6af2016-11-23 13:50:56 +0100398/**
399 * @brief Get a Call Home cert-to-name entry.
400 *
401 * If a parameter is NULL, it is ignored. If its dereferenced value is NULL,
402 * it is filled and returned. If the value is set, it is used as a filter.
403 * Returns first matching entry.
404 *
405 * @param[in] client_name Existing Call Home client name.
Michal Vaskoadf30f02019-06-24 09:34:47 +0200406 * @param[in] endpt_name Existing endpoint name of the client.
Michal Vaskodf5e6af2016-11-23 13:50:56 +0100407 * @param[in,out] id Priority of the entry.
408 * @param[in,out] fingerprint Fingerprint fo the entry.
409 * @param[in,out] map_type Mapping type of the entry.
410 * @param[in,out] name Specific username for the entry.
411 * @return 0 on success, -1 on not finding any match.
412 */
Michal Vaskoadf30f02019-06-24 09:34:47 +0200413int nc_server_tls_ch_client_endpt_get_ctn(const char *client_name, const char *endpt_name, uint32_t *id, char **fingerprint,
414 NC_TLS_CTN_MAPTYPE *map_type, char **name);
Michal Vaskodf5e6af2016-11-23 13:50:56 +0100415
Radek Krejci6799a052017-05-19 14:23:23 +0200416/** @} Server-side Call Home on TLS */
417
roman2eab4742023-06-06 10:00:26 +0200418#endif /* NC_ENABLED_SSH_TLS */
Michal Vasko45f298f2016-01-29 10:26:26 +0100419
Michal Vaskoc09730e2019-01-17 10:07:26 +0100420#ifdef __cplusplus
421}
422#endif
423
Michal Vasko45f298f2016-01-29 10:26:26 +0100424#endif /* NC_SESSION_SERVER_CH_H_ */