wpa_supplicant / hostapd
2.5
|
TLS interface functions and an internal TLS implementation. More...
#include "includes.h"
#include "common.h"
#include "tls.h"
#include "tls/tlsv1_client.h"
#include "tls/tlsv1_server.h"
Data Structures | |
struct | tls_global |
struct | tls_connection |
Functions | |
void * | tls_init (const struct tls_config *conf) |
Initialize TLS library. More... | |
void | tls_deinit (void *ssl_ctx) |
Deinitialize TLS library. More... | |
int | tls_get_errors (void *tls_ctx) |
Process pending errors. More... | |
struct tls_connection * | tls_connection_init (void *tls_ctx) |
Initialize a new TLS connection. More... | |
void | tls_connection_set_log_cb (struct tls_connection *conn, void(*log_cb)(void *ctx, const char *msg), void *ctx) |
void | tls_connection_deinit (void *tls_ctx, struct tls_connection *conn) |
Free TLS connection data. More... | |
int | tls_connection_established (void *tls_ctx, struct tls_connection *conn) |
Has the TLS connection been completed? More... | |
int | tls_connection_shutdown (void *tls_ctx, struct tls_connection *conn) |
Shutdown TLS connection. More... | |
int | tls_connection_set_params (void *tls_ctx, struct tls_connection *conn, const struct tls_connection_params *params) |
Set TLS connection parameters. More... | |
int | tls_global_set_params (void *tls_ctx, const struct tls_connection_params *params) |
Set TLS parameters for all TLS connection. More... | |
int | tls_global_set_verify (void *tls_ctx, int check_crl) |
Set global certificate verification options. More... | |
int | tls_connection_set_verify (void *tls_ctx, struct tls_connection *conn, int verify_peer, unsigned int flags, const u8 *session_ctx, size_t session_ctx_len) |
Set certificate verification options. More... | |
int | tls_connection_get_random (void *tls_ctx, struct tls_connection *conn, struct tls_random *data) |
Get random data from TLS connection. More... | |
int | tls_connection_prf (void *tls_ctx, struct tls_connection *conn, const char *label, int server_random_first, int skip_keyblock, u8 *out, size_t out_len) |
Use TLS-PRF to derive keying material. More... | |
struct wpabuf * | tls_connection_handshake (void *tls_ctx, struct tls_connection *conn, const struct wpabuf *in_data, struct wpabuf **appl_data) |
Process TLS handshake (client side) More... | |
struct wpabuf * | tls_connection_handshake2 (void *tls_ctx, struct tls_connection *conn, const struct wpabuf *in_data, struct wpabuf **appl_data, int *need_more_data) |
struct wpabuf * | tls_connection_server_handshake (void *tls_ctx, struct tls_connection *conn, const struct wpabuf *in_data, struct wpabuf **appl_data) |
Process TLS handshake (server side) More... | |
struct wpabuf * | tls_connection_encrypt (void *tls_ctx, struct tls_connection *conn, const struct wpabuf *in_data) |
Encrypt data into TLS tunnel. More... | |
struct wpabuf * | tls_connection_decrypt (void *tls_ctx, struct tls_connection *conn, const struct wpabuf *in_data) |
Decrypt data from TLS tunnel. More... | |
struct wpabuf * | tls_connection_decrypt2 (void *tls_ctx, struct tls_connection *conn, const struct wpabuf *in_data, int *need_more_data) |
int | tls_connection_resumed (void *tls_ctx, struct tls_connection *conn) |
Was session resumption used. More... | |
int | tls_connection_set_cipher_list (void *tls_ctx, struct tls_connection *conn, u8 *ciphers) |
Configure acceptable cipher suites. More... | |
int | tls_get_version (void *ssl_ctx, struct tls_connection *conn, char *buf, size_t buflen) |
Get the current TLS version number. More... | |
int | tls_get_cipher (void *tls_ctx, struct tls_connection *conn, char *buf, size_t buflen) |
Get current cipher name. More... | |
int | tls_connection_enable_workaround (void *tls_ctx, struct tls_connection *conn) |
Enable TLS workaround options. More... | |
int | tls_connection_client_hello_ext (void *tls_ctx, struct tls_connection *conn, int ext_type, const u8 *data, size_t data_len) |
Set TLS extension for ClientHello. More... | |
int | tls_connection_get_failed (void *tls_ctx, struct tls_connection *conn) |
Get connection failure status. More... | |
int | tls_connection_get_read_alerts (void *tls_ctx, struct tls_connection *conn) |
Get connection read alert status. More... | |
int | tls_connection_get_write_alerts (void *tls_ctx, struct tls_connection *conn) |
Get connection write alert status. More... | |
int | tls_connection_set_session_ticket_cb (void *tls_ctx, struct tls_connection *conn, tls_session_ticket_cb cb, void *ctx) |
int | tls_get_library_version (char *buf, size_t buf_len) |
void | tls_connection_set_success_data (struct tls_connection *conn, struct wpabuf *data) |
void | tls_connection_set_success_data_resumed (struct tls_connection *conn) |
const struct wpabuf * | tls_connection_get_success_data (struct tls_connection *conn) |
void | tls_connection_remove_session (struct tls_connection *conn) |
TLS interface functions and an internal TLS implementation.
This file interface functions for hostapd/wpa_supplicant to use the integrated TLSv1 implementation.
int tls_connection_client_hello_ext | ( | void * | tls_ctx, |
struct tls_connection * | conn, | ||
int | ext_type, | ||
const u8 * | data, | ||
size_t | data_len | ||
) |
Set TLS extension for ClientHello.
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
ext_type | Extension type |
data | Extension payload (NULL to remove extension) |
data_len | Extension payload length |
struct wpabuf* tls_connection_decrypt | ( | void * | tls_ctx, |
struct tls_connection * | conn, | ||
const struct wpabuf * | in_data | ||
) |
Decrypt data from TLS tunnel.
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
in_data | Encrypted TLS data |
This function is used after TLS handshake has been completed successfully to receive data from the encrypted tunnel. The caller is responsible for freeing the returned output data.
void tls_connection_deinit | ( | void * | tls_ctx, |
struct tls_connection * | conn | ||
) |
Free TLS connection data.
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
Release all resources allocated for TLS connection.
int tls_connection_enable_workaround | ( | void * | tls_ctx, |
struct tls_connection * | conn | ||
) |
Enable TLS workaround options.
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
This function is used to enable connection-specific workaround options for buffer SSL/TLS implementations.
struct wpabuf* tls_connection_encrypt | ( | void * | tls_ctx, |
struct tls_connection * | conn, | ||
const struct wpabuf * | in_data | ||
) |
Encrypt data into TLS tunnel.
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
in_data | Plaintext data to be encrypted |
This function is used after TLS handshake has been completed successfully to send data in the encrypted tunnel. The caller is responsible for freeing the returned output data.
int tls_connection_established | ( | void * | tls_ctx, |
struct tls_connection * | conn | ||
) |
Has the TLS connection been completed?
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
int tls_connection_get_failed | ( | void * | tls_ctx, |
struct tls_connection * | conn | ||
) |
Get connection failure status.
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
Returns >0 if connection has failed, 0 if not.
int tls_connection_get_random | ( | void * | tls_ctx, |
struct tls_connection * | conn, | ||
struct tls_random * | data | ||
) |
Get random data from TLS connection.
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
data | Structure of client/server random data (filled on success) |
int tls_connection_get_read_alerts | ( | void * | tls_ctx, |
struct tls_connection * | conn | ||
) |
Get connection read alert status.
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
int tls_connection_get_write_alerts | ( | void * | tls_ctx, |
struct tls_connection * | conn | ||
) |
Get connection write alert status.
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
struct wpabuf* tls_connection_handshake | ( | void * | tls_ctx, |
struct tls_connection * | conn, | ||
const struct wpabuf * | in_data, | ||
struct wpabuf ** | appl_data | ||
) |
Process TLS handshake (client side)
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
in_data | Input data from TLS server |
appl_data | Pointer to application data pointer, or NULL if dropped |
The caller is responsible for freeing the returned output data. If the final handshake message includes application data, this is decrypted and appl_data (if not NULL) is set to point this data. The caller is responsible for freeing appl_data.
This function is used during TLS handshake. The first call is done with in_data == NULL and the library is expected to return ClientHello packet. This packet is then send to the server and a response from server is given to TLS library by calling this function again with in_data pointing to the TLS message from the server.
If the TLS handshake fails, this function may return NULL. However, if the TLS library has a TLS alert to send out, that should be returned as the output data. In this case, tls_connection_get_failed() must return failure (> 0).
tls_connection_established() should return 1 once the TLS handshake has been completed successfully.
struct tls_connection* tls_connection_init | ( | void * | tls_ctx | ) |
Initialize a new TLS connection.
tls_ctx | TLS context data from tls_init() |
int tls_connection_prf | ( | void * | tls_ctx, |
struct tls_connection * | conn, | ||
const char * | label, | ||
int | server_random_first, | ||
int | skip_keyblock, | ||
u8 * | out, | ||
size_t | out_len | ||
) |
Use TLS-PRF to derive keying material.
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
label | Label (e.g., description of the key) for PRF |
server_random_first | seed is 0 = client_random|server_random, 1 = server_random|client_random |
skip_keyblock | Skip TLS key block from the beginning of PRF output |
out | Buffer for output data from TLS-PRF |
out_len | Length of the output buffer |
tls_connection_prf() is required so that further keying material can be derived from the master secret. Example implementation of this function is in tls_prf_sha1_md5() when it is called with seed set to client_random|server_random (or server_random|client_random). For TLSv1.2 and newer, a different PRF is needed, though.
int tls_connection_resumed | ( | void * | tls_ctx, |
struct tls_connection * | conn | ||
) |
Was session resumption used.
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
struct wpabuf* tls_connection_server_handshake | ( | void * | tls_ctx, |
struct tls_connection * | conn, | ||
const struct wpabuf * | in_data, | ||
struct wpabuf ** | appl_data | ||
) |
Process TLS handshake (server side)
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
in_data | Input data from TLS peer |
appl_data | Pointer to application data pointer, or NULL if dropped |
The caller is responsible for freeing the returned output data.
int tls_connection_set_cipher_list | ( | void * | tls_ctx, |
struct tls_connection * | conn, | ||
u8 * | ciphers | ||
) |
Configure acceptable cipher suites.
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
ciphers | Zero (TLS_CIPHER_NONE) terminated list of allowed ciphers (TLS_CIPHER_*). |
int tls_connection_set_params | ( | void * | tls_ctx, |
struct tls_connection * | conn, | ||
const struct tls_connection_params * | params | ||
) |
Set TLS connection parameters.
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
params | Connection parameters |
int tls_connection_set_verify | ( | void * | tls_ctx, |
struct tls_connection * | conn, | ||
int | verify_peer, | ||
unsigned int | flags, | ||
const u8 * | session_ctx, | ||
size_t | session_ctx_len | ||
) |
Set certificate verification options.
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
verify_peer | 1 = verify peer certificate |
flags | Connection flags (TLS_CONN_*) |
session_ctx | Session caching context or NULL to use default |
session_ctx_len | Length of session_ctx in bytes. |
int tls_connection_shutdown | ( | void * | tls_ctx, |
struct tls_connection * | conn | ||
) |
Shutdown TLS connection.
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
Shutdown current TLS connection without releasing all resources. New connection can be started by using the same conn without having to call tls_connection_init() or setting certificates etc. again. The new connection should try to use session resumption.
void tls_deinit | ( | void * | tls_ctx | ) |
Deinitialize TLS library.
tls_ctx | TLS context data from tls_init() |
Called once during program shutdown and once for each RSN pre-authentication session. If global library deinitialization is needed (i.e., one that is shared between both authentication types), the TLS library wrapper should maintain a reference counter and do global deinitialization only when moving from 1 to 0 references.
int tls_get_cipher | ( | void * | tls_ctx, |
struct tls_connection * | conn, | ||
char * | buf, | ||
size_t | buflen | ||
) |
Get current cipher name.
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
buf | Buffer for the cipher name |
buflen | buf size |
Get the name of the currently used cipher.
int tls_get_errors | ( | void * | tls_ctx | ) |
Process pending errors.
tls_ctx | TLS context data from tls_init() |
Process all pending TLS errors.
int tls_get_version | ( | void * | tls_ctx, |
struct tls_connection * | conn, | ||
char * | buf, | ||
size_t | buflen | ||
) |
Get the current TLS version number.
tls_ctx | TLS context data from tls_init() |
conn | Connection context data from tls_connection_init() |
buf | Buffer for returning the TLS version number |
buflen | buf size |
Get the currently used TLS version number.
int tls_global_set_params | ( | void * | tls_ctx, |
const struct tls_connection_params * | params | ||
) |
Set TLS parameters for all TLS connection.
tls_ctx | TLS context data from tls_init() |
params | Global TLS parameters |
int tls_global_set_verify | ( | void * | tls_ctx, |
int | check_crl | ||
) |
Set global certificate verification options.
tls_ctx | TLS context data from tls_init() |
check_crl | 0 = do not verify CRLs, 1 = verify CRL for the user certificate, 2 = verify CRL for all certificates |
void* tls_init | ( | const struct tls_config * | conf | ) |
Initialize TLS library.
conf | Configuration data for TLS library |
Called once during program startup and once for each RSN pre-authentication session. In other words, there can be two concurrent TLS contexts. If global library initialization is needed (i.e., one that is shared between both authentication types), the TLS library wrapper should maintain a reference counter and do global initialization only when moving from 0 to 1 reference.