Helium
ssl_ctx.h
Go to the documentation of this file.
1 /* *
2  * Lightway Core
3  * Copyright (C) 2021 Express VPN International Ltd.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
26 #ifndef SSL_CTX_H
27 #define SSL_CTX_H
28 
29 #include <he.h>
30 
44 
57 
70 
83 
93 
101 
122 
143 
151 
159 bool he_ssl_ctx_is_supported_version(he_ssl_ctx_t *context, uint8_t major_version,
160  uint8_t minor_version);
161 
169 bool he_ssl_ctx_is_latest_version(he_ssl_ctx_t *context, uint8_t major_version,
170  uint8_t minor_version);
171 
172 // Setters and getters for the configuration
185 he_return_code_t he_ssl_ctx_set_server_dn(he_ssl_ctx_t *ctx, const char *distinguished_name);
186 
192 const char *he_ssl_ctx_get_server_dn(he_ssl_ctx_t *ctx);
193 
203 
212 
219 
232 he_return_code_t he_ssl_ctx_set_ca(he_ssl_ctx_t *ctx, uint8_t *cert_buffer, size_t length);
233 
240 
245  const char *server_key);
246 
251 
260  he_connection_type_t connection_type);
261 
270 
280 
293 
303 
316 
338 he_return_code_t he_conn_outside_data_received(he_conn_t *conn, uint8_t *buffer, size_t length);
339 
349 
358  he_network_config_ipv4_cb_t network_config_cb);
359 
369 
376 
386 
395 
402 
409 
416 
425 
438 
448 
454 
460 
469 
470 #endif // SSL_CTX_H
he_return_code_t(* he_nudge_time_cb_t)(he_conn_t *conn, int timeout, void *context)
The prototype for the nudge time callback function.
Definition: he.h:367
void he_ssl_ctx_set_network_config_ipv4_cb(he_ssl_ctx_t *ctx, he_network_config_ipv4_cb_t network_config_cb)
Sets the function that will be called when Helium needs to pass network ctx to the host application...
Definition: ssl_ctx.c:410
he_return_code_t(* he_event_cb_t)(he_conn_t *conn, he_conn_event_t event, void *context)
The prototype for the event callback function.
Definition: he.h:345
he_return_code_t he_ssl_ctx_set_server_dn(he_ssl_ctx_t *ctx, const char *distinguished_name)
Set the expected Distinguished Name (DN) of the server.
Definition: ssl_ctx.c:306
bool he_ssl_ctx_is_server_cert_key_set(he_ssl_ctx_t *ctx)
Whether the server cert and keys have been set.
Definition: ssl_ctx.c:363
enum he_return_code he_return_code_t
All possible return codes for helium.
enum he_connection_type he_connection_type_t
Helium can operate in datagram or stream modes. This enum defines these two modes.
Definition: he.h:433
void he_ssl_ctx_set_event_cb(he_ssl_ctx_t *ctx, he_event_cb_t event_cb)
Sets the function that will be called when Helium needs to pass an event to the host application...
Definition: ssl_ctx.c:433
he_return_code_t he_ssl_ctx_set_ca(he_ssl_ctx_t *ctx, uint8_t *cert_buffer, size_t length)
Set the location and size of the CA certificate chain.
Definition: ssl_ctx.c:327
bool he_ssl_ctx_is_nudge_time_cb_set(he_ssl_ctx_t *ctx)
Check if the nudge time callback has been set.
Definition: ssl_ctx.c:426
bool he_ssl_ctx_is_server_dn_set(he_ssl_ctx_t *ctx)
Check if the server DN has been set.
Definition: ssl_ctx.c:314
he_return_code_t he_cleanup(void)
Cleans up all Helium global state.
Definition: ssl_ctx.c:44
void he_ssl_ctx_set_state_change_cb(he_ssl_ctx_t *ctx, he_state_change_cb_t state_change_cb)
Sets the function that should be called on Helium state changes.
Definition: ssl_ctx.c:377
he_ssl_ctx_t * he_ssl_ctx_create(void)
Creates a Helium SSL context.
Definition: ssl_ctx.c:101
void he_ssl_ctx_set_populate_network_config_ipv4_cb(he_ssl_ctx_t *ctx, he_populate_network_config_ipv4_cb_t pop_network_cb)
Sets the function that will be called when Helium needs to provide network ctx to a client...
Definition: ssl_ctx.c:449
he_return_code_t he_ssl_ctx_stop(he_ssl_ctx_t *context)
Try to cleanly stop the SSL contxt.
Definition: ssl_ctx.c:266
he_return_code_t(* he_inside_write_cb_t)(he_conn_t *conn, uint8_t *packet, size_t length, void *context)
The prototype for the inside write callback function.
Definition: he.h:305
he_return_code_t he_ssl_ctx_set_padding_type(he_ssl_ctx_t *ctx, he_padding_type_t padding_type)
Sets the padding mode and hence the level of padding (if any) to be used.
Definition: ssl_ctx.c:464
he_return_code_t he_ssl_ctx_is_valid_client(he_ssl_ctx_t *ctx)
Checks whether the client context has the basic configuration to allow Helium to connect.
Definition: ssl_ctx.c:67
bool he_ssl_ctx_is_roaming_disabled(he_ssl_ctx_t *ctx)
Check if roaming has been disabled.
Definition: ssl_ctx.c:460
void he_ssl_ctx_set_nudge_time_cb(he_ssl_ctx_t *ctx, he_nudge_time_cb_t nudge_time_cb)
Sets the function that will be called when Helium needs to update the nudge time. ...
Definition: ssl_ctx.c:422
bool he_ssl_ctx_is_network_config_ipv4_cb_set(he_ssl_ctx_t *ctx)
Check if the network ctx callback has been set.
Definition: ssl_ctx.c:415
bool he_ssl_ctx_is_outside_write_cb_set(he_ssl_ctx_t *ctx)
Check if the outside write callback has been set.
Definition: ssl_ctx.c:403
bool he_ssl_ctx_is_auth_cb_set(he_ssl_ctx_t *ctx)
Check if at least one auth callback has been set.
Definition: ssl_ctx.c:445
bool he_ssl_ctx_get_use_chacha20(he_ssl_ctx_t *ctx)
Returns whether CHACHA20 is enabled or not.
Definition: ssl_ctx.c:323
bool(* he_auth_cb_t)(he_conn_t *conn, char const *username, char const *password, void *context)
The prototype for the authentication callback.
Definition: he.h:381
he_return_code_t he_conn_outside_data_received(he_conn_t *conn, uint8_t *buffer, size_t length)
Called when the host application needs to deliver outside data to be processed by Helium...
Definition: flow.c:234
enum he_padding_type he_padding_type_t
Helium supports numerous padding levels, from none to full. This enum defines which options can be ch...
bool he_ssl_ctx_is_state_change_cb_set(he_ssl_ctx_t *ctx)
Check if the state change callback has been set.
Definition: ssl_ctx.c:381
void he_ssl_ctx_set_auth_buf_cb(he_ssl_ctx_t *ctx, he_auth_buf_cb_t auth_buf_cb)
Sets the function that will be called when Helium needs to authenticate a user.
Definition: ssl_ctx.c:441
bool he_ssl_ctx_is_latest_version(he_ssl_ctx_t *context, uint8_t major_version, uint8_t minor_version)
Validate whether the major/minor version is the latest.
Definition: ssl_ctx.c:299
he_return_code_t he_ssl_ctx_is_valid_server(he_ssl_ctx_t *ctx)
Checks whether the server context has the basic configuration to allow Helium to connect.
Definition: ssl_ctx.c:82
he_return_code_t he_ssl_ctx_set_disable_roaming(he_ssl_ctx_t *ctx)
Disables session roaming and removes the session ID from the packet header.
Definition: ssl_ctx.c:454
void he_ssl_ctx_destroy(he_ssl_ctx_t *ctx)
Releases all memory allocate by Helium for this context.
Definition: ssl_ctx.c:105
he_return_code_t he_ssl_ctx_set_aggressive_mode(he_ssl_ctx_t *ctx)
Sets the client to aggressive mode, where it will send each message three times to help improve the c...
Definition: ssl_ctx.c:473
bool(* he_auth_buf_cb_t)(he_conn_t *conn, uint8_t auth_type, uint8_t *buffer, uint16_t length, void *context)
The prototype for the authentication buffer callback.
Definition: he.h:396
he_return_code_t he_ssl_ctx_start(he_ssl_ctx_t *context)
Sets up all internal state so that client connections can be created.
Definition: ssl_ctx.c:137
he_return_code_t(* he_network_config_ipv4_cb_t)(he_conn_t *conn, he_network_config_ipv4_t *config, void *context)
The prototype for the network config callback function.
Definition: he.h:332
he_return_code_t he_ssl_ctx_set_connection_type(he_ssl_ctx_t *ctx, he_connection_type_t connection_type)
Set the connection type.
Definition: ssl_ctx.c:367
he_return_code_t he_ssl_ctx_set_use_chacha20(he_ssl_ctx_t *ctx, bool use)
Tell Helium to use CHACHA20 and Poly1305 instead of AES and SHA based encryption and authentication...
Definition: ssl_ctx.c:318
Core internal header file for libhelium.
const char * he_ssl_ctx_get_server_dn(he_ssl_ctx_t *ctx)
Get the Distinguished Name that Helium will use to verify the server&#39;s certificate.
Definition: ssl_ctx.c:310
void he_ssl_ctx_set_auth_cb(he_ssl_ctx_t *ctx, he_auth_cb_t auth_cb)
Sets the function that will be called when Helium needs to authenticate a user.
Definition: ssl_ctx.c:437
bool he_ssl_ctx_is_ca_set(he_ssl_ctx_t *ctx)
Check if the CA has been set.
Definition: ssl_ctx.c:347
bool he_ssl_ctx_is_supported_version(he_ssl_ctx_t *context, uint8_t major_version, uint8_t minor_version)
Validate whether a major/minor version is supported by this SSL context.
Definition: ssl_ctx.c:271
void he_ssl_ctx_set_inside_write_cb(he_ssl_ctx_t *ctx, he_inside_write_cb_t inside_write_cb)
Sets the function that will be called when Helium needs to do an inside write.
Definition: ssl_ctx.c:388
he_return_code_t he_init(void)
Initialises Helium global state.
Definition: ssl_ctx.c:33
he_return_code_t he_ssl_ctx_set_server_cert_key_files(he_ssl_ctx_t *ctx, const char *server_cert, const char *server_key)
Set the server cert and keys.
Definition: ssl_ctx.c:351
he_return_code_t(* he_populate_network_config_ipv4_cb_t)(he_conn_t *conn, he_network_config_ipv4_t *config, void *context)
The prototype for the population of the network config.
Definition: he.h:410
void he_ssl_ctx_set_outside_write_cb(he_ssl_ctx_t *ctx, he_outside_write_cb_t outside_write_cb)
Sets the function that will be called when Helium needs to do an outside write.
Definition: ssl_ctx.c:399
he_return_code_t(* he_outside_write_cb_t)(he_conn_t *conn, uint8_t *packet, size_t length, void *context)
The prototype for the outside write callback function.
Definition: he.h:319
bool he_ssl_ctx_is_inside_write_cb_set(he_ssl_ctx_t *ctx)
Check if the inside write callback has been set.
Definition: ssl_ctx.c:392
he_padding_type_t he_ssl_ctx_get_padding_type(he_ssl_ctx_t *ctx)
Returns the current padding mode.
Definition: ssl_ctx.c:470
Definition: he.h:483
he_return_code_t(* he_state_change_cb_t)(he_conn_t *conn, he_conn_state_t new_state, void *context)
The prototype for the state callback function.
Definition: he.h:291
he_return_code_t he_ssl_ctx_start_server(he_ssl_ctx_t *context)
Sets up all internal state so that server connections can be created.
Definition: ssl_ctx.c:207