Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 1 | /** |
| 2 | * \file libnetconf.h |
| 3 | * \author Radek Krejci <rkrejci@cesnet.cz> |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 4 | * \author Michal Vasko <mvasko@cesnet.cz> |
Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 5 | * \brief libnetconf2 main internal header. |
| 6 | * |
| 7 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 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 |
Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #ifndef NC_LIBNETCONF_H_ |
| 17 | #define NC_LIBNETCONF_H_ |
| 18 | |
| 19 | #include "config.h" |
Radek Krejci | 206fcd6 | 2015-10-07 15:42:48 +0200 | [diff] [blame] | 20 | #include "netconf.h" |
Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 21 | #include "log_p.h" |
Radek Krejci | ac6d347 | 2015-10-22 15:47:18 +0200 | [diff] [blame] | 22 | #include "session_p.h" |
| 23 | #include "messages_p.h" |
Radek Krejci | ac6d347 | 2015-10-22 15:47:18 +0200 | [diff] [blame] | 24 | |
| 25 | /* Tests whether string is empty or non-empty. */ |
| 26 | #define strisempty(str) ((str)[0] == '\0') |
| 27 | #define strnonempty(str) ((str)[0] != '\0') |
Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 28 | |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 29 | /** |
| 30 | * @mainpage About |
| 31 | * |
| 32 | * libnetconf2 is a NETCONF library in C handling NETCONF authentication and all NETCONF |
| 33 | * RPC communication both server and client-side. NETCONF datastore and session management is not a part of this library, |
| 34 | * but it helps a lot with the sessions. |
| 35 | * |
| 36 | * @section about-features Main Features |
| 37 | * |
| 38 | * - Creating SSH (using libssh) or TLS (using OpenSSL) authenticated NETCONF sessions. |
| 39 | * - Creating NETCONF sessions with a pre-established transport protocol |
| 40 | * (using this mechanism the communication can be tunneled through sshd(8), for instance). |
| 41 | * - Creating NETCONF Call Home sessions. |
| 42 | * - Creating, sending, receiving, and replying to RPCs. |
| 43 | * - Receiving notifications. |
| 44 | * |
| 45 | * - \todo Creating and sending notifications. |
| 46 | * |
| 47 | * @section about-license License |
| 48 | * |
| 49 | * Copyright (c) 2015-2016 CESNET, z.s.p.o. |
| 50 | * |
| 51 | * (The BSD 3-Clause License) |
| 52 | * |
| 53 | * Redistribution and use in source and binary forms, with or without |
| 54 | * modification, are permitted provided that the following conditions |
| 55 | * are met: |
| 56 | * 1. Redistributions of source code must retain the above copyright |
| 57 | * notice, this list of conditions and the following disclaimer. |
| 58 | * 2. Redistributions in binary form must reproduce the above copyright |
| 59 | * notice, this list of conditions and the following disclaimer in |
| 60 | * the documentation and/or other materials provided with the |
| 61 | * distribution. |
| 62 | * 3. Neither the name of the Company nor the names of its contributors |
| 63 | * may be used to endorse or promote products derived from this |
| 64 | * software without specific prior written permission. |
| 65 | */ |
| 66 | |
| 67 | /** |
| 68 | * @page howto How To ... |
| 69 | * |
| 70 | * - @subpage howtoinit |
| 71 | * - @subpage howtoclient |
| 72 | * - @subpage howtoserver |
| 73 | * - @subpage howtoclientcomm |
| 74 | * - @subpage howtoservercomm |
| 75 | */ |
| 76 | |
| 77 | /** |
| 78 | * @page howtoinit Init and Thread-safety Information |
| 79 | * |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 80 | * Before working with the library, it must be initialized using nc_client_init() |
Michal Vasko | 2639469 | 2016-03-17 16:24:55 +0100 | [diff] [blame] | 81 | * or nc_server_init(). Optionally, a client can use nc_client_set_schema_searchpath() |
| 82 | * to set the path to a directory with modules that will be loaded from there if they |
| 83 | * could not be downloaded from the server (it does not support \<get-schema\>). |
| 84 | * However, to be able to create at least the \<get-schema\> RPC, this directory must |
| 85 | * contain the module _ietf-netconf-monitoring_. If this directory is not set, |
| 86 | * the default _libnetconf2_ schema directory is used that includes this module |
| 87 | * and a few others. |
| 88 | * |
| 89 | * Based on how the library was compiled, also _libssh_ and/or |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 90 | * _libssh_/_libcrypto_ are initialized (for multi-threaded use) too. It is advised |
| 91 | * to compile _libnetconf2_, for instance, with TLS support even if you do not want |
| 92 | * to use _lnc2_ TLS functions, but only use _libssl/libcrypto_ functions in your |
| 93 | * application. You can then use _libnetconf2_ cleanup function and do not |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 94 | * trouble yourself with the cleanup. |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 95 | * |
| 96 | * To prevent any reachable memory at the end of your application, there |
| 97 | * are complementary destroy functions available. If your application is |
| 98 | * multi-threaded, call the destroy functions in the last thread, after all |
| 99 | * the other threads have ended. In every other thread you should call |
| 100 | * nc_thread_destroy() just before it exits. |
| 101 | * |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 102 | * If _libnetconf2_ is used in accordance with this information, there should |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 103 | * not be memory leaks of any kind at program exit. For thread-safety details |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 104 | * of _libssh_, _libssl_, and _libcrypto_, please refer to the corresponding project |
| 105 | * documentation. _libnetconf2_ thread-safety information is below. |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 106 | * |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 107 | * Client is __NOT__ thread-safe and there is no access control in the client |
| 108 | * functions at all. Server is __MOSTLY__ thread-safe meaning you can set all the |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 109 | * options simultaneously while listening for or accepting new sessions or |
| 110 | * polling the existing ones. It should even be safe to poll one session in |
| 111 | * several threads, but it is definitely discouraged. Generally, servers can |
| 112 | * use more threads without any problems as long as they keep their workflow sane |
| 113 | * (behavior such as freeing sessions only after no thread uses them or similar). |
| 114 | * |
| 115 | * Functions List |
| 116 | * -------------- |
| 117 | * |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 118 | * Available in __nc_client.h__. |
| 119 | * |
| 120 | * - nc_client_init() |
| 121 | * - nc_client_destroy() |
| 122 | * |
Michal Vasko | 2639469 | 2016-03-17 16:24:55 +0100 | [diff] [blame] | 123 | * - nc_client_set_schema_searchpath() |
| 124 | * - nc_client_get_schema_searchpath() |
| 125 | * |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 126 | * Available in __nc_server.h__. |
| 127 | * |
| 128 | * - nc_server_init() |
| 129 | * - nc_server_destroy() |
| 130 | * |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 131 | * Available in both __nc_client.h__ and __nc_server.h__. |
| 132 | * |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 133 | * - nc_thread_destroy() |
| 134 | */ |
| 135 | |
| 136 | /** |
| 137 | * @page howtoclient Client sessions |
| 138 | * |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 139 | * To connect to a NETCONF server, a NETCONF session must be established, |
| 140 | * which requires a working transport session. It is possible to create |
| 141 | * NETCONF sessions with SSH (using _libssh_) or TLS (using _libssl/libcrypto_) |
| 142 | * as the underlying transport protocol. It is also possible to establish |
| 143 | * the transport protocol outside _libnetconf2_ and then provide these file |
| 144 | * descriptors (FD) for full NETCONF session creation. |
| 145 | * |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 146 | * There are a lot of options for both an SSH and a TLS client. All of them |
| 147 | * have setters and getters so that there is no need to duplicate them in |
| 148 | * a client. |
| 149 | * |
| 150 | * SSH |
| 151 | * === |
| 152 | * |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 153 | * Connecting to a server using SSH does not strictly require to set any |
| 154 | * options, there are sensible default values for all the basic ones. |
| 155 | * Except all the SSH options, optionally some authetication callbacks can be set, |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 156 | * which are particulary useful in automated clients (passwords cannot be |
| 157 | * asked a user) or simply if any additional information is retrieved some |
| 158 | * other way than from standard terminal input. |
| 159 | * |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 160 | * Having the default options or changing any unsuitable ones, there are 2 functions |
| 161 | * to use for a new server connection. nc_connect_ssh() is the standard function |
| 162 | * that creates sessions using the set options. If there are some options, which |
| 163 | * cannot be changed with the provided API, there is nc_connect_libssh() available. |
| 164 | * It requires a _libssh_ session, in which all the SSH options can be modified |
| 165 | * and even the connection established. This allows for full customization and |
| 166 | * should fit any specific situation. |
| 167 | * |
| 168 | * New NETCONF sessions can also be created on existing authenticated SSH sessions. |
| 169 | * There is a new SSH channel needed, on which the NETCONF session is then created. |
| 170 | * Use nc_connect_ssh_channel() for this purpose. |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 171 | * |
| 172 | * Functions List |
| 173 | * -------------- |
| 174 | * |
| 175 | * Available in __nc_client.h__. |
| 176 | * |
| 177 | * - nc_client_ssh_set_auth_hostkey_check_clb() |
| 178 | * - nc_client_ssh_set_auth_password_clb() |
| 179 | * - nc_client_ssh_set_auth_interactive_clb() |
| 180 | * - nc_client_ssh_set_auth_privkey_passphrase_clb() |
| 181 | * - nc_client_ssh_add_keypair() |
| 182 | * - nc_client_ssh_del_keypair() |
| 183 | * - nc_client_ssh_get_keypair_count() |
| 184 | * - nc_client_ssh_get_keypair() |
| 185 | * - nc_client_ssh_set_auth_pref() |
| 186 | * - nc_client_ssh_get_auth_pref() |
| 187 | * - nc_client_ssh_set_username() |
| 188 | * - nc_client_ssh_get_username() |
| 189 | * |
| 190 | * - nc_connect_ssh() |
| 191 | * - nc_connect_libssh() |
| 192 | * - nc_connect_ssh_channel() |
| 193 | * |
| 194 | * |
| 195 | * TLS |
| 196 | * === |
| 197 | * |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 198 | * To connect to a server using TLS, there must be some client identification |
| 199 | * options set. Client must specify its certificate with a private key using |
| 200 | * nc_client_tls_set_cert_key_paths(). Also, the Certificate Authority of |
| 201 | * a server certificate must be considered trusted. Paths to all the trusted |
| 202 | * CA certificates can be set by nc_client_tls_set_trusted_ca_paths(). |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 203 | * |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 204 | * Then there are again 2 functions for connecting, nc_connect_tls() being |
| 205 | * the standard way of connecting. nc_connect_libssl() again enables |
| 206 | * to customize the TLS session in every way _libssl_ allows. |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 207 | * |
| 208 | * Functions List |
| 209 | * -------------- |
| 210 | * |
| 211 | * Available in __nc_client.h__. |
| 212 | * |
| 213 | * - nc_client_tls_set_cert_key_paths() |
| 214 | * - nc_client_tls_get_cert_key_paths() |
| 215 | * - nc_client_tls_set_trusted_ca_paths() |
| 216 | * - nc_client_tls_get_trusted_ca_paths() |
| 217 | * - nc_client_tls_set_crl_paths() |
| 218 | * - nc_client_tls_get_crl_paths() |
| 219 | * |
| 220 | * - nc_connect_tls() |
| 221 | * - nc_connect_libssl() |
| 222 | * |
| 223 | * |
| 224 | * FD |
| 225 | * == |
| 226 | * |
| 227 | * If you authenticated the connection using some tunneling software, you |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 228 | * can pass its file descriptors to _libnetconf2_ using nc_connect_inout(), |
| 229 | * which will continue to establish a full NETCONF session. |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 230 | * |
| 231 | * Funtions List |
| 232 | * ------------- |
| 233 | * |
| 234 | * Available in __nc_client.h__. |
| 235 | * |
| 236 | * - nc_connect_inout() |
| 237 | * |
| 238 | * |
| 239 | * Call Home |
| 240 | * ========= |
| 241 | * |
| 242 | * Call Home needs the same options set as standard SSH or TLS and the functions |
| 243 | * reflect it exactly. However, to accept a connection, the client must first |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 244 | * specify addresses and ports, which to listen on by nc_client_ssh_ch_add_bind_listen() |
| 245 | * and nc_client_tls_ch_add_bind_listen(). Then connections can be |
| 246 | * accepted using nc_accept_callhome(). |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 247 | * |
| 248 | * Functions List |
| 249 | * -------------- |
| 250 | * |
| 251 | * Available in __nc_client.h__. |
| 252 | * |
| 253 | * - nc_client_ssh_ch_set_auth_hostkey_check_clb() |
| 254 | * - nc_client_ssh_ch_set_auth_password_clb() |
| 255 | * - nc_client_ssh_ch_set_auth_interactive_clb() |
| 256 | * - nc_client_ssh_ch_set_auth_privkey_passphrase_clb() |
| 257 | * - nc_client_ssh_ch_add_bind_listen() |
| 258 | * - nc_client_ssh_ch_del_bind() |
| 259 | * - nc_client_ssh_ch_add_keypair() |
| 260 | * - nc_client_ssh_ch_del_keypair() |
| 261 | * - nc_client_ssh_ch_get_keypair_count() |
| 262 | * - nc_client_ssh_ch_get_keypair() |
| 263 | * - nc_client_ssh_ch_set_auth_pref() |
| 264 | * - nc_client_ssh_ch_get_auth_pref() |
| 265 | * - nc_client_ssh_ch_set_username() |
| 266 | * - nc_client_ssh_ch_get_username() |
| 267 | * |
| 268 | * - nc_client_tls_ch_add_bind_listen() |
| 269 | * - nc_client_tls_ch_del_bind() |
| 270 | * - nc_client_tls_ch_set_cert_key_paths() |
| 271 | * - nc_client_tls_ch_get_cert_key_paths() |
| 272 | * - nc_client_tls_ch_set_trusted_ca_paths() |
| 273 | * - nc_client_tls_ch_get_trusted_ca_paths() |
| 274 | * - nc_client_tls_ch_set_crl_paths() |
| 275 | * - nc_client_tls_ch_get_crl_paths() |
| 276 | * |
| 277 | * - nc_accept_callhome() |
| 278 | * |
| 279 | * |
| 280 | * Cleanup |
| 281 | * ======= |
| 282 | * |
| 283 | * These options and the schema searchpath are stored in dynamically |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 284 | * allocated memory. They are freed as a part of [destroying the client](@ref howtoinit). |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 285 | */ |
| 286 | |
| 287 | /** |
| 288 | * @page howtoserver Server sessions |
| 289 | * |
| 290 | * Init |
| 291 | * ==== |
| 292 | * |
Michal Vasko | a7b8ca5 | 2016-03-01 12:09:29 +0100 | [diff] [blame] | 293 | * Server takes an argument for its [initialization function](@ref howtoinit). |
| 294 | * In it, you set the server context, which determines what modules it |
| 295 | * supports and what capabilities to advertise. Few capabilities that |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 296 | * cannot be learnt from the context are set with separate functions |
| 297 | * nc_server_set_capab_withdefaults() and nc_server_set_capab_interleave(). |
| 298 | * Timeout for receiving the _hello_ message on a new session can be set |
| 299 | * by nc_server_set_hello_timeout() and the timeout for disconnecting |
| 300 | * an inactive session by nc_server_set_idle_timeout(). |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 301 | * |
| 302 | * Context does not only determine server modules, but its overall |
| 303 | * functionality as well. For every RPC the server should support, |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 304 | * an nc_rpc_clb callback should be set on that node in the context using nc_set_rpc_callback(). |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 305 | * Server then calls these as appropriate [during poll](@ref howtoservercomm). |
| 306 | * |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 307 | * Just like in the [client](@ref howtoclient), you can let _libnetconf2_ |
| 308 | * establish SSH or TLS transport or do it yourself and only provide the file |
| 309 | * descriptors of the connection. |
| 310 | * |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 311 | * Server options can be only set, there are no getters. |
| 312 | * |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 313 | * To be able to accept any connections, general endpoints must first be added |
| 314 | * with nc_server_add_endpt(). They can then be modified to accept either SSH, TLS, |
| 315 | * or both kinds of sessions. |
| 316 | * |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 317 | * Functions List |
| 318 | * -------------- |
| 319 | * |
| 320 | * Available in __nc_server.h__. |
| 321 | * |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 322 | * - nc_server_set_capab_withdefaults() |
| 323 | * - nc_server_set_capab_interleave() |
| 324 | * - nc_server_set_hello_timeout() |
| 325 | * - nc_server_set_idle_timeout() |
| 326 | * |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 327 | * - nc_server_add_endpt() |
| 328 | * - nc_server_del_endpt() |
| 329 | * |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 330 | * |
| 331 | * SSH |
| 332 | * === |
| 333 | * |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 334 | * To start listening for SSH connections you must set the address |
| 335 | * and port to listen on for a particular endpoint using nc_server_ssh_endpt_set_address() |
| 336 | * and nc_server_endpt_set_port(). |
| 337 | * To then successfully accept an SSH session you must also set the host key using |
| 338 | * nc_server_ssh_endpt_add_hostkey(). |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 339 | * |
| 340 | * Functions List |
| 341 | * -------------- |
| 342 | * |
| 343 | * Available in __nc_server.h__. |
| 344 | * |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 345 | * - nc_server_ssh_endpt_set_address() |
| 346 | * - nc_server_ssh_endpt_set_port() |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 347 | * |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 348 | * - nc_server_ssh_endpt_add_hostkey() |
| 349 | * - nc_server_ssh_endpt_del_hostkey() |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 350 | * - nc_server_ssh_endpt_set_banner() |
| 351 | * - nc_server_ssh_endpt_set_auth_methods() |
| 352 | * - nc_server_ssh_endpt_set_auth_attempts() |
| 353 | * - nc_server_ssh_endpt_set_auth_timeout() |
| 354 | * - nc_server_ssh_endpt_add_authkey() |
| 355 | * - nc_server_ssh_endpt_del_authkey() |
| 356 | * |
| 357 | * |
| 358 | * TLS |
| 359 | * === |
| 360 | * |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 361 | * TLS works with endpoints too, but its options differ |
| 362 | * significantly from the SSH ones, especially in the _cert-to-name_ |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 363 | * options that TLS uses to derive usernames from client certificates. |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 364 | * So, after starting listening on an endpoint by calling nc_server_tls_endpt_set_address() |
| 365 | * and nc_server_tls_endpt_set_port(), |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 366 | * you need to set the server certificate (nc_server_tls_endpt_set_cert() |
| 367 | * or nc_server_tls_endpt_set_cert_path()) and private key (nc_server_tls_endpt_set_key() |
| 368 | * or nc_server_tls_endpt_set_key_path()). |
| 369 | * |
| 370 | * To accept client certificates, they must first be considered trusted, |
| 371 | * which you have three ways of achieving. You can add each of their Certificate Authority |
| 372 | * certificates to the trusted ones or mark a specific client certificate |
| 373 | * as trusted using nc_server_tls_endpt_add_trusted_cert(). Lastly, you can |
| 374 | * set paths with all the trusted CA certificates with nc_server_tls_endpt_set_trusted_ca_paths(). |
| 375 | * |
| 376 | * Then, from each trusted client certificate a username must be derived |
| 377 | * for the NETCONF session. This is accomplished by finding a matching |
| 378 | * _cert-to-name_ entry. They are added using nc_server_tls_endpt_add_ctn(). |
| 379 | * |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 380 | * If you need to remove trusted certificates, you can do so with nc_server_tls_endpt_del_trusted_cert(). |
| 381 | * To clear all Certificate Revocation Lists use nc_server_tls_endpt_clear_crls(). |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 382 | * |
| 383 | * Functions List |
| 384 | * -------------- |
| 385 | * |
| 386 | * Available in __nc_server.h__. |
| 387 | * |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 388 | * - nc_server_tls_endpt_set_address() |
| 389 | * - nc_server_tls_endpt_set_port() |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 390 | * |
| 391 | * - nc_server_tls_endpt_set_cert() |
| 392 | * - nc_server_tls_endpt_set_cert_path() |
| 393 | * - nc_server_tls_endpt_set_key() |
| 394 | * - nc_server_tls_endpt_set_key_path() |
| 395 | * - nc_server_tls_endpt_add_trusted_cert() |
| 396 | * - nc_server_tls_endpt_add_trusted_cert_path() |
| 397 | * - nc_server_tls_endpt_set_trusted_ca_paths() |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 398 | * - nc_server_tls_endpt_del_trusted_cert(); |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 399 | * - nc_server_tls_endpt_set_crl_paths() |
| 400 | * - nc_server_tls_endpt_clear_crls() |
| 401 | * - nc_server_tls_endpt_add_ctn() |
| 402 | * - nc_server_tls_endpt_del_ctn() |
| 403 | * |
| 404 | * FD |
| 405 | * == |
| 406 | * |
| 407 | * If you used a tunneling software, which does its own authentication, |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 408 | * you can accept a NETCONF session on its file descriptors with |
| 409 | * nc_accept_inout(). |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 410 | * |
| 411 | * Functions List |
| 412 | * -------------- |
| 413 | * |
| 414 | * Available in __nc_server.h__. |
| 415 | * |
| 416 | * - nc_accept_inout() |
| 417 | * |
| 418 | * |
| 419 | * Call Home |
| 420 | * ========= |
| 421 | * |
| 422 | * Call Home does not work with endpoints like standard sessions. |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 423 | * Connecting is similar to the [client](@ref howtoclient), just call |
| 424 | * nc_connect_callhome_ssh() or nc_connect_callhome_tls(). Any options |
| 425 | * must be reset manually by nc_server_ssh_ch_clear_opts() |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 426 | * or using nc_server_tls_ch_del_trusted_cert() and nc_server_tls_ch_clear_crls() |
| 427 | * after another Call Home session (with different options than the previous one) |
| 428 | * is to be established. Also, monitoring of these sessions is up to the application. |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 429 | * |
| 430 | * Functions List |
| 431 | * -------------- |
| 432 | * |
| 433 | * Available in __nc_server.h__. |
| 434 | * |
| 435 | * - nc_connect_callhome_ssh() |
| 436 | * - nc_connect_callhome_tls() |
| 437 | * |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 438 | * - nc_server_ssh_ch_add_hostkey() |
| 439 | * - nc_server_ssh_ch_del_hostkey() |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 440 | * - nc_server_ssh_ch_set_banner() |
| 441 | * - nc_server_ssh_ch_set_auth_methods() |
| 442 | * - nc_server_ssh_ch_set_auth_attempts() |
| 443 | * - nc_server_ssh_ch_set_auth_timeout() |
| 444 | * - nc_server_ssh_ch_add_authkey() |
| 445 | * - nc_server_ssh_ch_del_authkey() |
| 446 | * - nc_server_ssh_ch_clear_opts() |
| 447 | * |
| 448 | * - nc_server_tls_ch_set_cert() |
| 449 | * - nc_server_tls_ch_set_cert_path() |
| 450 | * - nc_server_tls_ch_set_key() |
| 451 | * - nc_server_tls_ch_set_key_path() |
| 452 | * - nc_server_tls_ch_add_trusted_cert() |
| 453 | * - nc_server_tls_ch_add_trusted_cert_path() |
| 454 | * - nc_server_tls_ch_set_trusted_ca_paths() |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 455 | * - nc_server_tls_ch_del_trusted_cert(); |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 456 | * - nc_server_tls_ch_set_crl_paths() |
| 457 | * - nc_server_tls_ch_clear_crls() |
| 458 | * - nc_server_tls_ch_add_ctn() |
| 459 | * - nc_server_tls_ch_del_ctn() |
| 460 | * - nc_server_tls_ch_clear_opts() |
| 461 | * |
| 462 | * |
| 463 | * Connecting And Cleanup |
| 464 | * ====================== |
| 465 | * |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 466 | * When accepting connections with nc_accept(), all the endpoints are examined |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 467 | * and the first with a pending connection is used. To remove all |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 468 | * the endpoints and free any used dynamic memory, [destroy](@ref howtoinit) the server. |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 469 | * |
| 470 | * Functions List |
| 471 | * -------------- |
| 472 | * |
| 473 | * Available in __nc_server.h__. |
| 474 | * |
| 475 | * - nc_accept() |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 476 | */ |
| 477 | |
| 478 | /** |
| 479 | * @page howtoclientcomm Client communication |
| 480 | * |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 481 | * To send RPCs on a session, you simply create an RPC, send it using nc_send_rpc(), |
| 482 | * and then wait for a reply using nc_recv_reply(). If you are subscribed, there are 2 ways |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 483 | * of receiving notifications. Either you wait for them the same way |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 484 | * as for standard replies with nc_recv_notif() or you create a dispatcher |
| 485 | * with nc_recv_notif_dispatch() that asynchronously (in a separate thread) |
| 486 | * reads notifications and passes them to your callback. |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 487 | * |
| 488 | * Functions List |
| 489 | * -------------- |
| 490 | * |
| 491 | * Available in __nc_client.h__. |
| 492 | * |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 493 | * - nc_rpc_act_generic() |
| 494 | * - nc_rpc_act_generic_xml() |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 495 | * - nc_rpc_getconfig() |
| 496 | * - nc_rpc_edit() |
| 497 | * - nc_rpc_copy() |
| 498 | * - nc_rpc_delete() |
| 499 | * - nc_rpc_lock() |
| 500 | * - nc_rpc_unlock() |
| 501 | * - nc_rpc_get() |
| 502 | * - nc_rpc_kill() |
| 503 | * - nc_rpc_commit() |
| 504 | * - nc_rpc_discard() |
| 505 | * - nc_rpc_cancel() |
| 506 | * - nc_rpc_validate() |
| 507 | * - nc_rpc_getschema() |
| 508 | * - nc_rpc_subscribe() |
| 509 | * |
| 510 | * - nc_send_rpc() |
| 511 | * - nc_recv_reply() |
| 512 | * - nc_recv_notif() |
| 513 | * - nc_recv_notif_dispatch() |
| 514 | */ |
| 515 | |
| 516 | /** |
| 517 | * @page howtoservercomm Server communication |
| 518 | * |
| 519 | * Once at least one session is established, an nc_pollsession structure |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 520 | * should be created with nc_ps_new(), filled with the session using |
| 521 | * nc_ps_add_session() and finally polled with nc_ps_poll(). Based on |
| 522 | * the return value from the poll, further actions can be taken. More |
| 523 | * sessions can be polled at the same time and any requests received on |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 524 | * the sessions are [handled internally](@ref howtoserver). |
| 525 | * |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 526 | * If an SSH NETCONF session asks for a new channel, you can accept |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 527 | * this request with nc_ps_accept_ssh_channel() or nc_session_accept_ssh_channel() |
| 528 | * depending on the structure you want to use as the argument. |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 529 | * |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 530 | * Functions List |
| 531 | * -------------- |
| 532 | * |
Michal Vasko | 15b7a98 | 2016-03-02 10:53:31 +0100 | [diff] [blame] | 533 | * Available in __nc_server.h__. |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 534 | * |
| 535 | * - nc_ps_new() |
| 536 | * - nc_ps_add_session() |
| 537 | * - nc_ps_del_session() |
Michal Vasko | 0fdb7ac | 2016-03-01 09:03:12 +0100 | [diff] [blame] | 538 | * - nc_ps_session_count() |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 539 | * - nc_ps_free() |
| 540 | * |
| 541 | * - nc_ps_poll() |
| 542 | * - nc_ps_clear() |
| 543 | * - nc_ps_accept_ssh_channel() |
Michal Vasko | 3a889fd | 2016-09-30 12:16:37 +0200 | [diff] [blame] | 544 | * - nc_session_accept_ssh_channel() |
Michal Vasko | fdfd9dd | 2016-02-29 10:18:46 +0100 | [diff] [blame] | 545 | */ |
| 546 | |
Radek Krejci | d0d1952 | 2015-09-02 13:49:25 +0200 | [diff] [blame] | 547 | #endif /* NC_LIBNETCONF_H_ */ |