@@ -874,6 +874,64 @@ static int test_dtls13_short_read(void)
874
874
875
875
#endif /* WOLFSSL_DTLS13 */
876
876
877
+ static int test_dtls_short_ciphertext (void )
878
+ {
879
+ EXPECT_DECLS ;
880
+ WOLFSSL_CTX * ctx_c = NULL , * ctx_s = NULL ;
881
+ WOLFSSL * ssl_c = NULL , * ssl_s = NULL ;
882
+ struct test_memio_ctx test_ctx ;
883
+ unsigned char readBuf [50 ];
884
+
885
+ XMEMSET (& test_ctx , 0 , sizeof (test_ctx ));
886
+
887
+ /* Setup DTLS contexts */
888
+ ExpectIntEQ (test_memio_setup (& test_ctx , & ctx_c , & ctx_s , & ssl_c , & ssl_s ,
889
+ wolfDTLSv1_2_client_method , wolfDTLSv1_2_server_method ),
890
+ 0 );
891
+
892
+ /* Complete handshake */
893
+ ExpectIntEQ (test_memio_do_handshake (ssl_c , ssl_s , 10 , NULL ), 0 );
894
+
895
+ /* Create a message, that looks encrypted but shorter than minimum ciphertext length */
896
+ /* create the data in the buffer */
897
+ ExpectIntEQ (wolfSSL_write (ssl_c , "bad" , 3 ), 3 );
898
+
899
+ /* check client wrote the record */
900
+ ExpectIntGT (test_ctx .s_len , 14 );
901
+
902
+ /* modify the length field to be smaller than the content */
903
+ test_ctx .s_buff [11 ] = 0x00 ;
904
+ test_ctx .s_buff [12 ] = 0x02 ;
905
+ /* modify the amount of data to send */
906
+ test_ctx .s_len = 15 ;
907
+
908
+ /* Try to read the malformed record */
909
+ wolfSSL_SetLoggingPrefix ("server" );
910
+ ExpectIntEQ (wolfSSL_read (ssl_s , readBuf , sizeof (readBuf )), -1 );
911
+ ExpectIntEQ (wolfSSL_get_error (ssl_s , -1 ), WOLFSSL_ERROR_WANT_READ );
912
+ ExpectIntEQ (test_ctx .s_len , 0 );
913
+
914
+ ExpectIntEQ (test_dtls_communication (ssl_s , ssl_c ), TEST_SUCCESS );
915
+
916
+ /* Cleanup */
917
+ wolfSSL_SetLoggingPrefix ("client" );
918
+ ExpectIntEQ (wolfSSL_shutdown (ssl_c ), WOLFSSL_SHUTDOWN_NOT_DONE );
919
+ wolfSSL_SetLoggingPrefix ("server" );
920
+ ExpectIntEQ (wolfSSL_shutdown (ssl_s ), WOLFSSL_SHUTDOWN_NOT_DONE );
921
+ wolfSSL_SetLoggingPrefix ("client" );
922
+ ExpectIntEQ (wolfSSL_shutdown (ssl_c ), 1 );
923
+ wolfSSL_SetLoggingPrefix ("server" );
924
+ ExpectIntEQ (wolfSSL_shutdown (ssl_s ), 1 );
925
+
926
+ wolfSSL_SetLoggingPrefix (NULL );
927
+ wolfSSL_free (ssl_c );
928
+ wolfSSL_CTX_free (ctx_c );
929
+ wolfSSL_free (ssl_s );
930
+ wolfSSL_CTX_free (ctx_s );
931
+
932
+ return EXPECT_RESULT ();
933
+ }
934
+
877
935
static int test_dtls12_short_read (void )
878
936
{
879
937
EXPECT_DECLS ;
@@ -980,10 +1038,11 @@ int test_dtls_record_length_mismatch(void)
980
1038
#if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES ) && defined(WOLFSSL_DTLS )
981
1039
ExpectIntEQ (test_dtls12_record_length_mismatch (), TEST_SUCCESS );
982
1040
ExpectIntEQ (test_dtls12_short_read (), TEST_SUCCESS );
1041
+ ExpectIntEQ (test_dtls_short_ciphertext (), TEST_SUCCESS );
983
1042
#ifdef WOLFSSL_DTLS13
984
1043
ExpectIntEQ (test_dtls13_longer_length (), TEST_SUCCESS );
985
1044
ExpectIntEQ (test_dtls13_short_read (), TEST_SUCCESS );
986
1045
#endif /* WOLFSSL_DTLS13 */
987
1046
#endif
988
1047
return EXPECT_RESULT ();
989
- }
1048
+ }
0 commit comments