blob: cfe642ef343f81f7759ab6a5d77cee8cf2167732 [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 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of the Company nor the names of its contributors
18 * may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 */
22
23#ifndef NC_SESSION_SERVER_CH_H_
24#define NC_SESSION_SERVER_CH_H_
25
26#include <stdint.h>
27#include <libyang/libyang.h>
28
29#include "session.h"
30#include "netconf.h"
31
Radek Krejci53691be2016-02-22 13:58:37 +010032#ifdef NC_ENABLED_SSH
Michal Vasko45f298f2016-01-29 10:26:26 +010033
34/**
35 * @brief Establish an SSH Call Home connection with a listening NETCONF client.
36 *
37 * @param[in] host Host the client is listening on.
38 * @param[in] port Port the client is listening on.
Michal Vaskof0537d82016-01-29 14:42:38 +010039 * @param[in] timeout Timeout for transport-related operations in milliseconds.
40 * 0 for non-blocking call, -1 for infinite waiting.
Michal Vasko45f298f2016-01-29 10:26:26 +010041 * @param[out] session New Call Home session.
42 * @return 1 on success, 0 on timeout, -1 on error.
43 */
44int nc_connect_callhome_ssh(const char *host, uint16_t port, int timeout, struct nc_session **session);
45
46/**
47 * @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 +010048 * ECDSA keys can be set. If the particular type was already set, it is replaced.
Michal Vasko45f298f2016-01-29 10:26:26 +010049 *
50 * @param[in] privkey_path Path to a private key.
51 * @return 0 on success, -1 on error.
52 */
53int nc_server_ssh_ch_set_hostkey(const char *privkey_path);
54
55/**
56 * @brief Set Call Home SSH banner the server will send to every client.
57 *
58 * @param[in] banner SSH banner.
59 * @return 0 on success, -1 on error.
60 */
61int nc_server_ssh_ch_set_banner(const char *banner);
62
63/**
64 * @brief Set accepted Call Home SSH authentication methods. All (publickey, password, interactive)
Michal Vaskof0537d82016-01-29 14:42:38 +010065 * are supported by default.
Michal Vasko45f298f2016-01-29 10:26:26 +010066 *
67 * @param[in] auth_methods Accepted authentication methods bit field of NC_SSH_AUTH_TYPE.
68 * @return 0 on success, -1 on error.
69 */
70int nc_server_ssh_ch_set_auth_methods(int auth_methods);
71
72/**
73 * @brief Set Call Home SSH authentication attempts of every client. 3 by default.
74 *
75 * @param[in] auth_attempts Failed authentication attempts before a client is dropped.
76 * @return 0 on success, -1 on error.
77 */
78int nc_server_ssh_ch_set_auth_attempts(uint16_t auth_attempts);
79
80/**
81 * @brief Set Call Home SSH authentication timeout. 10 seconds by default.
82 *
83 * @param[in] auth_timeout Number of seconds before an unauthenticated client is dropped.
84 * @return 0 on success, -1 on error.
85 */
86int nc_server_ssh_ch_set_auth_timeout(uint16_t auth_timeout);
87
88/**
89 * @brief Add an authorized Call Home client SSH public key. This public key can be used for
Michal Vaskof0537d82016-01-29 14:42:38 +010090 * publickey authentication afterwards.
Michal Vasko45f298f2016-01-29 10:26:26 +010091 *
92 * @param[in] pubkey_path Path to the public key.
93 * @param[in] username Username that the client with the public key must use.
94 * @return 0 on success, -1 on error.
95 */
96int nc_server_ssh_ch_add_authkey(const char *pubkey_path, const char *username);
97
98/**
99 * @brief Remove an authorized Call Home client SSH public key.
100 *
101 * @param[in] pubkey_path Path to an authorized public key. NULL matches all the keys.
102 * @param[in] username Username for an authorized public key. NULL matches all the usernames.
103 * @return 0 on success, -1 on not finding any match.
104 */
105int nc_server_ssh_ch_del_authkey(const char *pubkey_path, const char *username);
106
107/**
108 * @brief Clear all the SSH Call Home options. Afterwards a new set of options
Michal Vaskof0537d82016-01-29 14:42:38 +0100109 * can be set for the next client to connect to.
Michal Vasko45f298f2016-01-29 10:26:26 +0100110 */
111void nc_server_ssh_ch_clear_opts(void);
112
Radek Krejci53691be2016-02-22 13:58:37 +0100113#endif /* NC_ENABLED_SSH */
Michal Vasko45f298f2016-01-29 10:26:26 +0100114
Radek Krejci53691be2016-02-22 13:58:37 +0100115#ifdef NC_ENABLED_TLS
Michal Vasko45f298f2016-01-29 10:26:26 +0100116
117/**
118 * @brief Establish a TLS Call Home connection with a listening NETCONF client.
119 *
120 * @param[in] host Host the client is listening on.
121 * @param[in] port Port the client is listening on.
Michal Vaskof0537d82016-01-29 14:42:38 +0100122 * @param[in] timeout Timeout for transport-related operations in milliseconds.
123 * 0 for non-blocking call, -1 for infinite waiting.
Michal Vasko45f298f2016-01-29 10:26:26 +0100124 * @param[out] session New Call Home session.
125 * @return 1 on success, 0 on timeout, -1 on error.
126 */
127int nc_connect_callhome_tls(const char *host, uint16_t port, int timeout, struct nc_session **session);
128
129/**
130 * @brief Set server Call Home TLS certificate. Alternative to nc_tls_server_set_cert_path().
Michal Vaskof0537d82016-01-29 14:42:38 +0100131 * There can only be one certificate for each key type, it is replaced if already set.
Michal Vasko45f298f2016-01-29 10:26:26 +0100132 *
133 * @param[in] cert Base64-encoded certificate in ASN.1 DER encoding.
134 * @return 0 on success, -1 on error.
135 */
136int nc_server_tls_ch_set_cert(const char *cert);
137
138/**
139 * @brief Set server Call Home TLS certificate. Alternative to nc_tls_server_set_cert().
Michal Vaskof0537d82016-01-29 14:42:38 +0100140 * There can only be one certificate for each key type, it is replaced if already set.
Michal Vasko45f298f2016-01-29 10:26:26 +0100141 *
142 * @param[in] cert_path Path to a certificate file in PEM format.
143 * @return 0 on success, -1 on error.
144 */
145int nc_server_tls_ch_set_cert_path(const char *cert_path);
146
147/**
148 * @brief Set server Call Home TLS private key matching the certificate.
Michal Vaskof0537d82016-01-29 14:42:38 +0100149 * Alternative to nc_tls_server_set_key_path(). There can only be one of every key
150 * type, it is replaced if already set.
Michal Vasko45f298f2016-01-29 10:26:26 +0100151 *
152 * @param[in] privkey Base64-encoded certificate in ASN.1 DER encoding.
153 * @param[in] is_rsa Whether \p privkey are the data of an RSA (1) or DSA (0) key.
154 * @return 0 on success, -1 on error.
155 */
156int nc_server_tls_ch_set_key(const char *privkey, int is_rsa);
157
158/**
159 * @brief Set server Call Home TLS private key matching the certificate.
Michal Vaskof0537d82016-01-29 14:42:38 +0100160 * Alternative to nc_tls_server_set_key_path(). There can only be one of every key
161 * type, it is replaced if already set.
Michal Vasko45f298f2016-01-29 10:26:26 +0100162 *
163 * @param[in] privkey_path Path to a private key file in PEM format.
164 * @return 0 on success, -1 on error.
165 */
166int nc_server_tls_ch_set_key_path(const char *privkey_path);
167
168/**
169 * @brief Add a Call Home trusted certificate. Can be both a CA or a client one.
170 *
Michal Vaskof0537d82016-01-29 14:42:38 +0100171 * @param[in] cert Base64-enocded certificate in ASN.1 DER encoding.
Michal Vasko45f298f2016-01-29 10:26:26 +0100172 * @return 0 on success, -1 on error.
173 */
174int nc_server_tls_ch_add_trusted_cert(const char *cert);
175
176/**
177 * @brief Add a Call Home trusted certificate. Can be both a CA or a client one.
178 *
179 * @param[in] cert_path Path to a trusted certificate file in PEM format.
180 * @return 0 on success, -1 on error.
181 */
182int nc_server_tls_ch_add_trusted_cert_path(const char *cert_path);
183
184/**
185 * @brief Set trusted Call Home Certificate Authority certificate locations. There
Michal Vaskof0537d82016-01-29 14:42:38 +0100186 * can only be one file and one directory, they are replaced if already set.
Michal Vasko45f298f2016-01-29 10:26:26 +0100187 *
188 * @param[in] cacert_file_path Path to a trusted CA cert store file in PEM format.
Michal Vaskof0537d82016-01-29 14:42:38 +0100189 * Can be NULL.
Michal Vasko45f298f2016-01-29 10:26:26 +0100190 * @param[in] cacert_dir_path Path to a trusted CA cert store hashed directory
Michal Vaskof0537d82016-01-29 14:42:38 +0100191 * (c_rehash utility can be used to create hashes)
192 * with PEM files. Can be NULL.
Michal Vasko45f298f2016-01-29 10:26:26 +0100193 * @return 0 on success, -1 on error.
194 */
195int nc_server_tls_ch_set_trusted_cacert_locations(const char *cacert_file_path, const char *cacert_dir_path);
196
197/**
198 * @brief Destroy and clean all the set Call Home certificates and private keys.
Michal Vaskof0537d82016-01-29 14:42:38 +0100199 * CRLs and CTN entries are not affected.
Michal Vasko45f298f2016-01-29 10:26:26 +0100200 */
201void nc_server_tls_ch_clear_certs(void);
202
203/**
204 * @brief Set Call Home Certificate Revocation List locations. There can only be
Michal Vaskof0537d82016-01-29 14:42:38 +0100205 * one file and one directory, they are replaced if already set.
Michal Vasko45f298f2016-01-29 10:26:26 +0100206 *
207 * @param[in] crl_file_path Path to a CRL store file in PEM format. Can be NULL.
208 * @param[in] crl_dir_path Path to a CRL store hashed directory (c_rehash utility
Michal Vaskof0537d82016-01-29 14:42:38 +0100209 * can be used to create hashes) with PEM files. Can be NULL.
Michal Vasko45f298f2016-01-29 10:26:26 +0100210 * @return 0 on success, -1 on error.
211 */
212int nc_server_tls_ch_set_crl_locations(const char *crl_file_path, const char *crl_dir_path);
213
214/**
215 * @brief Destroy and clean Call Home CRLs. Call Home certificates, private keys,
Michal Vaskof0537d82016-01-29 14:42:38 +0100216 * and CTN entries are not affected.
Michal Vasko45f298f2016-01-29 10:26:26 +0100217 */
218void nc_server_tls_ch_clear_crls(void);
219
220/**
221 * @brief Add a Call Home Cert-to-name entry.
222 *
223 * @param[in] id Priority of the entry.
224 * @param[in] fingerprint Matching certificate fingerprint.
225 * @param[in] map_type Type of username-certificate mapping.
226 * @param[in] name Specific username if \p map_type == NC_TLS_CTN_SPECIFED. Must be NULL otherwise.
227 * @return 0 on success, -1 on error.
228 */
229int nc_server_tls_ch_add_ctn(uint32_t id, const char *fingerprint, NC_TLS_CTN_MAPTYPE map_type, const char *name);
230
231/**
232 * @brief Remove a Call Home Cert-to-name entry.
233 *
234 * @param[in] id Priority of the entry. -1 matches all the priorities.
235 * @param[in] fingerprint Fingerprint fo the entry. NULL matches all the fingerprints.
236 * @param[in] map_type Mapping type of the entry. 0 matches all the mapping types.
237 * @param[in] name Specific username for the entry. NULL matches all the usernames.
238 * @return 0 on success, -1 on not finding any match.
239 */
240int nc_server_tls_ch_del_ctn(int64_t id, const char *fingerprint, NC_TLS_CTN_MAPTYPE map_type, const char *name);
241
242/**
243 * @brief Clear all the TLS Call Home options. Afterwards a new set of options
Michal Vaskof0537d82016-01-29 14:42:38 +0100244 * can be set for the next client to connect.
Michal Vasko45f298f2016-01-29 10:26:26 +0100245 */
246void nc_server_tls_ch_clear_opts(void);
247
Radek Krejci53691be2016-02-22 13:58:37 +0100248#endif /* NC_ENABLED_TLS */
Michal Vasko45f298f2016-01-29 10:26:26 +0100249
250#endif /* NC_SESSION_SERVER_CH_H_ */