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 | 5cbb653 | 2023-06-22 12:53:17 +0200 | [diff] [blame^] | 87 | int nc_config_new_add_operation(const struct ly_ctx *ctx, struct lyd_node *node, NC_OPERATION op); |
| 88 | |
| 89 | int nc_config_new_delete(const struct ly_ctx *ctx, struct lyd_node **tree, const char *path_fmt, ...); |
roman | 2eab474 | 2023-06-06 10:00:26 +0200 | [diff] [blame] | 90 | |
roman | d30af55 | 2023-06-16 15:18:27 +0200 | [diff] [blame] | 91 | /** |
| 92 | * @brief Creates YANG data nodes in a path and gives the final node a value. |
| 93 | * |
| 94 | * @param[in] ctx libyang context |
| 95 | * @param[in, out] tree The YANG data tree where the insertion will happen. On success |
| 96 | * the top level container is always returned. |
| 97 | * @param[in] value Value assigned to the final node in the path. |
| 98 | * @param[in] path_fmt Format of the path. |
| 99 | * @param[in] ... Parameters for the path format, essentially representing the lists' keys. |
| 100 | * @return 0 on success, 1 otherwise. |
| 101 | */ |
roman | 5cbb653 | 2023-06-22 12:53:17 +0200 | [diff] [blame^] | 102 | 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] | 103 | |
roman | 466719d | 2023-05-05 16:14:37 +0200 | [diff] [blame] | 104 | #ifdef __cplusplus |
| 105 | } |
| 106 | #endif |
| 107 | |
roman | 3f9b65c | 2023-06-05 14:26:58 +0200 | [diff] [blame] | 108 | #endif /* NC_CONFIG_NEW_H_ */ |