roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 1 | /** |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 2 | * @file config_new.h |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 3 | * @author Roman Janota <janota@cesnet.cz> |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 4 | * @brief libnetconf2 server new configuration creation header |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 5 | * |
| 6 | * @copyright |
| 7 | * Copyright (c) 2023 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 | |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 16 | #ifndef NC_CONFIG_NEW_H_ |
| 17 | #define NC_CONFIG_NEW_H_ |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 18 | |
| 19 | #include <libyang/libyang.h> |
roman | 2e797ef | 2023-06-19 10:47:49 +0200 | [diff] [blame] | 20 | #include <stdarg.h> |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 21 | |
| 22 | #include "session_p.h" |
| 23 | |
| 24 | #ifdef __cplusplus |
| 25 | extern "C" { |
| 26 | #endif |
| 27 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 28 | #ifdef NC_ENABLED_SSH_TLS |
| 29 | |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 30 | /* private key's pkcs8 header */ |
| 31 | #define NC_PKCS8_PRIVKEY_HEADER "-----BEGIN PRIVATE KEY-----\n" |
| 32 | |
| 33 | /* private key's pkcs8 footer */ |
| 34 | #define NC_PKCS8_PRIVKEY_FOOTER "\n-----END PRIVATE KEY-----\n" |
| 35 | |
| 36 | /* private key's openssh header */ |
| 37 | #define NC_OPENSSH_PRIVKEY_HEADER "-----BEGIN OPENSSH PRIVATE KEY-----\n" |
| 38 | |
| 39 | /* private key's openssh footer */ |
| 40 | #define NC_OPENSSH_PRIVKEY_FOOTER "\n-----END OPENSSH PRIVATE KEY-----\n" |
| 41 | |
| 42 | /* private key's pkcs1 rsa header */ |
| 43 | #define NC_PKCS1_RSA_PRIVKEY_HEADER "-----BEGIN RSA PRIVATE KEY-----\n" |
| 44 | |
| 45 | /* private key's sec1 ec header */ |
| 46 | #define NC_SEC1_EC_PRIVKEY_HEADER "-----BEGIN EC PRIVATE KEY-----\n" |
| 47 | |
| 48 | /* private key's header when getting an EC/RSA privkey from file using libssh */ |
| 49 | #define NC_LIBSSH_PRIVKEY_HEADER "-----BEGIN PRIVATE KEY-----\n" |
| 50 | |
| 51 | /* private key's footer when getting an EC/RSA privkey from file using libssh */ |
| 52 | #define NC_LIBSSH_PRIVKEY_FOOTER "\n-----END PRIVATE KEY-----\n" |
| 53 | |
| 54 | /* public key's ssh2 header */ |
| 55 | #define NC_SSH2_PUBKEY_HEADER "---- BEGIN SSH2 PUBLIC KEY ----\n" |
| 56 | |
| 57 | /* public key's SubjectPublicKeyInfo format header */ |
| 58 | #define NC_SUBJECT_PUBKEY_INFO_HEADER "-----BEGIN PUBLIC KEY-----\n" |
| 59 | |
| 60 | /* public key's SubjectPublicKeyInfo format footer */ |
| 61 | #define NC_SUBJECT_PUBKEY_INFO_FOOTER "\n-----END PUBLIC KEY-----\n" |
| 62 | |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 63 | /* certificate's PEM format header */ |
| 64 | #define NC_PEM_CERTIFICATE_HEADER "-----BEGIN CERTIFICATE-----\n" |
| 65 | |
| 66 | /* certificate's PEM format footer */ |
| 67 | #define NC_PEM_CERTIFICATE_FOOTER "\n-----END CERTIFICATE-----\n" |
| 68 | |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 69 | typedef enum { |
| 70 | NC_ALG_HOSTKEY, |
| 71 | NC_ALG_KEY_EXCHANGE, |
| 72 | NC_ALG_ENCRYPTION, |
| 73 | NC_ALG_MAC |
| 74 | } NC_ALG_TYPE; |
| 75 | |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 76 | int nc_server_config_new_get_keys(const char *privkey_path, const char *pubkey_path, |
| 77 | char **privkey, char **pubkey, NC_PRIVKEY_FORMAT *privkey_type, NC_PUBKEY_FORMAT *pubkey_type); |
| 78 | |
| 79 | int nc_server_config_new_get_pubkey(const char *pubkey_path, char **pubkey, NC_PUBKEY_FORMAT *pubkey_type); |
| 80 | |
| 81 | int nc_server_config_new_read_certificate(const char *cert_path, char **cert); |
| 82 | |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 83 | const char * nc_config_new_privkey_format_to_identityref(NC_PRIVKEY_FORMAT format); |
| 84 | |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 85 | #endif /* NC_ENABLED_SSH_TLS */ |
| 86 | |
roman | d30af55 | 2023-06-16 15:18:27 +0200 | [diff] [blame] | 87 | /** |
| 88 | * @brief Creates YANG data nodes in a path and gives the final node a value. |
| 89 | * |
roman | b6f4403 | 2023-06-30 15:07:56 +0200 | [diff] [blame] | 90 | * @param[in] ctx libyang context. |
roman | d30af55 | 2023-06-16 15:18:27 +0200 | [diff] [blame] | 91 | * @param[in, out] tree The YANG data tree where the insertion will happen. On success |
| 92 | * the top level container is always returned. |
| 93 | * @param[in] value Value assigned to the final node in the path. |
| 94 | * @param[in] path_fmt Format of the path. |
| 95 | * @param[in] ... Parameters for the path format, essentially representing the lists' keys. |
| 96 | * @return 0 on success, 1 otherwise. |
| 97 | */ |
roman | 5cbb653 | 2023-06-22 12:53:17 +0200 | [diff] [blame] | 98 | int nc_config_new_create(const struct ly_ctx *ctx, struct lyd_node **tree, const char *value, const char *path_fmt, ...); |
roman | d30af55 | 2023-06-16 15:18:27 +0200 | [diff] [blame] | 99 | |
roman | 142718b | 2023-06-29 09:15:29 +0200 | [diff] [blame] | 100 | /** |
roman | b6f4403 | 2023-06-30 15:07:56 +0200 | [diff] [blame] | 101 | * @brief Creates new YANG data nodes in a path and gives the final node a value. |
| 102 | * |
| 103 | * @param[in] ctx libyang context. |
| 104 | * @param[in] parent_path Path to the parent node. |
| 105 | * @param[in] child_name Name of the parent's child node to be created. |
| 106 | * @param[in] value Value to give to the child node. |
| 107 | * @param[out] tree YANG data tree where the insertion will happen. On success |
| 108 | * the top level container is always returned. |
| 109 | * @return 0 on success, 1 otherwise. |
| 110 | */ |
| 111 | int nc_config_new_create_append(const struct ly_ctx *ctx, const char *parent_path, const char *child_name, |
| 112 | const char *value, struct lyd_node **tree); |
| 113 | |
| 114 | /** |
roman | 142718b | 2023-06-29 09:15:29 +0200 | [diff] [blame] | 115 | * @brief Deletes a subtree from the YANG data. |
| 116 | * |
| 117 | * @param tree YANG data from which the subtree will be deleted. |
| 118 | * @param[in] path_fmt Format of the path |
| 119 | * @param[in] ... Parameters for the path format, essentially representing the lists' keys. |
| 120 | * @return 0 on success, non-zero otherwise. |
| 121 | */ |
| 122 | int nc_config_new_delete(struct lyd_node **tree, const char *path_fmt, ...); |
| 123 | |
roman | 8ba6efa | 2023-07-12 15:27:52 +0200 | [diff] [blame] | 124 | int nc_config_new_check_delete(struct lyd_node **tree, const char *path_fmt, ...); |
| 125 | |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 126 | #ifdef __cplusplus |
| 127 | } |
| 128 | #endif |
| 129 | |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 130 | #endif /* NC_CONFIG_NEW_H_ */ |