Skip to content

Commit

Permalink
Use key_state instead of multi for tls_send_payload parameter
Browse files Browse the repository at this point in the history
Currently, this function and other parts of OpenVPN assume that
multi->session[TM_ACTIVE].key[KS_PRIMARY] is always the right session
to send control message.

This assumption was only achieve through complicated session moving and
shuffling in our state machine in the past. The old logic basically also
always assumed that control messages are always for fully authenticated
clients. This assumption was never really true (see AUTH_FAILED message)
but has been broken even more by auth-pending. Cleaning up the state machine
transitions in 7dcde87 broke this assumption even more.

This change now allows to specify the key_state/TLS session that is used to
send the control message.

Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20230301135353.2811069-1-arne@rfc2549.org>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg26319.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 06af538)
  • Loading branch information
schwabe authored and cron2 committed Mar 20, 2023
1 parent a05ec70 commit 31279f7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/openvpn/forward.c
Expand Up @@ -372,8 +372,11 @@ send_control_channel_string_dowork(struct tls_multi *multi,
struct gc_arena gc = gc_new();
bool stat;

ASSERT(multi);
struct key_state *ks = get_key_scan(multi, 0);

/* buffered cleartext write onto TLS control channel */
stat = tls_send_payload(multi, (uint8_t *) str, strlen(str) + 1);
stat = tls_send_payload(ks, (uint8_t *) str, strlen(str) + 1);

msg(msglevel, "SENT CONTROL [%s]: '%s' (status=%d)",
tls_common_name(multi, false),
Expand Down
7 changes: 2 additions & 5 deletions src/openvpn/ssl.c
Expand Up @@ -4007,18 +4007,15 @@ tls_post_encrypt(struct tls_multi *multi, struct buffer *buf)
*/

bool
tls_send_payload(struct tls_multi *multi,
tls_send_payload(struct key_state *ks,
const uint8_t *data,
int size)
{
struct key_state *ks;
bool ret = false;

tls_clear_error();

ASSERT(multi);

ks = get_key_scan(multi, 0);
ASSERT(ks);

if (ks->state >= S_ACTIVE)
{
Expand Down
2 changes: 1 addition & 1 deletion src/openvpn/ssl.h
Expand Up @@ -424,7 +424,7 @@ void ssl_put_auth_challenge(const char *cr_str);
/*
* Send a payload over the TLS control channel
*/
bool tls_send_payload(struct tls_multi *multi,
bool tls_send_payload(struct key_state *ks,
const uint8_t *data,
int size);

Expand Down

0 comments on commit 31279f7

Please sign in to comment.