blob: ba93dcb8c18b52b50588f1151ca4a6475c68602d [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
roman3f9b65c2023-06-05 14:26:58 +020076int 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
79int nc_server_config_new_get_pubkey(const char *pubkey_path, char **pubkey, NC_PUBKEY_FORMAT *pubkey_type);
80
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
roman5cbb6532023-06-22 12:53:17 +020087int nc_config_new_add_operation(const struct ly_ctx *ctx, struct lyd_node *node, NC_OPERATION op);
88
89int nc_config_new_delete(const struct ly_ctx *ctx, struct lyd_node **tree, const char *path_fmt, ...);
roman2eab4742023-06-06 10:00:26 +020090
romand30af552023-06-16 15:18:27 +020091/**
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 */
roman5cbb6532023-06-22 12:53:17 +0200102int 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 +0200103
roman466719d2023-05-05 16:14:37 +0200104#ifdef __cplusplus
105}
106#endif
107
roman3f9b65c2023-06-05 14:26:58 +0200108#endif /* NC_CONFIG_NEW_H_ */