roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 1 | /** |
roman | e028ef9 | 2023-02-24 16:33:08 +0100 | [diff] [blame] | 2 | * @file server_config.h |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 3 | * @author Roman Janota <janota@cesnet.cz> |
| 4 | * @brief libnetconf2 server configuration |
| 5 | * |
| 6 | * @copyright |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 7 | * Copyright (c) 2023 CESNET, z.s.p.o. |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 8 | * |
| 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 |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 23 | #include <stdarg.h> |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 24 | #include <stdint.h> |
| 25 | |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 26 | #include <libyang/libyang.h> |
| 27 | |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 28 | #include "session.h" |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 29 | |
| 30 | /** |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 31 | * @brief Configure server based on the given diff data. |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 32 | * |
roman | f6f37a5 | 2023-05-25 14:27:51 +0200 | [diff] [blame] | 33 | * Expected data are a validated instance of a ietf-netconf-server YANG data. |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 34 | * 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 | * |
roman | f6f37a5 | 2023-05-25 14:27:51 +0200 | [diff] [blame] | 38 | * @param[in] diff ietf-netconf-server YANG diff data. |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 39 | * @return 0 on success, 1 on error. |
| 40 | */ |
roman | f6f37a5 | 2023-05-25 14:27:51 +0200 | [diff] [blame] | 41 | int nc_server_config_setup_diff(const struct lyd_node *diff); |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 42 | |
| 43 | /** |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 44 | * @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. |
roman | f6f37a5 | 2023-05-25 14:27:51 +0200 | [diff] [blame] | 49 | * The data must not contain any operation attribute, see ::nc_config_setup_diff() which works with diff. |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 50 | * 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 | */ |
roman | f6f37a5 | 2023-05-25 14:27:51 +0200 | [diff] [blame] | 55 | int nc_server_config_setup_data(const struct lyd_node *data); |
roman | f02273a | 2023-05-25 09:44:11 +0200 | [diff] [blame] | 56 | |
| 57 | /** |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 58 | * @brief Configure server based on the given ietf-netconf-server YANG data. |
roman | f6f37a5 | 2023-05-25 14:27:51 +0200 | [diff] [blame] | 59 | * Wrapper around ::nc_config_setup_server_data() hiding work with parsing the data. |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 60 | * |
| 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 | */ |
| 65 | int 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 | */ |
| 83 | int nc_server_config_load_modules(struct ly_ctx **ctx); |
| 84 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 85 | #ifdef NC_ENABLED_SSH_TLS |
| 86 | |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 87 | /** |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 88 | * @brief Creates new YANG configuration data nodes for a local-address and local-port. |
| 89 | * |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 90 | * @param[in] ctx libyang context. |
| 91 | * @param[in] endpt_name Arbitrary identifier of the endpoint. |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 92 | * @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. |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 95 | * If an endpoint with this identifier already exists, it's address and port will be overriden. |
| 96 | * @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. |
roman | 45cec4e | 2023-02-17 10:21:39 +0100 | [diff] [blame] | 99 | */ |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 100 | int nc_server_config_new_address_port(const struct ly_ctx *ctx, const char *endpt_name, NC_TRANSPORT_IMPL transport, |
| 101 | const char *address, const char *port, struct lyd_node **config); |
| 102 | |
| 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. |
| 108 | * If an endpoint with this identifier already exists, it's hostkey might be changed. |
| 109 | * @param[in] hostkey_name Arbitrary identifier of the hostkey. |
| 110 | * If a hostkey with this identifier already exists, it's contents will be changed. |
| 111 | * @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 | */ |
| 119 | int 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); |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 121 | |
| 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. |
| 130 | * If an endpoint with this identifier already exists, it's host-key algorithms will be replaced. |
| 131 | * @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 | */ |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 137 | int nc_server_config_new_ssh_host_key_algs(const struct ly_ctx *ctx, const char *endpt_name, |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 138 | 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. |
| 149 | * If an endpoint with this identifier already exists, it's key exchange algorithms will be replaced. |
| 150 | * @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 | */ |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 156 | int nc_server_config_new_ssh_key_exchange_algs(const struct ly_ctx *ctx, const char *endpt_name, struct lyd_node **config, |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 157 | 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. |
| 167 | * If an endpoint with this identifier already exists, it's encryption algorithms will be replaced. |
| 168 | * @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 | */ |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 174 | int nc_server_config_new_ssh_encryption_algs(const struct ly_ctx *ctx, const char *endpt_name, struct lyd_node **config, |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 175 | 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. |
| 184 | * If an endpoint with this identifier already exists, it's mac algorithms will be replaced. |
| 185 | * @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 | */ |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 191 | int nc_server_config_new_ssh_mac_algs(const struct ly_ctx *ctx, const char *endpt_name, struct lyd_node **config, |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 192 | int alg_count, ...); |
| 193 | |
| 194 | /** |
| 195 | * @brief Creates new YANG configuration data nodes for a client, which supports the public key authentication method. |
| 196 | * |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 197 | * @param[in] ctx libyang context. |
| 198 | * @param[in] endpt_name Arbitrary identifier of the endpoint. |
| 199 | * If an endpoint with this identifier already exists, it's user might be changed. |
| 200 | * @param[in] user_name Arbitrary identifier of the user. |
| 201 | * If an user with this identifier already exists, it's contents will be changed. |
| 202 | * @param[in] pubkey_name Arbitrary identifier of the user's public key. |
| 203 | * If a public key with this identifier already exists for this user, it's contents will be changed. |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 204 | * @param[in] pubkey_path Path to a file containing the user's public key. |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 205 | * @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 | */ |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 209 | int 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); |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 211 | |
| 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 | * |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 217 | * @param[in] ctx libyang context. |
| 218 | * @param[in] endpt_name Arbitrary identifier of the endpoint. |
| 219 | * If an endpoint with this identifier already exists, it's user might be changed. |
| 220 | * @param[in] user_name Arbitrary identifier of the user. |
| 221 | * If an user with this identifier already exists, it's contents will be changed. |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 222 | * @param[in] password Cleartext user's password. |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 223 | * @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 | */ |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 227 | int 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); |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 229 | |
| 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. |
| 235 | * If an endpoint with this identifier already exists, it's user might be changed. |
| 236 | * @param[in] user_name Arbitrary identifier of the user. |
| 237 | * If an user with this identifier already exists, it's contents will be changed. |
| 238 | * @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 | */ |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 242 | int nc_server_config_new_ssh_client_auth_none(const struct ly_ctx *ctx, const char *endpt_name, |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 243 | 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 | * |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 248 | * @param[in] ctx libyang context. |
| 249 | * @param[in] endpt_name Arbitrary identifier of the endpoint. |
| 250 | * If an endpoint with this identifier already exists, it's user might be changed. |
| 251 | * @param[in] user_name Arbitrary identifier of the user. |
| 252 | * If an user with this identifier already exists, it's contents will be changed. |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 253 | * @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/). |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 257 | * @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 | */ |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 261 | int 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 | |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 264 | /** |
roman | 2e797ef | 2023-06-19 10:47:49 +0200 | [diff] [blame^] | 265 | * @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. |
| 272 | * If an endpoint with this identifier already exists, it's contents will be changed. |
| 273 | * @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 | */ |
| 279 | int 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 | /** |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 283 | * @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. |
| 287 | * If an endpoint with this identifier already exists, it's server certificate will be changed. |
| 288 | * @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 | */ |
| 296 | int 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. |
| 304 | * If an endpoint with this identifier already exists, it's contents will be changed. |
| 305 | * @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 | */ |
| 312 | int 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. |
| 320 | * If an endpoint with this identifier already exists, it's contents will be changed. |
| 321 | * @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 | */ |
| 328 | int 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. |
| 336 | * If an endpoint with this identifier already exists, it's contents will be changed. |
| 337 | * @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 | */ |
| 346 | int 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 | |
roman | 12644fe | 2023-06-08 11:06:42 +0200 | [diff] [blame] | 349 | /** |
| 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. |
| 354 | * If an endpoint with this identifier already exists, it's contents will be changed. |
| 355 | * @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 | */ |
| 362 | int 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. |
| 370 | * If an endpoint with this identifier already exists, it's contents will be changed. |
| 371 | * @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 | */ |
| 381 | int nc_server_config_new_tls_ciphers(const struct ly_ctx *ctx, const char *endpt_name, struct lyd_node **config, |
roman | 08f67f4 | 2023-06-08 13:51:54 +0200 | [diff] [blame] | 382 | int cipher_count, ...); |
roman | 12644fe | 2023-06-08 11:06:42 +0200 | [diff] [blame] | 383 | |
roman | faecc58 | 2023-06-15 16:13:31 +0200 | [diff] [blame] | 384 | /** |
| 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. |
| 392 | * If an endpoint with this identifier already exists, it's contents will be changed. |
| 393 | * @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 | */ |
| 398 | int 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. |
| 408 | * If an endpoint with this identifier already exists, it's contents will be changed. |
| 409 | * @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 | */ |
| 415 | int 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. |
| 427 | * If an endpoint with this identifier already exists, it's contents will be changed. |
| 428 | * @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 | */ |
| 432 | int nc_server_config_new_tls_crl_cert_ext(const struct ly_ctx *ctx, const char *endpt_name, struct lyd_node **config); |
| 433 | |
roman | 2e797ef | 2023-06-19 10:47:49 +0200 | [diff] [blame^] | 434 | /** |
| 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. |
| 442 | * If an endpoint with this identifier already exists, it's contents will be changed. |
| 443 | * @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 | */ |
| 449 | int 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 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 452 | #endif /* NC_ENABLED_SSH_TLS */ |
roman | 45cec4e | 2023-02-17 10:21:39 +0100 | [diff] [blame] | 453 | |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 454 | #ifdef __cplusplus |
| 455 | } |
| 456 | #endif |
| 457 | |
| 458 | #endif /* NC_SESSION_SERVER_H_ */ |