2 * Copyright 2022 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
11 #include <openssl/configuration.h>
12 #include <openssl/bio.h>
13 #include "quictestlib.h"
14 #include "ssltestlib.h"
15 #include "../testutil.h"
16 #if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG)
17 # include "../threadstest.h"
19 #include "internal/quic_ssl.h"
20 #include "internal/quic_wire_pkt.h"
21 #include "internal/quic_record_tx.h"
22 #include "internal/quic_error.h"
23 #include "internal/packet.h"
24 #include "internal/tsan_assist.h"
26 #define GROWTH_ALLOWANCE 1024
31 /* Plain packet mutations */
32 /* Header for the plaintext packet */
33 QUIC_PKT_HDR pplainhdr
;
34 /* iovec for the plaintext packet data buffer */
35 OSSL_QTX_IOVEC pplainio
;
36 /* Allocated size of the plaintext packet data buffer */
37 size_t pplainbuf_alloc
;
38 qtest_fault_on_packet_plain_cb pplaincb
;
41 /* Handshake message mutations */
42 /* Handshake message buffer */
43 unsigned char *handbuf
;
44 /* Allocated size of the handshake message buffer */
46 /* Actual length of the handshake message */
48 qtest_fault_on_handshake_cb handshakecb
;
50 qtest_fault_on_enc_ext_cb encextcb
;
53 /* Cipher packet mutations */
54 qtest_fault_on_packet_cipher_cb pciphercb
;
57 /* Datagram mutations */
58 qtest_fault_on_datagram_cb datagramcb
;
60 /* The currently processed message */
62 /* Allocated size of msg data buffer */
66 static void packet_plain_finish(void *arg
);
67 static void handshake_finish(void *arg
);
69 static OSSL_TIME fake_now
;
71 static OSSL_TIME
fake_now_cb(void *arg
)
76 int qtest_create_quic_objects(OSSL_LIB_CTX
*libctx
, SSL_CTX
*clientctx
,
77 SSL_CTX
*serverctx
, char *certfile
, char *keyfile
,
78 int flags
, QUIC_TSERVER
**qtserv
, SSL
**cssl
,
81 /* ALPN value as recognised by QUIC_TSERVER */
82 unsigned char alpn
[] = { 8, 'o', 's', 's', 'l', 't', 'e', 's', 't' };
83 QUIC_TSERVER_ARGS tserver_args
= {0};
84 BIO
*cbio
= NULL
, *sbio
= NULL
, *fisbio
= NULL
;
85 BIO_ADDR
*peeraddr
= NULL
;
86 struct in_addr ina
= {0};
93 *cssl
= SSL_new(clientctx
);
98 /* SSL_set_alpn_protos returns 0 for success! */
99 if (!TEST_false(SSL_set_alpn_protos(*cssl
, alpn
, sizeof(alpn
))))
102 if (!TEST_ptr(peeraddr
= BIO_ADDR_new()))
105 if ((flags
& QTEST_FLAG_BLOCK
) != 0) {
106 #if !defined(OPENSSL_NO_POSIX_IO)
110 * For blocking mode we need to create actual sockets rather than doing
111 * everything in memory
113 if (!TEST_true(create_test_sockets(&cfd
, &sfd
, SOCK_DGRAM
, peeraddr
)))
115 cbio
= BIO_new_dgram(cfd
, 1);
116 if (!TEST_ptr(cbio
)) {
121 sbio
= BIO_new_dgram(sfd
, 1);
122 if (!TEST_ptr(sbio
)) {
130 if (!TEST_true(BIO_new_bio_dgram_pair(&cbio
, 0, &sbio
, 0)))
133 if (!TEST_true(BIO_dgram_set_caps(cbio
, BIO_DGRAM_CAP_HANDLES_DST_ADDR
))
134 || !TEST_true(BIO_dgram_set_caps(sbio
, BIO_DGRAM_CAP_HANDLES_DST_ADDR
)))
137 /* Dummy server address */
138 if (!TEST_true(BIO_ADDR_rawmake(peeraddr
, AF_INET
, &ina
, sizeof(ina
),
143 SSL_set_bio(*cssl
, cbio
, cbio
);
145 if (!TEST_true(SSL_set_blocking_mode(*cssl
,
146 (flags
& QTEST_FLAG_BLOCK
) != 0 ? 1 : 0)))
149 if (!TEST_true(SSL_set_initial_peer_addr(*cssl
, peeraddr
)))
153 *fault
= OPENSSL_zalloc(sizeof(**fault
));
158 fisbio
= BIO_new(qtest_get_bio_method());
159 if (!TEST_ptr(fisbio
))
162 BIO_set_data(fisbio
, fault
== NULL
? NULL
: *fault
);
164 if (!TEST_ptr(BIO_push(fisbio
, sbio
)))
167 tserver_args
.libctx
= libctx
;
168 tserver_args
.net_rbio
= sbio
;
169 tserver_args
.net_wbio
= fisbio
;
170 tserver_args
.alpn
= NULL
;
171 if (serverctx
!= NULL
&& !TEST_true(SSL_CTX_up_ref(serverctx
)))
173 tserver_args
.ctx
= serverctx
;
174 if ((flags
& QTEST_FLAG_FAKE_TIME
) != 0) {
175 fake_now
= ossl_time_zero();
176 /* zero time can have a special meaning, bump it */
178 tserver_args
.now_cb
= fake_now_cb
;
179 (void)ossl_quic_conn_set_override_now_cb(*cssl
, fake_now_cb
, NULL
);
182 if (!TEST_ptr(*qtserv
= ossl_quic_tserver_new(&tserver_args
, certfile
,
186 /* Ownership of fisbio and sbio is now held by *qtserv */
191 (*fault
)->qtserv
= *qtserv
;
193 BIO_ADDR_free(peeraddr
);
197 SSL_CTX_free(tserver_args
.ctx
);
198 BIO_ADDR_free(peeraddr
);
204 ossl_quic_tserver_free(*qtserv
);
206 OPENSSL_free(*fault
);
211 void qtest_add_time(uint64_t millis
)
213 fake_now
= ossl_time_add(fake_now
, ossl_ms2time(millis
));
216 QTEST_FAULT
*qtest_create_injector(QUIC_TSERVER
*ts
)
220 f
= OPENSSL_zalloc(sizeof(*f
));
229 int qtest_supports_blocking(void)
231 #if !defined(OPENSSL_NO_POSIX_IO) && defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG)
238 #define MAXLOOPS 1000
240 #if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG)
241 static int globserverret
= 0;
242 static QUIC_TSERVER
*globtserv
;
243 static const thread_t thread_zero
;
245 static void run_server_thread(void)
248 * This will operate in a busy loop because the server does not block,
249 * but should be acceptable because it is local and we expect this to be
252 globserverret
= qtest_create_quic_connection(globtserv
, NULL
);
256 int qtest_create_quic_connection(QUIC_TSERVER
*qtserv
, SSL
*clientssl
)
258 int retc
= -1, rets
= 0, abortctr
= 0, ret
= 0;
259 int clienterr
= 0, servererr
= 0;
260 #if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG)
262 * Pointless initialisation to avoid bogus compiler warnings about using
265 thread_t t
= thread_zero
;
268 if (!TEST_ptr(qtserv
)) {
270 } else if (clientssl
== NULL
) {
272 } else if (SSL_get_blocking_mode(clientssl
) > 0) {
273 #if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG)
275 * clientssl is blocking. We will need a thread to complete the
279 if (!TEST_true(run_thread(&t
, run_server_thread
)))
285 TEST_error("No thread support in this build");
291 if (!clienterr
&& retc
<= 0) {
294 retc
= SSL_connect(clientssl
);
296 err
= SSL_get_error(clientssl
, retc
);
298 if (err
!= SSL_ERROR_WANT_READ
&& err
!= SSL_ERROR_WANT_WRITE
) {
299 TEST_info("SSL_connect() failed %d, %d", retc
, err
);
300 TEST_openssl_errors();
307 * We're cheating. We don't take any notice of SSL_get_tick_timeout()
308 * and tick every time around the loop anyway. This is inefficient. We
309 * can get away with it in test code because we control both ends of
310 * the communications and don't expect network delays. This shouldn't
311 * be done in a real application.
313 if (!clienterr
&& retc
<= 0)
314 SSL_handle_events(clientssl
);
315 if (!servererr
&& rets
<= 0) {
317 ossl_quic_tserver_tick(qtserv
);
318 servererr
= ossl_quic_tserver_is_term_any(qtserv
);
320 rets
= ossl_quic_tserver_is_handshake_confirmed(qtserv
);
323 if (clienterr
&& servererr
)
326 if (clientssl
!= NULL
&& ++abortctr
== MAXLOOPS
) {
327 TEST_info("No progress made");
330 } while ((retc
<= 0 && !clienterr
) || (rets
<= 0 && !servererr
));
332 if (qtserv
== NULL
&& rets
> 0) {
333 #if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG)
334 if (!TEST_true(wait_for_thread(t
)) || !TEST_true(globserverret
))
337 TEST_error("Should not happen");
342 if (!clienterr
&& !servererr
)
348 #if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG)
349 static TSAN_QUALIFIER
int shutdowndone
;
351 static void run_server_shutdown_thread(void)
354 * This will operate in a busy loop because the server does not block,
355 * but should be acceptable because it is local and we expect this to be
359 ossl_quic_tserver_tick(globtserv
);
360 } while(!tsan_load(&shutdowndone
));
364 int qtest_shutdown(QUIC_TSERVER
*qtserv
, SSL
*clientssl
)
368 #if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG)
370 * Pointless initialisation to avoid bogus compiler warnings about using
373 thread_t t
= thread_zero
;
376 if (SSL_get_blocking_mode(clientssl
) > 0) {
377 #if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG)
379 * clientssl is blocking. We will need a thread to complete the
384 if (!TEST_true(run_thread(&t
, run_server_shutdown_thread
)))
389 TEST_error("No thread support in this build");
394 /* Busy loop in non-blocking mode. It should be quick because its local */
396 int rc
= SSL_shutdown(clientssl
);
407 ossl_quic_tserver_tick(qtserv
);
410 #if defined(OPENSSL_THREADS) && !defined(CRYPTO_TDEBUG)
411 tsan_store(&shutdowndone
, 1);
413 if (!TEST_true(wait_for_thread(t
)))
421 int qtest_check_server_transport_err(QUIC_TSERVER
*qtserv
, uint64_t code
)
423 const QUIC_TERMINATE_CAUSE
*cause
;
425 ossl_quic_tserver_tick(qtserv
);
428 * Check that the server has closed with the specified code from the client
430 if (!TEST_true(ossl_quic_tserver_is_term_any(qtserv
)))
433 cause
= ossl_quic_tserver_get_terminate_cause(qtserv
);
435 || !TEST_true(cause
->remote
)
436 || !TEST_false(cause
->app
)
437 || !TEST_uint64_t_eq(cause
->error_code
, code
))
443 int qtest_check_server_protocol_err(QUIC_TSERVER
*qtserv
)
445 return qtest_check_server_transport_err(qtserv
, QUIC_ERR_PROTOCOL_VIOLATION
);
448 int qtest_check_server_frame_encoding_err(QUIC_TSERVER
*qtserv
)
450 return qtest_check_server_transport_err(qtserv
, QUIC_ERR_FRAME_ENCODING_ERROR
);
453 void qtest_fault_free(QTEST_FAULT
*fault
)
458 packet_plain_finish(fault
);
459 handshake_finish(fault
);
464 static int packet_plain_mutate(const QUIC_PKT_HDR
*hdrin
,
465 const OSSL_QTX_IOVEC
*iovecin
, size_t numin
,
466 QUIC_PKT_HDR
**hdrout
,
467 const OSSL_QTX_IOVEC
**iovecout
,
471 QTEST_FAULT
*fault
= arg
;
475 /* Coalesce our data into a single buffer */
477 /* First calculate required buffer size */
478 for (i
= 0; i
< numin
; i
++)
479 bufsz
+= iovecin
[i
].buf_len
;
481 fault
->pplainio
.buf_len
= bufsz
;
483 /* Add an allowance for possible growth */
484 bufsz
+= GROWTH_ALLOWANCE
;
486 fault
->pplainio
.buf
= cur
= OPENSSL_malloc(bufsz
);
488 fault
->pplainio
.buf_len
= 0;
492 fault
->pplainbuf_alloc
= bufsz
;
494 /* Copy in the data from the input buffers */
495 for (i
= 0; i
< numin
; i
++) {
496 memcpy(cur
, iovecin
[i
].buf
, iovecin
[i
].buf_len
);
497 cur
+= iovecin
[i
].buf_len
;
500 fault
->pplainhdr
= *hdrin
;
502 /* Cast below is safe because we allocated the buffer */
503 if (fault
->pplaincb
!= NULL
504 && !fault
->pplaincb(fault
, &fault
->pplainhdr
,
505 (unsigned char *)fault
->pplainio
.buf
,
506 fault
->pplainio
.buf_len
, fault
->pplaincbarg
))
509 *hdrout
= &fault
->pplainhdr
;
510 *iovecout
= &fault
->pplainio
;
516 static void packet_plain_finish(void *arg
)
518 QTEST_FAULT
*fault
= arg
;
520 /* Cast below is safe because we allocated the buffer */
521 OPENSSL_free((unsigned char *)fault
->pplainio
.buf
);
522 fault
->pplainio
.buf_len
= 0;
523 fault
->pplainbuf_alloc
= 0;
524 fault
->pplainio
.buf
= NULL
;
527 int qtest_fault_set_packet_plain_listener(QTEST_FAULT
*fault
,
528 qtest_fault_on_packet_plain_cb pplaincb
,
531 fault
->pplaincb
= pplaincb
;
532 fault
->pplaincbarg
= pplaincbarg
;
534 return ossl_quic_tserver_set_plain_packet_mutator(fault
->qtserv
,
540 /* To be called from a packet_plain_listener callback */
541 int qtest_fault_resize_plain_packet(QTEST_FAULT
*fault
, size_t newlen
)
544 size_t oldlen
= fault
->pplainio
.buf_len
;
547 * Alloc'd size should always be non-zero, so if this fails we've been
550 if (fault
->pplainbuf_alloc
== 0)
553 if (newlen
> fault
->pplainbuf_alloc
) {
554 /* This exceeds our growth allowance. Fail */
558 /* Cast below is safe because we allocated the buffer */
559 buf
= (unsigned char *)fault
->pplainio
.buf
;
561 if (newlen
> oldlen
) {
562 /* Extend packet with 0 bytes */
563 memset(buf
+ oldlen
, 0, newlen
- oldlen
);
564 } /* else we're truncating or staying the same */
566 fault
->pplainio
.buf_len
= newlen
;
567 fault
->pplainhdr
.len
= newlen
;
573 * Prepend frame data into a packet. To be called from a packet_plain_listener
576 int qtest_fault_prepend_frame(QTEST_FAULT
*fault
, const unsigned char *frame
,
583 * Alloc'd size should always be non-zero, so if this fails we've been
586 if (fault
->pplainbuf_alloc
== 0)
589 /* Cast below is safe because we allocated the buffer */
590 buf
= (unsigned char *)fault
->pplainio
.buf
;
591 old_len
= fault
->pplainio
.buf_len
;
593 /* Extend the size of the packet by the size of the new frame */
594 if (!TEST_true(qtest_fault_resize_plain_packet(fault
,
595 old_len
+ frame_len
)))
598 memmove(buf
+ frame_len
, buf
, old_len
);
599 memcpy(buf
, frame
, frame_len
);
604 static int handshake_mutate(const unsigned char *msgin
, size_t msginlen
,
605 unsigned char **msgout
, size_t *msgoutlen
,
608 QTEST_FAULT
*fault
= arg
;
610 unsigned long payloadlen
;
611 unsigned int msgtype
;
614 buf
= OPENSSL_malloc(msginlen
+ GROWTH_ALLOWANCE
);
618 fault
->handbuf
= buf
;
619 fault
->handbuflen
= msginlen
;
620 fault
->handbufalloc
= msginlen
+ GROWTH_ALLOWANCE
;
621 memcpy(buf
, msgin
, msginlen
);
623 if (!PACKET_buf_init(&pkt
, buf
, msginlen
)
624 || !PACKET_get_1(&pkt
, &msgtype
)
625 || !PACKET_get_net_3(&pkt
, &payloadlen
)
626 || PACKET_remaining(&pkt
) != payloadlen
)
629 /* Parse specific message types */
631 case SSL3_MT_ENCRYPTED_EXTENSIONS
:
633 QTEST_ENCRYPTED_EXTENSIONS ee
;
635 if (fault
->encextcb
== NULL
)
639 * The EncryptedExtensions message is very simple. It just has an
640 * extensions block in it and nothing else.
642 ee
.extensions
= (unsigned char *)PACKET_data(&pkt
);
643 ee
.extensionslen
= payloadlen
;
644 if (!fault
->encextcb(fault
, &ee
, payloadlen
, fault
->encextcbarg
))
649 /* No specific handlers for these message types yet */
653 if (fault
->handshakecb
!= NULL
654 && !fault
->handshakecb(fault
, buf
, fault
->handbuflen
,
655 fault
->handshakecbarg
))
659 *msgoutlen
= fault
->handbuflen
;
664 static void handshake_finish(void *arg
)
666 QTEST_FAULT
*fault
= arg
;
668 OPENSSL_free(fault
->handbuf
);
669 fault
->handbuf
= NULL
;
672 int qtest_fault_set_handshake_listener(QTEST_FAULT
*fault
,
673 qtest_fault_on_handshake_cb handshakecb
,
674 void *handshakecbarg
)
676 fault
->handshakecb
= handshakecb
;
677 fault
->handshakecbarg
= handshakecbarg
;
679 return ossl_quic_tserver_set_handshake_mutator(fault
->qtserv
,
685 int qtest_fault_set_hand_enc_ext_listener(QTEST_FAULT
*fault
,
686 qtest_fault_on_enc_ext_cb encextcb
,
689 fault
->encextcb
= encextcb
;
690 fault
->encextcbarg
= encextcbarg
;
692 return ossl_quic_tserver_set_handshake_mutator(fault
->qtserv
,
698 /* To be called from a handshake_listener callback */
699 int qtest_fault_resize_handshake(QTEST_FAULT
*fault
, size_t newlen
)
702 size_t oldlen
= fault
->handbuflen
;
705 * Alloc'd size should always be non-zero, so if this fails we've been
708 if (fault
->handbufalloc
== 0)
711 if (newlen
> fault
->handbufalloc
) {
712 /* This exceeds our growth allowance. Fail */
716 buf
= (unsigned char *)fault
->handbuf
;
718 if (newlen
> oldlen
) {
719 /* Extend packet with 0 bytes */
720 memset(buf
+ oldlen
, 0, newlen
- oldlen
);
721 } /* else we're truncating or staying the same */
723 fault
->handbuflen
= newlen
;
727 /* To be called from message specific listener callbacks */
728 int qtest_fault_resize_message(QTEST_FAULT
*fault
, size_t newlen
)
730 /* First resize the underlying message */
731 if (!qtest_fault_resize_handshake(fault
, newlen
+ SSL3_HM_HEADER_LENGTH
))
734 /* Fixup the handshake message header */
735 fault
->handbuf
[1] = (unsigned char)((newlen
>> 16) & 0xff);
736 fault
->handbuf
[2] = (unsigned char)((newlen
>> 8) & 0xff);
737 fault
->handbuf
[3] = (unsigned char)((newlen
) & 0xff);
742 int qtest_fault_delete_extension(QTEST_FAULT
*fault
,
743 unsigned int exttype
, unsigned char *ext
,
746 PACKET pkt
, sub
, subext
;
748 const unsigned char *start
, *end
;
750 size_t msglen
= fault
->handbuflen
;
752 if (!PACKET_buf_init(&pkt
, ext
, *extlen
))
755 /* Extension block starts with 2 bytes for extension block length */
756 if (!PACKET_as_length_prefixed_2(&pkt
, &sub
))
760 start
= PACKET_data(&sub
);
761 if (!PACKET_get_net_2(&sub
, &type
)
762 || !PACKET_get_length_prefixed_2(&sub
, &subext
))
764 } while (type
!= exttype
);
767 end
= PACKET_data(&sub
);
770 * If we're not the last extension we need to move the rest earlier. The
771 * cast below is safe because we own the underlying buffer and we're no
772 * longer making PACKET calls.
774 if (end
< ext
+ *extlen
)
775 memmove((unsigned char *)start
, end
, end
- start
);
778 * Calculate new extensions payload length =
780 * - 2 extension block length bytes
781 * - length of removed extension
783 newlen
= *extlen
- 2 - (end
- start
);
785 /* Fixup the length bytes for the extension block */
786 ext
[0] = (unsigned char)((newlen
>> 8) & 0xff);
787 ext
[1] = (unsigned char)((newlen
) & 0xff);
790 * Length of the whole extension block is the new payload length plus the
791 * 2 bytes for the length
793 *extlen
= newlen
+ 2;
795 /* We can now resize the message */
796 if ((size_t)(end
- start
) + SSL3_HM_HEADER_LENGTH
> msglen
)
797 return 0; /* Should not happen */
798 msglen
-= (end
- start
) + SSL3_HM_HEADER_LENGTH
;
799 if (!qtest_fault_resize_message(fault
, msglen
))
805 #define BIO_TYPE_CIPHER_PACKET_FILTER (0x80 | BIO_TYPE_FILTER)
807 static BIO_METHOD
*pcipherbiometh
= NULL
;
809 # define BIO_MSG_N(array, stride, n) (*(BIO_MSG *)((char *)(array) + (n)*(stride)))
811 static int pcipher_sendmmsg(BIO
*b
, BIO_MSG
*msg
, size_t stride
,
812 size_t num_msg
, uint64_t flags
,
813 size_t *num_processed
)
816 BIO
*next
= BIO_next(b
);
817 ossl_ssize_t ret
= 0;
818 size_t i
= 0, tmpnump
;
821 unsigned char *tmpdata
;
826 fault
= BIO_get_data(b
);
828 || (fault
->pciphercb
== NULL
&& fault
->datagramcb
== NULL
))
829 return BIO_sendmmsg(next
, msg
, stride
, num_msg
, flags
, num_processed
);
836 for (i
= 0; i
< num_msg
; ++i
) {
837 fault
->msg
= BIO_MSG_N(msg
, stride
, i
);
839 /* Take a copy of the data so that callbacks can modify it */
840 tmpdata
= OPENSSL_malloc(fault
->msg
.data_len
+ GROWTH_ALLOWANCE
);
843 memcpy(tmpdata
, fault
->msg
.data
, fault
->msg
.data_len
);
844 fault
->msg
.data
= tmpdata
;
845 fault
->msgalloc
= fault
->msg
.data_len
+ GROWTH_ALLOWANCE
;
847 if (fault
->pciphercb
!= NULL
) {
848 if (!PACKET_buf_init(&pkt
, fault
->msg
.data
, fault
->msg
.data_len
))
852 if (!ossl_quic_wire_decode_pkt_hdr(&pkt
,
855 * Needs to be set to the actual short header CID length
856 * when testing the server implementation.
864 * hdr.data is const - but its our buffer so casting away the
867 if (!fault
->pciphercb(fault
, &hdr
, (unsigned char *)hdr
.data
,
868 hdr
.len
, fault
->pciphercbarg
))
872 * At the moment modifications to hdr by the callback
873 * are ignored. We might need to rewrite the QUIC header to
874 * enable tests to change this. We also don't yet have a
875 * mechanism for the callback to change the encrypted data
876 * length. It's not clear if that's needed or not.
878 } while (PACKET_remaining(&pkt
) > 0);
881 if (fault
->datagramcb
!= NULL
882 && !fault
->datagramcb(fault
, &fault
->msg
, stride
,
883 fault
->datagramcbarg
))
886 if (!BIO_sendmmsg(next
, &fault
->msg
, stride
, 1, flags
, &tmpnump
)) {
891 OPENSSL_free(fault
->msg
.data
);
892 fault
->msg
.data
= NULL
;
899 OPENSSL_free(fault
->msg
.data
);
900 fault
->msg
.data
= NULL
;
904 static long pcipher_ctrl(BIO
*b
, int cmd
, long larg
, void *parg
)
906 BIO
*next
= BIO_next(b
);
911 return BIO_ctrl(next
, cmd
, larg
, parg
);
914 BIO_METHOD
*qtest_get_bio_method(void)
918 if (pcipherbiometh
!= NULL
)
919 return pcipherbiometh
;
921 tmp
= BIO_meth_new(BIO_TYPE_CIPHER_PACKET_FILTER
, "Cipher Packet Filter");
926 if (!TEST_true(BIO_meth_set_sendmmsg(tmp
, pcipher_sendmmsg
))
927 || !TEST_true(BIO_meth_set_ctrl(tmp
, pcipher_ctrl
)))
930 pcipherbiometh
= tmp
;
934 return pcipherbiometh
;
937 int qtest_fault_set_packet_cipher_listener(QTEST_FAULT
*fault
,
938 qtest_fault_on_packet_cipher_cb pciphercb
,
941 fault
->pciphercb
= pciphercb
;
942 fault
->pciphercbarg
= pciphercbarg
;
947 int qtest_fault_set_datagram_listener(QTEST_FAULT
*fault
,
948 qtest_fault_on_datagram_cb datagramcb
,
951 fault
->datagramcb
= datagramcb
;
952 fault
->datagramcbarg
= datagramcbarg
;
957 /* To be called from a datagram_listener callback */
958 int qtest_fault_resize_datagram(QTEST_FAULT
*fault
, size_t newlen
)
960 if (newlen
> fault
->msgalloc
)
963 if (newlen
> fault
->msg
.data_len
)
964 memset((unsigned char *)fault
->msg
.data
+ fault
->msg
.data_len
, 0,
965 newlen
- fault
->msg
.data_len
);
967 fault
->msg
.data_len
= newlen
;