@@ -646,3 +646,77 @@ int test_dtls13_epochs(void) {
646646 return EXPECT_RESULT ();
647647}
648648
649+ int test_dtls13_ack_order (void )
650+ {
651+ EXPECT_DECLS ;
652+ #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES ) && defined(WOLFSSL_DTLS13 )
653+ WOLFSSL_CTX * ctx_c = NULL , * ctx_s = NULL ;
654+ WOLFSSL * ssl_c = NULL , * ssl_s = NULL ;
655+ struct test_memio_ctx test_ctx ;
656+ unsigned char readBuf [50 ];
657+ word32 length = 0 ;
658+ /* struct {
659+ * uint64 epoch;
660+ * uint64 sequence_number;
661+ * } RecordNumber;
662+ * Big endian */
663+ unsigned char expected_output [] = {
664+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x02 ,
665+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
666+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x02 ,
667+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 ,
668+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x02 ,
669+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x02 ,
670+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x03 ,
671+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
672+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x03 ,
673+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 ,
674+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x03 ,
675+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x02 ,
676+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x03 ,
677+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x04 ,
678+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x03 ,
679+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x06 ,
680+ };
681+
682+ XMEMSET (& test_ctx , 0 , sizeof (test_ctx ));
683+
684+ /* Get a populated DTLS object */
685+ ExpectIntEQ (test_memio_setup (& test_ctx , & ctx_c , & ctx_s , & ssl_c , & ssl_s ,
686+ wolfDTLSv1_3_client_method , wolfDTLSv1_3_server_method ), 0 );
687+ ExpectIntEQ (test_memio_do_handshake (ssl_c , ssl_s , 10 , NULL ), 0 );
688+ ExpectIntEQ (wolfSSL_read (ssl_c , readBuf , sizeof (readBuf )), -1 );
689+ /* Clear the buffer of any extra messages */
690+ ExpectIntEQ (wolfSSL_get_error (ssl_c , -1 ), WOLFSSL_ERROR_WANT_READ );
691+ ExpectIntEQ (wolfSSL_read (ssl_s , readBuf , sizeof (readBuf )), -1 );
692+ ExpectIntEQ (wolfSSL_get_error (ssl_s , -1 ), WOLFSSL_ERROR_WANT_READ );
693+ ExpectIntEQ (test_ctx .c_len , 0 );
694+ ExpectIntEQ (test_ctx .s_len , 0 );
695+
696+ /* Add seen records */
697+ ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 3 ), w64From32 (0 , 2 )), 0 );
698+ ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 3 ), w64From32 (0 , 0 )), 0 );
699+ ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 3 ), w64From32 (0 , 1 )), 0 );
700+ ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 3 ), w64From32 (0 , 4 )), 0 );
701+ ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 2 ), w64From32 (0 , 0 )), 0 );
702+ ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 3 ), w64From32 (0 , 6 )), 0 );
703+ ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 3 ), w64From32 (0 , 6 )), 0 );
704+ ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 2 ), w64From32 (0 , 1 )), 0 );
705+ ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 2 ), w64From32 (0 , 2 )), 0 );
706+ ExpectIntEQ (Dtls13RtxAddAck (ssl_c , w64From32 (0 , 2 ), w64From32 (0 , 2 )), 0 );
707+ ExpectIntEQ (Dtls13WriteAckMessage (ssl_c , ssl_c -> dtls13Rtx .seenRecords ,
708+ & length ), 0 );
709+ /* N * RecordNumber + 2 extra bytes for length */
710+ ExpectIntEQ (length , sizeof (expected_output ) + 2 );
711+ ExpectNotNull (mymemmem (ssl_c -> buffers .outputBuffer .buffer ,
712+ ssl_c -> buffers .outputBuffer .bufferSize , expected_output ,
713+ sizeof (expected_output )));
714+
715+
716+ wolfSSL_free (ssl_c );
717+ wolfSSL_CTX_free (ctx_c );
718+ wolfSSL_free (ssl_s );
719+ wolfSSL_CTX_free (ctx_s );
720+ #endif
721+ return EXPECT_RESULT ();
722+ }
0 commit comments