Go to the documentation of this file.
171 #define KEY_DIRECTION_BIDIRECTIONAL 0
172 #define KEY_DIRECTION_NORMAL 1
173 #define KEY_DIRECTION_INVERSE 2
250 #define CO_PACKET_ID_LONG_FORM (1<<0)
253 #define CO_IGNORE_PACKET_ID (1<<1)
259 #define CO_MUTE_REPLAY_WARNINGS (1<<2)
262 #define CO_USE_TLS_KEY_MATERIAL_EXPORT (1<<3)
266 #define CO_RESEND_WKC (1<<4)
270 #define CO_FORCE_TLSCRYPTV2_COOKIE (1<<5)
274 #define CO_USE_CC_EXIT_NOTIFY (1<<6)
278 #define CO_USE_DYNAMIC_TLS_CRYPT (1<<7)
287 #define CRYPT_ERROR(format) \
288 do { msg(D_CRYPT_ERRORS, "%s: " format, error_prefix); goto error_exit; } while (false)
294 #define OPENVPN_AEAD_MIN_IV_LEN (sizeof(packet_id_type) + 8)
296 #define RKF_MUST_SUCCEED (1<<0)
297 #define RKF_INLINE (1<<1)
325 const char *authname,
bool tls_mode,
bool warn);
338 int key_direction,
const struct key_type *kt,
413 const uint8_t *ad_start);
447 unsigned int pkt_id_size,
485 const char *key_file,
bool key_inline);
529 const char *prefix1);
533 bool key_inline,
const int key_direction,
534 const char *key_name,
const char *opt_name,
535 struct key2 *keydata);
int out_key
Index into the key2.keys array for the sending direction.
static bool cipher_valid(const char *ciphername)
Returns if the cipher is valid, based on the given cipher name.
int n
The number of key objects stored in the key2.keys array.
bool generate_ephemeral_key(struct buffer *key, const char *pem_name)
Generate ephermal key material into the key structure.
mbedtls_md_context_t hmac_ctx_t
Generic HMAC context.
void key2_print(const struct key2 *k, const struct key_type *kt, const char *prefix0, const char *prefix1)
Prints the keys in a key2 structure.
static bool key_ctx_bi_defined(const struct key_ctx_bi *key)
static bool cipher_defined(const char *ciphername)
Checks if the cipher is defined and is not the null (none) cipher.
cipher_ctx_t * cipher
Generic cipher context.
struct key_ctx encrypt
Cipher and/or HMAC contexts for sending direction.
void init_key_ctx_bi(struct key_ctx_bi *ctx, const struct key2 *key2, int key_direction, const struct key_type *kt, const char *name)
uint8_t hmac[MAX_HMAC_KEY_LENGTH]
Key material for HMAC operations.
Packet geometry parameters.
#define MAX_CIPHER_KEY_LENGTH
void write_pem_key_file(const char *filename, const char *key_name)
Generate a server key with enough randomness to fill a key struct and write to file.
long int get_random(void)
Container for unidirectional cipher and HMAC key material.
void free_key_ctx(struct key_ctx *ctx)
const char * keydirection2ascii(int kd, bool remote, bool humanreadable)
const char * print_key_filename(const char *str, bool is_inline)
To be used when printing a string that may contain inline data.
Container for two sets of OpenSSL cipher and/or HMAC contexts for both sending and receiving directio...
#define MAX_HMAC_KEY_LENGTH
Key ordering of the key2.keys array.
void init_key_ctx(struct key_ctx *ctx, const struct key *key, const struct key_type *kt, int enc, const char *prefix)
const char * digest
Message digest static parameters.
mbedtls_cipher_context_t cipher_ctx_t
Generic cipher context.
int ascii2keydirection(int msglevel, const char *str)
void openvpn_encrypt(struct buffer *buf, struct buffer work, struct crypto_options *opt)
Encrypt and HMAC sign a packet so that it can be sent as a data channel VPN tunnel packet to a remote...
Container for one set of cipher and/or HMAC contexts.
unsigned int crypto_max_overhead(void)
Return the worst-case OpenVPN crypto overhead (in bytes)
int in_key
Index into the key2.keys array for the receiving direction.
void crypto_read_openvpn_key(const struct key_type *key_type, struct key_ctx_bi *ctx, const char *key_file, bool key_inline, const int key_direction, const char *key_name, const char *opt_name, struct key2 *keydata)
bool openvpn_decrypt(struct buffer *buf, struct buffer work, struct crypto_options *opt, const struct frame *frame, const uint8_t *ad_start)
HMAC verify and decrypt a data channel packet received from a remote OpenVPN peer.
Wrapper structure for dynamically allocated memory.
#define OPENVPN_MAX_IV_LENGTH
Maximum length of an IV.
size_t implicit_iv_len
The length of implicit_iv.
void test_crypto(struct crypto_options *co, struct frame *f)
void must_have_n_keys(const char *filename, const char *option, const struct key2 *key2, int n)
int need_keys
The number of key objects necessary to support both sending and receiving.
int read_key(struct key *key, const struct key_type *kt, struct buffer *buf)
void prng_bytes(uint8_t *output, int len)
uint8_t implicit_iv[OPENVPN_MAX_IV_LENGTH]
The implicit part of the IV.
static struct key_type create_kt(const char *cipher, const char *md, const char *optname)
Creates and validates an instance of struct key_type with the provided algs.
void print_cipher(const char *cipher)
Print a cipher list entry.
Garbage collection arena used to keep track of dynamically allocated memory.
void key_direction_state_init(struct key_direction_state *kds, int key_direction)
uint8_t digest[SHA256_DIGEST_LENGTH]
const char * cipher
const name of the cipher
void verify_fix_key2(struct key2 *key2, const struct key_type *kt, const char *shared_secret_file)
int memcmp_constant_time(const void *a, const void *b, size_t size)
As memcmp(), but constant-time.
#define SHA256_DIGEST_LENGTH
void free_key_ctx_bi(struct key_ctx_bi *ctx)
bool crypto_check_replay(struct crypto_options *opt, const struct packet_id_net *pin, const char *error_prefix, struct gc_arena *gc)
Check packet ID for replay, and perform replay administration.
bool check_key(struct key *key, const struct key_type *kt)
static bool md_defined(const char *mdname)
Checks if the cipher is defined and is not the null (none) cipher.
unsigned int calculate_crypto_overhead(const struct key_type *kt, unsigned int pkt_id_size, bool occ)
Calculate the maximum overhead that our encryption has on a packet.
uint8_t cipher[MAX_CIPHER_KEY_LENGTH]
Key material for cipher operations.
void init_key_type(struct key_type *kt, const char *ciphername, const char *authname, bool tls_mode, bool warn)
Initialize a key_type structure with.
bool write_key(const struct key *key, const struct key_type *kt, struct buffer *buf)
Container for bidirectional cipher and HMAC key material.
bool md_valid(const char *digest)
Return if a message digest parameters is valid given the name of the digest.
Wrapper struct to pass around SHA256 digests.
int write_key_file(const int nkeys, const char *filename)
Write nkeys 1024-bits keys to file.
bool read_pem_key_file(struct buffer *key, const char *pem_name, const char *key_file, bool key_inline)
Read key material from a PEM encoded files into the key structure.
hmac_ctx_t * hmac
Generic HMAC context.
unsigned int flags
Bit-flags determining behavior of security operation functions.
struct key keys[2]
Two unidirectional sets of key material.
struct packet_id_persist * pid_persist
Persistent packet ID state for keeping state between successive OpenVPN process startups.
struct key_ctx decrypt
cipher and/or HMAC contexts for receiving direction.
bool check_tls_prf_working(void)
Checks if the current TLS library supports the TLS 1.0 PRF with MD5+SHA1 that OpenVPN uses when TLS K...
void read_key_file(struct key2 *key2, const char *file, const unsigned int flags)
Security parameter state for processing data channel packets.