summaryrefslogtreecommitdiff
path: root/deps/openssl/openssl/test/ssltestlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'deps/openssl/openssl/test/ssltestlib.c')
-rw-r--r--deps/openssl/openssl/test/ssltestlib.c395
1 files changed, 252 insertions, 143 deletions
diff --git a/deps/openssl/openssl/test/ssltestlib.c b/deps/openssl/openssl/test/ssltestlib.c
index b824f15248..eafac3cc42 100644
--- a/deps/openssl/openssl/test/ssltestlib.c
+++ b/deps/openssl/openssl/test/ssltestlib.c
@@ -9,8 +9,37 @@
#include <string.h>
-#include "e_os.h"
+#include "internal/nelem.h"
#include "ssltestlib.h"
+#include "testutil.h"
+#include "e_os.h"
+
+#ifdef OPENSSL_SYS_UNIX
+# include <unistd.h>
+
+static ossl_inline void ossl_sleep(unsigned int millis) {
+ usleep(millis * 1000);
+}
+#elif defined(_WIN32)
+# include <windows.h>
+
+static ossl_inline void ossl_sleep(unsigned int millis) {
+ Sleep(millis);
+}
+#else
+/* Fallback to a busy wait */
+static ossl_inline void ossl_sleep(unsigned int millis) {
+ struct timeval start, now;
+ unsigned int elapsedms;
+
+ gettimeofday(&start, NULL);
+ do {
+ gettimeofday(&now, NULL);
+ elapsedms = (((now.tv_sec - start.tv_sec) * 1000000)
+ + now.tv_usec - start.tv_usec) / 1000;
+ } while (elapsedms < millis);
+}
+#endif
static int tls_dump_new(BIO *bi);
static int tls_dump_free(BIO *a);
@@ -21,12 +50,11 @@ static int tls_dump_gets(BIO *bp, char *buf, int size);
static int tls_dump_puts(BIO *bp, const char *str);
/* Choose a sufficiently large type likely to be unused for this custom BIO */
-# define BIO_TYPE_TLS_DUMP_FILTER (0x80 | BIO_TYPE_FILTER)
-
-# define BIO_TYPE_MEMPACKET_TEST 0x81
+#define BIO_TYPE_TLS_DUMP_FILTER (0x80 | BIO_TYPE_FILTER)
+#define BIO_TYPE_MEMPACKET_TEST 0x81
static BIO_METHOD *method_tls_dump = NULL;
-static BIO_METHOD *method_mempacket_test = NULL;
+static BIO_METHOD *meth_mem = NULL;
/* Note: Not thread safe! */
const BIO_METHOD *bio_f_tls_dump_filter(void)
@@ -156,7 +184,7 @@ static void dump_data(const char *data, int len)
printf("*** Message Fragment len: %d\n", fraglen);
if (fragoff + fraglen > msglen)
printf("***---- HANDSHAKE MESSAGE FRAGMENT INVALID ----\n");
- else if(reclen < fraglen)
+ else if (reclen < fraglen)
printf("**---- HANDSHAKE MESSAGE FRAGMENT TRUNCATED ----\n");
else
printf("**---- END OF HANDSHAKE MESSAGE FRAGMENT ----\n");
@@ -252,7 +280,11 @@ typedef struct mempacket_test_ctx_st {
unsigned int currrec;
unsigned int currpkt;
unsigned int lastpkt;
+ unsigned int injected;
unsigned int noinject;
+ unsigned int dropepoch;
+ int droprec;
+ int duprec;
} MEMPACKET_TEST_CTX;
static int mempacket_test_new(BIO *bi);
@@ -265,37 +297,38 @@ static int mempacket_test_puts(BIO *bp, const char *str);
const BIO_METHOD *bio_s_mempacket_test(void)
{
- if (method_mempacket_test == NULL) {
- method_mempacket_test = BIO_meth_new(BIO_TYPE_MEMPACKET_TEST,
- "Mem Packet Test");
- if ( method_mempacket_test == NULL
- || !BIO_meth_set_write(method_mempacket_test, mempacket_test_write)
- || !BIO_meth_set_read(method_mempacket_test, mempacket_test_read)
- || !BIO_meth_set_puts(method_mempacket_test, mempacket_test_puts)
- || !BIO_meth_set_gets(method_mempacket_test, mempacket_test_gets)
- || !BIO_meth_set_ctrl(method_mempacket_test, mempacket_test_ctrl)
- || !BIO_meth_set_create(method_mempacket_test, mempacket_test_new)
- || !BIO_meth_set_destroy(method_mempacket_test, mempacket_test_free))
+ if (meth_mem == NULL) {
+ if (!TEST_ptr(meth_mem = BIO_meth_new(BIO_TYPE_MEMPACKET_TEST,
+ "Mem Packet Test"))
+ || !TEST_true(BIO_meth_set_write(meth_mem, mempacket_test_write))
+ || !TEST_true(BIO_meth_set_read(meth_mem, mempacket_test_read))
+ || !TEST_true(BIO_meth_set_puts(meth_mem, mempacket_test_puts))
+ || !TEST_true(BIO_meth_set_gets(meth_mem, mempacket_test_gets))
+ || !TEST_true(BIO_meth_set_ctrl(meth_mem, mempacket_test_ctrl))
+ || !TEST_true(BIO_meth_set_create(meth_mem, mempacket_test_new))
+ || !TEST_true(BIO_meth_set_destroy(meth_mem, mempacket_test_free)))
return NULL;
}
- return method_mempacket_test;
+ return meth_mem;
}
void bio_s_mempacket_test_free(void)
{
- BIO_meth_free(method_mempacket_test);
+ BIO_meth_free(meth_mem);
}
static int mempacket_test_new(BIO *bio)
{
- MEMPACKET_TEST_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx));
- if (ctx == NULL)
+ MEMPACKET_TEST_CTX *ctx;
+
+ if (!TEST_ptr(ctx = OPENSSL_zalloc(sizeof(*ctx))))
return 0;
- ctx->pkts = sk_MEMPACKET_new_null();
- if (ctx->pkts == NULL) {
+ if (!TEST_ptr(ctx->pkts = sk_MEMPACKET_new_null())) {
OPENSSL_free(ctx);
return 0;
}
+ ctx->dropepoch = 0;
+ ctx->droprec = -1;
BIO_set_init(bio, 1);
BIO_set_data(bio, ctx);
return 1;
@@ -309,13 +342,12 @@ static int mempacket_test_free(BIO *bio)
OPENSSL_free(ctx);
BIO_set_data(bio, NULL);
BIO_set_init(bio, 0);
-
return 1;
}
/* Record Header values */
-#define EPOCH_HI 4
-#define EPOCH_LO 5
+#define EPOCH_HI 3
+#define EPOCH_LO 4
#define RECORD_SEQUENCE 10
#define RECORD_LEN_HI 11
#define RECORD_LEN_LO 12
@@ -331,7 +363,6 @@ static int mempacket_test_read(BIO *bio, char *out, int outl)
unsigned int seq, offset, len, epoch;
BIO_clear_retry_flags(bio);
-
thispkt = sk_MEMPACKET_value(ctx->pkts, 0);
if (thispkt == NULL || thispkt->num != ctx->currpkt) {
/* Probably run out of data */
@@ -344,19 +375,17 @@ static int mempacket_test_read(BIO *bio, char *out, int outl)
if (outl > thispkt->len)
outl = thispkt->len;
- if (thispkt->type != INJECT_PACKET_IGNORE_REC_SEQ) {
+ if (thispkt->type != INJECT_PACKET_IGNORE_REC_SEQ
+ && (ctx->injected || ctx->droprec >= 0)) {
/*
* Overwrite the record sequence number. We strictly number them in
* the order received. Since we are actually a reliable transport
* we know that there won't be any re-ordering. We overwrite to deal
* with any packets that have been injected
*/
- rem = thispkt->len;
- rec = thispkt->data;
- while (rem > 0) {
- if (rem < DTLS1_RT_HEADER_LENGTH) {
+ for (rem = thispkt->len, rec = thispkt->data; rem > 0; rem -= len) {
+ if (rem < DTLS1_RT_HEADER_LENGTH)
return -1;
- }
epoch = (rec[EPOCH_HI] << 8) | rec[EPOCH_LO];
if (epoch != ctx->epoch) {
ctx->epoch = epoch;
@@ -369,20 +398,28 @@ static int mempacket_test_read(BIO *bio, char *out, int outl)
seq >>= 8;
offset++;
} while (seq > 0);
- ctx->currrec++;
len = ((rec[RECORD_LEN_HI] << 8) | rec[RECORD_LEN_LO])
+ DTLS1_RT_HEADER_LENGTH;
+ if (rem < (int)len)
+ return -1;
+ if (ctx->droprec == (int)ctx->currrec && ctx->dropepoch == epoch) {
+ if (rem > (int)len)
+ memmove(rec, rec + len, rem - len);
+ outl -= len;
+ ctx->droprec = -1;
+ if (outl == 0)
+ BIO_set_retry_read(bio);
+ } else {
+ rec += len;
+ }
- rec += len;
- rem -= len;
+ ctx->currrec++;
}
}
memcpy(out, thispkt->data, outl);
-
mempacket_free(thispkt);
-
return outl;
}
@@ -390,42 +427,64 @@ int mempacket_test_inject(BIO *bio, const char *in, int inl, int pktnum,
int type)
{
MEMPACKET_TEST_CTX *ctx = BIO_get_data(bio);
- MEMPACKET *thispkt, *looppkt, *nextpkt;
- int i;
+ MEMPACKET *thispkt = NULL, *looppkt, *nextpkt, *allpkts[3];
+ int i, duprec = ctx->duprec > 0;
+ const unsigned char *inu = (const unsigned char *)in;
+ size_t len = ((inu[RECORD_LEN_HI] << 8) | inu[RECORD_LEN_LO])
+ + DTLS1_RT_HEADER_LENGTH;
if (ctx == NULL)
return -1;
+ if ((size_t)inl < len)
+ return -1;
+
+ if ((size_t)inl == len)
+ duprec = 0;
+
+ /* We don't support arbitrary injection when duplicating records */
+ if (duprec && pktnum != -1)
+ return -1;
+
/* We only allow injection before we've started writing any data */
if (pktnum >= 0) {
if (ctx->noinject)
return -1;
+ ctx->injected = 1;
} else {
ctx->noinject = 1;
}
- thispkt = OPENSSL_malloc(sizeof(MEMPACKET));
- if (thispkt == NULL)
- return -1;
+ for (i = 0; i < (duprec ? 3 : 1); i++) {
+ if (!TEST_ptr(allpkts[i] = OPENSSL_malloc(sizeof(*thispkt))))
+ goto err;
+ thispkt = allpkts[i];
- thispkt->data = OPENSSL_malloc(inl);
- if (thispkt->data == NULL) {
- mempacket_free(thispkt);
- return -1;
+ if (!TEST_ptr(thispkt->data = OPENSSL_malloc(inl)))
+ goto err;
+ /*
+ * If we are duplicating the packet, we duplicate it three times. The
+ * first two times we drop the first record if there are more than one.
+ * In this way we know that libssl will not be able to make progress
+ * until it receives the last packet, and hence will be forced to
+ * buffer these records.
+ */
+ if (duprec && i != 2) {
+ memcpy(thispkt->data, in + len, inl - len);
+ thispkt->len = inl - len;
+ } else {
+ memcpy(thispkt->data, in, inl);
+ thispkt->len = inl;
+ }
+ thispkt->num = (pktnum >= 0) ? (unsigned int)pktnum : ctx->lastpkt + i;
+ thispkt->type = type;
}
- memcpy(thispkt->data, in, inl);
- thispkt->len = inl;
- thispkt->num = (pktnum >= 0) ? (unsigned int)pktnum : ctx->lastpkt;
- thispkt->type = type;
-
for(i = 0; (looppkt = sk_MEMPACKET_value(ctx->pkts, i)) != NULL; i++) {
/* Check if we found the right place to insert this packet */
if (looppkt->num > thispkt->num) {
- if (sk_MEMPACKET_insert(ctx->pkts, thispkt, i) == 0) {
- mempacket_free(thispkt);
- return -1;
- }
+ if (sk_MEMPACKET_insert(ctx->pkts, thispkt, i) == 0)
+ goto err;
/* If we're doing up front injection then we're done */
if (pktnum >= 0)
return inl;
@@ -443,10 +502,10 @@ int mempacket_test_inject(BIO *bio, const char *in, int inl, int pktnum,
else
return inl;
} while(1);
- } else if(looppkt->num == thispkt->num) {
+ } else if (looppkt->num == thispkt->num) {
if (!ctx->noinject) {
/* We injected two packets with the same packet number! */
- return -1;
+ goto err;
}
ctx->lastpkt++;
thispkt->num++;
@@ -456,15 +515,21 @@ int mempacket_test_inject(BIO *bio, const char *in, int inl, int pktnum,
* We didn't find any packets with a packet number equal to or greater than
* this one, so we just add it onto the end
*/
- if (!sk_MEMPACKET_push(ctx->pkts, thispkt)) {
- mempacket_free(thispkt);
- return -1;
- }
+ for (i = 0; i < (duprec ? 3 : 1); i++) {
+ thispkt = allpkts[i];
+ if (!sk_MEMPACKET_push(ctx->pkts, thispkt))
+ goto err;
- if (pktnum < 0)
- ctx->lastpkt++;
+ if (pktnum < 0)
+ ctx->lastpkt++;
+ }
return inl;
+
+ err:
+ for (i = 0; i < (ctx->duprec > 0 ? 3 : 1); i++)
+ mempacket_free(allpkts[i]);
+ return -1;
}
static int mempacket_test_write(BIO *bio, const char *in, int inl)
@@ -501,6 +566,18 @@ static long mempacket_test_ctrl(BIO *bio, int cmd, long num, void *ptr)
case BIO_CTRL_FLUSH:
ret = 1;
break;
+ case MEMPACKET_CTRL_SET_DROP_EPOCH:
+ ctx->dropepoch = (unsigned int)num;
+ break;
+ case MEMPACKET_CTRL_SET_DROP_REC:
+ ctx->droprec = (int)num;
+ break;
+ case MEMPACKET_CTRL_GET_DROP_REC:
+ ret = ctx->droprec;
+ break;
+ case MEMPACKET_CTRL_SET_DUPLICATE_REC:
+ ctx->duprec = (int)num;
+ break;
case BIO_CTRL_RESET:
case BIO_CTRL_DUP:
case BIO_CTRL_PUSH:
@@ -531,50 +608,34 @@ int create_ssl_ctx_pair(const SSL_METHOD *sm, const SSL_METHOD *cm,
SSL_CTX *serverctx = NULL;
SSL_CTX *clientctx = NULL;
- serverctx = SSL_CTX_new(sm);
- if (cctx != NULL)
- clientctx = SSL_CTX_new(cm);
- if (serverctx == NULL || (cctx != NULL && clientctx == NULL)) {
- printf("Failed to create SSL_CTX\n");
+ if (!TEST_ptr(serverctx = SSL_CTX_new(sm))
+ || (cctx != NULL && !TEST_ptr(clientctx = SSL_CTX_new(cm))))
goto err;
- }
- if (min_proto_version > 0
- && !SSL_CTX_set_min_proto_version(serverctx, min_proto_version)) {
- printf("Unable to set server min protocol versions\n");
+ if ((min_proto_version > 0
+ && !TEST_true(SSL_CTX_set_min_proto_version(serverctx,
+ min_proto_version)))
+ || (max_proto_version > 0
+ && !TEST_true(SSL_CTX_set_max_proto_version(serverctx,
+ max_proto_version))))
goto err;
- }
- if (max_proto_version > 0
- && !SSL_CTX_set_max_proto_version(serverctx, max_proto_version)) {
- printf("Unable to set server max protocol versions\n");
+ if (clientctx != NULL
+ && ((min_proto_version > 0
+ && !TEST_true(SSL_CTX_set_min_proto_version(clientctx,
+ min_proto_version)))
+ || (max_proto_version > 0
+ && !TEST_true(SSL_CTX_set_max_proto_version(clientctx,
+ max_proto_version)))))
goto err;
- }
- if (clientctx != NULL) {
- if (min_proto_version > 0
- && !SSL_CTX_set_max_proto_version(clientctx, max_proto_version)) {
- printf("Unable to set client max protocol versions\n");
- goto err;
- }
- if (max_proto_version > 0
- && !SSL_CTX_set_min_proto_version(clientctx, min_proto_version)) {
- printf("Unable to set client min protocol versions\n");
+ if (certfile != NULL && privkeyfile != NULL) {
+ if (!TEST_int_eq(SSL_CTX_use_certificate_file(serverctx, certfile,
+ SSL_FILETYPE_PEM), 1)
+ || !TEST_int_eq(SSL_CTX_use_PrivateKey_file(serverctx,
+ privkeyfile,
+ SSL_FILETYPE_PEM), 1)
+ || !TEST_int_eq(SSL_CTX_check_private_key(serverctx), 1))
goto err;
- }
- }
-
- if (SSL_CTX_use_certificate_file(serverctx, certfile,
- SSL_FILETYPE_PEM) <= 0) {
- printf("Failed to load server certificate\n");
- goto err;
- }
- if (SSL_CTX_use_PrivateKey_file(serverctx, privkeyfile,
- SSL_FILETYPE_PEM) <= 0) {
- printf("Failed to load server private key\n");
- }
- if (SSL_CTX_check_private_key(serverctx) <= 0) {
- printf("Failed to check private key\n");
- goto err;
}
#ifndef OPENSSL_NO_DH
@@ -584,15 +645,15 @@ int create_ssl_ctx_pair(const SSL_METHOD *sm, const SSL_METHOD *cm,
*sctx = serverctx;
if (cctx != NULL)
*cctx = clientctx;
-
return 1;
+
err:
SSL_CTX_free(serverctx);
SSL_CTX_free(clientctx);
return 0;
}
-#define MAXLOOPS 100000
+#define MAXLOOPS 1000000
/*
* NOTE: Transfers control of the BIOs - this function will free them on error
@@ -600,62 +661,46 @@ int create_ssl_ctx_pair(const SSL_METHOD *sm, const SSL_METHOD *cm,
int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,
SSL **cssl, BIO *s_to_c_fbio, BIO *c_to_s_fbio)
{
- SSL *serverssl, *clientssl;
+ SSL *serverssl = NULL, *clientssl = NULL;
BIO *s_to_c_bio = NULL, *c_to_s_bio = NULL;
- if (*sssl == NULL)
- serverssl = SSL_new(serverctx);
- else
+ if (*sssl != NULL)
serverssl = *sssl;
- if (*cssl == NULL)
- clientssl = SSL_new(clientctx);
- else
+ else if (!TEST_ptr(serverssl = SSL_new(serverctx)))
+ goto error;
+ if (*cssl != NULL)
clientssl = *cssl;
-
- if (serverssl == NULL || clientssl == NULL) {
- printf("Failed to create SSL object\n");
+ else if (!TEST_ptr(clientssl = SSL_new(clientctx)))
goto error;
- }
if (SSL_is_dtls(clientssl)) {
- s_to_c_bio = BIO_new(bio_s_mempacket_test());
- c_to_s_bio = BIO_new(bio_s_mempacket_test());
+ if (!TEST_ptr(s_to_c_bio = BIO_new(bio_s_mempacket_test()))
+ || !TEST_ptr(c_to_s_bio = BIO_new(bio_s_mempacket_test())))
+ goto error;
} else {
- s_to_c_bio = BIO_new(BIO_s_mem());
- c_to_s_bio = BIO_new(BIO_s_mem());
- }
- if (s_to_c_bio == NULL || c_to_s_bio == NULL) {
- printf("Failed to create mem BIOs\n");
- goto error;
+ if (!TEST_ptr(s_to_c_bio = BIO_new(BIO_s_mem()))
+ || !TEST_ptr(c_to_s_bio = BIO_new(BIO_s_mem())))
+ goto error;
}
- if (s_to_c_fbio != NULL)
- s_to_c_bio = BIO_push(s_to_c_fbio, s_to_c_bio);
- if (c_to_s_fbio != NULL)
- c_to_s_bio = BIO_push(c_to_s_fbio, c_to_s_bio);
- if (s_to_c_bio == NULL || c_to_s_bio == NULL) {
- printf("Failed to create chained BIOs\n");
+ if (s_to_c_fbio != NULL
+ && !TEST_ptr(s_to_c_bio = BIO_push(s_to_c_fbio, s_to_c_bio)))
+ goto error;
+ if (c_to_s_fbio != NULL
+ && !TEST_ptr(c_to_s_bio = BIO_push(c_to_s_fbio, c_to_s_bio)))
goto error;
- }
/* Set Non-blocking IO behaviour */
BIO_set_mem_eof_return(s_to_c_bio, -1);
BIO_set_mem_eof_return(c_to_s_bio, -1);
/* Up ref these as we are passing them to two SSL objects */
+ SSL_set_bio(serverssl, c_to_s_bio, s_to_c_bio);
BIO_up_ref(s_to_c_bio);
BIO_up_ref(c_to_s_bio);
-
- SSL_set_bio(serverssl, c_to_s_bio, s_to_c_bio);
SSL_set_bio(clientssl, s_to_c_bio, c_to_s_bio);
-
- /* BIOs will now be freed when SSL objects are freed */
- s_to_c_bio = c_to_s_bio = NULL;
- s_to_c_fbio = c_to_s_fbio = NULL;
-
*sssl = serverssl;
*cssl = clientssl;
-
return 1;
error:
@@ -669,10 +714,15 @@ int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,
return 0;
}
-int create_ssl_connection(SSL *serverssl, SSL *clientssl)
+/*
+ * Create an SSL connection, but does not ready any post-handshake
+ * NewSessionTicket messages.
+ */
+int create_bare_ssl_connection(SSL *serverssl, SSL *clientssl, int want)
{
int retc = -1, rets = -1, err, abortctr = 0;
int clienterr = 0, servererr = 0;
+ int isdtls = SSL_is_dtls(serverssl);
do {
err = SSL_ERROR_WANT_WRITE;
@@ -683,9 +733,11 @@ int create_ssl_connection(SSL *serverssl, SSL *clientssl)
}
if (!clienterr && retc <= 0 && err != SSL_ERROR_WANT_READ) {
- printf("SSL_connect() failed %d, %d\n", retc, err);
+ TEST_info("SSL_connect() failed %d, %d", retc, err);
clienterr = 1;
}
+ if (want != SSL_ERROR_NONE && err == want)
+ return 0;
err = SSL_ERROR_WANT_WRITE;
while (!servererr && rets <= 0 && err == SSL_ERROR_WANT_WRITE) {
@@ -694,17 +746,74 @@ int create_ssl_connection(SSL *serverssl, SSL *clientssl)
err = SSL_get_error(serverssl, rets);
}
- if (!servererr && rets <= 0 && err != SSL_ERROR_WANT_READ) {
- printf("SSL_accept() failed %d, %d\n", retc, err);
+ if (!servererr && rets <= 0
+ && err != SSL_ERROR_WANT_READ
+ && err != SSL_ERROR_WANT_X509_LOOKUP) {
+ TEST_info("SSL_accept() failed %d, %d", rets, err);
servererr = 1;
}
+ if (want != SSL_ERROR_NONE && err == want)
+ return 0;
if (clienterr && servererr)
return 0;
+ if (isdtls) {
+ if (rets > 0 && retc <= 0)
+ DTLSv1_handle_timeout(serverssl);
+ if (retc > 0 && rets <= 0)
+ DTLSv1_handle_timeout(clientssl);
+ }
if (++abortctr == MAXLOOPS) {
- printf("No progress made\n");
+ TEST_info("No progress made");
return 0;
}
+ if (isdtls && abortctr <= 50 && (abortctr % 10) == 0) {
+ /*
+ * It looks like we're just spinning. Pause for a short period to
+ * give the DTLS timer a chance to do something. We only do this for
+ * the first few times to prevent hangs.
+ */
+ ossl_sleep(50);
+ }
} while (retc <=0 || rets <= 0);
return 1;
}
+
+/*
+ * Create an SSL connection including any post handshake NewSessionTicket
+ * messages.
+ */
+int create_ssl_connection(SSL *serverssl, SSL *clientssl, int want)
+{
+ int i;
+ unsigned char buf;
+ size_t readbytes;
+
+ if (!create_bare_ssl_connection(serverssl, clientssl, want))
+ return 0;
+
+ /*
+ * We attempt to read some data on the client side which we expect to fail.
+ * This will ensure we have received the NewSessionTicket in TLSv1.3 where
+ * appropriate. We do this twice because there are 2 NewSesionTickets.
+ */
+ for (i = 0; i < 2; i++) {
+ if (SSL_read_ex(clientssl, &buf, sizeof(buf), &readbytes) > 0) {
+ if (!TEST_ulong_eq(readbytes, 0))
+ return 0;
+ } else if (!TEST_int_eq(SSL_get_error(clientssl, 0),
+ SSL_ERROR_WANT_READ)) {
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+void shutdown_ssl_connection(SSL *serverssl, SSL *clientssl)
+{
+ SSL_shutdown(clientssl);
+ SSL_shutdown(serverssl);
+ SSL_free(serverssl);
+ SSL_free(clientssl);
+}