59static const char *
now0key0 =
"SESS_ID_AT_0123456789abcdefAAAAAAAAAAAAAAAAAAAAAE5JsQJOVfo8jnI3RL3tBaR5NkE4yPfcylFUHmHSc5Bu";
61static const char *
zeroinline =
"-----BEGIN OpenVPN auth-token server key-----\n"
62 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"
63 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"
64 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\n"
65 "-----END OpenVPN auth-token server key-----";
67static const char *
allx01inline =
"-----BEGIN OpenVPN auth-token server key-----\n"
68 "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB\n"
69 "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB\n"
70 "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=\n"
71 "-----END OpenVPN auth-token server key-----";
73static const char *
random_key =
"-----BEGIN OpenVPN auth-token server key-----\n"
74 "+mmmf7IQ5cymtMVjKYTWk8IOcYanRlpQmV9Tb3EjkHYxueBVDg3yqRgzeBlVGzNLD//rAPiOVhau\n"
75 "3NDBjNOQB8951bfs7Cc2mYfay92Bh2gRJ5XEM/DMfzCWN+7uU6NWoTTHr4FuojnIQtjtqVAj/JS9\n"
76 "w+dTSp/vYHl+c7uHd19uVRu/qLqV85+rm4tUGIjO7FfYuwyPqwmhuIsi3hs9QkSimh888FmBpoKY\n"
77 "/tbKVTJZmSERKti9KEwtV2eVAR0znN5KW7lCB3mHVAhN7bUpcoDjfCzYIFARxwswTFu9gFkwqUMY\n"
78 "I1KUOgIsVNs4llACioeXplYekWETR+YkJwDc/A==\n"
79 "-----END OpenVPN auth-token server key-----";
81static const char *
random_token =
"SESS_ID_AT_ThhRItzOKNKrh3dfAAAAAFwzHpwAAAAAXDMenDdrq0RoH3dkA1f7O3wO+7kZcx2DusVZrRmFlWQM9HOb";
216 while (now < 100000 + ctx->
session->opt->auth_token_lifetime + 1)
240 memset(hmacstart, 0x8d, strlen(hmacstart));
269 if (
streq(name,
"session_state"))
304 free(token_sessiona);
417 const struct CMUnitTest tests[] = {
429#if defined(ENABLE_CRYPTO_OPENSSL)
430 OpenSSL_add_all_algorithms();
433 int ret = cmocka_run_group_tests_name(
"auth-token tests", tests, NULL, NULL);
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.
void wipe_auth_token(struct tls_multi *multi)
Wipes the authentication token out of the memory, frees and cleans up related buffers and flags.
#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 init_key_ctx(struct key_ctx *ctx, const struct key_parameters *key, const struct key_type *kt, int enc, const char *prefix)
void free_key_ctx(struct key_ctx *ctx)
#define MAX_HMAC_KEY_LENGTH
#define KS_PRIMARY
Primary key state index.
#define TM_ACTIVE
Active tls_session.
#define AUTH_TOKEN_HMAC_OK
Auth-token sent from client has valid hmac.
#define AUTH_TOKEN_EXPIRED
Auth-token sent from client has expired.
#define AUTH_TOKEN_VALID_EMPTYUSER
Auth-token is only valid for an empty username and not the username actually supplied from the client...
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.
const char * digest
Message digest static parameters.
Container for unidirectional cipher and HMAC key material.
uint8_t hmac[MAX_HMAC_KEY_LENGTH]
Key material for HMAC operations.
struct tls_session * session
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_renewal
unsigned int auth_token_lifetime
interval_t renegotiate_seconds
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]
static void auth_token_test_env(void **state)
static int teardown(void **state)
void auth_set_client_reason(struct tls_multi *multi, const char *reason)
Sets the reason why authentication of a client failed.
static void auth_token_test_known_keys(void **state)
static const char * zeroinline
static void auth_token_test_key_load(void **state)
static const char * random_token
static const char * now0key0
static void auth_token_test_timeout(void **state)
static void auth_token_test_random_keys(void **state)
void auth_token_test_session_mismatch(void **state)
static void auth_token_test_empty_user(void **state)
void setenv_str(struct env_set *es, const char *name, const char *value)
static void auth_token_fail_invalid_key(void **state)
static const char * random_key
static int setup(void **state)
static const char * lastsesion_statevalue
static void auth_token_basic_test(void **state)
static const char * allx01inline
static void zerohmac(char *token)
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.
static void openvpn_unit_test_setup(void)
Sets up the environment for unit tests like making both stderr and stdout non-buffered to avoid messa...