Skip to content

Commit 354bc3f

Browse files
author
Jon Chiappetta
committed
dual mode
1 parent 339e2d4 commit 354bc3f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+2346
-26509
lines changed

src/openvpn/auth_token.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ auth_token_kt(void)
3535
}
3636

3737
void
38-
add_session_token_env(struct tls_session *session, struct tls_multi *multi,
39-
const struct user_pass *up)
38+
add_session_token_env(struct tls_session *session, struct tls_multi *multi, const struct user_pass *up)
4039
{
4140
if (!multi->opt.auth_token_generate)
4241
{
4342
return;
4443
}
4544

46-
int auth_token_state_flags = session->key[KS_PRIMARY].auth_token_state_flags;
45+
struct key_state *ks = tls_select_encryption_key_init(multi);
46+
int auth_token_state_flags = ks->auth_token_state_flags;
4747

4848
const char *state;
4949

@@ -81,7 +81,7 @@ add_session_token_env(struct tls_session *session, struct tls_multi *multi,
8181
state = "Invalid";
8282
}
8383

84-
setenv_str(session->opt->es, "session_state", state);
84+
setenv_str(multi->opt.es, "session_state", state);
8585

8686
/* We had a valid session id before */
8787
const char *session_id_source;
@@ -111,7 +111,7 @@ add_session_token_env(struct tls_session *session, struct tls_multi *multi,
111111
memcpy(session_id, session_id_source + strlen(SESSION_ID_PREFIX),
112112
AUTH_TOKEN_SESSION_ID_LEN * 8 / 6);
113113

114-
setenv_str(session->opt->es, "session_id", session_id);
114+
setenv_str(multi->opt.es, "session_id", session_id);
115115
}
116116

117117
void
@@ -217,8 +217,8 @@ generate_auth_token(const struct user_pass *up, struct tls_multi *multi)
217217
* a new token with the empty username since we do not want to loose
218218
* the information that the username cannot be trusted
219219
*/
220-
struct key_state *ks = &multi->session[TM_ACTIVE].key[KS_PRIMARY];
221-
if (ks->auth_token_state_flags & AUTH_TOKEN_VALID_EMPTYUSER)
220+
struct key_state *ks = tls_select_encryption_key_init(multi);
221+
if (ks && ks->auth_token_state_flags & AUTH_TOKEN_VALID_EMPTYUSER)
222222
{
223223
hmac_ctx_update(ctx, (const uint8_t *)"", 0);
224224
}
@@ -415,10 +415,15 @@ void
415415
check_send_auth_token(struct context *c)
416416
{
417417
struct tls_multi *multi = c->c2.tls_multi;
418-
struct tls_session *session = &multi->session[TM_ACTIVE];
419418

420-
if (get_primary_key(multi)->state < S_GENERATED_KEYS
421-
|| get_primary_key(multi)->authenticated != KS_AUTH_TRUE)
419+
if (!multi)
420+
{
421+
return;
422+
}
423+
424+
struct key_state *ks = tls_select_encryption_key_init(multi);
425+
426+
if (ks->state < S_GENERATED_KEYS || ks->authenticated != KS_AUTH_TRUE)
422427
{
423428
/* the currently active session is still in renegotiation or another
424429
* not fully authorized state. We are either very close to a
@@ -447,11 +452,11 @@ check_send_auth_token(struct context *c)
447452

448453
generate_auth_token(&up, multi);
449454

450-
resend_auth_token_renegotiation(multi, session);
455+
resend_auth_token_renegotiation(multi);
451456
}
452457

453458
void
454-
resend_auth_token_renegotiation(struct tls_multi *multi, struct tls_session *session)
459+
resend_auth_token_renegotiation(struct tls_multi *multi)
455460
{
456461
/*
457462
* Auth token already sent to client, update auth-token on client.

src/openvpn/auth_token.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ is_auth_token(const char *password)
128128
* @param multi Pointer the multi object of the TLS session
129129
* @param session Pointer to the TLS session itself
130130
*/
131-
void resend_auth_token_renegotiation(struct tls_multi *multi, struct tls_session *session);
131+
void resend_auth_token_renegotiation(struct tls_multi *multi);
132132

133133

134134
/**

src/openvpn/buffer.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,7 @@ has_digit(const char *src)
413413
static inline void
414414
secure_memzero(void *data, size_t len)
415415
{
416-
#if defined(_WIN32)
417-
SecureZeroMemory(data, len);
418-
#elif defined(__GNUC__) || defined(__clang__)
416+
#if defined(__GNUC__) || defined(__clang__)
419417
memset(data, 0, len);
420418
__asm__ __volatile__("" : : "r"(data) : "memory");
421419
#else

src/openvpn/common.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ typedef uint64_t counter_type;
3535
* Time intervals
3636
*/
3737
typedef int interval_t;
38-
39-
/*
40-
* Used as an upper bound for timeouts.
41-
*/
42-
#define BIG_TIMEOUT (60 * 60 * 24 * 7) /* one week (in seconds) */
38+
#define LOOP_WAIT 7
4339

4440
/*
4541
* Printf formats for special types

src/openvpn/console_builtin.c

Lines changed: 3 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -41,101 +41,6 @@
4141
#include <termios.h>
4242
#endif
4343

44-
#ifdef _WIN32
45-
46-
#include "win32.h"
47-
48-
/**
49-
* Get input from a Windows console.
50-
*
51-
* @param prompt Prompt to display to the user
52-
* @param echo Should the user input be displayed in the console
53-
* @param input Pointer to the buffer the user input will be saved
54-
* @param capacity Size of the buffer for the user input
55-
*
56-
* @return Return false on input error, or if service
57-
* exit event is signaled.
58-
*/
59-
static bool
60-
get_console_input_win32(const char *prompt, const bool echo, char *input, const int capacity)
61-
{
62-
ASSERT(prompt);
63-
ASSERT(input);
64-
ASSERT(capacity > 0);
65-
66-
input[0] = '\0';
67-
68-
HANDLE in = GetStdHandle(STD_INPUT_HANDLE);
69-
int orig_stderr = get_orig_stderr(); /* guaranteed to be always valid */
70-
if ((in == INVALID_HANDLE_VALUE) || win32_service_interrupt(&win32_signal)
71-
|| (_write(orig_stderr, prompt, (unsigned int)strlen(prompt)) == -1))
72-
{
73-
msg(M_WARN | M_ERRNO, "get_console_input_win32(): unexpected error");
74-
return false;
75-
}
76-
77-
bool is_console = (GetFileType(in) == FILE_TYPE_CHAR);
78-
DWORD flags_save = 0;
79-
int status = 0;
80-
WCHAR *winput;
81-
82-
if (is_console)
83-
{
84-
if (GetConsoleMode(in, &flags_save))
85-
{
86-
DWORD flags = ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
87-
if (echo)
88-
{
89-
flags |= ENABLE_ECHO_INPUT;
90-
}
91-
SetConsoleMode(in, flags);
92-
}
93-
else
94-
{
95-
is_console = 0;
96-
}
97-
}
98-
99-
DWORD len = 0;
100-
101-
if (is_console)
102-
{
103-
winput = malloc(capacity * sizeof(WCHAR));
104-
if (winput == NULL)
105-
{
106-
return false;
107-
}
108-
109-
status = ReadConsoleW(in, winput, capacity, &len, NULL);
110-
WideCharToMultiByte(CP_UTF8, 0, winput, len, input, capacity, NULL, NULL);
111-
free(winput);
112-
}
113-
else
114-
{
115-
status = ReadFile(in, input, capacity, &len, NULL);
116-
}
117-
118-
string_null_terminate(input, (int)len, capacity);
119-
chomp(input);
120-
121-
if (!echo)
122-
{
123-
_write(orig_stderr, "\r\n", 2);
124-
}
125-
if (is_console)
126-
{
127-
SetConsoleMode(in, flags_save);
128-
}
129-
if (status && !win32_service_interrupt(&win32_signal))
130-
{
131-
return true;
132-
}
133-
134-
return false;
135-
}
136-
137-
#endif /* _WIN32 */
138-
13944

14045
#ifdef HAVE_TERMIOS_H
14146

@@ -198,9 +103,7 @@ get_console_input(const char *prompt, const bool echo, char *input, const int ca
198103
ASSERT(capacity > 0);
199104
input[0] = '\0';
200105

201-
#if defined(_WIN32)
202-
return get_console_input_win32(prompt, echo, input, capacity);
203-
#elif defined(HAVE_TERMIOS_H)
106+
#if defined(HAVE_TERMIOS_H)
204107
bool restore_tty = false;
205108
struct termios tty_tmp, tty_save;
206109

@@ -258,9 +161,9 @@ get_console_input(const char *prompt, const bool echo, char *input, const int ca
258161
}
259162

260163
close_tty(fp);
261-
#else /* if defined(_WIN32) */
164+
#else
262165
msg(M_FATAL, "Sorry, but I can't get console input on this OS (%s)", prompt);
263-
#endif /* if defined(_WIN32) */
166+
#endif
264167
return ret;
265168
}
266169

src/openvpn/crypto_backend.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
#ifdef ENABLE_CRYPTO_OPENSSL
3333
#include "crypto_openssl.h"
3434
#endif
35-
#ifdef ENABLE_CRYPTO_MBEDTLS
36-
#include "crypto_mbedtls.h"
37-
#endif
3835
#include "basic.h"
3936
#include "buffer.h"
4037

src/openvpn/crypto_epoch.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ epoch_replace_update_recv_key(struct crypto_options *co, uint16_t new_epoch)
304304
{
305305
epoch_key_iterate(&co->epoch_key_send);
306306
}
307+
308+
msg(M_INFO, "INFO epoch_replace_update_recv_key: epoch < new_epoch");
309+
307310
epoch_init_send_key_ctx(co);
308311
}
309312

@@ -402,14 +405,15 @@ epoch_check_send_iterate(struct crypto_options *opt)
402405
{
403406
if (opt->epoch_key_send.epoch == UINT16_MAX)
404407
{
408+
msg(M_INFO, "INFO epoch_check_send_iterate: epoch == UINT16_MAX");
405409
/* limit of epoch keys reached, cannot move to a newer key anymore */
406410
return;
407411
}
408412
if (opt->aead_usage_limit)
409413
{
410-
if (aead_usage_limit_reached(opt->aead_usage_limit, &opt->key_ctx_bi.encrypt,
411-
opt->packet_id.send.id))
414+
if (aead_usage_limit_reached(opt->aead_usage_limit, &opt->key_ctx_bi.encrypt, opt->packet_id.send.id))
412415
{
416+
msg(M_INFO, "INFO epoch_check_send_iterate: aead_usage_limit_reached");
413417
/* Send key limit reached */
414418
epoch_iterate_send_key(opt);
415419
}
@@ -429,10 +433,10 @@ epoch_check_send_iterate(struct crypto_options *opt)
429433
* decryption fail warn limit.
430434
* */
431435
else if (opt->key_ctx_bi.encrypt.epoch == opt->key_ctx_bi.decrypt.epoch
432-
&& (aead_usage_limit_reached(opt->aead_usage_limit, &opt->key_ctx_bi.decrypt,
433-
opt->packet_id.rec.id)
436+
&& (aead_usage_limit_reached(opt->aead_usage_limit, &opt->key_ctx_bi.decrypt, opt->packet_id.rec.id)
434437
|| cipher_decrypt_verify_fail_warn(&opt->key_ctx_bi.decrypt)))
435438
{
439+
msg(M_INFO, "INFO epoch_check_send_iterate: cipher_decrypt_verify_fail_warn");
436440
/* Receive key limit reached. Increase our own send key to signal
437441
* that we want to use a new epoch. Peer should then also move its
438442
* key but is not required to do this */
@@ -442,6 +446,7 @@ epoch_check_send_iterate(struct crypto_options *opt)
442446

443447
if (opt->packet_id.send.id == PACKET_ID_EPOCH_MAX)
444448
{
449+
msg(M_INFO, "INFO epoch_check_send_iterate: send.id == PACKET_ID_EPOCH_MAX");
445450
epoch_iterate_send_key(opt);
446451
}
447452
}

0 commit comments

Comments
 (0)