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 |
| 7 | * Copyright (c) 2015 - 2021 CESNET, z.s.p.o. |
| 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 | |
| 23 | #include <libyang/libyang.h> |
| 24 | #include <stdint.h> |
| 25 | |
| 26 | #include "netconf.h" |
| 27 | #include "session.h" |
| 28 | #include "session_p.h" |
| 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 | |
| 85 | /** |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 86 | * @brief Creates new YANG configuration data nodes for a hostkey. |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 87 | * |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 88 | * @param[in] privkey_path Path to a file containing a private key. |
| 89 | * The private key has to be in a PEM format. Only RSA and ECDSA keys are supported. |
| 90 | * @param[in] pubkey_path Path to a file containing a public key. If NULL, public key will be |
| 91 | * generated from the private key. |
| 92 | * @param[in] ctx libyang context. |
| 93 | * @param[in] endpt_name Arbitrary identifier of the endpoint. |
| 94 | * If an endpoint with this identifier already exists, it's hostkey might be changed. |
| 95 | * @param[in] hostkey_name Arbitrary identifier of the hostkey. |
| 96 | * If a hostkey with this identifier already exists, it's contents will be changed. |
| 97 | * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created. |
| 98 | * Otherwise the new YANG data will be added to the previous data and may override it. |
| 99 | * @return 0 on success, non-zero otherwise. |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 100 | */ |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 101 | int nc_server_config_new_ssh_hostkey(const char *privkey_path, const char *pubkey_path, const struct ly_ctx *ctx, |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 102 | const char *endpt_name, const char *hostkey_name, struct lyd_node **config); |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 103 | |
roman | 45cec4e | 2023-02-17 10:21:39 +0100 | [diff] [blame] | 104 | /** |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 105 | * @brief Creates new YANG configuration data nodes for a local-address and local-port. |
| 106 | * |
| 107 | * @param[in] address New listening address. |
| 108 | * @param[in] port New listening port. |
| 109 | * @param[in] ctx libyang context. |
| 110 | * @param[in] endpt_name Arbitrary identifier of the endpoint. |
| 111 | * If an endpoint with this identifier already exists, it's address and port will be overriden. |
| 112 | * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created. |
| 113 | * Otherwise the new YANG data will be added to the previous data and may override it. |
| 114 | * @return 0 on success, non-zero otherwise. |
roman | 45cec4e | 2023-02-17 10:21:39 +0100 | [diff] [blame] | 115 | */ |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 116 | int nc_server_config_new_ssh_address_port(const char *address, const char *port, const struct ly_ctx *ctx, |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 117 | const char *endpt_name, struct lyd_node **config); |
| 118 | |
| 119 | /** |
| 120 | * @brief Creates new YANG configuration data nodes for host-key algorithms replacing any previous ones. |
| 121 | * |
| 122 | * Supported algorithms are: ssh-ed25519, ecdsa-sha2-nistp256, ecdsa-sha2-nistp384, ecdsa-sha2-nistp521, |
| 123 | * rsa-sha2-512, rsa-sha2-256, ssh-rsa and ssh-dss. |
| 124 | * |
| 125 | * @param[in] ctx libyang context |
| 126 | * @param[in] endpt_name Arbitrary identifier of the endpoint. |
| 127 | * If an endpoint with this identifier already exists, it's host-key algorithms will be replaced. |
| 128 | * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created. |
| 129 | * Otherwise the new YANG data will be added to the previous data and may override it. |
| 130 | * @param[in] alg_count Number of following algorithms. |
| 131 | * @param[in] ... String literals of host-key algorithms in a decreasing order of preference. |
| 132 | * @return 0 on success, non-zero otherwise. |
| 133 | */ |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 134 | 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] | 135 | struct lyd_node **config, int alg_count, ...); |
| 136 | |
| 137 | /** |
| 138 | * @brief Creates new YANG configuration data nodes for key exchange algorithms replacing any previous ones. |
| 139 | * |
| 140 | * Supported algorithms are: diffie-hellman-group-exchange-sha1, curve25519-sha256, ecdh-sha2-nistp256, |
| 141 | * ecdh-sha2-nistp384, ecdh-sha2-nistp521, diffie-hellman-group18-sha512, diffie-hellman-group16-sha512, |
| 142 | * diffie-hellman-group-exchange-sha256 and diffie-hellman-group14-sha256. |
| 143 | * |
| 144 | * @param[in] ctx libyang context |
| 145 | * @param[in] endpt_name Arbitrary identifier of the endpoint. |
| 146 | * If an endpoint with this identifier already exists, it's key exchange algorithms will be replaced. |
| 147 | * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created. |
| 148 | * Otherwise the new YANG data will be added to the previous data and may override it. |
| 149 | * @param[in] alg_count Number of following algorithms. |
| 150 | * @param[in] ... String literals of key exchange algorithms in a decreasing order of preference. |
| 151 | * @return 0 on success, non-zero otherwise. |
| 152 | */ |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 153 | 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] | 154 | int alg_count, ...); |
| 155 | |
| 156 | /** |
| 157 | * @brief Creates new YANG configuration data nodes for encryption algorithms replacing any previous ones. |
| 158 | * |
| 159 | * Supported algorithms are: aes256-ctr, aes192-ctr, aes128-ctr, aes256-cbc, aes192-cbc, aes128-cbc, blowfish-cbc |
| 160 | * triple-des-cbc and none. |
| 161 | * |
| 162 | * @param[in] ctx libyang context |
| 163 | * @param[in] endpt_name Arbitrary identifier of the endpoint. |
| 164 | * If an endpoint with this identifier already exists, it's encryption algorithms will be replaced. |
| 165 | * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created. |
| 166 | * Otherwise the new YANG data will be added to the previous data and may override it. |
| 167 | * @param[in] alg_count Number of following algorithms. |
| 168 | * @param[in] ... String literals of encryption algorithms in a decreasing order of preference. |
| 169 | * @return 0 on success, non-zero otherwise. |
| 170 | */ |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 171 | 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] | 172 | int alg_count, ...); |
| 173 | |
| 174 | /** |
| 175 | * @brief Creates new YANG configuration data nodes for mac algorithms replacing any previous ones. |
| 176 | * |
| 177 | * Supported algorithms are: hmac-sha2-256, hmac-sha2-512 and hmac-sha1. |
| 178 | * |
| 179 | * @param[in] ctx libyang context |
| 180 | * @param[in] endpt_name Arbitrary identifier of the endpoint. |
| 181 | * If an endpoint with this identifier already exists, it's mac algorithms will be replaced. |
| 182 | * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created. |
| 183 | * Otherwise the new YANG data will be added to the previous data and may override it. |
| 184 | * @param[in] alg_count Number of following algorithms. |
| 185 | * @param[in] ... String literals of mac algorithms in a decreasing order of preference. |
| 186 | * @return 0 on success, non-zero otherwise. |
| 187 | */ |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 188 | 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] | 189 | int alg_count, ...); |
| 190 | |
| 191 | /** |
| 192 | * @brief Creates new YANG configuration data nodes for a client, which supports the public key authentication method. |
| 193 | * |
| 194 | * @param[in] pubkey_path Path to a file containing the user's public key. |
| 195 | * @param[in] ctx libyang context. |
| 196 | * @param[in] endpt_name Arbitrary identifier of the endpoint. |
| 197 | * If an endpoint with this identifier already exists, it's user might be changed. |
| 198 | * @param[in] user_name Arbitrary identifier of the user. |
| 199 | * If an user with this identifier already exists, it's contents will be changed. |
| 200 | * @param[in] pubkey_name Arbitrary identifier of the user's public key. |
| 201 | * If a public key with this identifier already exists for this user, it's contents will be changed. |
| 202 | * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created. |
| 203 | * Otherwise the new YANG data will be added to the previous data and may override it. |
| 204 | * @return 0 on success, non-zero otherwise. |
| 205 | */ |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 206 | int nc_server_config_new_ssh_client_auth_pubkey(const char *pubkey_path, const struct ly_ctx *ctx, const char *endpt_name, |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 207 | const char *user_name, const char *pubkey_name, struct lyd_node **config); |
| 208 | |
| 209 | /** |
| 210 | * @brief Creates new YANG configuration data nodes for a client, which supports the password authentication method. |
| 211 | * |
| 212 | * This function sets the password for the given user. |
| 213 | * |
| 214 | * @param[in] password Cleartext user's password. |
| 215 | * @param[in] ctx libyang context. |
| 216 | * @param[in] endpt_name Arbitrary identifier of the endpoint. |
| 217 | * If an endpoint with this identifier already exists, it's user might be changed. |
| 218 | * @param[in] user_name Arbitrary identifier of the user. |
| 219 | * If an user with this identifier already exists, it's contents will be changed. |
| 220 | * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created. |
| 221 | * Otherwise the new YANG data will be added to the previous data and may override it. |
| 222 | * @return 0 on success, non-zero otherwise. |
| 223 | */ |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 224 | int nc_server_config_new_ssh_client_auth_password(const char *password, const struct ly_ctx *ctx, const char *endpt_name, |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 225 | const char *user_name, struct lyd_node **config); |
| 226 | |
| 227 | /** |
| 228 | * @brief Creates new YANG configuration data nodes for a client, which supports the none authentication method. |
| 229 | * |
| 230 | * @param[in] ctx libyang context. |
| 231 | * @param[in] endpt_name Arbitrary identifier of the endpoint. |
| 232 | * If an endpoint with this identifier already exists, it's user might be changed. |
| 233 | * @param[in] user_name Arbitrary identifier of the user. |
| 234 | * If an user with this identifier already exists, it's contents will be changed. |
| 235 | * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created. |
| 236 | * Otherwise the new YANG data will be added to the previous data and may override it. |
| 237 | * @return 0 on success, non-zero otherwise. |
| 238 | */ |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 239 | 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] | 240 | const char *user_name, struct lyd_node **config); |
| 241 | |
| 242 | /** |
| 243 | * @brief Creates new YANG configuration data nodes for a client, which supports the interactive authentication method. |
| 244 | * |
| 245 | * @param[in] pam_config_name Name of the PAM configuration file. |
| 246 | * @param[in] pam_config_name Optional. The absolute path to the directory in which the configuration file |
| 247 | * with the name conf_name is located. A newer version (>= 1.4) of PAM library is required to be able to specify |
| 248 | * the path. If NULL is passed, then the PAM's system directories will be searched (usually /etc/pam.d/). |
| 249 | * @param[in] ctx libyang context. |
| 250 | * @param[in] endpt_name Arbitrary identifier of the endpoint. |
| 251 | * If an endpoint with this identifier already exists, it's user might be changed. |
| 252 | * @param[in] user_name Arbitrary identifier of the user. |
| 253 | * If an user with this identifier already exists, it's contents will be changed. |
| 254 | * @param[in,out] config Configuration YANG data tree. If *config is NULL, it will be created. |
| 255 | * Otherwise the new YANG data will be added to the previous data and may override it. |
| 256 | * @return 0 on success, non-zero otherwise. |
| 257 | */ |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 258 | int nc_server_config_new_ssh_client_auth_interactive(const char *pam_config_name, const char *pam_config_dir, |
roman | 9b1379c | 2023-03-31 10:11:10 +0200 | [diff] [blame] | 259 | const struct ly_ctx *ctx, const char *endpt_name, |
| 260 | const char *user_name, struct lyd_node **config); |
roman | 45cec4e | 2023-02-17 10:21:39 +0100 | [diff] [blame] | 261 | |
roman | c1d2b09 | 2023-02-02 08:58:27 +0100 | [diff] [blame] | 262 | #ifdef __cplusplus |
| 263 | } |
| 264 | #endif |
| 265 | |
| 266 | #endif /* NC_SESSION_SERVER_H_ */ |