Skip to content

Commit

Permalink
cover a special fallback case
Browse files Browse the repository at this point in the history
  • Loading branch information
radkesvat committed Jun 20, 2024
1 parent 4d6c6b6 commit e3c13c6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
18 changes: 12 additions & 6 deletions tunnels/server/openssl/openssl_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ typedef struct oss_server_con_state_s
bool fallback_mode;
bool fallback_init_sent;
bool fallback_first_sent;
bool first_sent;
bool init_sent;
bool fallback_disabled;
buffer_stream_t *fallback_buf;
SSL *ssl;
BIO *rbio;
BIO *wbio;
bool first_sent;
bool init_sent;
int reply_sent_tit;

int reply_sent_tit;

} oss_server_con_state_t;

Expand Down Expand Up @@ -157,7 +159,7 @@ static void fallbackWrite(tunnel_t *self, context_t *c)
cstate->fallback_first_sent = true;
}

c->payload = bufferStreamRead(cstate->fallback_buf, record_len);
c->payload = bufferStreamIdealRead(cstate->fallback_buf);
state->fallback->upStream(state->fallback, c);
}

Expand Down Expand Up @@ -212,10 +214,14 @@ static void upStream(tunnel_t *self, context_t *c)
// assert(-1 == BIO_read(cstate->wbio, rawBuf(buf), avail));
if (n > 0)
{
// since then, we should not go to fallback
cstate->fallback_disabled = true;

setLen(buf, n);
context_t *answer = newContextFrom(c);
answer->payload = buf;
self->dw->downStream(self->dw, answer);

if (! isAlive(c->line))
{
reuseContextBuffer(c);
Expand All @@ -241,7 +247,7 @@ static void upStream(tunnel_t *self, context_t *c)
{
reuseContextBuffer(c); // payload already buffered
printSSLError();
if (state->fallback != NULL)
if (state->fallback != NULL && ! cstate->fallback_disabled)
{
cstate->fallback_mode = true;
fallbackWrite(self, c);
Expand Down Expand Up @@ -660,7 +666,7 @@ tunnel_t *newOpenSSLServer(node_instance_context_t *instance_info)
}
t->upStream = &upStream;
t->downStream = &downStream;

return t;
}

Expand Down
21 changes: 12 additions & 9 deletions tunnels/server/wolfssl/wolfssl_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ typedef struct wssl_server_state_s
typedef struct wssl_server_con_state_s
{

bool handshake_completed;

bool fallback;
bool handshake_completed;
bool fallback_mode;
bool fallback_init_sent;
bool fallback_first_sent;
bool first_sent;
bool init_sent;
bool fallback_disabled;
buffer_stream_t *fallback_buf;
SSL *ssl;
BIO *rbio;
BIO *wbio;
bool first_sent;
bool init_sent;
int reply_sent_tit;

} wssl_server_con_state_t;

Expand Down Expand Up @@ -151,7 +150,7 @@ static void fallbackWrite(tunnel_t *self, context_t *c)
cstate->fallback_first_sent = true;
}

c->payload = bufferStreamRead(cstate->fallback_buf, record_len);
c->payload = bufferStreamIdealRead(cstate->fallback_buf);
state->fallback->upStream(state->fallback, c);
}

Expand Down Expand Up @@ -208,10 +207,14 @@ static void upStream(tunnel_t *self, context_t *c)
// assert(-1 == BIO_read(cstate->wbio, rawBuf(buf), avail));
if (n > 0)
{
// since then, we should not go to fallback
cstate->fallback_disabled = true;

setLen(buf, n);
context_t *answer = newContextFrom(c);
answer->payload = buf;
self->dw->downStream(self->dw, answer);

if (! isAlive(c->line))
{
reuseContextBuffer(c);
Expand All @@ -237,7 +240,7 @@ static void upStream(tunnel_t *self, context_t *c)
{
reuseContextBuffer(c); // payload already buffered
printSSLError();
if (state->fallback != NULL)
if (state->fallback != NULL && ! cstate->fallback_disabled)
{
cstate->fallback = true;
fallbackWrite(self, c);
Expand Down Expand Up @@ -656,7 +659,7 @@ tunnel_t *newWolfSSLServer(node_instance_context_t *instance_info)
}
t->upStream = &upStream;
t->downStream = &downStream;

return t;
}

Expand Down

0 comments on commit e3c13c6

Please sign in to comment.