21#define AUTH_TOKEN_SESSION_ID_LEN 12
22#define AUTH_TOKEN_SESSION_ID_BASE64_LEN (AUTH_TOKEN_SESSION_ID_LEN * 8 / 6)
24#if AUTH_TOKEN_SESSION_ID_LEN % 3
25#error AUTH_TOKEN_SESSION_ID_LEN needs to be multiple a 3
29#define TOKEN_DATA_LEN (2 * sizeof(int64_t) + AUTH_TOKEN_SESSION_ID_LEN + 32)
34 return create_kt(
"none",
"SHA256",
"auth-gen-token");
59 state =
"Authenticated";
67 state =
"AuthenticatedEmptyUser";
71 state =
"ExpiredEmptyUser";
87 const char *session_id_source;
146 msg(
M_FATAL,
"ERROR: Cannot load auth-token secret");
153 msg(
M_FATAL,
"ERROR: not enough data in auth-token secret");
168 int64_t timestamp =
htonll((uint64_t)
now);
169 int64_t initial_timestamp = timestamp;
182 char old_tstamp_decode[9];
194 old_tstamp_initial[12] =
'\0';
197 memcpy(&initial_timestamp, &old_tstamp_decode,
sizeof(initial_timestamp));
199 old_tstamp_initial[0] =
'\0';
204 msg(
M_FATAL,
"Failed to get enough randomness for "
205 "authentication token");
213 uint8_t hmac_output[256/8];
232 hmac_ctx_update(ctx, (uint8_t *) &initial_timestamp,
sizeof(initial_timestamp));
312 msg(
M_WARN,
"ERROR: --auth-token wrong size (%d!=%d)",
317 unsigned int ret = 0;
327 timestamp =
ntohll(timestamp);
346 msg(
M_WARN,
"--auth-gen-token: HMAC on token from client failed (%s)",
354 &&
now < timestamp + 2 *
session->opt->auth_token_renewal;
358 msg(
M_WARN,
"Timestamp (%" PRIu64 ") of auth-token is out of the renewal window",
366 msg(
M_WARN,
"Initial timestamp (%" PRIu64 ") in token from client earlier than "
367 "current timestamp %" PRIu64 ". Broken/unsynchronised clock?",
382 msg(
M_INFO,
"--auth-gen-token: auth-token from client expired");
393 msg(
M_WARN,
"--auth-gen-token: session id in token changed (Rejecting "
440 msg(
D_SHOW_KEYS,
"initial auth-token not generated yet, skipping "
441 "auth-token renewal.");
447 msg(
D_SHOW_KEYS,
"username not locked, skipping auth-token renewal.");
void auth_token_write_server_key_file(const char *filename)
Generate a auth-token server secret key, and write to file.
static bool check_hmac_token(hmac_ctx_t *ctx, const uint8_t *b64decoded, const char *username)
void auth_token_init_secret(struct key_ctx *key_ctx, const char *key_file, bool key_inline)
Loads an HMAC secret from a file or if no file is present generates a epheremal secret for the run ti...
void generate_auth_token(const struct user_pass *up, struct tls_multi *multi)
Generate an auth token based on username and timestamp.
#define AUTH_TOKEN_SESSION_ID_LEN
unsigned int verify_auth_token(struct user_pass *up, struct tls_multi *multi, struct tls_session *session)
Verifies the auth token to be in the format that generate_auth_token create and checks if the token i...
static struct key_type auth_token_kt(void)
#define AUTH_TOKEN_SESSION_ID_BASE64_LEN
void add_session_token_env(struct tls_session *session, struct tls_multi *multi, const struct user_pass *up)
Put the session id, and auth token status into the environment if auth-token is enabled.
const char * auth_token_pem_name
void check_send_auth_token(struct context *c)
Checks if the timer to resend the auth-token has expired and if a new auth-token should be send to th...
void wipe_auth_token(struct tls_multi *multi)
Wipes the authentication token out of the memory, frees and cleans up related buffers and flags.
void resend_auth_token_renegotiation(struct tls_multi *multi, struct tls_session *session)
Checks if a client should be sent a new auth token to update its current auth-token.
static bool is_auth_token(const char *password)
Return if the password string has the format of a password.
#define SESSION_ID_PREFIX
The prefix given to auth tokens start with, this prefix is special cased to not show up in log files ...
void free_buf(struct buffer *buf)
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
struct buffer alloc_buf(size_t size)
char * string_alloc(const char *str, struct gc_arena *gc)
static bool buf_read(struct buffer *src, void *dest, int size)
static void secure_memzero(void *data, size_t len)
Securely zeroise memory.
static bool buf_write(struct buffer *dest, const void *src, size_t size)
static bool buf_write_u8(struct buffer *dest, uint8_t data)
static void strncpynt(char *dest, const char *src, size_t maxlen)
static void gc_free(struct gc_arena *a)
static struct gc_arena gc_new(void)
void init_key_ctx(struct key_ctx *ctx, const struct key_parameters *key, const struct key_type *kt, int enc, const char *prefix)
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.
bool generate_ephemeral_key(struct buffer *key, const char *key_name)
Generate ephermal key material into the key structure.
void write_pem_key_file(const char *filename, const char *pem_name)
Generate a server key with enough randomness to fill a key struct and write to file.
void key_parameters_from_key(struct key_parameters *key_params, const struct key *key)
Converts a struct key representation into a struct key_parameters representation.
Data Channel Cryptography Module.
int memcmp_constant_time(const void *a, const void *b, size_t size)
As memcmp(), but constant-time.
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 hmac_ctx_update(hmac_ctx_t *ctx, const uint8_t *src, int src_len)
void hmac_ctx_reset(hmac_ctx_t *ctx)
void hmac_ctx_final(hmac_ctx_t *ctx, uint8_t *dst)
int hmac_ctx_size(hmac_ctx_t *ctx)
int rand_bytes(uint8_t *output, int len)
Wrapper for secure random number generator.
mbedtls_md_context_t hmac_ctx_t
Generic HMAC context.
void setenv_str(struct env_set *es, const char *name, const char *value)
#define KS_PRIMARY
Primary key state index.
#define TM_ACTIVE
Active tls_session.
#define S_GENERATED_KEYS
The data channel keys have been generated The TLS session is fully authenticated when reaching this s...
void send_push_reply_auth_token(struct tls_multi *multi)
Sends a push reply message only containin the auth-token to update the auth-token on the client.
int openvpn_base64_decode(const char *str, void *data, int size)
int openvpn_base64_encode(const void *data, int size, char **str)
Control Channel SSL/Data channel negotiation module.
Control Channel Common Data Structures.
#define AUTH_TOKEN_HMAC_OK
Auth-token sent from client has valid hmac.
#define AUTH_TOKEN_EXPIRED
Auth-token sent from client has expired.
@ KS_AUTH_TRUE
Key state is authenticated.
static const struct key_state * get_primary_key(const struct tls_multi *multi)
gets an item of key_state objects in the order they should be scanned by data channel modules.
#define AUTH_TOKEN_VALID_EMPTYUSER
Auth-token is only valid for an empty username and not the username actually supplied from the client...
void auth_set_client_reason(struct tls_multi *multi, const char *client_reason)
Sets the reason why authentication of a client failed.
Control Channel Verification Module.
Wrapper structure for dynamically allocated memory.
int len
Length in bytes of the actual content within the allocated memory.
struct tls_multi * tls_multi
TLS state structure for this VPN tunnel.
Contains all state information for one tunnel.
struct context_2 c2
Level 2 context.
Garbage collection arena used to keep track of dynamically allocated memory.
Container for one set of cipher and/or HMAC contexts.
hmac_ctx_t * hmac
Generic HMAC context.
internal structure similar to struct key that holds key information but is not represented on wire an...
Security parameter state of one TLS and data channel key session.
unsigned int auth_token_state_flags
The state of the auth-token sent from the client.
Container for unidirectional cipher and HMAC key material.
Security parameter state for a single VPN tunnel.
char * auth_token_initial
The first auth-token we sent to a client.
struct tls_session session[TM_SIZE]
Array of tls_session objects representing control channel sessions with the remote peer.
char * auth_token
If server sends a generated auth-token, this is the token to use for future user/pass authentications...
struct key_ctx auth_token_key
unsigned int auth_token_lifetime
bool auth_token_generate
Generate auth-tokens on successful user/pass auth,seet via options->auth_token_generate.
Security parameter state of a single session within a VPN tunnel.
struct key_state key[KS_SIZE]
char password[USER_PASS_LEN]
char username[USER_PASS_LEN]