Helium
|
Functions for managing the connection. More...
#include "he_internal.h"
Go to the source code of this file.
Macros | |
#define | HE_WOLF_TIMEOUT_MULTIPLIER 100 |
#define | HE_WOLF_RENEGOTIATION_TIMEOUT_MULTIPLIER 100 |
#define | HE_WOLF_QUICK_TIMEOUT_DIVIDER 4 |
Functions | |
he_conn_t * | he_conn_create (void) |
Creates a Helium connection struct. More... | |
void | he_conn_destroy (he_conn_t *conn) |
Releases all memory allocate by Helium for this connection. More... | |
he_return_code_t | he_conn_is_valid_client (he_ssl_ctx_t *ssl_ctx, he_conn_t *conn) |
Checks whether the client conn has the basic values to allow Helium to connect. More... | |
he_return_code_t | he_conn_is_valid_server (he_ssl_ctx_t *ssl_ctx, he_conn_t *conn) |
Checks whether the client conn has the basic values to allow Helium to connect. More... | |
int | he_conn_set_username (he_conn_t *conn, const char *username) |
Set the username to authenticate with. More... | |
const char * | he_conn_get_username (const he_conn_t *conn) |
Get the username that Helium will authenticate with, previously set by he_conn_set_username. More... | |
bool | he_conn_is_username_set (const he_conn_t *conn) |
Check if the password has been set. More... | |
he_return_code_t | he_conn_set_password (he_conn_t *conn, const char *password) |
Sets the password Helium should use to authenticate with. More... | |
bool | he_conn_is_password_set (const he_conn_t *conn) |
Check if the password has been set. More... | |
he_return_code_t | he_conn_set_auth_token (he_conn_t *conn, const uint8_t *token, size_t len) |
Sets the authentication token the Lightway client should use to authenticate with. More... | |
bool | he_conn_is_auth_token_set (const he_conn_t *conn) |
Check if the auth token has been set. More... | |
he_return_code_t | he_conn_set_auth_buffer2 (he_conn_t *conn, const uint8_t *buffer, uint16_t length) |
Sets the opaque buffer Helium should use to authenticate with. More... | |
bool | he_conn_is_auth_buffer_set (const he_conn_t *conn) |
Check if the auth buffer has been set. More... | |
he_return_code_t | he_conn_set_outside_mtu (he_conn_t *conn, uint16_t mtu) |
Set the MTU for the outside transport mechanism. Usually this will be the MTU of the device's internet connection. More... | |
uint16_t | he_conn_get_outside_mtu (he_conn_t *conn) |
Get the MTU value for the outside transport mechanism. More... | |
bool | he_conn_is_outside_mtu_set (he_conn_t *conn) |
Check if the outside MTU has been set. More... | |
he_return_code_t | he_conn_set_context (he_conn_t *conn, void *data) |
Store a pointer in the context that will be made available in all Helium callbacks. More... | |
void * | he_conn_get_context (he_conn_t *conn) |
Retrieve the pointer to the user supplied context. More... | |
he_return_code_t | he_conn_set_sni_hostname (he_conn_t *conn, const char *hostname) |
Set SNI hostname. More... | |
he_return_code_t | he_conn_client_connect (he_conn_t *conn, he_ssl_ctx_t *ssl_ctx, he_plugin_chain_t *inside_plugins, he_plugin_chain_t *outside_plugins) |
Tries to establish a connection with a Helium server. More... | |
he_return_code_t | he_conn_server_connect (he_conn_t *conn, he_ssl_ctx_t *ssl_ctx, he_plugin_chain_t *inside_plugins, he_plugin_chain_t *outside_plugins) |
Tries to establish a connection with a Helium client. More... | |
he_return_code_t | he_conn_disconnect (he_conn_t *conn) |
Try to cleanly disconnect from the remote Helium instance (client or server). More... | |
he_return_code_t | he_conn_send_keepalive (he_conn_t *conn) |
Tell Helium to send a keepalive message. This can be used to avoid NAT timing out. More... | |
he_return_code_t | he_conn_send_server_config (he_conn_t *conn, uint8_t *buffer, size_t length) |
Tell Helium to send a server config message to client. More... | |
he_return_code_t | he_conn_schedule_renegotiation (he_conn_t *conn) |
Tell Helium to schedule a renegotiation. More... | |
int | he_conn_get_nudge_time (he_conn_t *conn) |
Returns the number of milliseconds that host application should wait before nudging Helium. More... | |
he_return_code_t | he_conn_nudge (he_conn_t *conn) |
Nudges Helium. More... | |
he_conn_state_t | he_conn_get_state (he_conn_t *conn) |
Returns the state that the conn is currently in. More... | |
uint64_t | he_conn_get_session_id (he_conn_t *conn) |
Returns the session ID for this connection. | |
he_return_code_t | he_conn_set_session_id (he_conn_t *conn, uint64_t session_id) |
Sets the session ID for this connection. | |
uint64_t | he_conn_get_pending_session_id (he_conn_t *conn) |
Returns the pending session ID for this connection, if there is one. More... | |
bool | he_conn_is_error_fatal (he_conn_t *conn, he_return_code_t error_msg) |
Returns true if a given error (a return from libhelium where he_return_code_t != HE_SUCCESS) is obviously fatal and should terminate the connection. More... | |
he_return_code_t | he_conn_rotate_session_id (he_conn_t *conn, uint64_t *new_session_id) |
Rotate the session ID for this connection. More... | |
bool | he_conn_supports_renegotiation (he_conn_t *conn) |
Whether this particular connection supports renegotiation. More... | |
he_return_code_t | he_conn_set_protocol_version (he_conn_t *conn, uint8_t major_version, uint8_t minor_version) |
On the server, sets the major/minor version number for this connection. More... | |
he_return_code_t | he_conn_get_protocol_version (he_conn_t *conn, uint8_t *major_version, uint8_t *minor_version) |
On the server, get the current major/minor version number for this connection. More... | |
const char * | he_conn_get_current_cipher (he_conn_t *conn) |
Returns the name of the cipher used by the ssl context. More... | |
he_connection_protocol_t | he_conn_get_current_protocol (he_conn_t *conn) |
Returns the current connection protocol. More... | |
const char * | he_conn_get_curve_name (he_conn_t *conn) |
Returns the name of the curve used by the ssl context. More... | |
he_return_code_t | he_conn_start_pmtu_discovery (he_conn_t *conn) |
Tell Helium to start a PMTU discovery. More... | |
uint16_t | he_conn_get_effective_pmtu (he_conn_t *conn) |
Get current effective PMTU of the connection. More... | |
he_return_code_t | he_conn_pmtud_probe_timeout (he_conn_t *conn) |
Called when a PMTUD probe timer expired. More... | |
int | he_conn_get_ssl_error (he_conn_t *conn) |
Returns detailed SSL error that corresponds to WolfSSL's detailed errors. More... | |
void | he_conn_set_ssl_error (he_conn_t *conn, int error) |
Functions for managing the connection.
Lightway Core Copyright (C) 2021 Express VPN International Ltd.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#define HE_WOLF_QUICK_TIMEOUT_DIVIDER 4 |
Divider to use when wolfSSL signals that it wants to perform a short timeout to check for any additional out of order messages before performing retransmission.
#define HE_WOLF_TIMEOUT_MULTIPLIER 100 |
D/TLS is a UDP based protocol and requires the application (rather than the OS as with TCP) to keep track of the need to do retransmits on packet loss.
Currently Wolf has timeouts based in seconds. However this is not sufficient for our goal of sub-second connection times.
As WolfSSL lacks millisecond timers we use its internal timers but change its definition to be in 100 millisecond intervals instead of seconds. So a wolf timeout of 1 second means 100 milliseconds.
By default wolf's DTLS max timeout is 64 seconds which translates to 6.4 seconds. Since it scales from 1 to 64 by a factor of 2 each timeout. The total timeout is 12.7 seconds with this scaling which for our purposes is plenty.
he_return_code_t he_conn_client_connect | ( | he_conn_t * | conn, |
he_ssl_ctx_t * | ssl_ctx, | ||
he_plugin_chain_t * | inside_plugins, | ||
he_plugin_chain_t * | outside_plugins | ||
) |
Tries to establish a connection with a Helium server.
conn | A pointer to a valid Helium connection |
ssl_ctx | A pointer to valid and started SSL context |
inside_plugins | A pointer to a valid plugin chain |
outside_plugins | A pointer to a valid plugin chain |
This function has a lot of return codes as it is where Helium tries to apply and configure the crypto engine. All of the return codes except for HE_SUCCESS are effectively fatal errors. Trying to call he_conn_client_connect again without changing the connection is unlikely to succeed.
he_conn_t* he_conn_create | ( | void | ) |
Creates a Helium connection struct.
This function must be called to create the initial Helium connection for use with other functions.
void he_conn_destroy | ( | he_conn_t * | conn | ) |
Releases all memory allocate by Helium for this connection.
conn | A pointer to a valid Helium connection |
It will first remove all of the callbacks which means no Helium callbacks will be triggered after calling this function. It is thus an error to call any Helium functions on this connection after it has been destroyed.
he_return_code_t he_conn_disconnect | ( | he_conn_t * | conn | ) |
Try to cleanly disconnect from the remote Helium instance (client or server).
void* he_conn_get_context | ( | he_conn_t * | conn | ) |
Retrieve the pointer to the user supplied context.
conn | A pointer to a valid HE context |
const char* he_conn_get_current_cipher | ( | he_conn_t * | conn | ) |
Returns the name of the cipher used by the ssl context.
conn | A pointer to a valid connection |
he_connection_protocol_t he_conn_get_current_protocol | ( | he_conn_t * | conn | ) |
Returns the current connection protocol.
conn | A pointer to a valid connection |
const char* he_conn_get_curve_name | ( | he_conn_t * | conn | ) |
Returns the name of the curve used by the ssl context.
conn | A pointer to a valid connection |
uint16_t he_conn_get_effective_pmtu | ( | he_conn_t * | conn | ) |
Get current effective PMTU of the connection.
conn | A pointer to a valid connection |
int he_conn_get_nudge_time | ( | he_conn_t * | conn | ) |
Returns the number of milliseconds that host application should wait before nudging Helium.
conn | A pointer to a valid connection |
uint16_t he_conn_get_outside_mtu | ( | he_conn_t * | conn | ) |
Get the MTU value for the outside transport mechanism.
conn | A pointer to a valid connection. |
uint64_t he_conn_get_pending_session_id | ( | he_conn_t * | conn | ) |
Returns the pending session ID for this connection, if there is one.
conn | A pointer to a valid connection |
he_return_code_t he_conn_get_protocol_version | ( | he_conn_t * | conn, |
uint8_t * | major_version, | ||
uint8_t * | minor_version | ||
) |
On the server, get the current major/minor version number for this connection.
conn | A pointer to a valid server connection |
major_version | Pointer to the connection major version |
minor_version | Pointer to the connection minor version |
int he_conn_get_ssl_error | ( | he_conn_t * | conn | ) |
Returns detailed SSL error that corresponds to WolfSSL's detailed errors.
conn | A pointer to a valid server connection |
he_conn_state_t he_conn_get_state | ( | he_conn_t * | conn | ) |
Returns the state that the conn is currently in.
conn | A pointer to a valid connection |
const char* he_conn_get_username | ( | const he_conn_t * | conn | ) |
Get the username that Helium will authenticate with, previously set by he_conn_set_username.
conn | A pointer to a valid connection |
bool he_conn_is_auth_buffer_set | ( | const he_conn_t * | conn | ) |
Check if the auth buffer has been set.
conn | A pointer to a valid connection |
It is anticipated that this feature will be used for implementing UIs that don't maintain their own connection state.
bool he_conn_is_auth_token_set | ( | const he_conn_t * | conn | ) |
Check if the auth token has been set.
conn | A pointer to a valid connection |
It is anticipated that this feature will be used for implementing UIs that don't maintain their own connection state.
bool he_conn_is_error_fatal | ( | he_conn_t * | conn, |
he_return_code_t | error_msg | ||
) |
Returns true if a given error (a return from libhelium where he_return_code_t != HE_SUCCESS) is obviously fatal and should terminate the connection.
It is not required to call this function – users are welcome to capture their errors, close connections and reconnect even if this function returns false.
bool he_conn_is_outside_mtu_set | ( | he_conn_t * | conn | ) |
Check if the outside MTU has been set.
conn | A pointer to a valid connection |
It is anticipated that this feature will be used for implementing UIs that don't maintain their own connection state.
bool he_conn_is_password_set | ( | const he_conn_t * | conn | ) |
Check if the password has been set.
conn | A pointer to a valid connection |
It is anticipated that this feature will be used for implementing UIs that don't maintain their own connection state.
bool he_conn_is_username_set | ( | const he_conn_t * | conn | ) |
Check if the password has been set.
conn | A pointer to a valid connection |
It is anticipated that this feature will be used for implementing UIs that don't maintain their own connection state.
he_return_code_t he_conn_is_valid_client | ( | he_ssl_ctx_t * | ssl_ctx, |
he_conn_t * | conn | ||
) |
Checks whether the client conn has the basic values to allow Helium to connect.
ssl_ctx | A pointer to a valid SSL context |
conn | A pointer to a valid connection conn |
he_conn_client_connect
because that function will call this function before attempting to connect. he_return_code_t he_conn_is_valid_server | ( | he_ssl_ctx_t * | ssl_ctx, |
he_conn_t * | conn | ||
) |
Checks whether the client conn has the basic values to allow Helium to connect.
ssl_ctx | A pointer to a valid SSL context |
conn | A pointer to a valid connection conn |
he_conn_server_connect
because that function will call this function before attempting to connect. he_return_code_t he_conn_nudge | ( | he_conn_t * | conn | ) |
Nudges Helium.
conn | A pointer to a valid connection |
he_return_code_t he_conn_pmtud_probe_timeout | ( | he_conn_t * | conn | ) |
Called when a PMTUD probe timer expired.
conn | A pointer to a valid connection |
he_return_code_t he_conn_rotate_session_id | ( | he_conn_t * | conn, |
uint64_t * | new_session_id | ||
) |
Rotate the session ID for this connection.
After calling this function, the value returned by he_conn_get_session_id will NOT be updated. The value returned by he_conn_get_pending_session_id is guaranteed to be the same as the value pointed to by new_session_id if that parameter is not null.
After the event "HE_EVENT_PENDING_SESSION_ACKNOWLEDGED" fires, he_conn_get_pending_session_id will return 0, and the value for he_conn_get_session_id will be the same as the session ID generated by this call.
conn | A pointer to a valid connection |
new_session_id | A uint64_t pointer; if not null the value will be updated with the new session ID |
he_return_code_t he_conn_schedule_renegotiation | ( | he_conn_t * | conn | ) |
Tell Helium to schedule a renegotiation.
conn | A pointer to a valid connection |
Note that this schedules a key rotation or D/TLS renegotiation on the next time we process data on this connection; calling this function provides no time-based guarantees, only that when we see this connection again we will renegotiate.
he_return_code_t he_conn_send_keepalive | ( | he_conn_t * | conn | ) |
Tell Helium to send a keepalive message. This can be used to avoid NAT timing out.
conn | A pointer to a valid connection |
This is used to send a heartbeat message to a Helium server and get a reply. Its primary use is to ensure that the connection doesn't time out due to NAT traversal. This feature is not mandatory, but as Helium cannot by itself know when to send these, it is up to the host application to call this function at the required intervals.
he_return_code_t he_conn_send_server_config | ( | he_conn_t * | conn, |
uint8_t * | buffer, | ||
size_t | length | ||
) |
Tell Helium to send a server config message to client.
conn | A pointer to a valid connection |
This is used to send a server config message to a Helium client from server. The server must have already established the TLS connection, but it's OK the client is not authenticated yet.
he_return_code_t he_conn_server_connect | ( | he_conn_t * | conn, |
he_ssl_ctx_t * | ssl_ctx, | ||
he_plugin_chain_t * | inside_plugins, | ||
he_plugin_chain_t * | outside_plugins | ||
) |
Tries to establish a connection with a Helium client.
conn | A pointer to a valid Helium connection |
ssl_ctx | A pointer to valid and started SSL context |
inside_plugins | A pointer to a valid plugin chain |
outside_plugins | A pointer to a valid plugin chain |
This function has a lot of return codes as it is where Helium tries to apply and configure the crypto engine. All of the return codes except for HE_SUCCESS are effectively fatal errors. Trying to call he_conn_client_connect again without changing the connection is unlikely to succeed.
he_return_code_t he_conn_set_auth_buffer2 | ( | he_conn_t * | conn, |
const uint8_t * | buffer, | ||
uint16_t | length | ||
) |
Sets the opaque buffer Helium should use to authenticate with.
conn | A pointer to a valid connection |
buffer | A pointer to the authentication buffer to use |
length | The length of the buffer in bytes. |
he_return_code_t he_conn_set_auth_token | ( | he_conn_t * | conn, |
const uint8_t * | token, | ||
size_t | len | ||
) |
Sets the authentication token the Lightway client should use to authenticate with.
conn | A pointer to a valid connection |
token | A pointer to the buffer containing the token |
len | The length of the token in bytes, it must be smaller than HE_MAX_MTU |
It's recommended to use a signed JSON Web Token (JWT - RFC 7519) as the auth token, but implementations might choose to use other formats.
he_return_code_t he_conn_set_context | ( | he_conn_t * | conn, |
void * | data | ||
) |
Store a pointer in the context that will be made available in all Helium callbacks.
conn | A valid connection |
data | A pointer to a user provided data structure |
Helium will interact with the host application primarily through the use of callback functions. To avoid the need for global variables, a pointer to some data structure can be set on the context. This context will be passed in all function callbacks as void pointer.
he_return_code_t he_conn_set_outside_mtu | ( | he_conn_t * | conn, |
uint16_t | mtu | ||
) |
Set the MTU for the outside transport mechanism. Usually this will be the MTU of the device's internet connection.
conn | A pointer to a valid connection |
mtu | The MTU of the outside transport mechanism in bytes |
he_return_code_t he_conn_set_password | ( | he_conn_t * | conn, |
const char * | password | ||
) |
Sets the password Helium should use to authenticate with.
conn | A pointer to a valid connection |
password | A pointer to the password |
he_return_code_t he_conn_set_protocol_version | ( | he_conn_t * | conn, |
uint8_t | major_version, | ||
uint8_t | minor_version | ||
) |
On the server, sets the major/minor version number for this connection.
conn | A pointer to a valid server connection |
major_version | The connection major version |
minor_version | The connection minor version |
he_return_code_t he_conn_set_sni_hostname | ( | he_conn_t * | conn, |
const char * | hostname | ||
) |
Set SNI hostname.
conn | A valid connection |
hostname | A null-terminated string contains the SNI hostname |
If the hostname is not empty, the client will enable SNI and set the hostname in the ClientHello message when connecting to the server. Available for TLS v1.3 only.
int he_conn_set_username | ( | he_conn_t * | conn, |
const char * | username | ||
) |
Set the username to authenticate with.
conn | A pointer to a valid conn |
username | A pointer to the username |
he_return_code_t he_conn_start_pmtu_discovery | ( | he_conn_t * | conn | ) |
Tell Helium to start a PMTU discovery.
conn | A pointer to a valid connection |
bool he_conn_supports_renegotiation | ( | he_conn_t * | conn | ) |
Whether this particular connection supports renegotiation.
Only pre-Dec 2020 clients won't support this.