Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file session_server.h |
| 3 | * \author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * \brief libnetconf2 session server manipulation |
| 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 8 | * 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 Vasko | afd416b | 2016-02-25 14:51:46 +0100 | [diff] [blame] | 11 | * |
Radek Krejci | 9b81f5b | 2016-02-24 13:14:49 +0100 | [diff] [blame] | 12 | * https://opensource.org/licenses/BSD-3-Clause |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | #ifndef NC_SESSION_SERVER_H_ |
| 16 | #define NC_SESSION_SERVER_H_ |
| 17 | |
| 18 | #include <stdint.h> |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 19 | #include <libyang/libyang.h> |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 20 | |
| 21 | #include "session.h" |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 22 | #include "netconf.h" |
| 23 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 24 | /** |
| 25 | * @brief Prototype of callbacks that are called if some RPCs are received. |
| 26 | * |
| 27 | * If \p session termination reason is changed in the callback, one last reply |
| 28 | * is sent and then the session is considered invalid. |
| 29 | * |
| 30 | * @param[in] rpc Parsed client RPC request. |
| 31 | * @param[in] session Session the RPC arrived on. |
| 32 | * @return Server reply. If NULL, an operation-failed error will be sent to the client. |
| 33 | */ |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 34 | typedef struct nc_server_reply *(*nc_rpc_clb)(struct lyd_node *rpc, struct nc_session *session); |
| 35 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 36 | /** |
Michal Vasko | 7b09624 | 2016-01-29 15:55:10 +0100 | [diff] [blame] | 37 | * @brief Set the termination reason for a session. Use only in #nc_rpc_clb callbacks. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 38 | * |
| 39 | * @param[in] session Session to modify. |
| 40 | * @param[in] reason Reason of termination. |
| 41 | */ |
| 42 | void nc_session_set_term_reason(struct nc_session *session, NC_SESSION_TERM_REASON reason); |
| 43 | |
| 44 | /** |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 45 | * @brief Initialize libssh and/or libssl/libcrypto and the server using a libyang context. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 46 | * |
| 47 | * The context is not modified internally, only its dictionary is used for holding |
Michal Vasko | a43589b | 2016-02-17 13:24:59 +0100 | [diff] [blame] | 48 | * all the strings, which is thread-safe. Reading models is considered thread-safe |
| 49 | * as models cannot be removed and are rarely modified (augments or deviations). |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 50 | * |
Michal Vasko | 5494f51 | 2016-03-01 12:13:44 +0100 | [diff] [blame] | 51 | * If the callbacks on schema nodes (their private data) are modified after |
| 52 | * server initialization with that particular context, they will be called (changes |
| 53 | * will take effect). However, there could be race conditions as the access to |
| 54 | * these callbacks is not thread-safe. |
| 55 | * |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 56 | * Server capabilities are generated based on its content. Changing the context |
| 57 | * in ways that result in changed capabilities (adding models, changing features) |
| 58 | * is discouraged after sessions are established as it is not possible to change |
| 59 | * capabilities of a session. |
| 60 | * |
| 61 | * This context can safely be destroyed only after calling the last libnetconf2 |
| 62 | * function in an application. |
| 63 | * |
| 64 | * Supported RPCs of models in the context are expected to have the private field |
| 65 | * in the corresponding RPC schema node set to a nc_rpc_clb function callback. |
| 66 | * This callback is called by nc_ps_poll() if the particular RPC request is |
| 67 | * received. Callbacks for ietf-netconf:get-schema (supporting YANG and YIN format |
| 68 | * only) and ietf-netconf:close-session are set internally if left unset. |
| 69 | * |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 70 | * @param[in] ctx Core NETCONF server context. |
| 71 | * @return 0 on success, -1 on error. |
| 72 | */ |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 73 | int nc_server_init(struct ly_ctx *ctx); |
| 74 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 75 | /** |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 76 | * @brief Destroy any dynamically allocated libssh and/or libssl/libcrypto and |
| 77 | * server resources. |
Michal Vasko | b48aa81 | 2016-01-18 14:13:09 +0100 | [diff] [blame] | 78 | */ |
| 79 | void nc_server_destroy(void); |
| 80 | |
| 81 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 82 | * @brief Set the with-defaults capability extra parameters. |
| 83 | * |
| 84 | * For the capability to be actually advertised, the server context must also |
| 85 | * include the ietf-netconf-with-defaults model. |
| 86 | * |
| 87 | * Changing this option has the same ill effects as changing capabilities while |
| 88 | * sessions are already established. |
| 89 | * |
| 90 | * @param[in] basic_mode basic-mode with-defaults parameter. |
| 91 | * @param[in] also_supported NC_WD_MODE bit array, also-supported with-defaults |
| 92 | * parameter. |
| 93 | * @return 0 on success, -1 on error. |
| 94 | */ |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 95 | int nc_server_set_capab_withdefaults(NC_WD_MODE basic_mode, int also_supported); |
| 96 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 97 | /** |
Michal Vasko | 55f0397 | 2016-04-13 08:56:01 +0200 | [diff] [blame] | 98 | * @brief Get with-defaults capability extra parameters. |
| 99 | * |
| 100 | * At least one argument must be non-NULL. |
| 101 | * |
| 102 | * @param[in,out] basic_mode basic-mode parameter. |
| 103 | * @param[in,out] also_supported also-supported parameter. |
| 104 | */ |
| 105 | void nc_server_get_capab_withdefaults(NC_WD_MODE *basic_mode, int *also_supported); |
| 106 | |
| 107 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 108 | * @brief Set the interleave capability. |
| 109 | * |
| 110 | * For the capability to be actually advertised, the server context must also |
| 111 | * include the nc-notifications model. |
| 112 | * |
| 113 | * Changing this option has the same ill effects as changing capabilities while |
| 114 | * sessions are already established. |
| 115 | * |
| 116 | * @param[in] interleave_support 1 to suport interleave, 0 to not. |
| 117 | */ |
| 118 | void nc_server_set_capab_interleave(int interleave_support); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 119 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 120 | /** |
Michal Vasko | 55f0397 | 2016-04-13 08:56:01 +0200 | [diff] [blame] | 121 | * @brief Get the interleave capability state. |
| 122 | * |
| 123 | * @return 1 for supported, 0 for not supported. |
| 124 | */ |
| 125 | int nc_server_get_capab_interleave(void); |
| 126 | |
| 127 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 128 | * @brief Set server timeout for receiving a hello message. |
| 129 | * |
| 130 | * @param[in] hello_timeout Hello message timeout. 0 for infinite waiting. |
| 131 | */ |
| 132 | void nc_server_set_hello_timeout(uint16_t hello_timeout); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 133 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 134 | /** |
Michal Vasko | 55f0397 | 2016-04-13 08:56:01 +0200 | [diff] [blame] | 135 | * @brief get server timeout for receiving a hello message. |
| 136 | * |
| 137 | * @return Hello message timeout, 0 is infinite. |
| 138 | */ |
| 139 | uint16_t nc_server_get_hello_timeout(void); |
| 140 | |
| 141 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 142 | * @brief Set server timeout for dropping an idle session. |
| 143 | * |
| 144 | * @param[in] idle_timeout Idle session timeout. 0 to never drop a session |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 145 | * because of inactivity. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 146 | */ |
| 147 | void nc_server_set_idle_timeout(uint16_t idle_timeout); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 148 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 149 | /** |
Michal Vasko | 55f0397 | 2016-04-13 08:56:01 +0200 | [diff] [blame] | 150 | * @brief Get server timeout for dropping an idle session. |
| 151 | * |
| 152 | * @return Idle session timeout, 0 for for never dropping |
| 153 | * a session because of inactivity. |
| 154 | */ |
| 155 | uint16_t nc_server_get_idle_timeout(void); |
| 156 | |
| 157 | /** |
Michal Vasko | 4ffa3b2 | 2016-05-24 16:36:25 +0200 | [diff] [blame] | 158 | * @brief Get all the server capabilities as will be sent to every client. |
| 159 | * |
| 160 | * A few capabilities (with-defaults, interleave) depend on the current |
| 161 | * server options. |
| 162 | * |
| 163 | * @param[in] ctx Context to read most capabilities from. |
| 164 | * @return Array of capabilities stored in the \p ctx dictionary, NULL on error. |
| 165 | */ |
| 166 | const char **nc_server_get_cpblts(struct ly_ctx *ctx); |
| 167 | |
| 168 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 169 | * @brief Accept a new session on a pre-established transport session. |
| 170 | * |
| 171 | * @param[in] fdin File descriptor to read (unencrypted) XML data from. |
| 172 | * @param[in] fdout File descriptor to write (unencrypted) XML data to. |
| 173 | * @param[in] username NETCONF username as provided by the transport protocol. |
| 174 | * @param[out] session New session on success. |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 175 | * @return NC_MSG_HELLO on success, NC_MSG_BAD_HELLO on client \<hello\> message |
| 176 | * parsing fail, NC_MSG_WOULDBLOCK on timeout, NC_MSG_ERROR on other errors. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 177 | */ |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 178 | NC_MSG_TYPE nc_accept_inout(int fdin, int fdout, const char *username, struct nc_session **session); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 179 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 180 | /** |
| 181 | * @brief Create an empty structure for polling sessions. |
| 182 | * |
| 183 | * @return Empty pollsession structure, NULL on error. |
| 184 | */ |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 185 | struct nc_pollsession *nc_ps_new(void); |
Michal Vasko | fb89d77 | 2016-01-08 12:25:35 +0100 | [diff] [blame] | 186 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 187 | /** |
| 188 | * @brief Free a pollsession structure. |
| 189 | * |
Michal Vasko | 01082bf | 2016-04-07 10:44:21 +0200 | [diff] [blame] | 190 | * !IMPORTANT! Make sure that \p ps is not accessible (is not used) |
| 191 | * by any thread before and after this call! |
| 192 | * |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 193 | * @param[in] ps Pollsession structure to free. |
| 194 | */ |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 195 | void nc_ps_free(struct nc_pollsession *ps); |
Michal Vasko | fb89d77 | 2016-01-08 12:25:35 +0100 | [diff] [blame] | 196 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 197 | /** |
| 198 | * @brief Add a session to a pollsession structure. |
| 199 | * |
| 200 | * @param[in] ps Pollsession structure to modify. |
| 201 | * @param[in] session Session to add to \p ps. |
| 202 | * @return 0 on success, -1 on error. |
| 203 | */ |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 204 | int nc_ps_add_session(struct nc_pollsession *ps, struct nc_session *session); |
Michal Vasko | fb89d77 | 2016-01-08 12:25:35 +0100 | [diff] [blame] | 205 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 206 | /** |
| 207 | * @brief Remove a session from a pollsession structure. |
| 208 | * |
| 209 | * @param[in] ps Pollsession structure to modify. |
| 210 | * @param[in] session Session to remove from \p ps. |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 211 | * @return 0 on success, -1 on not found. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 212 | */ |
Michal Vasko | 05ba9df | 2016-01-13 14:40:27 +0100 | [diff] [blame] | 213 | int nc_ps_del_session(struct nc_pollsession *ps, struct nc_session *session); |
| 214 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 215 | /** |
Michal Vasko | 0fdb7ac | 2016-03-01 09:03:12 +0100 | [diff] [blame] | 216 | * @brief Learn the number of sessions in a pollsession structure. |
| 217 | * |
| 218 | * @param[in] ps Pollsession structure to check. |
Michal Vasko | 0521911 | 2016-07-26 11:36:11 +0200 | [diff] [blame] | 219 | * @return Number of sessions (even invalid ones) in \p ps, -1 on error. |
Michal Vasko | 0fdb7ac | 2016-03-01 09:03:12 +0100 | [diff] [blame] | 220 | */ |
| 221 | uint16_t nc_ps_session_count(struct nc_pollsession *ps); |
| 222 | |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 223 | #define NC_PSPOLL_TIMEOUT 0x0001 /**< Timeout elapsed. */ |
| 224 | #define NC_PSPOLL_RPC 0x0002 /**< RPC was correctly parsed and processed. */ |
| 225 | #define NC_PSPOLL_BAD_RPC 0x0004 /**< RPC was received, but failed to be parsed. */ |
| 226 | #define NC_PSPOLL_REPLY_ERROR 0x0008 /**< Response to the RPC was a \<rpc-reply\> of type error. */ |
| 227 | #define NC_PSPOLL_SESSION_TERM 0x0010 /**< Some session was terminated. */ |
Michal Vasko | 0521911 | 2016-07-26 11:36:11 +0200 | [diff] [blame] | 228 | #define NC_PSPOLL_SESSION_ERROR 0x0020 /**< Some session was terminated incorrectly (not by a \<close-session\> or \<kill-session\> RPC). */ |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 229 | #define NC_PSPOLL_PENDING 0x0040 /**< Unhandled pending events on other session. */ |
| 230 | #define NC_PSPOLL_ERROR 0x0080 /**< Other fatal errors (they are printed). */ |
| 231 | |
| 232 | #ifdef NC_ENABLED_SSH |
| 233 | # define NC_PSPOLL_SSH_MSG 0x0100 /**< SSH message received (and processed, if relevant, only with SSH support). */ |
| 234 | # define NC_PSPOLL_SSH_CHANNEL 0x0200 /**< New SSH channel opened on an existing session (only with SSH support). */ |
| 235 | #endif |
| 236 | |
Michal Vasko | 0fdb7ac | 2016-03-01 09:03:12 +0100 | [diff] [blame] | 237 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 238 | * @brief Poll sessions and process any received RPCs. |
| 239 | * |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 240 | * All the sessions must be running. Only one event on one session |
Michal Vasko | 96164bf | 2016-01-21 15:41:58 +0100 | [diff] [blame] | 241 | * is handled in one function call. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 242 | * |
| 243 | * @param[in] ps Pollsession structure to use. |
Michal Vasko | 11d142a | 2016-01-19 15:58:24 +0100 | [diff] [blame] | 244 | * @param[in] timeout Poll timeout in milliseconds. 0 for non-blocking call, -1 for |
Michal Vasko | 96830e3 | 2016-02-01 10:54:18 +0100 | [diff] [blame] | 245 | * infinite waiting. |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 246 | * @param[in] session Session that was processed and that specific return bits concern. |
| 247 | * Can be NULL. |
| 248 | * @return Bitfield of NC_PSPOLL_* macros, almost any combination can be returned. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 249 | */ |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 250 | int nc_ps_poll(struct nc_pollsession *ps, int timeout, struct nc_session **session); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 251 | |
Michal Vasko | 11d142a | 2016-01-19 15:58:24 +0100 | [diff] [blame] | 252 | /** |
Michal Vasko | cad3ac4 | 2016-03-01 09:06:01 +0100 | [diff] [blame] | 253 | * @brief Remove sessions from a pollsession structure and |
| 254 | * call nc_session_free() on them. |
Michal Vasko | d09eae6 | 2016-02-01 10:32:52 +0100 | [diff] [blame] | 255 | * |
Michal Vasko | cad3ac4 | 2016-03-01 09:06:01 +0100 | [diff] [blame] | 256 | * Calling this function with \p all false makes sense if nc_ps_poll() returned 3. |
Michal Vasko | d09eae6 | 2016-02-01 10:32:52 +0100 | [diff] [blame] | 257 | * |
| 258 | * @param[in] ps Pollsession structure to clear. |
Michal Vasko | cad3ac4 | 2016-03-01 09:06:01 +0100 | [diff] [blame] | 259 | * @param[in] all Whether to free all sessions, or only the invalid ones. |
Michal Vasko | e1a64ec | 2016-03-01 12:21:58 +0100 | [diff] [blame] | 260 | * @param[in] data_free Session user data destructor. |
Michal Vasko | d09eae6 | 2016-02-01 10:32:52 +0100 | [diff] [blame] | 261 | */ |
Michal Vasko | e1a64ec | 2016-03-01 12:21:58 +0100 | [diff] [blame] | 262 | void nc_ps_clear(struct nc_pollsession *ps, int all, void (*data_free)(void *)); |
Michal Vasko | d09eae6 | 2016-02-01 10:32:52 +0100 | [diff] [blame] | 263 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 264 | #if defined(NC_ENABLED_SSH) || defined(NC_ENABLED_TLS) |
Michal Vasko | 9e036d5 | 2016-01-08 10:49:26 +0100 | [diff] [blame] | 265 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 266 | /** |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 267 | * @brief Add a new endpoint. |
| 268 | * |
| 269 | * Before the endpoint can accept any connections, its address and port must |
| 270 | * be set on at least one transport protocol. |
| 271 | * |
| 272 | * @param[in] name Arbitrary unique endpoint name. |
| 273 | * @return 0 on success, -1 on error. |
| 274 | */ |
| 275 | int nc_server_add_endpt(const char *name); |
| 276 | |
| 277 | /** |
| 278 | * @brief Stop listening on and remove an endpoint. |
| 279 | * |
| 280 | * @param[in] name Endpoint name. NULL matches all endpoints. |
| 281 | * @return 0 on success, -1 on not finding any match. |
| 282 | */ |
| 283 | int nc_server_del_endpt(const char *name); |
| 284 | |
| 285 | /** |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 286 | * @brief Accept new sessions on all the listening endpoints. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 287 | * |
Michal Vasko | 11d142a | 2016-01-19 15:58:24 +0100 | [diff] [blame] | 288 | * @param[in] timeout Timeout for receiving a new connection in milliseconds, 0 for |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 289 | * non-blocking call, -1 for infinite waiting. |
Michal Vasko | 96164bf | 2016-01-21 15:41:58 +0100 | [diff] [blame] | 290 | * @param[out] session New session. |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 291 | * @return NC_MSG_HELLO on success, NC_MSG_BAD_HELLO on client \<hello\> message |
| 292 | * parsing fail, NC_MSG_WOULDBLOCK on timeout, NC_MSG_ERROR on other errors. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 293 | */ |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 294 | NC_MSG_TYPE nc_accept(int timeout, struct nc_session **session); |
Michal Vasko | 9e036d5 | 2016-01-08 10:49:26 +0100 | [diff] [blame] | 295 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 296 | #endif /* NC_ENABLED_SSH || NC_ENABLED_TLS */ |
Michal Vasko | 9e036d5 | 2016-01-08 10:49:26 +0100 | [diff] [blame] | 297 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 298 | #ifdef NC_ENABLED_SSH |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 299 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 300 | /** |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 301 | * @brief Accept a new NETCONF session on an SSH session of a running NETCONF \p orig_session. |
| 302 | * Call this function only when nc_ps_poll() returns NC_PSPOLL_SSH_CHANNEL on \p orig_session. |
| 303 | * |
| 304 | * @param[in] orig_session Session that has a new SSH channel ready. |
| 305 | * @param[out] session New session. |
| 306 | * @return NC_MSG_HELLO on success, NC_MSG_BAD_HELLO on client \<hello\> message |
| 307 | * parsing fail, NC_MSG_WOULDBLOCK on timeout, NC_MSG_ERROR on other errors. |
| 308 | */ |
| 309 | NC_MSG_TYPE nc_session_accept_ssh_channel(struct nc_session *orig_session, struct nc_session **session); |
| 310 | |
| 311 | /** |
Michal Vasko | 96164bf | 2016-01-21 15:41:58 +0100 | [diff] [blame] | 312 | * @brief Accept a new NETCONF session on an SSH session of a running NETCONF session |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 313 | * that was polled in \p ps. Call this function only when nc_ps_poll() on \p ps returns NC_PSPOLL_SSH_CHANNEL. |
Michal Vasko | c0fde01 | 2016-03-01 09:07:23 +0100 | [diff] [blame] | 314 | * The new session is only returned in \p session, it is not added to \p ps. |
Michal Vasko | 96164bf | 2016-01-21 15:41:58 +0100 | [diff] [blame] | 315 | * |
| 316 | * @param[in] ps Unmodified pollsession structure from the previous nc_ps_poll() call. |
| 317 | * @param[out] session New session. |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 318 | * @return NC_MSG_HELLO on success, NC_MSG_BAD_HELLO on client \<hello\> message |
| 319 | * parsing fail, NC_MSG_WOULDBLOCK on timeout, NC_MSG_ERROR on other errors. |
Michal Vasko | 96164bf | 2016-01-21 15:41:58 +0100 | [diff] [blame] | 320 | */ |
Michal Vasko | 71090fc | 2016-05-24 16:37:28 +0200 | [diff] [blame] | 321 | NC_MSG_TYPE nc_ps_accept_ssh_channel(struct nc_pollsession *ps, struct nc_session **session); |
Michal Vasko | 96164bf | 2016-01-21 15:41:58 +0100 | [diff] [blame] | 322 | |
| 323 | /** |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 324 | * @brief Change SSH endpoint listening address. |
| 325 | * |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 326 | * On error the previous listening socket (if any) is left untouched. |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 327 | * |
| 328 | * @param[in] endpt_name Existing endpoint name. |
| 329 | * @param[in] address New listening address. |
| 330 | * @return 0 on success, -1 on error. |
| 331 | */ |
| 332 | int nc_server_ssh_endpt_set_address(const char *endpt_name, const char *address); |
| 333 | |
| 334 | /** |
| 335 | * @brief Change SSH endpoint listening port. |
| 336 | * |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 337 | * On error the previous listening socket (if any) is left untouched. |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 338 | * |
| 339 | * @param[in] endpt_name Existing endpoint name. |
| 340 | * @param[in] port New listening port. |
| 341 | * @return 0 on success, -1 on error. |
| 342 | */ |
| 343 | int nc_server_ssh_endpt_set_port(const char *endpt_name, uint16_t port); |
| 344 | |
| 345 | /** |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 346 | * @brief Add endpoint SSH host keys the server will identify itself with. Any RSA, DSA, and |
| 347 | * ECDSA keys can be added. However, a maximum of one key of each type will be used |
| 348 | * during SSH authentication, later keys replacing the earlier ones. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 349 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 350 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 351 | * @param[in] privkey_path Path to a private key. |
| 352 | * @return 0 on success, -1 on error. |
| 353 | */ |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 354 | int nc_server_ssh_endpt_add_hostkey(const char *endpt_name, const char *privkey_path); |
| 355 | |
| 356 | /** |
| 357 | * @brief Delete endpoint SSH host keys. Their order is preserved. |
| 358 | * |
| 359 | * @param[in] endpt_name Existing endpoint name. |
| 360 | * @param[in] privkey_path Path to a private key. NULL matches all the keys. |
| 361 | * @return 0 on success, -1 on error. |
| 362 | */ |
| 363 | int nc_server_ssh_endpt_del_hostkey(const char *endpt_name, const char *privkey_path); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 364 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 365 | /** |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 366 | * @brief Set endpoint SSH banner the server will send to every client. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 367 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 368 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 369 | * @param[in] banner SSH banner. |
| 370 | * @return 0 on success, -1 on error. |
| 371 | */ |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 372 | int nc_server_ssh_endpt_set_banner(const char *endpt_name, const char *banner); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 373 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 374 | /** |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 375 | * @brief Set endpoint accepted SSH authentication methods. All (publickey, password, interactive) |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 376 | * are supported by default. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 377 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 378 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 379 | * @param[in] auth_methods Accepted authentication methods bit field of NC_SSH_AUTH_TYPE. |
| 380 | * @return 0 on success, -1 on error. |
| 381 | */ |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 382 | int nc_server_ssh_endpt_set_auth_methods(const char *endpt_name, int auth_methods); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 383 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 384 | /** |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 385 | * @brief Set endpoint SSH authentication attempts of every client. 3 by default. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 386 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 387 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 5e6f4cc | 2016-01-20 13:27:44 +0100 | [diff] [blame] | 388 | * @param[in] auth_attempts Failed authentication attempts before a client is dropped. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 389 | * @return 0 on success, -1 on error. |
| 390 | */ |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 391 | int nc_server_ssh_endpt_set_auth_attempts(const char *endpt_name, uint16_t auth_attempts); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 392 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 393 | /** |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 394 | * @brief Set endpoint SSH authentication timeout. 10 seconds by default. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 395 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 396 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 397 | * @param[in] auth_timeout Number of seconds before an unauthenticated client is dropped. |
| 398 | * @return 0 on success, -1 on error. |
| 399 | */ |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 400 | int nc_server_ssh_endpt_set_auth_timeout(const char *endpt_name, uint16_t auth_timeout); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 401 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 402 | /** |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 403 | * @brief Add an endpoint authorized client SSH public key. This public key can be used for |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 404 | * publickey authentication afterwards. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 405 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 406 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 407 | * @param[in] pubkey_path Path to the public key. |
| 408 | * @param[in] username Username that the client with the public key must use. |
| 409 | * @return 0 on success, -1 on error. |
| 410 | */ |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 411 | int nc_server_ssh_endpt_add_authkey(const char *endpt_name, const char *pubkey_path, const char *username); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 412 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 413 | /** |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 414 | * @brief Remove an endpoint authorized client SSH public key. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 415 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 416 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 417 | * @param[in] pubkey_path Path to an authorized public key. NULL matches all the keys. |
| 418 | * @param[in] username Username for an authorized public key. NULL matches all the usernames. |
| 419 | * @return 0 on success, -1 on not finding any match. |
| 420 | */ |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 421 | int nc_server_ssh_endpt_del_authkey(const char *endpt_name, const char *pubkey_path, const char *username); |
| 422 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 423 | #endif /* NC_ENABLED_SSH */ |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 424 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 425 | #ifdef NC_ENABLED_TLS |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 426 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 427 | /** |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 428 | * @brief Change TLS endpoint listening address. |
| 429 | * |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 430 | * On error the previous listening socket (if any) is left untouched. |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 431 | * |
| 432 | * @param[in] endpt_name Existing endpoint name. |
| 433 | * @param[in] address New listening address. |
| 434 | * @return 0 on success, -1 on error. |
| 435 | */ |
| 436 | int nc_server_tls_endpt_set_address(const char *endpt_name, const char *address); |
| 437 | |
| 438 | /** |
| 439 | * @brief Change TLS endpoint listening port. |
| 440 | * |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 441 | * On error the previous listening socket (if any) is left untouched. |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 442 | * |
| 443 | * @param[in] endpt_name Existing endpoint name. |
| 444 | * @param[in] port New listening port. |
| 445 | * @return 0 on success, -1 on error. |
| 446 | */ |
| 447 | int nc_server_tls_endpt_set_port(const char *endpt_name, uint16_t port); |
| 448 | |
| 449 | /** |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 450 | * @brief Set server TLS certificate. Alternative to nc_tls_server_set_cert_path(). |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 451 | * There can only be one certificate for each key type, it is replaced if |
| 452 | * already set. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 453 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 454 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 455 | * @param[in] cert Base64-encoded certificate in ASN.1 DER encoding. |
| 456 | * @return 0 on success, -1 on error. |
| 457 | */ |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 458 | int nc_server_tls_endpt_set_cert(const char *endpt_name, const char *cert); |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 459 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 460 | /** |
| 461 | * @brief Set server TLS certificate. Alternative to nc_tls_server_set_cert(). |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 462 | * There can only be one certificate for each key type, it is replaced if |
| 463 | * already set. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 464 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 465 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 466 | * @param[in] cert_path Path to a certificate file in PEM format. |
| 467 | * @return 0 on success, -1 on error. |
| 468 | */ |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 469 | int nc_server_tls_endpt_set_cert_path(const char *endpt_name, const char *cert_path); |
Michal Vasko | 0457bb4 | 2016-01-08 15:49:13 +0100 | [diff] [blame] | 470 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 471 | /** |
| 472 | * @brief Set server TLS private key matching the certificate. |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 473 | * Alternative to nc_tls_server_set_key_path(). There can only be one of |
| 474 | * every key type, it is replaced if already set. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 475 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 476 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 477 | * @param[in] privkey Base64-encoded certificate in ASN.1 DER encoding. |
| 478 | * @param[in] is_rsa Whether \p privkey are the data of an RSA (1) or DSA (0) key. |
| 479 | * @return 0 on success, -1 on error. |
| 480 | */ |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 481 | int nc_server_tls_endpt_set_key(const char *endpt_name, const char *privkey, int is_rsa); |
Michal Vasko | c14e3c8 | 2016-01-11 16:14:30 +0100 | [diff] [blame] | 482 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 483 | /** |
| 484 | * @brief Set server TLS private key matching the certificate. |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 485 | * Alternative to nc_tls_server_set_key_path(). There can only be one of |
| 486 | * every key type, it is replaced if already set. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 487 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 488 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 489 | * @param[in] privkey_path Path to a private key file in PEM format. |
| 490 | * @return 0 on success, -1 on error. |
| 491 | */ |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 492 | int nc_server_tls_endpt_set_key_path(const char *endpt_name, const char *privkey_path); |
Michal Vasko | 0457bb4 | 2016-01-08 15:49:13 +0100 | [diff] [blame] | 493 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 494 | /** |
Michal Vasko | 5d2ad08 | 2016-02-09 11:47:59 +0100 | [diff] [blame] | 495 | * @brief Add a trusted certificate. Can be both a CA or a client one. Can be |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 496 | * safely used together with nc_server_tls_endpt_set_trusted_ca_paths(). |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 497 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 498 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 499 | * @param[in] cert_name Arbitary name identifying this certificate. |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 500 | * @param[in] cert Base64-enocded certificate in ASN.1 DER encoding. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 501 | * @return 0 on success, -1 on error. |
| 502 | */ |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 503 | int nc_server_tls_endpt_add_trusted_cert(const char *endpt_name, const char *cert_name, const char *cert); |
Michal Vasko | 0457bb4 | 2016-01-08 15:49:13 +0100 | [diff] [blame] | 504 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 505 | /** |
Michal Vasko | 5d2ad08 | 2016-02-09 11:47:59 +0100 | [diff] [blame] | 506 | * @brief Add a trusted certificate. Can be both a CA or a client one. Can be |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 507 | * safely used together with nc_server_tls_endpt_set_trusted_ca_paths(). |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 508 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 509 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 510 | * @param[in] cert_name Arbitary name identifying this certificate. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 511 | * @param[in] cert_path Path to a trusted certificate file in PEM format. |
| 512 | * @return 0 on success, -1 on error. |
| 513 | */ |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 514 | int nc_server_tls_endpt_add_trusted_cert_path(const char *endpt_name, const char *cert_name, const char *cert_path); |
Michal Vasko | 0457bb4 | 2016-01-08 15:49:13 +0100 | [diff] [blame] | 515 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 516 | /** |
| 517 | * @brief Set trusted Certificate Authority certificate locations. There can only be |
Michal Vasko | 5d2ad08 | 2016-02-09 11:47:59 +0100 | [diff] [blame] | 518 | * one file and one directory, they are replaced if already set. Can be safely |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 519 | * used with nc_server_tls_endpt_add_trusted_cert() or its _path variant. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 520 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 521 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 96830e3 | 2016-02-01 10:54:18 +0100 | [diff] [blame] | 522 | * @param[in] ca_file Path to a trusted CA cert store file in PEM format. Can be NULL. |
| 523 | * @param[in] ca_dir Path to a trusted CA cert store hashed directory (c_rehash utility |
| 524 | * can be used to create hashes) with PEM files. Can be NULL. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 525 | * @return 0 on success, -1 on error. |
| 526 | */ |
Michal Vasko | 96830e3 | 2016-02-01 10:54:18 +0100 | [diff] [blame] | 527 | int nc_server_tls_endpt_set_trusted_ca_paths(const char *endpt_name, const char *ca_file, const char *ca_dir); |
Michal Vasko | 0457bb4 | 2016-01-08 15:49:13 +0100 | [diff] [blame] | 528 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 529 | /** |
| 530 | * @brief Destroy and clean all the set certificates and private keys. CRLs and |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 531 | * CTN entries are not affected. |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 532 | * |
| 533 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 534 | * @param[in] cert_name Name of the certificate to delete. NULL deletes all the certificates. |
| 535 | * @return 0 on success, -1 on not found. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 536 | */ |
Michal Vasko | e2713da | 2016-08-22 16:06:40 +0200 | [diff] [blame] | 537 | int nc_server_tls_endpt_del_trusted_cert(const char *endpt_name, const char *cert_name); |
Michal Vasko | 0457bb4 | 2016-01-08 15:49:13 +0100 | [diff] [blame] | 538 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 539 | /** |
| 540 | * @brief Set Certificate Revocation List locations. There can only be one file |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 541 | * and one directory, they are replaced if already set. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 542 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 543 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 96830e3 | 2016-02-01 10:54:18 +0100 | [diff] [blame] | 544 | * @param[in] crl_file Path to a CRL store file in PEM format. Can be NULL. |
| 545 | * @param[in] crl_dir Path to a CRL store hashed directory (c_rehash utility |
| 546 | * can be used to create hashes) with PEM files. Can be NULL. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 547 | * @return 0 on success, -1 on error. |
| 548 | */ |
Michal Vasko | 96830e3 | 2016-02-01 10:54:18 +0100 | [diff] [blame] | 549 | int nc_server_tls_endpt_set_crl_paths(const char *endpt_name, const char *crl_file, const char *crl_dir); |
Michal Vasko | 0457bb4 | 2016-01-08 15:49:13 +0100 | [diff] [blame] | 550 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 551 | /** |
Michal Vasko | 96830e3 | 2016-02-01 10:54:18 +0100 | [diff] [blame] | 552 | * @brief Destroy and clean CRLs. Certificates, private keys, and CTN entries are |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 553 | * not affected. |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 554 | * |
| 555 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 556 | */ |
Michal Vasko | c6b9c7b | 2016-01-28 11:10:08 +0100 | [diff] [blame] | 557 | void nc_server_tls_endpt_clear_crls(const char *endpt_name); |
Michal Vasko | 0457bb4 | 2016-01-08 15:49:13 +0100 | [diff] [blame] | 558 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 559 | /** |
| 560 | * @brief Add a Cert-to-name entry. |
| 561 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 562 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 563 | * @param[in] id Priority of the entry. |
| 564 | * @param[in] fingerprint Matching certificate fingerprint. |
| 565 | * @param[in] map_type Type of username-certificate mapping. |
| 566 | * @param[in] name Specific username if \p map_type == NC_TLS_CTN_SPECIFED. Must be NULL otherwise. |
| 567 | * @return 0 on success, -1 on error. |
| 568 | */ |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 569 | int nc_server_tls_endpt_add_ctn(const char *endpt_name, uint32_t id, const char *fingerprint, NC_TLS_CTN_MAPTYPE map_type, const char *name); |
Michal Vasko | c14e3c8 | 2016-01-11 16:14:30 +0100 | [diff] [blame] | 570 | |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 571 | /** |
| 572 | * @brief Remove a Cert-to-name entry. |
| 573 | * |
Michal Vasko | da51477 | 2016-02-01 11:32:01 +0100 | [diff] [blame] | 574 | * @param[in] endpt_name Existing endpoint name. |
Michal Vasko | 1a38c86 | 2016-01-15 15:50:07 +0100 | [diff] [blame] | 575 | * @param[in] id Priority of the entry. -1 matches all the priorities. |
| 576 | * @param[in] fingerprint Fingerprint fo the entry. NULL matches all the fingerprints. |
| 577 | * @param[in] map_type Mapping type of the entry. 0 matches all the mapping types. |
| 578 | * @param[in] name Specific username for the entry. NULL matches all the usernames. |
| 579 | * @return 0 on success, -1 on not finding any match. |
| 580 | */ |
Michal Vasko | 3031aae | 2016-01-27 16:07:18 +0100 | [diff] [blame] | 581 | int nc_server_tls_endpt_del_ctn(const char *endpt_name, int64_t id, const char *fingerprint, NC_TLS_CTN_MAPTYPE map_type, const char *name); |
Michal Vasko | 0457bb4 | 2016-01-08 15:49:13 +0100 | [diff] [blame] | 582 | |
Radek Krejci | 53691be | 2016-02-22 13:58:37 +0100 | [diff] [blame] | 583 | #endif /* NC_ENABLED_TLS */ |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 584 | |
Michal Vasko | f835235 | 2016-05-24 09:11:36 +0200 | [diff] [blame] | 585 | /** |
Michal Vasko | c45ebd3 | 2016-05-25 11:17:36 +0200 | [diff] [blame] | 586 | * @brief Get session start time. |
Michal Vasko | f835235 | 2016-05-24 09:11:36 +0200 | [diff] [blame] | 587 | * |
| 588 | * @param[in] session Session to get the information from. |
Michal Vasko | c45ebd3 | 2016-05-25 11:17:36 +0200 | [diff] [blame] | 589 | * @return Session start time. |
Michal Vasko | f835235 | 2016-05-24 09:11:36 +0200 | [diff] [blame] | 590 | */ |
Michal Vasko | c45ebd3 | 2016-05-25 11:17:36 +0200 | [diff] [blame] | 591 | time_t nc_session_get_start_time(const struct nc_session *session); |
Michal Vasko | f835235 | 2016-05-24 09:11:36 +0200 | [diff] [blame] | 592 | |
Michal Vasko | 086311b | 2016-01-08 09:53:11 +0100 | [diff] [blame] | 593 | #endif /* NC_SESSION_SERVER_H_ */ |