@@ -1062,6 +1062,55 @@ int test_wolfSSL_SendUserCanceled_paths(void)
10621062 return EXPECT_RESULT ();
10631063}
10641064
1065+ /* Test that a fatal alert closure stops later application writes.
1066+ *
1067+ * RFC 8446 section 6.2 / RFC 5246 7.2.2: Once a fatal alert has been sent or
1068+ * received, no further application data may be sent. This is flagged by
1069+ * sentOrRcvdFatalAlert. Subsequent writes should fail to queue.
1070+ *
1071+ * @return TEST_SUCCESS on success.
1072+ */
1073+ int test_wolfSSL_write_after_fatal_alert (void )
1074+ {
1075+ EXPECT_DECLS ;
1076+ #if defined(HAVE_MANUAL_MEMIO_TESTS_DEPENDENCIES ) && !defined(NO_TLS ) && \
1077+ !defined(WOLFSSL_NO_TLS12 )
1078+ WOLFSSL_CTX * ctx_c = NULL ;
1079+ WOLFSSL_CTX * ctx_s = NULL ;
1080+ WOLFSSL * ssl_c = NULL ;
1081+ WOLFSSL * ssl_s = NULL ;
1082+ struct test_memio_ctx test_ctx ;
1083+ const char msg [] = "must not be sent" ;
1084+
1085+ XMEMSET (& test_ctx , 0 , sizeof (test_ctx ));
1086+ ExpectIntEQ (test_memio_setup (& test_ctx , & ctx_c , & ctx_s , & ssl_c , & ssl_s ,
1087+ wolfTLSv1_2_client_method , wolfTLSv1_2_server_method ), 0 );
1088+ ExpectIntEQ (test_memio_do_handshake (ssl_c , ssl_s , 10 , NULL ), 0 );
1089+
1090+ /* A fatal alert was sent (or received); no close_notify follows a fatal
1091+ * alert. */
1092+ if (ssl_c != NULL ) {
1093+ ssl_c -> options .isClosed = 1 ;
1094+ ssl_c -> options .sentOrRcvdFatalAlert = 1 ;
1095+ ssl_c -> error = WOLFSSL_ERROR_NONE ;
1096+
1097+ ExpectIntEQ (wolfSSL_write (ssl_c , msg , (int )sizeof (msg )),
1098+ WC_NO_ERR_TRACE (WOLFSSL_FATAL_ERROR ));
1099+ /* Check the recorded error rather than the value reported, which
1100+ * wolfSSL_get_error() translates for OpenSSL compatibility. */
1101+ ExpectIntEQ (ssl_c -> error , WC_NO_ERR_TRACE (SOCKET_PEER_CLOSED_E ));
1102+ /* No record was queued for the peer. */
1103+ ExpectIntEQ (ssl_c -> buffers .outputBuffer .length , 0 );
1104+ }
1105+
1106+ wolfSSL_free (ssl_c );
1107+ wolfSSL_free (ssl_s );
1108+ wolfSSL_CTX_free (ctx_c );
1109+ wolfSSL_CTX_free (ctx_s );
1110+ #endif
1111+ return EXPECT_RESULT ();
1112+ }
1113+
10651114/* Test that an error the read side recorded is the one the write reports.
10661115 *
10671116 * With a write duplicate in use the read side hands errors over through
0 commit comments