2 * Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
12 #include "internal/nelem.h"
13 #include "ssltestlib.h"
17 #ifdef OPENSSL_SYS_UNIX
19 #ifndef OPENSSL_NO_KTLS
20 # include <netinet/in.h>
21 # include <netinet/in.h>
22 # include <arpa/inet.h>
23 # include <sys/socket.h>
28 static ossl_inline void ossl_sleep(unsigned int millis) {
29 usleep(millis * 1000);
34 static ossl_inline void ossl_sleep(unsigned int millis) {
38 /* Fallback to a busy wait */
39 static ossl_inline void ossl_sleep(unsigned int millis) {
40 struct timeval start, now;
41 unsigned int elapsedms;
43 gettimeofday(&start, NULL);
45 gettimeofday(&now, NULL);
46 elapsedms = (((now.tv_sec - start.tv_sec) * 1000000)
47 + now.tv_usec - start.tv_usec) / 1000;
48 } while (elapsedms < millis);
52 static int tls_dump_new(BIO *bi);
53 static int tls_dump_free(BIO *a);
54 static int tls_dump_read(BIO *b, char *out, int outl);
55 static int tls_dump_write(BIO *b, const char *in, int inl);
56 static long tls_dump_ctrl(BIO *b, int cmd, long num, void *ptr);
57 static int tls_dump_gets(BIO *bp, char *buf, int size);
58 static int tls_dump_puts(BIO *bp, const char *str);
60 /* Choose a sufficiently large type likely to be unused for this custom BIO */
61 #define BIO_TYPE_TLS_DUMP_FILTER (0x80 | BIO_TYPE_FILTER)
62 #define BIO_TYPE_MEMPACKET_TEST 0x81
64 static BIO_METHOD *method_tls_dump = NULL;
65 static BIO_METHOD *meth_mem = NULL;
67 /* Note: Not thread safe! */
68 const BIO_METHOD *bio_f_tls_dump_filter(void)
70 if (method_tls_dump == NULL) {
71 method_tls_dump = BIO_meth_new(BIO_TYPE_TLS_DUMP_FILTER,
73 if ( method_tls_dump == NULL
74 || !BIO_meth_set_write(method_tls_dump, tls_dump_write)
75 || !BIO_meth_set_read(method_tls_dump, tls_dump_read)
76 || !BIO_meth_set_puts(method_tls_dump, tls_dump_puts)
77 || !BIO_meth_set_gets(method_tls_dump, tls_dump_gets)
78 || !BIO_meth_set_ctrl(method_tls_dump, tls_dump_ctrl)
79 || !BIO_meth_set_create(method_tls_dump, tls_dump_new)
80 || !BIO_meth_set_destroy(method_tls_dump, tls_dump_free))
83 return method_tls_dump;
86 void bio_f_tls_dump_filter_free(void)
88 BIO_meth_free(method_tls_dump);
91 static int tls_dump_new(BIO *bio)
97 static int tls_dump_free(BIO *bio)
104 static void copy_flags(BIO *bio)
107 BIO *next = BIO_next(bio);
109 flags = BIO_test_flags(next, BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_RWS);
110 BIO_clear_flags(bio, BIO_FLAGS_SHOULD_RETRY | BIO_FLAGS_RWS);
111 BIO_set_flags(bio, flags);
114 #define RECORD_CONTENT_TYPE 0
115 #define RECORD_VERSION_HI 1
116 #define RECORD_VERSION_LO 2
117 #define RECORD_EPOCH_HI 3
118 #define RECORD_EPOCH_LO 4
119 #define RECORD_SEQUENCE_START 5
120 #define RECORD_SEQUENCE_END 10
121 #define RECORD_LEN_HI 11
122 #define RECORD_LEN_LO 12
126 #define MSG_LEN_MID 2
130 #define MSG_FRAG_OFF_HI 6
131 #define MSG_FRAG_OFF_MID 7
132 #define MSG_FRAG_OFF_LO 8
133 #define MSG_FRAG_LEN_HI 9
134 #define MSG_FRAG_LEN_MID 10
135 #define MSG_FRAG_LEN_LO 11
138 static void dump_data(const char *data, int len)
140 int rem, i, content, reclen, msglen, fragoff, fraglen, epoch;
143 printf("---- START OF PACKET ----\n");
146 rec = (unsigned char *)data;
151 printf("*---- START OF RECORD ----\n");
152 if (rem < DTLS1_RT_HEADER_LENGTH) {
153 printf("*---- RECORD TRUNCATED ----\n");
156 content = rec[RECORD_CONTENT_TYPE];
157 printf("** Record Content-type: %d\n", content);
158 printf("** Record Version: %02x%02x\n",
159 rec[RECORD_VERSION_HI], rec[RECORD_VERSION_LO]);
160 epoch = (rec[RECORD_EPOCH_HI] << 8) | rec[RECORD_EPOCH_LO];
161 printf("** Record Epoch: %d\n", epoch);
162 printf("** Record Sequence: ");
163 for (i = RECORD_SEQUENCE_START; i <= RECORD_SEQUENCE_END; i++)
164 printf("%02x", rec[i]);
165 reclen = (rec[RECORD_LEN_HI] << 8) | rec[RECORD_LEN_LO];
166 printf("\n** Record Length: %d\n", reclen);
168 /* Now look at message */
169 rec += DTLS1_RT_HEADER_LENGTH;
170 rem -= DTLS1_RT_HEADER_LENGTH;
171 if (content == SSL3_RT_HANDSHAKE) {
172 printf("**---- START OF HANDSHAKE MESSAGE FRAGMENT ----\n");
174 printf("**---- HANDSHAKE MESSAGE FRAGMENT ENCRYPTED ----\n");
175 } else if (rem < DTLS1_HM_HEADER_LENGTH
176 || reclen < DTLS1_HM_HEADER_LENGTH) {
177 printf("**---- HANDSHAKE MESSAGE FRAGMENT TRUNCATED ----\n");
179 printf("*** Message Type: %d\n", rec[MSG_TYPE]);
180 msglen = (rec[MSG_LEN_HI] << 16) | (rec[MSG_LEN_MID] << 8)
182 printf("*** Message Length: %d\n", msglen);
183 printf("*** Message sequence: %d\n",
184 (rec[MSG_SEQ_HI] << 8) | rec[MSG_SEQ_LO]);
185 fragoff = (rec[MSG_FRAG_OFF_HI] << 16)
186 | (rec[MSG_FRAG_OFF_MID] << 8)
187 | rec[MSG_FRAG_OFF_LO];
188 printf("*** Message Fragment offset: %d\n", fragoff);
189 fraglen = (rec[MSG_FRAG_LEN_HI] << 16)
190 | (rec[MSG_FRAG_LEN_MID] << 8)
191 | rec[MSG_FRAG_LEN_LO];
192 printf("*** Message Fragment len: %d\n", fraglen);
193 if (fragoff + fraglen > msglen)
194 printf("***---- HANDSHAKE MESSAGE FRAGMENT INVALID ----\n");
195 else if (reclen < fraglen)
196 printf("**---- HANDSHAKE MESSAGE FRAGMENT TRUNCATED ----\n");
198 printf("**---- END OF HANDSHAKE MESSAGE FRAGMENT ----\n");
202 printf("*---- RECORD TRUNCATED ----\n");
207 printf("*---- END OF RECORD ----\n");
210 printf("---- END OF PACKET ----\n\n");
214 static int tls_dump_read(BIO *bio, char *out, int outl)
217 BIO *next = BIO_next(bio);
219 ret = BIO_read(next, out, outl);
229 static int tls_dump_write(BIO *bio, const char *in, int inl)
232 BIO *next = BIO_next(bio);
234 ret = BIO_write(next, in, inl);
240 static long tls_dump_ctrl(BIO *bio, int cmd, long num, void *ptr)
243 BIO *next = BIO_next(bio);
253 ret = BIO_ctrl(next, cmd, num, ptr);
259 static int tls_dump_gets(BIO *bio, char *buf, int size)
261 /* We don't support this - not needed anyway */
265 static int tls_dump_puts(BIO *bio, const char *str)
267 return tls_dump_write(bio, str, strlen(str));
271 struct mempacket_st {
278 static void mempacket_free(MEMPACKET *pkt)
280 if (pkt->data != NULL)
281 OPENSSL_free(pkt->data);
285 typedef struct mempacket_test_ctx_st {
286 STACK_OF(MEMPACKET) *pkts;
288 unsigned int currrec;
289 unsigned int currpkt;
290 unsigned int lastpkt;
291 unsigned int injected;
292 unsigned int noinject;
293 unsigned int dropepoch;
296 } MEMPACKET_TEST_CTX;
298 static int mempacket_test_new(BIO *bi);
299 static int mempacket_test_free(BIO *a);
300 static int mempacket_test_read(BIO *b, char *out, int outl);
301 static int mempacket_test_write(BIO *b, const char *in, int inl);
302 static long mempacket_test_ctrl(BIO *b, int cmd, long num, void *ptr);
303 static int mempacket_test_gets(BIO *bp, char *buf, int size);
304 static int mempacket_test_puts(BIO *bp, const char *str);
306 const BIO_METHOD *bio_s_mempacket_test(void)
308 if (meth_mem == NULL) {
309 if (!TEST_ptr(meth_mem = BIO_meth_new(BIO_TYPE_MEMPACKET_TEST,
311 || !TEST_true(BIO_meth_set_write(meth_mem, mempacket_test_write))
312 || !TEST_true(BIO_meth_set_read(meth_mem, mempacket_test_read))
313 || !TEST_true(BIO_meth_set_puts(meth_mem, mempacket_test_puts))
314 || !TEST_true(BIO_meth_set_gets(meth_mem, mempacket_test_gets))
315 || !TEST_true(BIO_meth_set_ctrl(meth_mem, mempacket_test_ctrl))
316 || !TEST_true(BIO_meth_set_create(meth_mem, mempacket_test_new))
317 || !TEST_true(BIO_meth_set_destroy(meth_mem, mempacket_test_free)))
323 void bio_s_mempacket_test_free(void)
325 BIO_meth_free(meth_mem);
328 static int mempacket_test_new(BIO *bio)
330 MEMPACKET_TEST_CTX *ctx;
332 if (!TEST_ptr(ctx = OPENSSL_zalloc(sizeof(*ctx))))
334 if (!TEST_ptr(ctx->pkts = sk_MEMPACKET_new_null())) {
340 BIO_set_init(bio, 1);
341 BIO_set_data(bio, ctx);
345 static int mempacket_test_free(BIO *bio)
347 MEMPACKET_TEST_CTX *ctx = BIO_get_data(bio);
349 sk_MEMPACKET_pop_free(ctx->pkts, mempacket_free);
351 BIO_set_data(bio, NULL);
352 BIO_set_init(bio, 0);
356 /* Record Header values */
359 #define RECORD_SEQUENCE 10
360 #define RECORD_LEN_HI 11
361 #define RECORD_LEN_LO 12
363 #define STANDARD_PACKET 0
365 static int mempacket_test_read(BIO *bio, char *out, int outl)
367 MEMPACKET_TEST_CTX *ctx = BIO_get_data(bio);
371 unsigned int seq, offset, len, epoch;
373 BIO_clear_retry_flags(bio);
374 thispkt = sk_MEMPACKET_value(ctx->pkts, 0);
375 if (thispkt == NULL || thispkt->num != ctx->currpkt) {
376 /* Probably run out of data */
377 BIO_set_retry_read(bio);
380 (void)sk_MEMPACKET_shift(ctx->pkts);
383 if (outl > thispkt->len)
386 if (thispkt->type != INJECT_PACKET_IGNORE_REC_SEQ
387 && (ctx->injected || ctx->droprec >= 0)) {
389 * Overwrite the record sequence number. We strictly number them in
390 * the order received. Since we are actually a reliable transport
391 * we know that there won't be any re-ordering. We overwrite to deal
392 * with any packets that have been injected
394 for (rem = thispkt->len, rec = thispkt->data; rem > 0; rem -= len) {
395 if (rem < DTLS1_RT_HEADER_LENGTH)
397 epoch = (rec[EPOCH_HI] << 8) | rec[EPOCH_LO];
398 if (epoch != ctx->epoch) {
405 rec[RECORD_SEQUENCE - offset] = seq & 0xFF;
410 len = ((rec[RECORD_LEN_HI] << 8) | rec[RECORD_LEN_LO])
411 + DTLS1_RT_HEADER_LENGTH;
414 if (ctx->droprec == (int)ctx->currrec && ctx->dropepoch == epoch) {
416 memmove(rec, rec + len, rem - len);
420 BIO_set_retry_read(bio);
429 memcpy(out, thispkt->data, outl);
430 mempacket_free(thispkt);
434 int mempacket_test_inject(BIO *bio, const char *in, int inl, int pktnum,
437 MEMPACKET_TEST_CTX *ctx = BIO_get_data(bio);
438 MEMPACKET *thispkt = NULL, *looppkt, *nextpkt, *allpkts[3];
439 int i, duprec = ctx->duprec > 0;
440 const unsigned char *inu = (const unsigned char *)in;
441 size_t len = ((inu[RECORD_LEN_HI] << 8) | inu[RECORD_LEN_LO])
442 + DTLS1_RT_HEADER_LENGTH;
447 if ((size_t)inl < len)
450 if ((size_t)inl == len)
453 /* We don't support arbitrary injection when duplicating records */
454 if (duprec && pktnum != -1)
457 /* We only allow injection before we've started writing any data */
466 for (i = 0; i < (duprec ? 3 : 1); i++) {
467 if (!TEST_ptr(allpkts[i] = OPENSSL_malloc(sizeof(*thispkt))))
469 thispkt = allpkts[i];
471 if (!TEST_ptr(thispkt->data = OPENSSL_malloc(inl)))
474 * If we are duplicating the packet, we duplicate it three times. The
475 * first two times we drop the first record if there are more than one.
476 * In this way we know that libssl will not be able to make progress
477 * until it receives the last packet, and hence will be forced to
478 * buffer these records.
480 if (duprec && i != 2) {
481 memcpy(thispkt->data, in + len, inl - len);
482 thispkt->len = inl - len;
484 memcpy(thispkt->data, in, inl);
487 thispkt->num = (pktnum >= 0) ? (unsigned int)pktnum : ctx->lastpkt + i;
488 thispkt->type = type;
491 for(i = 0; (looppkt = sk_MEMPACKET_value(ctx->pkts, i)) != NULL; i++) {
492 /* Check if we found the right place to insert this packet */
493 if (looppkt->num > thispkt->num) {
494 if (sk_MEMPACKET_insert(ctx->pkts, thispkt, i) == 0)
496 /* If we're doing up front injection then we're done */
500 * We need to do some accounting on lastpkt. We increment it first,
501 * but it might now equal the value of injected packets, so we need
507 nextpkt = sk_MEMPACKET_value(ctx->pkts, i);
508 if (nextpkt != NULL && nextpkt->num == ctx->lastpkt)
513 } else if (looppkt->num == thispkt->num) {
514 if (!ctx->noinject) {
515 /* We injected two packets with the same packet number! */
523 * We didn't find any packets with a packet number equal to or greater than
524 * this one, so we just add it onto the end
526 for (i = 0; i < (duprec ? 3 : 1); i++) {
527 thispkt = allpkts[i];
528 if (!sk_MEMPACKET_push(ctx->pkts, thispkt))
538 for (i = 0; i < (ctx->duprec > 0 ? 3 : 1); i++)
539 mempacket_free(allpkts[i]);
543 static int mempacket_test_write(BIO *bio, const char *in, int inl)
545 return mempacket_test_inject(bio, in, inl, -1, STANDARD_PACKET);
548 static long mempacket_test_ctrl(BIO *bio, int cmd, long num, void *ptr)
551 MEMPACKET_TEST_CTX *ctx = BIO_get_data(bio);
556 ret = (long)(sk_MEMPACKET_num(ctx->pkts) == 0);
558 case BIO_CTRL_GET_CLOSE:
559 ret = BIO_get_shutdown(bio);
561 case BIO_CTRL_SET_CLOSE:
562 BIO_set_shutdown(bio, (int)num);
564 case BIO_CTRL_WPENDING:
567 case BIO_CTRL_PENDING:
568 thispkt = sk_MEMPACKET_value(ctx->pkts, 0);
577 case MEMPACKET_CTRL_SET_DROP_EPOCH:
578 ctx->dropepoch = (unsigned int)num;
580 case MEMPACKET_CTRL_SET_DROP_REC:
581 ctx->droprec = (int)num;
583 case MEMPACKET_CTRL_GET_DROP_REC:
586 case MEMPACKET_CTRL_SET_DUPLICATE_REC:
587 ctx->duprec = (int)num;
600 static int mempacket_test_gets(BIO *bio, char *buf, int size)
602 /* We don't support this - not needed anyway */
606 static int mempacket_test_puts(BIO *bio, const char *str)
608 return mempacket_test_write(bio, str, strlen(str));
611 int create_ssl_ctx_pair(const SSL_METHOD *sm, const SSL_METHOD *cm,
612 int min_proto_version, int max_proto_version,
613 SSL_CTX **sctx, SSL_CTX **cctx, char *certfile,
616 SSL_CTX *serverctx = NULL;
617 SSL_CTX *clientctx = NULL;
619 if (!TEST_ptr(serverctx = SSL_CTX_new(sm))
620 || (cctx != NULL && !TEST_ptr(clientctx = SSL_CTX_new(cm))))
623 if ((min_proto_version > 0
624 && !TEST_true(SSL_CTX_set_min_proto_version(serverctx,
626 || (max_proto_version > 0
627 && !TEST_true(SSL_CTX_set_max_proto_version(serverctx,
628 max_proto_version))))
630 if (clientctx != NULL
631 && ((min_proto_version > 0
632 && !TEST_true(SSL_CTX_set_min_proto_version(clientctx,
634 || (max_proto_version > 0
635 && !TEST_true(SSL_CTX_set_max_proto_version(clientctx,
636 max_proto_version)))))
639 if (certfile != NULL && privkeyfile != NULL) {
640 if (!TEST_int_eq(SSL_CTX_use_certificate_file(serverctx, certfile,
641 SSL_FILETYPE_PEM), 1)
642 || !TEST_int_eq(SSL_CTX_use_PrivateKey_file(serverctx,
644 SSL_FILETYPE_PEM), 1)
645 || !TEST_int_eq(SSL_CTX_check_private_key(serverctx), 1))
649 #ifndef OPENSSL_NO_DH
650 SSL_CTX_set_dh_auto(serverctx, 1);
659 SSL_CTX_free(serverctx);
660 SSL_CTX_free(clientctx);
664 #define MAXLOOPS 1000000
666 #if !defined(OPENSSL_NO_KTLS) && !defined(OPENSSL_NO_SOCK)
667 static int set_nb(int fd)
671 flags = fcntl(fd,F_GETFL,0);
674 flags = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
678 int create_test_sockets(int *cfd, int *sfd)
680 struct sockaddr_in sin;
681 const char *host = "127.0.0.1";
682 int cfd_connected = 0, ret = 0;
683 socklen_t slen = sizeof(sin);
689 memset ((char *) &sin, 0, sizeof(sin));
690 sin.sin_family = AF_INET;
691 sin.sin_addr.s_addr = inet_addr(host);
693 afd = socket(AF_INET, SOCK_STREAM, 0);
697 if (bind(afd, (struct sockaddr*)&sin, sizeof(sin)) < 0)
700 if (getsockname(afd, (struct sockaddr*)&sin, &slen) < 0)
703 if (listen(afd, 1) < 0)
706 *cfd = socket(AF_INET, SOCK_STREAM, 0);
710 if (set_nb(afd) == -1)
713 while (*sfd == -1 || !cfd_connected ) {
714 *sfd = accept(afd, NULL, 0);
715 if (*sfd == -1 && errno != EAGAIN)
718 if (!cfd_connected && connect(*cfd, (struct sockaddr*)&sin, sizeof(sin)) < 0)
724 if (set_nb(*cfd) == -1 || set_nb(*sfd) == -1)
740 int create_ssl_objects2(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,
741 SSL **cssl, int sfd, int cfd)
743 SSL *serverssl = NULL, *clientssl = NULL;
744 BIO *s_to_c_bio = NULL, *c_to_s_bio = NULL;
748 else if (!TEST_ptr(serverssl = SSL_new(serverctx)))
752 else if (!TEST_ptr(clientssl = SSL_new(clientctx)))
755 if (!TEST_ptr(s_to_c_bio = BIO_new_socket(sfd, BIO_NOCLOSE))
756 || !TEST_ptr(c_to_s_bio = BIO_new_socket(cfd, BIO_NOCLOSE)))
759 SSL_set_bio(clientssl, c_to_s_bio, c_to_s_bio);
760 SSL_set_bio(serverssl, s_to_c_bio, s_to_c_bio);
768 BIO_free(s_to_c_bio);
769 BIO_free(c_to_s_bio);
775 * NOTE: Transfers control of the BIOs - this function will free them on error
777 int create_ssl_objects(SSL_CTX *serverctx, SSL_CTX *clientctx, SSL **sssl,
778 SSL **cssl, BIO *s_to_c_fbio, BIO *c_to_s_fbio)
780 SSL *serverssl = NULL, *clientssl = NULL;
781 BIO *s_to_c_bio = NULL, *c_to_s_bio = NULL;
785 else if (!TEST_ptr(serverssl = SSL_new(serverctx)))
789 else if (!TEST_ptr(clientssl = SSL_new(clientctx)))
792 if (SSL_is_dtls(clientssl)) {
793 if (!TEST_ptr(s_to_c_bio = BIO_new(bio_s_mempacket_test()))
794 || !TEST_ptr(c_to_s_bio = BIO_new(bio_s_mempacket_test())))
797 if (!TEST_ptr(s_to_c_bio = BIO_new(BIO_s_mem()))
798 || !TEST_ptr(c_to_s_bio = BIO_new(BIO_s_mem())))
802 if (s_to_c_fbio != NULL
803 && !TEST_ptr(s_to_c_bio = BIO_push(s_to_c_fbio, s_to_c_bio)))
805 if (c_to_s_fbio != NULL
806 && !TEST_ptr(c_to_s_bio = BIO_push(c_to_s_fbio, c_to_s_bio)))
809 /* Set Non-blocking IO behaviour */
810 BIO_set_mem_eof_return(s_to_c_bio, -1);
811 BIO_set_mem_eof_return(c_to_s_bio, -1);
813 /* Up ref these as we are passing them to two SSL objects */
814 SSL_set_bio(serverssl, c_to_s_bio, s_to_c_bio);
815 BIO_up_ref(s_to_c_bio);
816 BIO_up_ref(c_to_s_bio);
817 SSL_set_bio(clientssl, s_to_c_bio, c_to_s_bio);
825 BIO_free(s_to_c_bio);
826 BIO_free(c_to_s_bio);
827 BIO_free(s_to_c_fbio);
828 BIO_free(c_to_s_fbio);
834 * Create an SSL connection, but does not ready any post-handshake
835 * NewSessionTicket messages.
837 int create_bare_ssl_connection(SSL *serverssl, SSL *clientssl, int want)
839 int retc = -1, rets = -1, err, abortctr = 0;
840 int clienterr = 0, servererr = 0;
841 int isdtls = SSL_is_dtls(serverssl);
844 err = SSL_ERROR_WANT_WRITE;
845 while (!clienterr && retc <= 0 && err == SSL_ERROR_WANT_WRITE) {
846 retc = SSL_connect(clientssl);
848 err = SSL_get_error(clientssl, retc);
851 if (!clienterr && retc <= 0 && err != SSL_ERROR_WANT_READ) {
852 TEST_info("SSL_connect() failed %d, %d", retc, err);
855 if (want != SSL_ERROR_NONE && err == want)
858 err = SSL_ERROR_WANT_WRITE;
859 while (!servererr && rets <= 0 && err == SSL_ERROR_WANT_WRITE) {
860 rets = SSL_accept(serverssl);
862 err = SSL_get_error(serverssl, rets);
865 if (!servererr && rets <= 0
866 && err != SSL_ERROR_WANT_READ
867 && err != SSL_ERROR_WANT_X509_LOOKUP) {
868 TEST_info("SSL_accept() failed %d, %d", rets, err);
871 if (want != SSL_ERROR_NONE && err == want)
873 if (clienterr && servererr)
876 if (rets > 0 && retc <= 0)
877 DTLSv1_handle_timeout(serverssl);
878 if (retc > 0 && rets <= 0)
879 DTLSv1_handle_timeout(clientssl);
881 if (++abortctr == MAXLOOPS) {
882 TEST_info("No progress made");
885 if (isdtls && abortctr <= 50 && (abortctr % 10) == 0) {
887 * It looks like we're just spinning. Pause for a short period to
888 * give the DTLS timer a chance to do something. We only do this for
889 * the first few times to prevent hangs.
893 } while (retc <=0 || rets <= 0);
899 * Create an SSL connection including any post handshake NewSessionTicket
902 int create_ssl_connection(SSL *serverssl, SSL *clientssl, int want)
908 if (!create_bare_ssl_connection(serverssl, clientssl, want))
912 * We attempt to read some data on the client side which we expect to fail.
913 * This will ensure we have received the NewSessionTicket in TLSv1.3 where
914 * appropriate. We do this twice because there are 2 NewSesionTickets.
916 for (i = 0; i < 2; i++) {
917 if (SSL_read_ex(clientssl, &buf, sizeof(buf), &readbytes) > 0) {
918 if (!TEST_ulong_eq(readbytes, 0))
920 } else if (!TEST_int_eq(SSL_get_error(clientssl, 0),
921 SSL_ERROR_WANT_READ)) {
929 void shutdown_ssl_connection(SSL *serverssl, SSL *clientssl)
931 SSL_shutdown(clientssl);
932 SSL_shutdown(serverssl);