Skip to content

Commit

Permalink
s_server normal shutdown
Browse files Browse the repository at this point in the history
Partially fixes #11209

Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from #11734)
  • Loading branch information
beldmit committed May 6, 2020
1 parent a96e6c3 commit edbb56e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
1 change: 1 addition & 0 deletions apps/include/s_apps.h
Expand Up @@ -32,6 +32,7 @@ int init_client(int *sock, const char *host, const char *port,
const char *bindhost, const char *bindport,
int family, int type, int protocol);
int should_retry(int i);
void do_ssl_shutdown(SSL *ssl);

long bio_dump_callback(BIO *bio, int cmd, const char *argp,
int argi, long argl, long ret);
Expand Down
21 changes: 21 additions & 0 deletions apps/lib/s_socket.c
Expand Up @@ -392,4 +392,25 @@ int do_server(int *accept_sock, const char *host, const char *port,
return ret;
}

void do_ssl_shutdown(SSL *ssl)
{
int ret;

do {
/* We only do unidirectional shutdown */
ret = SSL_shutdown(ssl);
if (ret < 0) {
switch (SSL_get_error(ssl, ret)) {
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
case SSL_ERROR_WANT_ASYNC:
case SSL_ERROR_WANT_ASYNC_JOB:
/* We just do busy waiting. Nothing clever */
continue;
}
ret = 0;
}
} while (ret < 0);
}

#endif /* OPENSSL_NO_SOCK */
21 changes: 0 additions & 21 deletions apps/s_client.c
Expand Up @@ -98,27 +98,6 @@ static int restore_errno(void)
return ret;
}

static void do_ssl_shutdown(SSL *ssl)
{
int ret;

do {
/* We only do unidirectional shutdown */
ret = SSL_shutdown(ssl);
if (ret < 0) {
switch (SSL_get_error(ssl, ret)) {
case SSL_ERROR_WANT_READ:
case SSL_ERROR_WANT_WRITE:
case SSL_ERROR_WANT_ASYNC:
case SSL_ERROR_WANT_ASYNC_JOB:
/* We just do busy waiting. Nothing clever */
continue;
}
ret = 0;
}
} while (ret < 0);
}

/* Default PSK identity and key */
static char *psk_identity = "Client_identity";

Expand Down
8 changes: 3 additions & 5 deletions apps/s_server.c
Expand Up @@ -1884,7 +1884,6 @@ int s_server_main(int argc, char *argv[])
}
BIO_printf(bio_err, "id_prefix '%s' set.\n", session_id_prefix);
}
SSL_CTX_set_quiet_shutdown(ctx, 1);
if (exc != NULL)
ssl_ctx_set_excert(ctx, exc);

Expand Down Expand Up @@ -1982,7 +1981,6 @@ int s_server_main(int argc, char *argv[])
}
BIO_printf(bio_err, "id_prefix '%s' set.\n", session_id_prefix);
}
SSL_CTX_set_quiet_shutdown(ctx2, 1);
if (exc != NULL)
ssl_ctx_set_excert(ctx2, exc);

Expand Down Expand Up @@ -2770,7 +2768,7 @@ static int sv_body(int s, int stype, int prot, unsigned char *context)
err:
if (con != NULL) {
BIO_printf(bio_s_out, "shutting down SSL\n");
SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
do_ssl_shutdown(con);
SSL_free(con);
}
BIO_printf(bio_s_out, "CONNECTION CLOSED\n");
Expand Down Expand Up @@ -3439,7 +3437,7 @@ static int www_body(int s, int stype, int prot, unsigned char *context)
}
end:
/* make sure we re-use sessions */
SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
do_ssl_shutdown(con);

err:
OPENSSL_free(buf);
Expand Down Expand Up @@ -3593,7 +3591,7 @@ static int rev_body(int s, int stype, int prot, unsigned char *context)
}
end:
/* make sure we re-use sessions */
SSL_set_shutdown(con, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN);
do_ssl_shutdown(con);

err:

Expand Down

0 comments on commit edbb56e

Please sign in to comment.