Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 1 | /** |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 2 | * @file session_server_ch.h |
| 3 | * @author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * @brief libnetconf2 Call Home session server manipulation |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 5 | * |
Michal Vasko | 95ea9ff | 2021-11-09 12:29:14 +0100 | [diff] [blame] | 6 | * @copyright |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 7 | * Copyright (c) 2015 - 2021 CESNET, z.s.p.o. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 8 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 9 | * 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 Vasko | afd416b | 2016-02-25 14:51:46 +0100 | [diff] [blame] | 12 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 13 | * https://opensource.org/licenses/BSD-3-Clause |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #ifndef NC_SESSION_SERVER_CH_H_ |
| 17 | #define NC_SESSION_SERVER_CH_H_ |
| 18 | |
Michal Vasko | c09730e | 2019-01-17 10:07:26 +0100 | [diff] [blame] | 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 23 | #include <libyang/libyang.h> |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 24 | #include <stdint.h> |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 25 | #include <time.h> |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 26 | |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 27 | #include "netconf.h" |
Michal Vasko | b83a3fa | 2021-05-26 09:53:42 +0200 | [diff] [blame] | 28 | #include "session.h" |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 29 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 30 | #ifdef NC_ENABLED_SSH_TLS |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 31 | |
| 32 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 33 | * @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 Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 41 | * @brief Add a new Call Home client. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 42 | * |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 43 | * @param[in] name Arbitrary unique client name. |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 44 | * @return 0 on success, -1 on error. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 45 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 46 | int nc_server_ch_add_client(const char *name); |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 47 | |
| 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 Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 54 | int nc_server_ch_del_client(const char *name); |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 55 | |
| 56 | /** |
Michal Vasko | fb1724b | 2020-01-31 11:02:00 +0100 | [diff] [blame] | 57 | * @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 | */ |
| 62 | int nc_server_ch_is_client(const char *name); |
| 63 | |
| 64 | /** |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 65 | * @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 Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 69 | * @param[in] ti Transport protocol to use. |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 70 | * @return 0 on success, -1 on error. |
| 71 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 72 | int nc_server_ch_client_add_endpt(const char *client_name, const char *endpt_name, NC_TRANSPORT_IMPL ti); |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * @brief Remove a Call Home client endpoint. |
| 76 | * |
| 77 | * @param[in] client_name Existing client name. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 78 | * @param[in] endpt_name Existing endpoint of @p client_name. NULL matches all endpoints. |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 79 | * @param[in] ti Client transport protocol. NULL matches any protocol. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 80 | * Redundant to set if @p endpt_name is set, client names are |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 81 | * unique disregarding their protocol. |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 82 | * @return 0 on success, -1 on error. |
| 83 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 84 | int nc_server_ch_client_del_endpt(const char *client_name, const char *endpt_name, NC_TRANSPORT_IMPL ti); |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 85 | |
| 86 | /** |
Michal Vasko | fb1724b | 2020-01-31 11:02:00 +0100 | [diff] [blame] | 87 | * @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 | */ |
| 93 | int nc_server_ch_client_is_endpt(const char *client_name, const char *endpt_name); |
| 94 | |
| 95 | /** |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 96 | * @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 Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 101 | * @param[in] endpt_name Existing endpoint name of @p client_name. |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 102 | * @param[in] address New listening address. |
| 103 | * @return 0 on success, -1 on error. |
| 104 | */ |
| 105 | int 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 Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 113 | * @param[in] endpt_name Existing endpoint name of @p client_name. |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 114 | * @param[in] port New listening port. |
| 115 | * @return 0 on success, -1 on error. |
| 116 | */ |
| 117 | int nc_server_ch_client_endpt_set_port(const char *client_name, const char *endpt_name, uint16_t port); |
| 118 | |
| 119 | /** |
Michal Vasko | e49a15f | 2019-05-27 14:18:36 +0200 | [diff] [blame] | 120 | * @brief Change Call Home client endpoint keepalives state. Affects only new connections. |
| 121 | * |
| 122 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 123 | * @param[in] endpt_name Existing endpoint name of @p client_name. |
Michal Vasko | e49a15f | 2019-05-27 14:18:36 +0200 | [diff] [blame] | 124 | * @param[in] enable Whether to enable or disable keepalives. |
| 125 | * @return 0 on success, -1 on error. |
| 126 | */ |
| 127 | int 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 Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 133 | * @param[in] endpt_name Existing endpoint name of @p client_name. |
Michal Vasko | e49a15f | 2019-05-27 14:18:36 +0200 | [diff] [blame] | 134 | * @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 | */ |
| 139 | int 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 Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 143 | * @brief Set Call Home client connection type. |
| 144 | * |
| 145 | * @param[in] client_name Existing Call Home client name. |
| 146 | * @param[in] conn_type Call Home connection type. |
| 147 | * @return 0 on success, -1 on error. |
| 148 | */ |
| 149 | int nc_server_ch_client_set_conn_type(const char *client_name, NC_CH_CONN_TYPE conn_type); |
| 150 | |
| 151 | /** |
Michal Vasko | e49a15f | 2019-05-27 14:18:36 +0200 | [diff] [blame] | 152 | * @brief Set Call Home client periodic connection period for reconnecting. |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 153 | * |
| 154 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | e49a15f | 2019-05-27 14:18:36 +0200 | [diff] [blame] | 155 | * @param[in] period Call Home periodic connection period in minutes. |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 156 | * @return 0 on success, -1 on error. |
| 157 | */ |
Michal Vasko | e49a15f | 2019-05-27 14:18:36 +0200 | [diff] [blame] | 158 | int nc_server_ch_client_periodic_set_period(const char *client_name, uint16_t period); |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 159 | |
| 160 | /** |
Michal Vasko | e49a15f | 2019-05-27 14:18:36 +0200 | [diff] [blame] | 161 | * @brief Set Call Home client periodic connection period anchor time. |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 162 | * |
| 163 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | e49a15f | 2019-05-27 14:18:36 +0200 | [diff] [blame] | 164 | * @param[in] anchor_time Call Home periodic connection anchor time for the period. |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 165 | * @return 0 on success, -1 on error. |
| 166 | */ |
Michal Vasko | e49a15f | 2019-05-27 14:18:36 +0200 | [diff] [blame] | 167 | int nc_server_ch_client_periodic_set_anchor_time(const char *client_name, time_t anchor_time); |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 168 | |
| 169 | /** |
| 170 | * @brief Set Call Home client periodic connection idle timeout. |
| 171 | * |
| 172 | * @param[in] client_name Existing Call Home client name. |
| 173 | * @param[in] idle_timeout Call Home periodic idle timeout. |
| 174 | * @return 0 on success, -1 on error. |
| 175 | */ |
Michal Vasko | e49a15f | 2019-05-27 14:18:36 +0200 | [diff] [blame] | 176 | int nc_server_ch_client_periodic_set_idle_timeout(const char *client_name, uint16_t idle_timeout); |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 177 | |
| 178 | /** |
| 179 | * @brief Set Call Home client start-with policy. |
| 180 | * |
| 181 | * @param[in] client_name Existing Call Home client name. |
| 182 | * @param[in] start_with Call Home client start-with. |
| 183 | * @return 0 on success, -1 on error. |
| 184 | */ |
| 185 | int nc_server_ch_client_set_start_with(const char *client_name, NC_CH_START_WITH start_with); |
| 186 | |
| 187 | /** |
| 188 | * @brief Set Call Home client overall max attempts. |
| 189 | * |
| 190 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | 50d2a5c | 2017-02-14 10:29:49 +0100 | [diff] [blame] | 191 | * @param[in] max_attempts Call Home overall max reconnect attempts. |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 192 | * @return 0 on success, -1 on error. |
| 193 | */ |
| 194 | int nc_server_ch_client_set_max_attempts(const char *client_name, uint8_t max_attempts); |
| 195 | |
| 196 | /** |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 197 | * @brief Callback for getting a locked context for new Call Home sessions. |
| 198 | * |
| 199 | * @param[in] cb_data Arbitrary ctx callback data. |
| 200 | * @return Context for the session to use during its lifetime; |
| 201 | * @return NULL on error and session fails to be created. |
| 202 | */ |
| 203 | typedef const struct ly_ctx *(*nc_server_ch_session_acquire_ctx_cb)(void *cb_data); |
| 204 | |
| 205 | /** |
| 206 | * @brief Callback for releasing a locked context for Call Home sessions. |
| 207 | * |
| 208 | * @param[in] cb_data Arbitrary ctx callback data. |
| 209 | */ |
| 210 | typedef void (*nc_server_ch_session_release_ctx_cb)(void *cb_data); |
| 211 | |
| 212 | /** |
| 213 | * @brief Callback for new Call Home sessions. |
| 214 | * |
| 215 | * @param[in] client_name Name of the CH client which established the session. |
| 216 | * @param[in] new_session New established CH session, the pointer is internally discarded afterwards. |
| 217 | * @return 0 on success; |
| 218 | * @return non-zero on error and @p new_session is freed. |
| 219 | */ |
| 220 | typedef int (*nc_server_ch_new_session_cb)(const char *client_name, struct nc_session *new_session); |
| 221 | |
| 222 | /** |
| 223 | * @brief Dispatch a thread connecting to a listening NETCONF client and creating Call Home sessions. |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 224 | * |
| 225 | * @param[in] client_name Existing client name. |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 226 | * @param[in] acquire_ctx_cb Callback for acquiring new session context. |
| 227 | * @param[in] release_ctx_cb Callback for releasing session context. |
| 228 | * @param[in] ctx_cb_data Arbitrary user data passed to @p acquire_ctx_cb and @p release_ctx_cb. |
| 229 | * @param[in] new_session_cb Callback called for every established session on the client. |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 230 | * @return 0 if the thread was successfully created, -1 on error. |
| 231 | */ |
Michal Vasko | 9322407 | 2021-11-09 12:14:28 +0100 | [diff] [blame] | 232 | int nc_connect_ch_client_dispatch(const char *client_name, nc_server_ch_session_acquire_ctx_cb acquire_ctx_cb, |
| 233 | nc_server_ch_session_release_ctx_cb release_ctx_cb, void *ctx_cb_data, nc_server_ch_new_session_cb new_session_cb); |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 234 | |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 235 | /** @} Server-side Call Home */ |
| 236 | |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 237 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 238 | * @defgroup server_ch_ssh Server-side Call Home on SSH |
| 239 | * @ingroup server_ch |
| 240 | * |
| 241 | * @brief SSH settings for the Call Home functionality |
| 242 | * @{ |
| 243 | */ |
| 244 | |
| 245 | /** |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 246 | * @brief Add Call Home SSH host keys the server will identify itself with. Only the name is set, the key itself |
| 247 | * wil be retrieved using a callback. |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 248 | * |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 249 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 250 | * @param[in] endpt_name Existing endpoint name of the client. |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 251 | * @param[in] name Arbitrary name of the host key. |
Michal Vasko | 7d25588 | 2017-02-09 13:35:08 +0100 | [diff] [blame] | 252 | * @param[in] idx Optional index where to add the key. -1 adds at the end. |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 253 | * @return 0 on success, -1 on error. |
| 254 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 255 | int nc_server_ssh_ch_client_endpt_add_hostkey(const char *client_name, const char *endpt_name, const char *name, int16_t idx); |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 256 | |
| 257 | /** |
| 258 | * @brief Delete Call Home SSH host keys. Their order is preserved. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 259 | * |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 260 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 261 | * @param[in] endpt_name Existing endpoint name of the client. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 262 | * @param[in] name Name of the host key. NULL matches all the keys, but if @p idx != -1 then this must be NULL. |
| 263 | * @param[in] idx Index of the hostkey. -1 matches all indices, but if @p name != NULL then this must be -1. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 264 | * @return 0 on success, -1 on error. |
| 265 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 266 | int nc_server_ssh_ch_client_endpt_del_hostkey(const char *client_name, const char *endpt_name, const char *name, int16_t idx); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 267 | |
| 268 | /** |
Michal Vasko | fbfe8b6 | 2017-02-14 10:22:30 +0100 | [diff] [blame] | 269 | * @brief Move Call Home SSH host key. |
| 270 | * |
Michal Vasko | 50d2a5c | 2017-02-14 10:29:49 +0100 | [diff] [blame] | 271 | * @param[in] client_name Exisitng Call Home client name. |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 272 | * @param[in] endpt_name Existing endpoint name of the client. |
Michal Vasko | fbfe8b6 | 2017-02-14 10:22:30 +0100 | [diff] [blame] | 273 | * @param[in] key_mov Name of the host key that will be moved. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 274 | * @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 Vasko | fbfe8b6 | 2017-02-14 10:22:30 +0100 | [diff] [blame] | 275 | * @return 0 in success, -1 on error. |
| 276 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 277 | int nc_server_ssh_ch_client_endpt_mov_hostkey(const char *client_name, const char *endpt_name, const char *key_mov, |
| 278 | const char *key_after); |
Michal Vasko | fbfe8b6 | 2017-02-14 10:22:30 +0100 | [diff] [blame] | 279 | |
| 280 | /** |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 281 | * @brief Set accepted Call Home SSH authentication methods. All (publickey, password, interactive) |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 282 | * are supported by default. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 283 | * |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 284 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 285 | * @param[in] endpt_name Existing endpoint name of the client. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 286 | * @param[in] auth_methods Accepted authentication methods bit field of NC_SSH_AUTH_TYPE. |
| 287 | * @return 0 on success, -1 on error. |
| 288 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 289 | int nc_server_ssh_ch_client_endpt_set_auth_methods(const char *client_name, const char *endpt_name, int auth_methods); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 290 | |
| 291 | /** |
Michal Vasko | ddce121 | 2019-05-24 09:58:49 +0200 | [diff] [blame] | 292 | * @brief Get accepted Call Home SSH authentication methods. |
| 293 | * |
| 294 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 295 | * @param[in] endpt_name Existing endpoint name of the client. |
Michal Vasko | ddce121 | 2019-05-24 09:58:49 +0200 | [diff] [blame] | 296 | * @return Accepted authentication methods bit field of NC_SSH_AUTH_TYPE. |
| 297 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 298 | int nc_server_ssh_ch_client_endpt_get_auth_methods(const char *client_name, const char *endpt_name); |
Michal Vasko | ddce121 | 2019-05-24 09:58:49 +0200 | [diff] [blame] | 299 | |
| 300 | /** |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 301 | * @brief Set Call Home SSH authentication attempts of every client. 3 by default. |
| 302 | * |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 303 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 304 | * @param[in] endpt_name Existing endpoint name of the client. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 305 | * @param[in] auth_attempts Failed authentication attempts before a client is dropped. |
| 306 | * @return 0 on success, -1 on error. |
| 307 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 308 | int nc_server_ssh_ch_client_endpt_set_auth_attempts(const char *client_name, const char *endpt_name, uint16_t auth_attempts); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 309 | |
| 310 | /** |
Michal Vasko | cbad4c5 | 2019-06-27 16:30:35 +0200 | [diff] [blame] | 311 | * @brief Set Call Home SSH authentication timeout. 30 seconds by default. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 312 | * |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 313 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 314 | * @param[in] endpt_name Existing endpoint name of the client. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 315 | * @param[in] auth_timeout Number of seconds before an unauthenticated client is dropped. |
| 316 | * @return 0 on success, -1 on error. |
| 317 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 318 | int nc_server_ssh_ch_client_endpt_set_auth_timeout(const char *client_name, const char *endpt_name, uint16_t auth_timeout); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 319 | |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 320 | /** @} Server-side Call Home on SSH */ |
| 321 | |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 322 | /** |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 323 | * @defgroup server_ch_tls Server-side Call Home on TLS |
| 324 | * @ingroup server_ch |
| 325 | * |
| 326 | * @brief TLS settings for the Call Home functionality |
| 327 | * @{ |
| 328 | */ |
| 329 | |
| 330 | /** |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 331 | * @brief Set the server Call Home TLS certificate. Only the name is set, the certificate itself |
| 332 | * wil be retrieved using a callback. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 333 | * |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 334 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 335 | * @param[in] endpt_name Existing endpoint name of the client. |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 336 | * @param[in] name Arbitrary certificate name. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 337 | * @return 0 on success, -1 on error. |
| 338 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 339 | int nc_server_tls_ch_client_endpt_set_server_cert(const char *client_name, const char *endpt_name, const char *name); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 340 | |
| 341 | /** |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 342 | * @brief Add a Call Home trusted certificate list. Can be both a CA or a client one. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 343 | * |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 344 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 345 | * @param[in] endpt_name Existing endpoint name of the client. |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 346 | * @param[in] name Arbitary name identifying this certificate list. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 347 | * @return 0 on success, -1 on error. |
| 348 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 349 | int nc_server_tls_ch_client_endpt_add_trusted_cert_list(const char *client_name, const char *endpt_name, const char *name); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 350 | |
| 351 | /** |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 352 | * @brief Remove a set Call Home trusted certificate list. CRLs and CTN entries are not affected. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 353 | * |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 354 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 355 | * @param[in] endpt_name Existing endpoint name of the client. |
Michal Vasko | 4c1fb49 | 2017-01-30 14:31:07 +0100 | [diff] [blame] | 356 | * @param[in] name Name of the certificate list to delete. NULL deletes all the lists. |
| 357 | * @return 0 on success, -1 on not found. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 358 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 359 | int nc_server_tls_ch_client_endpt_del_trusted_cert_list(const char *client_name, const char *endpt_name, const char *name); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 360 | |
| 361 | /** |
| 362 | * @brief Set trusted Call Home Certificate Authority certificate locations. There |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 363 | * can only be one file and one directory, they are replaced if already set. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 364 | * |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 365 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 366 | * @param[in] endpt_name Existing endpoint name of the client. |
Michal Vasko | b34b3e8 | 2016-02-26 15:04:58 +0100 | [diff] [blame] | 367 | * @param[in] ca_file Path to a trusted CA cert store file in PEM format. |
| 368 | * Can be NULL. |
| 369 | * @param[in] ca_dir Path to a trusted CA cert store hashed directory |
| 370 | * (c_rehash utility can be used to create hashes) |
| 371 | * with PEM files. Can be NULL. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 372 | * @return 0 on success, -1 on error. |
| 373 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 374 | int nc_server_tls_ch_client_endpt_set_trusted_ca_paths(const char *client_name, const char *endpt_name, const char *ca_file, |
| 375 | const char *ca_dir); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 376 | |
| 377 | /** |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 378 | * @brief Set Call Home Certificate Revocation List locations. There can only be |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 379 | * one file and one directory, they are replaced if already set. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 380 | * |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 381 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 382 | * @param[in] endpt_name Existing endpoint name of the client. |
Michal Vasko | b34b3e8 | 2016-02-26 15:04:58 +0100 | [diff] [blame] | 383 | * @param[in] crl_file Path to a CRL store file in PEM format. Can be NULL. |
| 384 | * @param[in] crl_dir Path to a CRL store hashed directory (c_rehash utility |
| 385 | * can be used to create hashes) with PEM files. Can be NULL. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 386 | * @return 0 on success, -1 on error. |
| 387 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 388 | int nc_server_tls_ch_client_endpt_set_crl_paths(const char *client_name, const char *endpt_name, const char *crl_file, |
| 389 | const char *crl_dir); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 390 | |
| 391 | /** |
| 392 | * @brief Destroy and clean Call Home CRLs. Call Home certificates, private keys, |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 393 | * and CTN entries are not affected. |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 394 | * |
| 395 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 396 | * @param[in] endpt_name Existing endpoint name of the client. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 397 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 398 | void nc_server_tls_ch_client_endpt_clear_crls(const char *client_name, const char *endpt_name); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 399 | |
| 400 | /** |
Michal Vasko | 3cf4aaa | 2017-02-01 15:03:36 +0100 | [diff] [blame] | 401 | * @brief Add a cert-to-name entry. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 402 | * |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 403 | * It is possible to add an entry step-by-step, specifying first only @p ip and in later calls |
| 404 | * @p fingerprint, @p map_type, and optionally @p name spearately. |
Michal Vasko | 3cf4aaa | 2017-02-01 15:03:36 +0100 | [diff] [blame] | 405 | * |
Michal Vasko | 50d2a5c | 2017-02-14 10:29:49 +0100 | [diff] [blame] | 406 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 407 | * @param[in] endpt_name Existing endpoint name of the client. |
Michal Vasko | 3cf4aaa | 2017-02-01 15:03:36 +0100 | [diff] [blame] | 408 | * @param[in] id Priority of the entry. It must be unique. If already exists, the entry with this id |
| 409 | * is modified. |
| 410 | * @param[in] fingerprint Matching certificate fingerprint. If NULL, kept temporarily unset. |
| 411 | * @param[in] map_type Type of username-certificate mapping. If 0, kept temporarily unset. |
Michal Vasko | c446a38 | 2021-06-18 08:54:05 +0200 | [diff] [blame] | 412 | * @param[in] name Specific username used only if @p map_type == NC_TLS_CTN_SPECIFED. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 413 | * @return 0 on success, -1 on error. |
| 414 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 415 | int nc_server_tls_ch_client_endpt_add_ctn(const char *client_name, const char *endpt_name, uint32_t id, |
| 416 | const char *fingerprint, NC_TLS_CTN_MAPTYPE map_type, const char *name); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 417 | |
| 418 | /** |
Michal Vasko | 58c22a2 | 2016-11-23 13:49:53 +0100 | [diff] [blame] | 419 | * @brief Remove a Call Home cert-to-name entry. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 420 | * |
Michal Vasko | 2e6defd | 2016-10-07 15:48:15 +0200 | [diff] [blame] | 421 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 422 | * @param[in] endpt_name Existing endpoint name of the client. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 423 | * @param[in] id Priority of the entry. -1 matches all the priorities. |
| 424 | * @param[in] fingerprint Fingerprint fo the entry. NULL matches all the fingerprints. |
| 425 | * @param[in] map_type Mapping type of the entry. 0 matches all the mapping types. |
| 426 | * @param[in] name Specific username for the entry. NULL matches all the usernames. |
| 427 | * @return 0 on success, -1 on not finding any match. |
| 428 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 429 | int nc_server_tls_ch_client_endpt_del_ctn(const char *client_name, const char *endpt_name, int64_t id, |
| 430 | const char *fingerprint, NC_TLS_CTN_MAPTYPE map_type, const char *name); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 431 | |
Michal Vasko | df5e6af | 2016-11-23 13:50:56 +0100 | [diff] [blame] | 432 | /** |
| 433 | * @brief Get a Call Home cert-to-name entry. |
| 434 | * |
| 435 | * If a parameter is NULL, it is ignored. If its dereferenced value is NULL, |
| 436 | * it is filled and returned. If the value is set, it is used as a filter. |
| 437 | * Returns first matching entry. |
| 438 | * |
| 439 | * @param[in] client_name Existing Call Home client name. |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 440 | * @param[in] endpt_name Existing endpoint name of the client. |
Michal Vasko | df5e6af | 2016-11-23 13:50:56 +0100 | [diff] [blame] | 441 | * @param[in,out] id Priority of the entry. |
| 442 | * @param[in,out] fingerprint Fingerprint fo the entry. |
| 443 | * @param[in,out] map_type Mapping type of the entry. |
| 444 | * @param[in,out] name Specific username for the entry. |
| 445 | * @return 0 on success, -1 on not finding any match. |
| 446 | */ |
Michal Vasko | adf30f0 | 2019-06-24 09:34:47 +0200 | [diff] [blame] | 447 | int nc_server_tls_ch_client_endpt_get_ctn(const char *client_name, const char *endpt_name, uint32_t *id, char **fingerprint, |
| 448 | NC_TLS_CTN_MAPTYPE *map_type, char **name); |
Michal Vasko | df5e6af | 2016-11-23 13:50:56 +0100 | [diff] [blame] | 449 | |
Radek Krejci | 6799a05 | 2017-05-19 14:23:23 +0200 | [diff] [blame] | 450 | /** @} Server-side Call Home on TLS */ |
| 451 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 452 | #endif /* NC_ENABLED_SSH_TLS */ |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 453 | |
Michal Vasko | c09730e | 2019-01-17 10:07:26 +0100 | [diff] [blame] | 454 | #ifdef __cplusplus |
| 455 | } |
| 456 | #endif |
| 457 | |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 458 | #endif /* NC_SESSION_SERVER_CH_H_ */ |