blob: 9cb99a67b70f1ebc88cf3b880b02d0b8f267905b [file] [log] [blame]
Michal Vasko45f298f2016-01-29 10:26:26 +01001/**
2 * \file session_server_ch.h
3 * \author Michal Vasko <mvasko@cesnet.cz>
4 * \brief libnetconf2 Call Home session server manipulation
5 *
6 * Copyright (c) 2015 CESNET, z.s.p.o.
7 *
Radek Krejci9b81f5b2016-02-24 13:14:49 +01008 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
Michal Vasko45f298f2016-01-29 10:26:26 +010013 */
14
15#ifndef NC_SESSION_SERVER_CH_H_
16#define NC_SESSION_SERVER_CH_H_
17
18#include <stdint.h>
19#include <libyang/libyang.h>
20
21#include "session.h"
22#include "netconf.h"
23
Radek Krejci53691be2016-02-22 13:58:37 +010024#ifdef NC_ENABLED_SSH
Michal Vasko45f298f2016-01-29 10:26:26 +010025
26/**
27 * @brief Establish an SSH Call Home connection with a listening NETCONF client.
28 *
29 * @param[in] host Host the client is listening on.
30 * @param[in] port Port the client is listening on.
Michal Vaskof0537d82016-01-29 14:42:38 +010031 * @param[in] timeout Timeout for transport-related operations in milliseconds.
32 * 0 for non-blocking call, -1 for infinite waiting.
Michal Vasko45f298f2016-01-29 10:26:26 +010033 * @param[out] session New Call Home session.
34 * @return 1 on success, 0 on timeout, -1 on error.
35 */
36int nc_connect_callhome_ssh(const char *host, uint16_t port, int timeout, struct nc_session **session);
37
38/**
39 * @brief Set Call Home SSH host keys the server will identify itself with. Each of RSA, DSA, and
Michal Vaskof0537d82016-01-29 14:42:38 +010040 * ECDSA keys can be set. If the particular type was already set, it is replaced.
Michal Vasko45f298f2016-01-29 10:26:26 +010041 *
42 * @param[in] privkey_path Path to a private key.
43 * @return 0 on success, -1 on error.
44 */
45int nc_server_ssh_ch_set_hostkey(const char *privkey_path);
46
47/**
48 * @brief Set Call Home SSH banner the server will send to every client.
49 *
50 * @param[in] banner SSH banner.
51 * @return 0 on success, -1 on error.
52 */
53int nc_server_ssh_ch_set_banner(const char *banner);
54
55/**
56 * @brief Set accepted Call Home SSH authentication methods. All (publickey, password, interactive)
Michal Vaskof0537d82016-01-29 14:42:38 +010057 * are supported by default.
Michal Vasko45f298f2016-01-29 10:26:26 +010058 *
59 * @param[in] auth_methods Accepted authentication methods bit field of NC_SSH_AUTH_TYPE.
60 * @return 0 on success, -1 on error.
61 */
62int nc_server_ssh_ch_set_auth_methods(int auth_methods);
63
64/**
65 * @brief Set Call Home SSH authentication attempts of every client. 3 by default.
66 *
67 * @param[in] auth_attempts Failed authentication attempts before a client is dropped.
68 * @return 0 on success, -1 on error.
69 */
70int nc_server_ssh_ch_set_auth_attempts(uint16_t auth_attempts);
71
72/**
73 * @brief Set Call Home SSH authentication timeout. 10 seconds by default.
74 *
75 * @param[in] auth_timeout Number of seconds before an unauthenticated client is dropped.
76 * @return 0 on success, -1 on error.
77 */
78int nc_server_ssh_ch_set_auth_timeout(uint16_t auth_timeout);
79
80/**
81 * @brief Add an authorized Call Home client SSH public key. This public key can be used for
Michal Vaskof0537d82016-01-29 14:42:38 +010082 * publickey authentication afterwards.
Michal Vasko45f298f2016-01-29 10:26:26 +010083 *
84 * @param[in] pubkey_path Path to the public key.
85 * @param[in] username Username that the client with the public key must use.
86 * @return 0 on success, -1 on error.
87 */
88int nc_server_ssh_ch_add_authkey(const char *pubkey_path, const char *username);
89
90/**
91 * @brief Remove an authorized Call Home client SSH public key.
92 *
93 * @param[in] pubkey_path Path to an authorized public key. NULL matches all the keys.
94 * @param[in] username Username for an authorized public key. NULL matches all the usernames.
95 * @return 0 on success, -1 on not finding any match.
96 */
97int nc_server_ssh_ch_del_authkey(const char *pubkey_path, const char *username);
98
99/**
100 * @brief Clear all the SSH Call Home options. Afterwards a new set of options
Michal Vaskof0537d82016-01-29 14:42:38 +0100101 * can be set for the next client to connect to.
Michal Vasko45f298f2016-01-29 10:26:26 +0100102 */
103void nc_server_ssh_ch_clear_opts(void);
104
Radek Krejci53691be2016-02-22 13:58:37 +0100105#endif /* NC_ENABLED_SSH */
Michal Vasko45f298f2016-01-29 10:26:26 +0100106
Radek Krejci53691be2016-02-22 13:58:37 +0100107#ifdef NC_ENABLED_TLS
Michal Vasko45f298f2016-01-29 10:26:26 +0100108
109/**
110 * @brief Establish a TLS Call Home connection with a listening NETCONF client.
111 *
112 * @param[in] host Host the client is listening on.
113 * @param[in] port Port the client is listening on.
Michal Vaskof0537d82016-01-29 14:42:38 +0100114 * @param[in] timeout Timeout for transport-related operations in milliseconds.
115 * 0 for non-blocking call, -1 for infinite waiting.
Michal Vasko45f298f2016-01-29 10:26:26 +0100116 * @param[out] session New Call Home session.
117 * @return 1 on success, 0 on timeout, -1 on error.
118 */
119int nc_connect_callhome_tls(const char *host, uint16_t port, int timeout, struct nc_session **session);
120
121/**
122 * @brief Set server Call Home TLS certificate. Alternative to nc_tls_server_set_cert_path().
Michal Vaskof0537d82016-01-29 14:42:38 +0100123 * There can only be one certificate for each key type, it is replaced if already set.
Michal Vasko45f298f2016-01-29 10:26:26 +0100124 *
125 * @param[in] cert Base64-encoded certificate in ASN.1 DER encoding.
126 * @return 0 on success, -1 on error.
127 */
128int nc_server_tls_ch_set_cert(const char *cert);
129
130/**
131 * @brief Set server Call Home TLS certificate. Alternative to nc_tls_server_set_cert().
Michal Vaskof0537d82016-01-29 14:42:38 +0100132 * There can only be one certificate for each key type, it is replaced if already set.
Michal Vasko45f298f2016-01-29 10:26:26 +0100133 *
134 * @param[in] cert_path Path to a certificate file in PEM format.
135 * @return 0 on success, -1 on error.
136 */
137int nc_server_tls_ch_set_cert_path(const char *cert_path);
138
139/**
140 * @brief Set server Call Home TLS private key matching the certificate.
Michal Vaskof0537d82016-01-29 14:42:38 +0100141 * Alternative to nc_tls_server_set_key_path(). There can only be one of every key
142 * type, it is replaced if already set.
Michal Vasko45f298f2016-01-29 10:26:26 +0100143 *
144 * @param[in] privkey Base64-encoded certificate in ASN.1 DER encoding.
145 * @param[in] is_rsa Whether \p privkey are the data of an RSA (1) or DSA (0) key.
146 * @return 0 on success, -1 on error.
147 */
148int nc_server_tls_ch_set_key(const char *privkey, int is_rsa);
149
150/**
151 * @brief Set server Call Home TLS private key matching the certificate.
Michal Vaskof0537d82016-01-29 14:42:38 +0100152 * Alternative to nc_tls_server_set_key_path(). There can only be one of every key
153 * type, it is replaced if already set.
Michal Vasko45f298f2016-01-29 10:26:26 +0100154 *
155 * @param[in] privkey_path Path to a private key file in PEM format.
156 * @return 0 on success, -1 on error.
157 */
158int nc_server_tls_ch_set_key_path(const char *privkey_path);
159
160/**
161 * @brief Add a Call Home trusted certificate. Can be both a CA or a client one.
162 *
Michal Vaskof0537d82016-01-29 14:42:38 +0100163 * @param[in] cert Base64-enocded certificate in ASN.1 DER encoding.
Michal Vasko45f298f2016-01-29 10:26:26 +0100164 * @return 0 on success, -1 on error.
165 */
166int nc_server_tls_ch_add_trusted_cert(const char *cert);
167
168/**
169 * @brief Add a Call Home trusted certificate. Can be both a CA or a client one.
170 *
171 * @param[in] cert_path Path to a trusted certificate file in PEM format.
172 * @return 0 on success, -1 on error.
173 */
174int nc_server_tls_ch_add_trusted_cert_path(const char *cert_path);
175
176/**
177 * @brief Set trusted Call Home Certificate Authority certificate locations. There
Michal Vaskof0537d82016-01-29 14:42:38 +0100178 * can only be one file and one directory, they are replaced if already set.
Michal Vasko45f298f2016-01-29 10:26:26 +0100179 *
180 * @param[in] cacert_file_path Path to a trusted CA cert store file in PEM format.
Michal Vaskof0537d82016-01-29 14:42:38 +0100181 * Can be NULL.
Michal Vasko45f298f2016-01-29 10:26:26 +0100182 * @param[in] cacert_dir_path Path to a trusted CA cert store hashed directory
Michal Vaskof0537d82016-01-29 14:42:38 +0100183 * (c_rehash utility can be used to create hashes)
184 * with PEM files. Can be NULL.
Michal Vasko45f298f2016-01-29 10:26:26 +0100185 * @return 0 on success, -1 on error.
186 */
187int nc_server_tls_ch_set_trusted_cacert_locations(const char *cacert_file_path, const char *cacert_dir_path);
188
189/**
190 * @brief Destroy and clean all the set Call Home certificates and private keys.
Michal Vaskof0537d82016-01-29 14:42:38 +0100191 * CRLs and CTN entries are not affected.
Michal Vasko45f298f2016-01-29 10:26:26 +0100192 */
193void nc_server_tls_ch_clear_certs(void);
194
195/**
196 * @brief Set Call Home Certificate Revocation List locations. There can only be
Michal Vaskof0537d82016-01-29 14:42:38 +0100197 * one file and one directory, they are replaced if already set.
Michal Vasko45f298f2016-01-29 10:26:26 +0100198 *
199 * @param[in] crl_file_path Path to a CRL store file in PEM format. Can be NULL.
200 * @param[in] crl_dir_path Path to a CRL store hashed directory (c_rehash utility
Michal Vaskof0537d82016-01-29 14:42:38 +0100201 * can be used to create hashes) with PEM files. Can be NULL.
Michal Vasko45f298f2016-01-29 10:26:26 +0100202 * @return 0 on success, -1 on error.
203 */
204int nc_server_tls_ch_set_crl_locations(const char *crl_file_path, const char *crl_dir_path);
205
206/**
207 * @brief Destroy and clean Call Home CRLs. Call Home certificates, private keys,
Michal Vaskof0537d82016-01-29 14:42:38 +0100208 * and CTN entries are not affected.
Michal Vasko45f298f2016-01-29 10:26:26 +0100209 */
210void nc_server_tls_ch_clear_crls(void);
211
212/**
213 * @brief Add a Call Home Cert-to-name entry.
214 *
215 * @param[in] id Priority of the entry.
216 * @param[in] fingerprint Matching certificate fingerprint.
217 * @param[in] map_type Type of username-certificate mapping.
218 * @param[in] name Specific username if \p map_type == NC_TLS_CTN_SPECIFED. Must be NULL otherwise.
219 * @return 0 on success, -1 on error.
220 */
221int nc_server_tls_ch_add_ctn(uint32_t id, const char *fingerprint, NC_TLS_CTN_MAPTYPE map_type, const char *name);
222
223/**
224 * @brief Remove a Call Home Cert-to-name entry.
225 *
226 * @param[in] id Priority of the entry. -1 matches all the priorities.
227 * @param[in] fingerprint Fingerprint fo the entry. NULL matches all the fingerprints.
228 * @param[in] map_type Mapping type of the entry. 0 matches all the mapping types.
229 * @param[in] name Specific username for the entry. NULL matches all the usernames.
230 * @return 0 on success, -1 on not finding any match.
231 */
232int nc_server_tls_ch_del_ctn(int64_t id, const char *fingerprint, NC_TLS_CTN_MAPTYPE map_type, const char *name);
233
234/**
235 * @brief Clear all the TLS Call Home options. Afterwards a new set of options
Michal Vaskof0537d82016-01-29 14:42:38 +0100236 * can be set for the next client to connect.
Michal Vasko45f298f2016-01-29 10:26:26 +0100237 */
238void nc_server_tls_ch_clear_opts(void);
239
Radek Krejci53691be2016-02-22 13:58:37 +0100240#endif /* NC_ENABLED_TLS */
Michal Vasko45f298f2016-01-29 10:26:26 +0100241
242#endif /* NC_SESSION_SERVER_CH_H_ */