@@ -4322,6 +4322,26 @@ typedef struct Sch13Args {
43224322#endif
43234323} Sch13Args;
43244324
4325+ #ifdef WOLFSSL_EARLY_DATA
4326+ /* Check if early data can potentially be sent.
4327+ * Returns 1 if early data is possible, 0 otherwise.
4328+ */
4329+ static int EarlyDataPossible(WOLFSSL* ssl)
4330+ {
4331+ /* Need session resumption OR PSK callback configured */
4332+ if (ssl->options.resuming) {
4333+ return 1;
4334+ }
4335+ #ifndef NO_PSK
4336+ if (ssl->options.client_psk_tls13_cb != NULL ||
4337+ ssl->options.client_psk_cb != NULL) {
4338+ return 1;
4339+ }
4340+ #endif
4341+ return 0;
4342+ }
4343+ #endif /* WOLFSSL_EARLY_DATA */
4344+
43254345int SendTls13ClientHello(WOLFSSL* ssl)
43264346{
43274347 int ret;
@@ -4461,14 +4481,8 @@ int SendTls13ClientHello(WOLFSSL* ssl)
44614481 case TLS_ASYNC_FINALIZE:
44624482 {
44634483#ifdef WOLFSSL_EARLY_DATA
4464- #ifndef NO_PSK
4465- if (!ssl->options.resuming &&
4466- ssl->options.client_psk_tls13_cb == NULL &&
4467- ssl->options.client_psk_cb == NULL)
4468- #else
4469- if (!ssl->options.resuming)
4470- #endif
4471- ssl->earlyData = no_early_data;
4484+ if (!EarlyDataPossible(ssl))
4485+ ssl->earlyData = no_early_data;
44724486 if (ssl->options.serverState == SERVER_HELLO_RETRY_REQUEST_COMPLETE)
44734487 ssl->earlyData = no_early_data;
44744488 if (ssl->earlyData == no_early_data)
@@ -14994,6 +15008,12 @@ int wolfSSL_write_early_data(WOLFSSL* ssl, const void* data, int sz, int* outSz)
1499415008 if (ssl->options.side == WOLFSSL_SERVER_END)
1499515009 return SIDE_ERROR;
1499615010
15011+ /* Early data requires PSK or session resumption */
15012+ if (!EarlyDataPossible(ssl)) {
15013+ ssl->error = BAD_STATE_E;
15014+ return WOLFSSL_FATAL_ERROR;
15015+ }
15016+
1499715017 if (ssl->options.handShakeState == NULL_STATE) {
1499815018 if (ssl->error != WC_NO_ERR_TRACE(WC_PENDING_E))
1499915019 ssl->earlyData = expecting_early_data;
0 commit comments