OpenVPN
tls_crypt.c File Reference
#include "syshead.h"
#include "argv.h"
#include "base64.h"
#include "crypto.h"
#include "integer.h"
#include "platform.h"
#include "run_command.h"
#include "session_id.h"
#include "ssl.h"
#include "buffer.h"
#include "tls_crypt.h"
Include dependency graph for tls_crypt.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static struct key_type tls_crypt_kt (void)
unsigned int tls_crypt_buf_overhead (void)
 Returns the maximum overhead (in bytes) added to the destination buffer by tls_crypt_wrap().
void tls_crypt_init_key (struct key_ctx_bi *key, struct key2 *keydata, const char *key_file, bool key_inline, bool tls_server)
 Initialize a key_ctx_bi structure for use with --tls-crypt.
static void xor_key2 (struct key2 *key, const struct key2 *other)
 Will produce key = key XOR other.
bool tls_session_generate_dynamic_tls_crypt_key (struct tls_session *session)
 Generates a TLS-Crypt key to be used with dynamic tls-crypt using the TLS EKM exporter function.
bool tls_crypt_wrap (const struct buffer *src, struct buffer *dst, struct crypto_options *opt)
 Wrap a control channel packet (both authenticates and encrypts the data).
bool tls_crypt_unwrap (const struct buffer *src, struct buffer *dst, struct crypto_options *opt)
 Unwrap a control channel packet (decrypts, authenticates and performs replay checks).
static void tls_crypt_v2_load_client_key (struct key_ctx_bi *key, const struct key2 *key2, bool tls_server)
void tls_crypt_v2_init_client_key (struct key_ctx_bi *key, struct key2 *original_key, struct buffer *wkc_buf, const char *key_file, bool key_inline)
 Initialize a tls-crypt-v2 client key.
void tls_crypt_v2_init_server_key (struct key_ctx *key_ctx, bool encrypt, const char *key_file, bool key_inline)
 Initialize a tls-crypt-v2 server key (used to encrypt/decrypt client keys).
static bool tls_crypt_v2_wrap_client_key (struct buffer *wkc, const struct key2 *src_key, const struct buffer *src_metadata, struct key_ctx *server_key, struct gc_arena *gc)
static bool tls_crypt_v2_unwrap_client_key (struct key2 *client_key, struct buffer *metadata, struct buffer wrapped_client_key, struct key_ctx *server_key)
static bool tls_crypt_v2_check_client_key_age (const struct buffer *tls_crypt_v2_metadata, int max_days)
static bool tls_crypt_v2_verify_metadata (const struct buffer *tls_crypt_v2_metadata, const struct tls_options *opt)
bool tls_crypt_v2_extract_client_key (struct buffer *buf, struct tls_wrap_ctx *ctx, const struct tls_options *opt)
 Extract a tls-crypt-v2 client key from a P_CONTROL_HARD_RESET_CLIENT_V3 message, and load the key into the supplied tls wrap context.
void tls_crypt_v2_write_server_key_file (const char *filename)
 Generate a tls-crypt-v2 server key, and write to file.
void tls_crypt_v2_write_client_key_file (const char *filename, const char *b64_metadata, const char *server_key_file, bool server_key_inline)
 Generate a tls-crypt-v2 client key, and write to file.

Variables

const char * tls_crypt_v2_cli_pem_name = "OpenVPN tls-crypt-v2 client key"
const char * tls_crypt_v2_srv_pem_name = "OpenVPN tls-crypt-v2 server key"
static const uint8_t TLS_CRYPT_METADATA_TYPE_USER = 0x00
 Metadata contains user-specified data.
static const uint8_t TLS_CRYPT_METADATA_TYPE_TIMESTAMP = 0x01
 Metadata contains a 64-bit unix timestamp in network byte order.

Function Documentation

◆ tls_crypt_kt()

◆ tls_crypt_v2_check_client_key_age()

bool tls_crypt_v2_check_client_key_age ( const struct buffer * tls_crypt_v2_metadata,
int max_days )
static

Definition at line 531 of file tls_crypt.c.

References BLENZ, CBPTR, M_WARN, msg, now, ntohll, and TLS_CRYPT_METADATA_TYPE_TIMESTAMP.

Referenced by tls_crypt_v2_extract_client_key().

◆ tls_crypt_v2_load_client_key()

void tls_crypt_v2_load_client_key ( struct key_ctx_bi * key,
const struct key2 * key2,
bool tls_server )
inlinestatic

◆ tls_crypt_v2_unwrap_client_key()

◆ tls_crypt_v2_verify_metadata()

◆ tls_crypt_v2_wrap_client_key()

◆ xor_key2()

void xor_key2 ( struct key2 * key,
const struct key2 * other )
static

Will produce key = key XOR other.

Definition at line 79 of file tls_crypt.c.

References ASSERT, key::cipher, key::hmac, key2::keys, MAX_CIPHER_KEY_LENGTH, MAX_HMAC_KEY_LENGTH, and key2::n.

Referenced by tls_session_generate_dynamic_tls_crypt_key().

Variable Documentation

◆ TLS_CRYPT_METADATA_TYPE_TIMESTAMP

const uint8_t TLS_CRYPT_METADATA_TYPE_TIMESTAMP = 0x01
static

Metadata contains a 64-bit unix timestamp in network byte order.

Definition at line 47 of file tls_crypt.c.

Referenced by create_metadata_days_ago(), tls_crypt_v2_check_client_key_age(), and tls_crypt_v2_write_client_key_file().

◆ TLS_CRYPT_METADATA_TYPE_USER

const uint8_t TLS_CRYPT_METADATA_TYPE_USER = 0x00
static

Metadata contains user-specified data.

Definition at line 45 of file tls_crypt.c.

Referenced by tls_crypt_v2_write_client_key_file().

◆ tls_crypt_v2_cli_pem_name

const char* tls_crypt_v2_cli_pem_name = "OpenVPN tls-crypt-v2 client key"

Definition at line 41 of file tls_crypt.c.

Referenced by tls_crypt_v2_init_client_key(), and tls_crypt_v2_write_client_key_file().

◆ tls_crypt_v2_srv_pem_name

const char* tls_crypt_v2_srv_pem_name = "OpenVPN tls-crypt-v2 server key"

Definition at line 42 of file tls_crypt.c.

Referenced by tls_crypt_v2_init_server_key(), and tls_crypt_v2_write_server_key_file().