3 #elif defined(_MSC_VER) 23 #define AUTH_TOKEN_SESSION_ID_LEN 12 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) 41 msg(
M_WARN,
"ERROR: --tls-crypt requires HMAC-SHA-256 support.");
72 state =
"Authenticated";
80 state =
"AuthenticatedEmptyUser";
84 state =
"ExpiredEmptyUser";
100 const char *session_id_source;
144 bool key_loaded =
false;
149 key_file, key_inline);
159 msg(
M_FATAL,
"ERROR: Cannot load auth-token secret");
164 if (!
buf_read(&server_secret_key, &key,
sizeof(key)))
166 msg(
M_FATAL,
"ERROR: not enough data in auth-token secret");
168 init_key_ctx(key_ctx, &key, &kt,
false,
"auth-token secret");
178 int64_t timestamp =
htonll((uint64_t)
now);
179 int64_t initial_timestamp = timestamp;
192 char old_tstamp_decode[9];
201 old_tsamp_initial[12] =
'\0';
209 uint64_t *tstamp_ptr = (uint64_t *) old_tstamp_decode;
210 initial_timestamp = *tstamp_ptr;
212 old_tsamp_initial[0] =
'\0';
221 msg(
M_FATAL,
"Failed to get enough randomness for " 222 "authentication token");
230 uint8_t hmac_output[256/8];
248 hmac_ctx_update(ctx, (uint8_t *) &initial_timestamp,
sizeof(initial_timestamp));
257 ASSERT(
buf_write(&token, &initial_timestamp,
sizeof(initial_timestamp)));
287 uint8_t hmac_output[256/8];
316 msg(
M_WARN,
"ERROR: --auth-token wrong size (%d!=%d)",
321 unsigned int ret = 0;
323 const uint8_t *sessid = b64decoded;
325 const uint8_t *tstamp = tstamp_initial +
sizeof(int64_t);
327 uint64_t timestamp =
ntohll(*((uint64_t *) (tstamp)));
328 uint64_t timestamp_initial =
ntohll(*((uint64_t *) (tstamp_initial)));
344 msg(
M_WARN,
"--auth-token-gen: HMAC on token from client failed (%s)",
351 bool in_renog_time =
now >= timestamp
360 if (!in_renog_time && !initialtoken)
366 if (timestamp < timestamp_initial)
368 msg(
M_WARN,
"Initial timestamp (%" PRIu64 " in token from client earlier than " 369 "current timestamp %" PRIu64 ". Broken/unsynchronised clock?",
370 timestamp_initial, timestamp);
384 msg(
M_INFO,
"--auth-token-gen: auth-token from client expired");
static bool buf_write_u8(struct buffer *dest, int data)
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.
int auth_token_state_flags
The state of the auth-token sent from the client last time.
uint8_t hmac_length
HMAC length, in bytes.
void generate_auth_token(const struct user_pass *up, struct tls_multi *multi)
Generate an auth token based on username and timestamp.
void free_buf(struct buffer *buf)
void init_key_ctx(struct key_ctx *ctx, const struct key *key, const struct key_type *kt, int enc, const char *prefix)
unsigned int auth_token_lifetime
static void secure_memzero(void *data, size_t len)
Securely zeroise memory.
#define AUTH_TOKEN_EXPIRED
Auth-token sent from client has expired.
#define SESSION_ID_PREFIX
The prefix given to auth tokens start with, this prefix is special cased to not show up in log files ...
char * auth_token_initial
The first auth-token we sent to a client, for clients that do not update their auth-token (older Open...
static void gc_free(struct gc_arena *a)
Security parameter state for a single VPN tunnel.
struct buffer alloc_buf(size_t size)
void setenv_str(struct env_set *es, const char *name, const char *value)
#define AUTH_TOKEN_SESSION_ID_LEN
bool auth_token_generate
Generate auth-tokens on successful user/pass auth,seet via options->auth_token_generate.
bool generate_ephemeral_key(struct buffer *key, const char *key_name)
Generate ephermal key material into the key structure.
mbedtls_md_context_t hmac_ctx_t
Generic HMAC context.
char username[USER_PASS_LEN]
static bool buf_read(struct buffer *src, void *dest, int size)
static struct key_type auth_token_kt(void)
#define AUTH_TOKEN_HMAC_OK
Auth-token sent from client has valid hmac.
interval_t renegotiate_seconds
#define AUTH_TOKEN_VALID_EMPTYUSER
Auth-token is only valid for an empty username and not the username actually supplied from the client...
int rand_bytes(uint8_t *output, int len)
Wrapper for secure random number generator.
static struct gc_arena gc_new(void)
static bool check_hmac_token(hmac_ctx_t *ctx, const uint8_t *b64decoded, const char *username)
int memcmp_constant_time(const void *a, const void *b, size_t size)
As memcmp(), but constant-time.
void hmac_ctx_update(hmac_ctx_t *ctx, const uint8_t *src, int src_len)
void auth_set_client_reason(struct tls_multi *multi, const char *client_reason)
Sets the reason why authentication of a client failed.
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.
int openvpn_base64_decode(const char *str, void *data, int size)
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 wipe_auth_token(struct tls_multi *multi)
Wipes the authentication token out of the memory, frees and cleans up related buffers and flags...
Container for one set of cipher and/or HMAC contexts.
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...
int hmac_ctx_size(const hmac_ctx_t *ctx)
const md_kt_t * md_kt_get(const char *digest)
Return message digest parameters, based on the given digest name.
hmac_ctx_t * hmac
Generic HMAC context.
int openvpn_base64_encode(const void *data, int size, char **str)
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...
unsigned char md_kt_size(const md_kt_t *kt)
Returns the size of the message digest, in bytes.
struct key_ctx auth_token_key
char * auth_token
If server sends a generated auth-token, this is the token to use for future user/pass authentications...
const md_kt_t * digest
Message digest static parameters.
Security parameter state of a single session within a VPN tunnel.
Wrapper structure for dynamically allocated memory.
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Garbage collection arena used to keep track of dynamically allocated memory.
void auth_token_write_server_key_file(const char *filename)
Generate a auth-token server secret key, and write to file.
static bool buf_write(struct buffer *dest, const void *src, size_t size)
char password[USER_PASS_LEN]
void hmac_ctx_final(hmac_ctx_t *ctx, uint8_t *dst)
const cipher_kt_t * cipher
Cipher static parameters.
const char * auth_token_pem_name
void hmac_ctx_reset(hmac_ctx_t *ctx)
Container for unidirectional cipher and HMAC key material.
static bool is_auth_token(const char *password)
Return if the password string has the format of a password.