Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file session_client_ch.h |
| 3 | * \author Michal Vasko <mvasko@cesnet.cz> |
| 4 | * \brief libnetconf2 Call Home session client 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_CLIENT_CH_H_ |
| 24 | #define NC_SESSION_CLIENT_CH_H_ |
| 25 | |
| 26 | #include <libyang/libyang.h> |
| 27 | |
| 28 | #include "session.h" |
| 29 | #include "netconf.h" |
| 30 | #include "messages_client.h" |
| 31 | |
| 32 | #if defined(ENABLE_SSH) || defined(ENABLE_TLS) |
| 33 | |
| 34 | /** |
| 35 | * @brief Accept a Call Home connection on any of the listening binds. |
| 36 | * |
| 37 | * @param[in] timeout Timeout for receiving a new connection in milliseconds, 0 for |
| 38 | * non-blocking call, -1 for infinite waiting. |
| 39 | * @param[in] ctx Session context to use. Can be NULL. |
| 40 | * @param[out] session New session. |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 41 | * @return 1 on success, 0 on timeout, -1 on error. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 42 | */ |
| 43 | int nc_accept_callhome(int timeout, struct ly_ctx *ctx, struct nc_session **session); |
| 44 | |
| 45 | #endif /* ENABLE_SSH || ENABLE_TLS */ |
| 46 | |
| 47 | #ifdef ENABLE_SSH |
| 48 | |
| 49 | /** |
| 50 | * @brief Add a new client bind and start listening on it for SSH Call Home connections. |
| 51 | * |
| 52 | * @param[in] address IP address to bind to. |
| 53 | * @param[in] port Port to bind to. |
| 54 | * @return 0 on success, -1 on error. |
| 55 | */ |
| 56 | int nc_client_ssh_ch_add_bind_listen(const char *address, uint16_t port); |
| 57 | |
| 58 | /** |
| 59 | * @brief Remove an SSH listening client bind. |
| 60 | * |
| 61 | * @param[in] address IP address the socket was bound to. NULL matches all. |
| 62 | * @param[in] port Port the socket was bound to. 0 matches all. |
| 63 | * @return 0 on success, -1 on not found. |
| 64 | */ |
| 65 | int nc_client_ssh_ch_del_bind(const char *address, uint16_t port); |
| 66 | |
| 67 | /** |
| 68 | * @brief Add an SSH public and private key pair to be used for Call Home client authentication. |
| 69 | * |
| 70 | * Private key can be encrypted, the passphrase will be asked for before using it. |
| 71 | * |
| 72 | * Function is provided only via nc_client.h header file and only when libnetconf2 is compiled with libssh support. |
| 73 | * |
| 74 | * @param[in] pub_key Path to the public key. |
| 75 | * @param[in] priv_key Path to the private key. |
Michal Vasko | f0537d8 | 2016-01-29 14:42:38 +0100 | [diff] [blame] | 76 | * @return 0 on success, -1 on error. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 77 | */ |
| 78 | int nc_client_ssh_ch_add_keypair(const char *pub_key, const char *priv_key); |
| 79 | |
| 80 | /** |
| 81 | * @brief Remove an SSH public and private key pair that was used for Call Home client authentication. |
| 82 | * |
| 83 | * Function is provided only via nc_client.h header file and only when libnetconf2 is compiled with libssh support. |
| 84 | * |
| 85 | * @param[in] idx Index of the keypair starting with 0. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 86 | * @return 0 on success, -1 on error. |
| 87 | */ |
| 88 | int nc_client_ssh_ch_del_keypair(int idx); |
| 89 | |
| 90 | /** |
| 91 | * @brief Get the number of public an private key pairs set to be used for Call Home client authentication. |
| 92 | * |
| 93 | * @return Keypair count. |
| 94 | */ |
| 95 | int nc_client_ssh_ch_get_keypair_count(void); |
| 96 | |
| 97 | /** |
| 98 | * @brief Get a specific keypair set to be used for Call Home client authentication. |
| 99 | * |
| 100 | * @param[in] idx Index of the specific keypair. |
| 101 | * @param[out] pub_key Path to the public key. |
| 102 | * @param[out] priv_key Path to the private key. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 103 | * @return 0 on success, -1 on error. |
| 104 | */ |
| 105 | int nc_client_ssh_ch_get_keypair(int idx, const char **pub_key, const char **priv_key); |
| 106 | |
| 107 | /** |
| 108 | * @brief Set SSH Call Home authentication method preference. |
| 109 | * |
| 110 | * Function is provided only via nc_client.h header file and only when libnetconf2 is compiled with libssh support. |
| 111 | * |
| 112 | * @param[in] auth_type Authentication method to modify the prefrence of. |
| 113 | * @param[in] pref Preference of \p auth_type. Negative values disable the method. |
| 114 | */ |
| 115 | void nc_client_ssh_ch_set_auth_pref(NC_SSH_AUTH_TYPE auth_type, int16_t pref); |
| 116 | |
| 117 | /** |
| 118 | * @brief Get SSH Call Home authentication method preference. |
| 119 | * |
| 120 | * Function is provided only via nc_client.h header file and only when libnetconf2 is compiled with libssh support. |
| 121 | * |
| 122 | * @param[in] auth_type Authentication method to retrieve the prefrence of. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 123 | * @return Preference of the \p auth_type. |
| 124 | */ |
| 125 | int16_t nc_client_ssh_ch_get_auth_pref(NC_SSH_AUTH_TYPE auth_type); |
| 126 | |
| 127 | /** |
| 128 | * @brief Set client Call Home SSH username used for authentication. |
| 129 | * |
| 130 | * @param[in] username Username to use. |
| 131 | * @return 0 on success, -1 on error. |
| 132 | */ |
| 133 | int nc_client_ssh_ch_set_username(const char *username); |
| 134 | |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 135 | /** |
| 136 | * @brief Get client Call Home SSH username used for authentication. |
| 137 | * |
| 138 | * @return Username used. |
| 139 | */ |
| 140 | const char *nc_client_ssh_ch_get_username(void); |
| 141 | |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 142 | #endif /* ENABLE_SSH */ |
| 143 | |
| 144 | #ifdef ENABLE_TLS |
| 145 | |
| 146 | /** |
| 147 | * @brief Add a new client bind and start listening on it for TLS Call Home connections. |
| 148 | * |
| 149 | * @param[in] address IP address to bind to. |
| 150 | * @param[in] port Port to bind to. |
| 151 | * @return 0 on success, -1 on error. |
| 152 | */ |
| 153 | int nc_client_tls_ch_add_bind_listen(const char *address, uint16_t port); |
| 154 | |
| 155 | /** |
| 156 | * @brief Remove a TLS listening client bind. |
| 157 | * |
| 158 | * @param[in] address IP address the socket was bound to. NULL matches all. |
| 159 | * @param[in] port Port the socket was bound to. 0 matches all. |
| 160 | * @return 0 on success, -1 on not found. |
| 161 | */ |
| 162 | int nc_client_tls_ch_del_bind(const char *address, uint16_t port); |
| 163 | |
| 164 | /** |
| 165 | * @brief Set client Call Home authentication identity - a certificate and a private key. |
| 166 | * |
| 167 | * Function is provided only via nc_client.h header file and only when libnetconf2 is compiled with TLS support. |
| 168 | * |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 169 | * @param[in] client_cert Path to the file containing the client certificate. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 170 | * @param[in] client_key Path to the file containing the private key for the \p client_cert. |
| 171 | * If NULL, key is expected to be stored with \p client_cert. |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 172 | * @return 0 on success, -1 on error. |
| 173 | */ |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 174 | int nc_client_tls_ch_set_cert_key_paths(const char *client_cert, const char *client_key); |
| 175 | |
| 176 | /** |
| 177 | * @brief Get client Call Home authentication identity - a certificate and a private key. |
| 178 | * |
| 179 | * Function is provided only via nc_client.h header file and only when libnetconf2 is compiled with TLS support. |
| 180 | * |
| 181 | * @param[out] client_cert Path to the file containing the client certificate. Can be NULL. |
| 182 | * @param[out] client_key Path to the file containing the private key for the \p client_cert. |
| 183 | * Can be NULL. |
| 184 | */ |
| 185 | void nc_client_tls_ch_get_cert_key_paths(const char **client_cert, const char **client_key); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 186 | |
| 187 | /** |
| 188 | * @brief Set client Call Home trusted CA certificates. |
| 189 | * |
| 190 | * @param[in] ca_file Location of the CA certificate file used to verify server certificates. |
| 191 | * For more info, see the documentation for SSL_CTX_load_verify_locations() from OpenSSL. |
| 192 | * @param[in] ca_dir Location of the CA certificates directory used to verify the server certificates. |
| 193 | * For more info, see the documentation for SSL_CTX_load_verify_locations() from OpenSSL. |
| 194 | * @return 0 on success, -1 on error. |
| 195 | */ |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 196 | int nc_client_tls_ch_set_trusted_ca_paths(const char *ca_file, const char *ca_dir); |
| 197 | |
| 198 | /** |
| 199 | * @brief Get client Call Home trusted CA certificates. |
| 200 | * |
| 201 | * @param[out] ca_file Location of the CA certificate file used to verify server certificates. |
| 202 | * Can be NULL. |
| 203 | * @param[out] ca_dir Location of the CA certificates directory used to verify the server certificates. |
| 204 | * Can be NULL. |
| 205 | */ |
| 206 | void nc_client_tls_ch_get_trusted_ca_paths(const char **ca_file, const char **ca_dir); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 207 | |
| 208 | /** |
| 209 | * @brief Set client Call Home Certificate Revocation Lists. |
| 210 | * |
| 211 | * @param[in] crl_file Location of the CRL certificate file used to check for revocated certificates. |
| 212 | * @param[in] crl_dir Location of the CRL certificate directory used to check for revocated certificates. |
| 213 | * @return 0 on success, -1 on error. |
| 214 | */ |
Michal Vasko | e22c673 | 2016-01-29 11:03:02 +0100 | [diff] [blame] | 215 | int nc_client_tls_ch_set_crl_paths(const char *crl_file, const char *crl_dir); |
| 216 | |
| 217 | /** |
| 218 | * @brief Get client Call Home Certificate Revocation Lists. |
| 219 | * |
| 220 | * @param[out] crl_file Location of the CRL certificate file used to check for revocated certificates. |
| 221 | * Can be NULL. |
| 222 | * @param[out] crl_dir Location of the CRL certificate directory used to check for revocated certificates. |
| 223 | * Can be NULL. |
| 224 | */ |
| 225 | void nc_client_tls_ch_get_crl_paths(const char **crl_file, const char **crl_dir); |
Michal Vasko | 45f298f | 2016-01-29 10:26:26 +0100 | [diff] [blame] | 226 | |
| 227 | #endif /* ENABLE_TLS */ |
| 228 | |
| 229 | #endif /* NC_SESSION_CLIENT_CH_H_ */ |