blob: 103416e5f5657caff3e0c8648143488696a671f3 [file] [log] [blame]
romanc1d2b092023-02-02 08:58:27 +01001/**
romane028ef92023-02-24 16:33:08 +01002 * @file server_config.h
romanc1d2b092023-02-02 08:58:27 +01003 * @author Roman Janota <janota@cesnet.cz>
4 * @brief libnetconf2 server configuration
5 *
6 * @copyright
roman3f9b65c2023-06-05 14:26:58 +02007 * Copyright (c) 2023 CESNET, z.s.p.o.
romanc1d2b092023-02-02 08:58:27 +01008 *
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
12 *
13 * https://opensource.org/licenses/BSD-3-Clause
14 */
15
16#ifndef NC_CONFIG_SERVER_H_
17#define NC_CONFIG_SERVER_H_
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
roman3f9b65c2023-06-05 14:26:58 +020023#include <stdarg.h>
romanc1d2b092023-02-02 08:58:27 +010024#include <stdint.h>
25
roman3f9b65c2023-06-05 14:26:58 +020026#include <libyang/libyang.h>
27
romanc1d2b092023-02-02 08:58:27 +010028#include "session.h"
romanc1d2b092023-02-02 08:58:27 +010029
30/**
romanf02273a2023-05-25 09:44:11 +020031 * @brief Configure server based on the given diff data.
romanc1d2b092023-02-02 08:58:27 +010032 *
romanf6f37a52023-05-25 14:27:51 +020033 * Expected data are a validated instance of a ietf-netconf-server YANG data.
romanc1d2b092023-02-02 08:58:27 +010034 * The data must be in the diff format and supported operations are: create, replace,
35 * delete and none. Context must already have implemented the required modules, see
36 * ::nc_config_load_modules().
37 *
romanf6f37a52023-05-25 14:27:51 +020038 * @param[in] diff ietf-netconf-server YANG diff data.
romanc1d2b092023-02-02 08:58:27 +010039 * @return 0 on success, 1 on error.
40 */
romanf6f37a52023-05-25 14:27:51 +020041int nc_server_config_setup_diff(const struct lyd_node *diff);
romanc1d2b092023-02-02 08:58:27 +010042
43/**
romanf02273a2023-05-25 09:44:11 +020044 * @brief Configure server based on the given data.
45 *
46 * Expected data is a validated instance of a ietf-netconf-server YANG data.
47 * Behaves as if all the nodes in data had the replace operation. That means that the current configuration will be deleted
48 * and just the given data will all be applied.
romanf6f37a52023-05-25 14:27:51 +020049 * The data must not contain any operation attribute, see ::nc_config_setup_diff() which works with diff.
romanf02273a2023-05-25 09:44:11 +020050 * Context must already have implemented the required modules, see * ::nc_config_load_modules().
51 *
52 * @param[in] data ietf-netconf-server YANG data.
53 * @return 0 on success, 1 on error.
54 */
romanf6f37a52023-05-25 14:27:51 +020055int nc_server_config_setup_data(const struct lyd_node *data);
romanf02273a2023-05-25 09:44:11 +020056
57/**
romanc1d2b092023-02-02 08:58:27 +010058 * @brief Configure server based on the given ietf-netconf-server YANG data.
romanf6f37a52023-05-25 14:27:51 +020059 * Wrapper around ::nc_config_setup_server_data() hiding work with parsing the data.
romanc1d2b092023-02-02 08:58:27 +010060 *
61 * @param[in] ctx libyang context.
62 * @param[in] path Path to the file with YANG data in XML format.
63 * @return 0 on success, 1 on error.
64 */
65int nc_server_config_setup_path(const struct ly_ctx *ctx, const char *path);
66
67/**
68 * @brief Implements all the required modules and their features in the context.
69 * Needs to be called before any other configuration functions.
70 *
71 * If ctx is :
72 * - NULL: a new context will be created and if the call is successful you have to free it,
73 * - non NULL: modules will simply be implemented.
74 *
75 * Implemented modules: ietf-netconf-server, ietf-x509-cert-to-name, ietf-crypto-types,
76 * ietf-tcp-common, ietf-ssh-common, iana-ssh-encryption-algs, iana-ssh-key-exchange-algs,
77 * iana-ssh-mac-algs, iana-ssh-public-key-algs, ietf-keystore, ietf-ssh-server, ietf-truststore,
78 * ietf-tls-server and libnetconf2-netconf-server.
79 *
80 * @param[in, out] ctx Optional context in which the modules will be implemented. Created if ctx is null.
81 * @return 0 on success, 1 on error.
82 */
83int nc_server_config_load_modules(struct ly_ctx **ctx);
84
roman2eab4742023-06-06 10:00:26 +020085#ifdef NC_ENABLED_SSH_TLS
86
romanc1d2b092023-02-02 08:58:27 +010087/**
roman9b1379c2023-03-31 10:11:10 +020088 * @brief Creates new YANG configuration data nodes for a local-address and local-port.
89 *
roman9b1379c2023-03-31 10:11:10 +020090 * @param[in] ctx libyang context.
91 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman3f9b65c2023-06-05 14:26:58 +020092 * @param[in] transport Either SSH or TLS transport for the given endpoint.
93 * @param[in] address New listening address.
94 * @param[in] port New listening port.
roman142718b2023-06-29 09:15:29 +020095 * If an endpoint with this identifier already exists, its address and port will be overriden.
roman9b1379c2023-03-31 10:11:10 +020096 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
97 * Otherwise the new YANG data will be added to the previous data and may override it.
98 * @return 0 on success, non-zero otherwise.
roman45cec4e2023-02-17 10:21:39 +010099 */
roman3f9b65c2023-06-05 14:26:58 +0200100int nc_server_config_new_address_port(const struct ly_ctx *ctx, const char *endpt_name, NC_TRANSPORT_IMPL transport,
roman142718b2023-06-29 09:15:29 +0200101 const char *address, uint16_t port, struct lyd_node **config);
roman3f9b65c2023-06-05 14:26:58 +0200102
103/**
104 * @brief Creates new YANG configuration data nodes for a hostkey.
105 *
106 * @param[in] ctx libyang context.
107 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200108 * If an endpoint with this identifier already exists, its hostkey might be changed.
roman3f9b65c2023-06-05 14:26:58 +0200109 * @param[in] hostkey_name Arbitrary identifier of the hostkey.
roman142718b2023-06-29 09:15:29 +0200110 * If a hostkey with this identifier already exists, its contents will be changed.
roman3f9b65c2023-06-05 14:26:58 +0200111 * @param[in] privkey_path Path to a file containing a private key.
112 * The private key has to be in a PEM format. Only RSA and ECDSA keys are supported.
113 * @param[in] pubkey_path Path to a file containing a public key. If NULL, public key will be
114 * generated from the private key.
115 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
116 * Otherwise the new YANG data will be added to the previous data and may override it.
117 * @return 0 on success, non-zero otherwise.
118 */
119int nc_server_config_new_ssh_hostkey(const struct ly_ctx *ctx,
120 const char *endpt_name, const char *hostkey_name, const char *privkey_path, const char *pubkey_path, struct lyd_node **config);
roman9b1379c2023-03-31 10:11:10 +0200121
122/**
123 * @brief Creates new YANG configuration data nodes for host-key algorithms replacing any previous ones.
124 *
125 * Supported algorithms are: ssh-ed25519, ecdsa-sha2-nistp256, ecdsa-sha2-nistp384, ecdsa-sha2-nistp521,
126 * rsa-sha2-512, rsa-sha2-256, ssh-rsa and ssh-dss.
127 *
128 * @param[in] ctx libyang context
129 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200130 * If an endpoint with this identifier already exists, its host-key algorithms will be replaced.
roman9b1379c2023-03-31 10:11:10 +0200131 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
132 * Otherwise the new YANG data will be added to the previous data and may override it.
133 * @param[in] alg_count Number of following algorithms.
134 * @param[in] ... String literals of host-key algorithms in a decreasing order of preference.
135 * @return 0 on success, non-zero otherwise.
136 */
roman466719d2023-05-05 16:14:37 +0200137int nc_server_config_new_ssh_host_key_algs(const struct ly_ctx *ctx, const char *endpt_name,
roman9b1379c2023-03-31 10:11:10 +0200138 struct lyd_node **config, int alg_count, ...);
139
140/**
141 * @brief Creates new YANG configuration data nodes for key exchange algorithms replacing any previous ones.
142 *
143 * Supported algorithms are: diffie-hellman-group-exchange-sha1, curve25519-sha256, ecdh-sha2-nistp256,
144 * ecdh-sha2-nistp384, ecdh-sha2-nistp521, diffie-hellman-group18-sha512, diffie-hellman-group16-sha512,
145 * diffie-hellman-group-exchange-sha256 and diffie-hellman-group14-sha256.
146 *
147 * @param[in] ctx libyang context
148 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200149 * If an endpoint with this identifier already exists, its key exchange algorithms will be replaced.
roman9b1379c2023-03-31 10:11:10 +0200150 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
151 * Otherwise the new YANG data will be added to the previous data and may override it.
152 * @param[in] alg_count Number of following algorithms.
153 * @param[in] ... String literals of key exchange algorithms in a decreasing order of preference.
154 * @return 0 on success, non-zero otherwise.
155 */
roman466719d2023-05-05 16:14:37 +0200156int nc_server_config_new_ssh_key_exchange_algs(const struct ly_ctx *ctx, const char *endpt_name, struct lyd_node **config,
roman9b1379c2023-03-31 10:11:10 +0200157 int alg_count, ...);
158
159/**
160 * @brief Creates new YANG configuration data nodes for encryption algorithms replacing any previous ones.
161 *
162 * Supported algorithms are: aes256-ctr, aes192-ctr, aes128-ctr, aes256-cbc, aes192-cbc, aes128-cbc, blowfish-cbc
163 * triple-des-cbc and none.
164 *
165 * @param[in] ctx libyang context
166 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200167 * If an endpoint with this identifier already exists, its encryption algorithms will be replaced.
roman9b1379c2023-03-31 10:11:10 +0200168 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
169 * Otherwise the new YANG data will be added to the previous data and may override it.
170 * @param[in] alg_count Number of following algorithms.
171 * @param[in] ... String literals of encryption algorithms in a decreasing order of preference.
172 * @return 0 on success, non-zero otherwise.
173 */
roman466719d2023-05-05 16:14:37 +0200174int nc_server_config_new_ssh_encryption_algs(const struct ly_ctx *ctx, const char *endpt_name, struct lyd_node **config,
roman9b1379c2023-03-31 10:11:10 +0200175 int alg_count, ...);
176
177/**
178 * @brief Creates new YANG configuration data nodes for mac algorithms replacing any previous ones.
179 *
180 * Supported algorithms are: hmac-sha2-256, hmac-sha2-512 and hmac-sha1.
181 *
182 * @param[in] ctx libyang context
183 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200184 * If an endpoint with this identifier already exists, its mac algorithms will be replaced.
roman9b1379c2023-03-31 10:11:10 +0200185 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
186 * Otherwise the new YANG data will be added to the previous data and may override it.
187 * @param[in] alg_count Number of following algorithms.
188 * @param[in] ... String literals of mac algorithms in a decreasing order of preference.
189 * @return 0 on success, non-zero otherwise.
190 */
roman466719d2023-05-05 16:14:37 +0200191int nc_server_config_new_ssh_mac_algs(const struct ly_ctx *ctx, const char *endpt_name, struct lyd_node **config,
roman9b1379c2023-03-31 10:11:10 +0200192 int alg_count, ...);
193
194/**
195 * @brief Creates new YANG configuration data nodes for a client, which supports the public key authentication method.
196 *
roman9b1379c2023-03-31 10:11:10 +0200197 * @param[in] ctx libyang context.
198 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200199 * If an endpoint with this identifier already exists, its user might be changed.
roman9b1379c2023-03-31 10:11:10 +0200200 * @param[in] user_name Arbitrary identifier of the user.
roman142718b2023-06-29 09:15:29 +0200201 * If an user with this identifier already exists, its contents will be changed.
roman9b1379c2023-03-31 10:11:10 +0200202 * @param[in] pubkey_name Arbitrary identifier of the user's public key.
roman142718b2023-06-29 09:15:29 +0200203 * If a public key with this identifier already exists for this user, its contents will be changed.
roman3f9b65c2023-06-05 14:26:58 +0200204 * @param[in] pubkey_path Path to a file containing the user's public key.
roman9b1379c2023-03-31 10:11:10 +0200205 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
206 * Otherwise the new YANG data will be added to the previous data and may override it.
207 * @return 0 on success, non-zero otherwise.
208 */
roman3f9b65c2023-06-05 14:26:58 +0200209int nc_server_config_new_ssh_client_auth_pubkey(const struct ly_ctx *ctx, const char *endpt_name,
210 const char *user_name, const char *pubkey_name, const char *pubkey_path, struct lyd_node **config);
roman9b1379c2023-03-31 10:11:10 +0200211
212/**
213 * @brief Creates new YANG configuration data nodes for a client, which supports the password authentication method.
214 *
215 * This function sets the password for the given user.
216 *
roman9b1379c2023-03-31 10:11:10 +0200217 * @param[in] ctx libyang context.
218 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200219 * If an endpoint with this identifier already exists, its user might be changed.
roman9b1379c2023-03-31 10:11:10 +0200220 * @param[in] user_name Arbitrary identifier of the user.
roman142718b2023-06-29 09:15:29 +0200221 * If an user with this identifier already exists, its contents will be changed.
roman3f9b65c2023-06-05 14:26:58 +0200222 * @param[in] password Cleartext user's password.
roman9b1379c2023-03-31 10:11:10 +0200223 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
224 * Otherwise the new YANG data will be added to the previous data and may override it.
225 * @return 0 on success, non-zero otherwise.
226 */
roman3f9b65c2023-06-05 14:26:58 +0200227int nc_server_config_new_ssh_client_auth_password(const struct ly_ctx *ctx, const char *endpt_name,
228 const char *user_name, const char *password, struct lyd_node **config);
roman9b1379c2023-03-31 10:11:10 +0200229
230/**
231 * @brief Creates new YANG configuration data nodes for a client, which supports the none authentication method.
232 *
233 * @param[in] ctx libyang context.
234 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200235 * If an endpoint with this identifier already exists, its user might be changed.
roman9b1379c2023-03-31 10:11:10 +0200236 * @param[in] user_name Arbitrary identifier of the user.
roman142718b2023-06-29 09:15:29 +0200237 * If an user with this identifier already exists, its contents will be changed.
roman9b1379c2023-03-31 10:11:10 +0200238 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
239 * Otherwise the new YANG data will be added to the previous data and may override it.
240 * @return 0 on success, non-zero otherwise.
241 */
roman466719d2023-05-05 16:14:37 +0200242int nc_server_config_new_ssh_client_auth_none(const struct ly_ctx *ctx, const char *endpt_name,
roman9b1379c2023-03-31 10:11:10 +0200243 const char *user_name, struct lyd_node **config);
244
245/**
246 * @brief Creates new YANG configuration data nodes for a client, which supports the interactive authentication method.
247 *
roman9b1379c2023-03-31 10:11:10 +0200248 * @param[in] ctx libyang context.
249 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200250 * If an endpoint with this identifier already exists, its user might be changed.
roman9b1379c2023-03-31 10:11:10 +0200251 * @param[in] user_name Arbitrary identifier of the user.
roman142718b2023-06-29 09:15:29 +0200252 * If an user with this identifier already exists, its contents will be changed.
roman3f9b65c2023-06-05 14:26:58 +0200253 * @param[in] pam_config_name Name of the PAM configuration file.
254 * @param[in] pam_config_name Optional. The absolute path to the directory in which the configuration file
255 * with the name conf_name is located. A newer version (>= 1.4) of PAM library is required to be able to specify
256 * the path. If NULL is passed, then the PAM's system directories will be searched (usually /etc/pam.d/).
roman9b1379c2023-03-31 10:11:10 +0200257 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
258 * Otherwise the new YANG data will be added to the previous data and may override it.
259 * @return 0 on success, non-zero otherwise.
260 */
roman3f9b65c2023-06-05 14:26:58 +0200261int nc_server_config_new_ssh_client_auth_interactive(const struct ly_ctx *ctx, const char *endpt_name,
262 const char *user_name, const char *pam_config_name, const char *pam_config_dir, struct lyd_node **config);
263
roman3f9b65c2023-06-05 14:26:58 +0200264/**
roman2e797ef2023-06-19 10:47:49 +0200265 * @brief Creates new YANG configuration data nodes, which will be a reference to another SSH endpoint's clients.
266 *
267 * Whenever an user tries to connect to the referencing endpoint, all of its users will be tried first. If no match is
268 * found, the referenced endpoint's configured clients will be tried.
269 *
270 * @param[in] ctx libyang context
271 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200272 * If an endpoint with this identifier already exists, its contents will be changed.
roman2e797ef2023-06-19 10:47:49 +0200273 * @param[in] referenced_endpt Identifier of an endpoint, which has to exist whenever this data
274 * is applied. The referenced endpoint can reference another one and so on, but there mustn't be a cycle.
275 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
276 * Otherwise the new YANG data will be added to the previous data and may override it.
277 * @return 0 on success, non-zero otherwise.
278 */
279int nc_config_new_ssh_endpoint_client_reference(const struct ly_ctx *ctx, const char *endpt_name,
280 const char *referenced_endpt, struct lyd_node **config);
281
282/**
roman3f9b65c2023-06-05 14:26:58 +0200283 * @brief Creates new YANG configuration data nodes for a server's certificate.
284 *
285 * @param[in] ctx libyang context.
286 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200287 * If an endpoint with this identifier already exists, its server certificate will be changed.
roman3f9b65c2023-06-05 14:26:58 +0200288 * @param[in] pubkey_path Optional path to the server's public key file. If not provided,
289 * it will be generated from the private key.
290 * @param[in] privkey_path Path to the server's private key file.
291 * @param[in] certificate_path Path to the server's certificate file.
292 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
293 * Otherwise the new YANG data will be added to the previous data and may override it.
294 * @return 0 on success, non-zero otherwise.
295 */
296int nc_server_config_new_tls_server_certificate(const struct ly_ctx *ctx, const char *endpt_name, const char *pubkey_path,
297 const char *privkey_path, const char *certificate_path, struct lyd_node **config);
298
299/**
300 * @brief Creates new YANG configuration data nodes for a client's (end-entity) certificate.
301 *
302 * @param[in] ctx libyang context.
303 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200304 * If an endpoint with this identifier already exists, its contents will be changed.
roman3f9b65c2023-06-05 14:26:58 +0200305 * @param[in] cert_name Arbitrary identifier of the client's certificate.
306 * If a client certificate with this indetifier already exists, it will be changed.
307 * @param[in] cert_path Path to the client's certificate file.
308 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
309 * Otherwise the new YANG data will be added to the previous data and may override it.
310 * @return 0 on success, non-zero otherwise.
311 */
312int nc_server_config_new_tls_client_certificate(const struct ly_ctx *ctx, const char *endpt_name, const char *cert_name,
313 const char *cert_path, struct lyd_node **config);
314
315/**
316 * @brief Creates new YANG configuration data nodes for a client certificate authority (trust-anchor) certificate.
317 *
318 * @param[in] ctx libyang context.
319 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200320 * If an endpoint with this identifier already exists, its contents will be changed.
roman3f9b65c2023-06-05 14:26:58 +0200321 * @param[in] cert_name Arbitrary identifier of the certificate authority certificate.
322 * If a CA with this indetifier already exists, it will be changed.
323 * @param[in] cert_path Path to the CA certificate file.
324 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
325 * Otherwise the new YANG data will be added to the previous data and may override it.
326 * @return 0 on success, non-zero otherwise.
327 */
328int nc_server_config_new_tls_client_ca(const struct ly_ctx *ctx, const char *endpt_name, const char *cert_name,
329 const char *cert_path, struct lyd_node **config);
330
331/**
332 * @brief Creates new YANG configuration data nodes for a cert-to-name entry.
333 *
334 * @param[in] ctx libyang context.
335 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200336 * If an endpoint with this identifier already exists, its contents will be changed.
roman3f9b65c2023-06-05 14:26:58 +0200337 * @param[in] id ID of the entry. The lower the ID, the higher the priority of the entry (it will be checked earlier).
338 * @param[in] fingerprint Optional fingerprint of the entry. The fingerprint should always be set, however if it is
339 * not set, it will match any certificate. Entry with no fingerprint should therefore be placed only as the last entry.
340 * @param[in] map_type Mapping username to the certificate option.
341 * @param[in] name Username for this cert-to-name entry.
342 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
343 * Otherwise the new YANG data will be added to the previous data and may override it.
344 * @return 0 on success, non-zero otherwise.
345 */
346int nc_server_config_new_tls_ctn(const struct ly_ctx *ctx, const char *endpt_name, uint32_t id, const char *fingerprint,
347 NC_TLS_CTN_MAPTYPE map_type, const char *name, struct lyd_node **config);
348
roman12644fe2023-06-08 11:06:42 +0200349/**
350 * @brief Creates new YANG configuration data nodes for a TLS version.
351 *
352 * @param[in] ctx libyang context.
353 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200354 * If an endpoint with this identifier already exists, its contents will be changed.
roman12644fe2023-06-08 11:06:42 +0200355 * @param[in] tls_version TLS version to be used. Call this multiple times to set
356 * the accepted versions of the TLS protocol and let the client and server negotiate
357 * the given version.
358 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
359 * Otherwise the new YANG data will be added to the previous data and may override it.
360 * @return 0 on success, non-zero otherwise.
361 */
362int nc_server_config_new_tls_version(const struct ly_ctx *ctx, const char *endpt_name,
363 NC_TLS_VERSION tls_version, struct lyd_node **config);
364
365/**
366 * @brief Creates new YANG configuration data nodes for a TLS cipher.
367 *
368 * @param[in] ctx libyang context.
369 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200370 * If an endpoint with this identifier already exists, its contents will be changed.
roman12644fe2023-06-08 11:06:42 +0200371 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
372 * Otherwise the new YANG data will be added to the previous data and may override it.
373 * @param[in] cipher_count Number of ciphers.
374 * @param[in] ... TLS ciphers. These ciphers MUST be in the format as listed in the
375 * iana-tls-cipher-suite-algs YANG model (lowercase and separated by dashes). Regardless
376 * of the TLS protocol version used, all of these ciphers will be tried and some of them
377 * might not be set (TLS handshake might fail then). For the list of supported ciphers see
378 * the OpenSSL documentation.
379 * @return 0 on success, non-zero otherwise.
380 */
381int nc_server_config_new_tls_ciphers(const struct ly_ctx *ctx, const char *endpt_name, struct lyd_node **config,
roman08f67f42023-06-08 13:51:54 +0200382 int cipher_count, ...);
roman12644fe2023-06-08 11:06:42 +0200383
romanfaecc582023-06-15 16:13:31 +0200384/**
385 * @brief Creates new YANG configuration data nodes for a Certificate Revocation List via a local file.
386 *
387 * Beware that you can choose up to one function between the three CRL alternatives on a given endpoint and calling
388 * this function will remove any CRL YANG nodes created by the other two functions.
389 *
390 * @param[in] ctx libyang context.
391 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200392 * If an endpoint with this identifier already exists, its contents will be changed.
romanfaecc582023-06-15 16:13:31 +0200393 * @param[in] path Path to a DER/PEM encoded CRL file.
394 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
395 * Otherwise the new YANG data will be added to the previous data and may override it.
396 * @return 0 on success, non-zero otherwise.
397 */
398int nc_server_config_new_tls_crl_path(const struct ly_ctx *ctx, const char *endpt_name, const char *path, struct lyd_node **config);
399
400/**
401 * @brief Creates new YANG configuration data nodes for a Certificate Revocation List via an URL.
402 *
403 * Beware that you can choose up to one function between the three CRL alternatives on a given endpoint and calling
404 * this function will remove any CRL YANG nodes created by the other two functions.
405 *
406 * @param[in] ctx libyang context.
407 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200408 * If an endpoint with this identifier already exists, its contents will be changed.
romanfaecc582023-06-15 16:13:31 +0200409 * @param[in] url URL from which the CRL file will be downloaded. The file has to be in the DER or PEM format.
410 * The allowed protocols are all the protocols supported by CURL.
411 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
412 * Otherwise the new YANG data will be added to the previous data and may override it.
413 * @return 0 on success, non-zero otherwise.
414 */
415int nc_server_config_new_tls_crl_url(const struct ly_ctx *ctx, const char *endpt_name, const char *url, struct lyd_node **config);
416
417/**
418 * @brief Creates new YANG configuration data nodes for a Certificate Revocation List via certificate extensions.
419 *
420 * The chain of configured Certificate Authorities will be examined. For each certificate in this chain all the
421 * CRLs from the URLs specified in their extension fields CRL Distribution Points will be downloaded and used.
422 * Beware that you can choose up to one function between the three CRL alternatives on a given endpoint and calling
423 * this function will remove any CRL YANG nodes created by the other two functions.
424 *
425 * @param[in] ctx libyang context.
426 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200427 * If an endpoint with this identifier already exists, its contents will be changed.
romanfaecc582023-06-15 16:13:31 +0200428 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
429 * Otherwise the new YANG data will be added to the previous data and may override it.
430 * @return 0 on success, non-zero otherwise.
431 */
432int nc_server_config_new_tls_crl_cert_ext(const struct ly_ctx *ctx, const char *endpt_name, struct lyd_node **config);
433
roman2e797ef2023-06-19 10:47:49 +0200434/**
435 * @brief Creates new YANG configuration data nodes, which will be a reference to another TLS endpoint's certificates.
436 *
437 * Whenever an user tries to connect to the referencing endpoint, all of its certificates will be tried first. If no match is
438 * found, the referenced endpoint's configured certificates will be tried. The same applies to cert-to-name entries.
439 *
440 * @param[in] ctx libyang context
441 * @param[in] endpt_name Arbitrary identifier of the endpoint.
roman142718b2023-06-29 09:15:29 +0200442 * If an endpoint with this identifier already exists, its contents will be changed.
roman2e797ef2023-06-19 10:47:49 +0200443 * @param[in] referenced_endpt Identifier of an endpoint, which has to exist whenever this data
444 * is applied. The referenced endpoint can reference another one and so on, but there mustn't be a cycle.
445 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
446 * Otherwise the new YANG data will be added to the previous data and may override it.
447 * @return 0 on success, non-zero otherwise.
448 */
449int nc_config_new_tls_endpoint_client_reference(const struct ly_ctx *ctx, const char *endpt_name,
450 const char *referenced_endpt, struct lyd_node **config);
451
roman142718b2023-06-29 09:15:29 +0200452/**
453 * @brief Creates new YANG configuration data nodes for a call-home client's address and port.
454 *
455 * @param[in] ctx libyang context.
456 * @param[in] ch_client_name Arbitrary identifier of the call-home client.
457 * If a call-home client with this identifier already exists, its contents will be changed.
458 * @param[in] endpt_name Arbitrary identifier of the client's endpoint.
459 * If the client's endpoint with this identifier already exists, its contents will be changed.
460 * @param[in] transport Transport protocol to be used on this endpoint - either SSH or TLS.
461 * @param[in] address Address to connect to.
462 * @param[in] port Port to connect to.
463 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
464 * Otherwise the new YANG data will be added to the previous data and may override it.
465 * @return 0 on success, non-zero otherwise.
466 */
roman5cbb6532023-06-22 12:53:17 +0200467int nc_server_config_new_ch_address_port(const struct ly_ctx *ctx, const char *ch_client_name, const char *endpt_name,
468 NC_TRANSPORT_IMPL transport, const char *address, const char *port, struct lyd_node **config);
469
roman142718b2023-06-29 09:15:29 +0200470/**
471 * @brief Creates new YANG data nodes for a call-home SSH hostkey.
472 *
473 * @param[in] ctx libyang context.
474 * @param[in] ch_client_name Arbitrary identifier of the call-home client.
475 * If a call-home client with this identifier already exists, its contents will be changed.
476 * @param[in] endpt_name Arbitrary identifier of the client's endpoint.
477 * If the client's endpoint with this identifier already exists, its contents will be changed.
478 * @param[in] hostkey_name Arbitrary identifier of the endpoint's hostkey.
479 * If the endpoint's hostkey with this identifier already exists, its contents will be changed.
480 * @param[in] privkey_path Path to a file containing a private key.
481 * The private key has to be in a PEM format. Only RSA and ECDSA keys are supported.
482 * @param[in] pubkey_path Path to a file containing a public key. If NULL, public key will be
483 * generated from the private key.
484 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
485 * Otherwise the new YANG data will be added to the previous data and may override it.
486 * @return 0 on success, non-zero otherwise.
487 */
roman5cbb6532023-06-22 12:53:17 +0200488int nc_server_config_new_ssh_ch_hostkey(const struct ly_ctx *ctx, const char *ch_client_name, const char *endpt_name,
489 const char *hostkey_name, const char *privkey_path, const char *pubkey_path, struct lyd_node **config);
490
roman142718b2023-06-29 09:15:29 +0200491/**
492 * @brief Creates new YANG data nodes for a call-home client's public key.
493 *
494 * @param[in] ctx libyang context.
495 * @param[in] ch_client_name Arbitrary identifier of the call-home client.
496 * If a call-home client with this identifier already exists, its contents will be changed.
497 * @param[in] endpt_name Arbitrary identifier of the client's endpoint.
498 * If the client's endpoint with this identifier already exists, its contents will be changed.
499 * @param[in] user_name Arbitrary identifier of the endpoint's user.
500 * If the endpoint's user with this identifier already exists, its contents will be changed.
501 * @param[in] pubkey_name Arbitrary identifier of the user's public key.
502 * If the user's public key with this identifier already exists, its contents will be changed.
503 * @param[in] pubkey_path Path to a file containing a public key.
504 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
505 * Otherwise the new YANG data will be added to the previous data and may override it.
506 * @return 0 on success, non-zero otherwise.
507 */
roman5cbb6532023-06-22 12:53:17 +0200508int nc_server_config_new_ssh_ch_client_auth_pubkey(const struct ly_ctx *ctx, const char *ch_client_name, const char *endpt_name,
509 const char *user_name, const char *pubkey_name, const char *pubkey_path, struct lyd_node **config);
510
roman142718b2023-06-29 09:15:29 +0200511/**
512 * @brief Deletes a call-home client from the YANG data.
513 *
514 * @param[in] ctx libyang context.
515 * @param[in] ch_client_name The name of the client to be deleted from the data.
516 * The client has to be present in the data.
517 * @param[in,out] config Modified configuration YANG data tree.
518 * @return 0 on success, non-zero otherwise.
519 */
roman5cbb6532023-06-22 12:53:17 +0200520int nc_server_config_new_del_ch_client(const struct ly_ctx *ctx, const char *ch_client_name, struct lyd_node **config);
521
roman142718b2023-06-29 09:15:29 +0200522/**
523 * @brief Creates new YANG data nodes for an asymmetric key in the keystore.
524 *
525 * @param[in] ctx libyang context.
526 * @param[in] name Name of the asymmetric key pair.
527 * This name is used to reference the key pair.
528 * @param[in] privkey_path Path to a private key file.
529 * @param[in] pubkey_path Optional path a public key file.
530 * If not supplied, it will be generated from the private key.
531 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
532 * Otherwise the new YANG data will be added to the previous data and may override it.
533 * @return 0 on success, non-zero otherwise.
534 */
535int nc_server_config_new_keystore_asym_key(const struct ly_ctx *ctx, const char *name, const char *privkey_path,
536 const char *pubkey_path, struct lyd_node **config);
537
538/**
539 * @brief Creates new YANG data nodes for a reference to an asymmetric key located in the keystore.
540 *
541 * This asymmetric key pair will be used as the SSH hostkey.
542 *
543 * @param[in] ctx libyang context.
544 * @param[in] endpt_name Arbitrary identifier of an endpoint.
545 * If an endpoint with this identifier already exists, its contents will be changed.
546 * @param[in] hostkey_name Arbitrary identifier of the endpoint's hostkey.
547 * If an endpoint's hostkey with this identifier already exists, its contents will be changed.
548 * @param[in] keystore_reference Name of the asymmetric key pair to be referenced and used as a hostkey.
549 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
550 * Otherwise the new YANG data will be added to the previous data and may override it.
551 * @return 0 on success, non-zero otherwise.
552 */
553int nc_server_config_new_ssh_keystore_reference(const struct ly_ctx *ctx, const char *endpt_name, const char *hostkey_name,
554 const char *keystore_reference, struct lyd_node **config);
555
556/**
557 * @brief Creates new YANG data nodes for a public key in the truststore.
558 *
559 * @param[in] ctx libyang context.
560 * @param[in] bag_name Arbitrary identifier of the public key bag.
561 * This name is used to reference the public keys in the bag.
562 * If a public key bag with this name already exists, its contents will be changed.
563 * @param[in] pubkey_name Arbitrary identifier of the public key.
564 * If a public key with this name already exists, its contents will be changed.
565 * @param[in] pubkey_path Path to a file containing a public key.
566 * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created.
567 * Otherwise the new YANG data will be added to the previous data and may override it.
568 * @return 0 on success, non-zero otherwise.
569 */
570int nc_server_config_new_truststore_pubkey(const struct ly_ctx *ctx, const char *bag_name, const char *pubkey_name,
571 const char *pubkey_path, struct lyd_node **config);
572
573/**
574 * @brief Creates new YANG data nodes for a reference to a public key bag located in the truststore.
575 *
576 * The public key's located in the bag will be used for client authentication.
577 *
578 * @param[in] ctx libyang context.
579 * @param[in] endpt_name Arbitrary identifier of an endpoint.
580 * If an endpoint with this identifier already exists, its contents will be changed.
581 * @param[in] user_name Arbitrary identifier of the endpoint's user.
582 * If an endpoint's user with this identifier already exists, its contents will be changed.
583 * @param[in] truststore_reference Name of the public key bag to be referenced and used for authentication.
584 * @param config Configuration YANG data tree. If *config is NULL, it will be created.
585 * Otherwise the new YANG data will be added to the previous data and may override it.
586 * @return 0 on success, non-zero otherwise.
587 */
588int nc_server_config_new_ssh_truststore_reference(const struct ly_ctx *ctx, const char *endpt_name, const char *user_name,
589 const char *truststore_reference, struct lyd_node **config);
590
romanb6f44032023-06-30 15:07:56 +0200591/**
592 * @brief Creates new YANG configuration data nodes for a call-home server's certificate.
593 *
594 * @param[in] ctx libyang context.
595 * @param[in] ch_client_name Arbitrary identifier of the call-home client.
596 * If a call-home client with this identifier already exists, its contents will be changed.
597 * @param[in] endpt_name Arbitrary identifier of the call-home client's endpoint.
598 * If a call-home client's endpoint with this identifier already exists, its contents will be changed.
599 * @param[in] pubkey_path Optional path to the server's public key file. If not provided,
600 * it will be generated from the private key.
601 * @param[in] privkey_path Path to the server's private key file.
602 * @param[in] certificate_path Path to the server's certificate file.
603 * @param config Configuration YANG data tree. If *config is NULL, it will be created.
604 * Otherwise the new YANG data will be added to the previous data and may override it.
605 * @return 0 on success, non-zero otherwise.
606 */
607int nc_server_config_new_ch_tls_server_certificate(const struct ly_ctx *ctx, const char *ch_client_name, const char *endpt_name,
608 const char *pubkey_path, const char *privkey_path, const char *certificate_path, struct lyd_node **config);
609
610/**
611 * @brief Creates new YANG configuration data nodes for a call-home client's (end-entity) certificate.
612 *
613 * @param[in] ctx libyang context.
614 * @param[in] ch_client_name Arbitrary identifier of the call-home client.
615 * If a call-home client with this identifier already exists, its contents will be changed.
616 * @param[in] endpt_name Arbitrary identifier of the call-home client's endpoint.
617 * If a call-home client's endpoint with this identifier already exists, its contents will be changed.
618 * @param[in] cert_name Arbitrary identifier of the call-home endpoint's end-entity certificate.
619 * If an call-home endpoint's end-entity certificate with this identifier already exists, its contents will be changed.
620 * @param[in] cert_path Path to the certificate file.
621 * @param config Configuration YANG data tree. If *config is NULL, it will be created.
622 * Otherwise the new YANG data will be added to the previous data and may override it.
623 * @return 0 on success, non-zero otherwise.
624 */
625int nc_server_config_new_ch_tls_client_certificate(const struct ly_ctx *ctx, const char *ch_client_name, const char *endpt_name,
626 const char *cert_name, const char *cert_path, struct lyd_node **config);
627
628/**
629 * @brief Creates new YANG configuration data nodes for a client certificate authority (trust-anchor) certificate.
630 *
631 * @param[in] ctx libyang context.
632 * @param[in] ch_client_name Arbitrary identifier of the call-home client.
633 * If a call-home client with this identifier already exists, its contents will be changed.
634 * @param[in] endpt_name Arbitrary identifier of the call-home client's endpoint.
635 * If a call-home client's endpoint with this identifier already exists, its contents will be changed.
636 * @param[in] cert_name Arbitrary identifier of the call-home endpoint's certificate authority certificate.
637 * If an call-home endpoint's CA certificate with this identifier already exists, its contents will be changed.
638 * @param[in] cert_path Path to the certificate file.
639 * @param config Configuration YANG data tree. If *config is NULL, it will be created.
640 * Otherwise the new YANG data will be added to the previous data and may override it.
641 * @return 0 on success, non-zero otherwise.
642 */
643int nc_server_config_new_ch_tls_client_ca(const struct ly_ctx *ctx, const char *ch_client_name, const char *endpt_name,
644 const char *cert_name, const char *cert_path, struct lyd_node **config);
645
646/**
647 * @brief Creates new YANG configuration data nodes for a call-home cert-to-name entry.
648 *
649 * @param[in] ctx libyang context.
650 * @param[in] ch_client_name Arbitrary identifier of the call-home client.
651 * If a call-home client with this identifier already exists, its contents will be changed.
652 * @param[in] endpt_name Arbitrary identifier of the call-home client's endpoint.
653 * If a call-home client's endpoint with this identifier already exists, its contents will be changed.
654 * @param[in] id ID of the entry. The lower the ID, the higher the priority of the entry (it will be checked earlier).
655 * @param[in] fingerprint Optional fingerprint of the entry. The fingerprint should always be set, however if it is
656 * not set, it will match any certificate. Entry with no fingerprint should therefore be placed only as the last entry.
657 * @param[in] map_type Mapping username to the certificate option.
658 * @param[in] name Username for this cert-to-name entry.
659 * @param config Configuration YANG data tree. If *config is NULL, it will be created.
660 * Otherwise the new YANG data will be added to the previous data and may override it.
661 * @return 0 on success, non-zero otherwise.
662 */
663int nc_server_config_new_ch_tls_ctn(const struct ly_ctx *ctx, const char *ch_client_name, const char *endpt_name,
664 uint32_t id, const char *fingerprint, NC_TLS_CTN_MAPTYPE map_type, const char *name, struct lyd_node **config);
665
roman2eab4742023-06-06 10:00:26 +0200666#endif /* NC_ENABLED_SSH_TLS */
roman45cec4e2023-02-17 10:21:39 +0100667
romanb6f44032023-06-30 15:07:56 +0200668/**
669 * @brief Creates new YANG configuration data nodes for the call-home persistent connection type.
670 *
671 * @param[in] ctx libyang context.
672 * @param[in] ch_client_name Arbitrary identifier of the call-home client.
673 * If a call-home client with this identifier already exists, its contents will be changed.
674 * @param config Configuration YANG data tree. If *config is NULL, it will be created.
675 * Otherwise the new YANG data will be added to the previous data and may override it.
676 * @return 0 on success, non-zero otherwise.
677 */
678int nc_server_config_new_ch_persistent(const struct ly_ctx *ctx, const char *ch_client_name, struct lyd_node **config);
679
680/**
681 * @brief Creates new YANG configuration data nodes for the period parameter of the call-home periodic connection type.
682 *
683 * @param[in] ctx libyang context.
684 * @param[in] ch_client_name Arbitrary identifier of the call-home client.
685 * If a call-home client with this identifier already exists, its contents will be changed.
686 * @param[in] period Duration between periodic connections.
687 * @param config Configuration YANG data tree. If *config is NULL, it will be created.
688 * Otherwise the new YANG data will be added to the previous data and may override it.
689 * @return 0 on success, non-zero otherwise.
690 */
691int nc_server_config_new_ch_period(const struct ly_ctx *ctx, const char *ch_client_name, uint16_t period,
692 struct lyd_node **config);
693
694/**
695 * @brief Creates new YANG configuration data nodes for the anchor time parameter of the call-home periodic connection type.
696 *
697 * @param[in] ctx libyang context.
698 * @param[in] ch_client_name Arbitrary identifier of the call-home client.
699 * If a call-home client with this identifier already exists, its contents will be changed.
700 * @param[in] anchor_time Timestamp before or after which a series of periodic connections are determined.
701 * @param config Configuration YANG data tree. If *config is NULL, it will be created.
702 * Otherwise the new YANG data will be added to the previous data and may override it.
703 * @return 0 on success, non-zero otherwise.
704 */
705int nc_server_config_new_ch_anchor_time(const struct ly_ctx *ctx, const char *ch_client_name,
706 const char *anchor_time, struct lyd_node **config);
707
708/**
709 * @brief Creates new YANG configuration data nodes for the idle timeout parameter of the call-home periodic connection type.
710 *
711 * @param[in] ctx libyang context.
712 * @param[in] ch_client_name Arbitrary identifier of the call-home client.
713 * If a call-home client with this identifier already exists, its contents will be changed.
714 * @param[in] idle_timeout Specifies the maximum number of seconds that a session may remain idle.
715 * @param config Configuration YANG data tree. If *config is NULL, it will be created.
716 * Otherwise the new YANG data will be added to the previous data and may override it.
717 * @return 0 on success, non-zero otherwise.
718 */
719int nc_server_config_new_ch_idle_timeout(const struct ly_ctx *ctx, const char *ch_client_name,
720 uint16_t idle_timeout, struct lyd_node **config);
721
722/**
723 * @brief Creates new YANG configuration data nodes for the call-home reconnect strategy.
724 *
725 * @param[in] ctx libyang context.
726 * @param[in] ch_client_name Arbitrary identifier of the call-home client.
727 * If a call-home client with this identifier already exists, its contents will be changed.
728 * @param[in] start_with Specifies which endpoint to try if a connection is unsuccessful. Default value is NC_CH_FIRST_LISTED.
729 * @param[in] max_attempts The number of unsuccessful connection attempts before moving to the next endpoint. Default value is 3.
730 * @param[in] max_wait The number of seconds after which a connection to an endpoint is deemed unsuccessful. Default value if 5.
731 * @param config Configuration YANG data tree. If *config is NULL, it will be created.
732 * Otherwise the new YANG data will be added to the previous data and may override it.
733 * @return 0 on success, non-zero otherwise.
734 */
735int nc_server_config_new_ch_reconnect_strategy(const struct ly_ctx *ctx, const char *ch_client_name,
736 NC_CH_START_WITH start_with, uint8_t max_attempts, uint16_t max_wait, struct lyd_node **config);
737
romanc1d2b092023-02-02 08:58:27 +0100738#ifdef __cplusplus
739}
740#endif
741
742#endif /* NC_SESSION_SERVER_H_ */