blob: 3fae017c0e203217f24a85999838662dd4613e6b [file] [log] [blame]
roman466719d2023-05-05 16:14:37 +02001/**
roman3f9b65c2023-06-05 14:26:58 +02002 * @file config_new.h
roman466719d2023-05-05 16:14:37 +02003 * @author Roman Janota <janota@cesnet.cz>
roman3f9b65c2023-06-05 14:26:58 +02004 * @brief libnetconf2 server new configuration creation header
roman466719d2023-05-05 16:14:37 +02005 *
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
roman3f9b65c2023-06-05 14:26:58 +020016#ifndef NC_CONFIG_NEW_H_
17#define NC_CONFIG_NEW_H_
roman466719d2023-05-05 16:14:37 +020018
19#include <libyang/libyang.h>
roman2e797ef2023-06-19 10:47:49 +020020#include <stdarg.h>
roman466719d2023-05-05 16:14:37 +020021
22#include "session_p.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
roman2eab4742023-06-06 10:00:26 +020028#ifdef NC_ENABLED_SSH_TLS
29
roman466719d2023-05-05 16:14:37 +020030/* 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
roman3f9b65c2023-06-05 14:26:58 +020063/* 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
roman466719d2023-05-05 16:14:37 +020069typedef enum {
70 NC_ALG_HOSTKEY,
71 NC_ALG_KEY_EXCHANGE,
72 NC_ALG_ENCRYPTION,
73 NC_ALG_MAC
74} NC_ALG_TYPE;
75
roman13145912023-08-17 15:36:54 +020076int nc_server_config_new_get_asym_key_pair(const char *privkey_path, const char *pubkey_path, NC_PUBKEY_FORMAT wanted_pubkey_type,
77 char **privkey, NC_PRIVKEY_FORMAT *privkey_type, char **pubkey);
roman3f9b65c2023-06-05 14:26:58 +020078
roman13145912023-08-17 15:36:54 +020079int nc_server_config_new_get_ssh_pubkey_file(const char *pubkey_path, char **pubkey);
roman3f9b65c2023-06-05 14:26:58 +020080
81int nc_server_config_new_read_certificate(const char *cert_path, char **cert);
82
roman3f9b65c2023-06-05 14:26:58 +020083const char * nc_config_new_privkey_format_to_identityref(NC_PRIVKEY_FORMAT format);
84
roman2eab4742023-06-06 10:00:26 +020085#endif /* NC_ENABLED_SSH_TLS */
86
romand30af552023-06-16 15:18:27 +020087/**
88 * @brief Creates YANG data nodes in a path and gives the final node a value.
89 *
romanb6f44032023-06-30 15:07:56 +020090 * @param[in] ctx libyang context.
romand30af552023-06-16 15:18:27 +020091 * @param[in, out] tree The YANG data tree where the insertion will happen. On success
Roytak7b9bf292023-10-04 14:06:38 +020092 * this is set to the top level container.
romand30af552023-06-16 15:18:27 +020093 * @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 */
roman5cbb6532023-06-22 12:53:17 +020098int nc_config_new_create(const struct ly_ctx *ctx, struct lyd_node **tree, const char *value, const char *path_fmt, ...);
romand30af552023-06-16 15:18:27 +020099
roman142718b2023-06-29 09:15:29 +0200100/**
Roytak7b9bf292023-10-04 14:06:38 +0200101 * @brief Creates a YANG data node by appending it to a specified parent node.
romanb6f44032023-06-30 15:07:56 +0200102 *
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.
Roytak7b9bf292023-10-04 14:06:38 +0200106 * @param[in] value Value given to the child node.
romanb6f44032023-06-30 15:07:56 +0200107 * @param[out] tree YANG data tree where the insertion will happen. On success
Roytak7b9bf292023-10-04 14:06:38 +0200108 * this is set to the top level container.
romanb6f44032023-06-30 15:07:56 +0200109 * @return 0 on success, 1 otherwise.
110 */
111int 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/**
roman142718b2023-06-29 09:15:29 +0200115 * @brief Deletes a subtree from the YANG data.
116 *
117 * @param tree YANG data from which the subtree will be deleted.
Roytak7b9bf292023-10-04 14:06:38 +0200118 * @param[in] path_fmt Format of the path. The last node will be the top level node of the deleted tree.
roman142718b2023-06-29 09:15:29 +0200119 * @param[in] ... Parameters for the path format, essentially representing the lists' keys.
120 * @return 0 on success, non-zero otherwise.
121 */
122int nc_config_new_delete(struct lyd_node **tree, const char *path_fmt, ...);
123
Roytak7b9bf292023-10-04 14:06:38 +0200124/**
125 * @brief Deletes a subtree from the YANG data, but doesn't return an error if the node doesn't exist.
126 *
127 * @param tree YANG data from which the subtree will be deleted.
128 * @param[in] path_fmt Format of the path. The last node will be the top level node of the deleted tree.
129 * @param[in] ... Parameters for the path format, essentially representing the lists' keys.
130 * @return 0 on success, non-zero otherwise.
131 */
roman8ba6efa2023-07-12 15:27:52 +0200132int nc_config_new_check_delete(struct lyd_node **tree, const char *path_fmt, ...);
133
roman466719d2023-05-05 16:14:37 +0200134#ifdef __cplusplus
135}
136#endif
137
roman3f9b65c2023-06-05 14:26:58 +0200138#endif /* NC_CONFIG_NEW_H_ */