@@ -24554,15 +24554,6 @@ static int CheckResumptionConsistency(WOLFSSL* ssl)
2455424554 WOLFSSL_ERROR_VERBOSE(EXT_MASTER_SECRET_NEEDED_E);
2455524555 return EXT_MASTER_SECRET_NEEDED_E;
2455624556 }
24557- #ifdef HAVE_EXTENDED_MASTER
24558- /* Resumption skips MakeMasterSecret, so enforce required EMS here. */
24559- if (!skipEmsCheck && ssl->options.requireEMS && !ssl->options.haveEMS) {
24560- WOLFSSL_MSG("EMS required but not negotiated with peer");
24561- SendAlert(ssl, alert_fatal, handshake_failure);
24562- WOLFSSL_ERROR_VERBOSE(EXT_MASTER_SECRET_NEEDED_E);
24563- return EXT_MASTER_SECRET_NEEDED_E;
24564- }
24565- #endif /* HAVE_EXTENDED_MASTER */
2456624557#ifndef NO_RESUME_SUITE_CHECK
2456724558 /* Suite must match (RFC 5246 7.4.1.3), tickets included. Skip when no suite
2456824559 * was retained (both zero = TLS_NULL_WITH_NULL_NULL, e.g. EAP-FAST PAC). */
@@ -34553,6 +34544,31 @@ static void MakePSKPreMasterSecret(Arrays* arrays, byte use_psk_key)
3455334544 }
3455434545#endif /* HAVE_TLS_EXTENSIONS */
3455534546
34547+ #ifdef HAVE_EXTENDED_MASTER
34548+ /* The negotiated EMS state is final once the ServerHello extensions
34549+ * are parsed: abort a requiring client here, before any key material
34550+ * is computed or sent. */
34551+ if (ssl->options.requireEMS && !ssl->options.haveEMS) {
34552+ byte skipEmsCheck = 0;
34553+ #ifdef HAVE_SECRET_CALLBACK
34554+ /* Skip for EAP-FAST (session-secret callback): the master secret
34555+ * comes from the callback. */
34556+ skipEmsCheck = (ssl->sessionSecretCb != NULL
34557+ #ifdef HAVE_SESSION_TICKET
34558+ && ssl->session != NULL
34559+ && ssl->session->ticketLen > 0
34560+ #endif
34561+ ) ? 1 : 0;
34562+ #endif
34563+ if (!skipEmsCheck) {
34564+ WOLFSSL_MSG("EMS required but not negotiated with peer");
34565+ SendAlert(ssl, alert_fatal, handshake_failure);
34566+ WOLFSSL_ERROR_VERBOSE(EXT_MASTER_SECRET_NEEDED_E);
34567+ return EXT_MASTER_SECRET_NEEDED_E;
34568+ }
34569+ }
34570+ #endif /* HAVE_EXTENDED_MASTER */
34571+
3455634572#if !defined(NO_WOLFSSL_CLIENT) && !defined(WOLFSSL_NO_TLS12) && \
3455734573 defined(HAVE_SERVER_RENEGOTIATION_INFO) && \
3455834574 !defined(WOLFSSL_HARDEN_TLS_NO_SCR_CHECK)
@@ -40665,7 +40681,7 @@ static int AddPSKtoPreMasterSecret(WOLFSSL* ssl)
4066540681#endif /* !WOLFSSL_NO_TICKET_EXPIRE && !NO_ASN_TIME */
4066640682
4066740683 if (!ssl->options.resuming) {
40668- /* Expired above : DoClientHello falls back to a full handshake. */
40684+ /* Resumption abandoned : DoClientHello runs a full handshake. */
4066940685 return ret;
4067040686 }
4067140687
@@ -40680,13 +40696,25 @@ static int AddPSKtoPreMasterSecret(WOLFSSL* ssl)
4068040696 }
4068140697 /* if old sess used EMS, but new doesn't, MUST abort */
4068240698 else if (session->haveEMS && !ssl->options.haveEMS) {
40683- WOLFSSL_MSG("Trying to resume a session with EMS without "
40684- "using EMS");
40685- #ifdef WOLFSSL_EXTRA_ALERTS
40686- SendAlert(ssl, alert_fatal, handshake_failure);
40687- #endif
40688- ret = EXT_MASTER_SECRET_NEEDED_E;
40689- WOLFSSL_ERROR_VERBOSE(ret);
40699+ #ifdef HAVE_EXTENDED_MASTER
40700+ if (ssl->options.disableEMS) {
40701+ /* Local disable, not a client downgrade: decline the
40702+ * resumption and do a full handshake. */
40703+ WOLFSSL_MSG("EMS disabled locally, declining resumption "
40704+ "of an EMS session. Do full handshake.");
40705+ ssl->options.resuming = 0;
40706+ }
40707+ else
40708+ #endif
40709+ {
40710+ WOLFSSL_MSG("Trying to resume a session with EMS without "
40711+ "using EMS");
40712+ #ifdef WOLFSSL_EXTRA_ALERTS
40713+ SendAlert(ssl, alert_fatal, handshake_failure);
40714+ #endif
40715+ ret = EXT_MASTER_SECRET_NEEDED_E;
40716+ WOLFSSL_ERROR_VERBOSE(ret);
40717+ }
4069040718 }
4069140719 }
4069240720 else {
0 commit comments