@@ -3038,7 +3038,7 @@ void FreeSSL_Ctx(WOLFSSL_CTX* ctx)
30383038 !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(NO_TLS)
30393039 TicketEncCbCtx_Free(&ctx->ticketKeyCtx);
30403040#endif
3041- wolfSSL_RefFree (&ctx->ref);
3041+ wolfSSL_RefWithMutexFree (&ctx->ref);
30423042 XFREE(ctx, heap, DYNAMIC_TYPE_CTX);
30433043 }
30443044 else {
@@ -21697,20 +21697,20 @@ static int DoAlert(WOLFSSL* ssl, byte* input, word32* inOutIdx, int* type)
2169721697 byte code;
2169821698 word32 dataSz = (word32)ssl->curSize;
2169921699
21700- #if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA)
21701- if (ssl->hsInfoOn)
21702- AddPacketName(ssl, "Alert");
21703- if (ssl->toInfoOn) {
21704- /* add record header back on to info + alert bytes level/code */
21705- int ret = AddPacketInfo(ssl, "Alert", alert, input + *inOutIdx,
21706- ALERT_SIZE, READ_PROTO, RECORD_HEADER_SZ, ssl->heap);
21707- if (ret != 0)
21708- return ret;
21709- #ifdef WOLFSSL_CALLBACKS
21710- AddLateRecordHeader(&ssl->curRL, &ssl->timeoutInfo);
21711- #endif
21712- }
21713- #endif
21700+ #if defined(WOLFSSL_CALLBACKS) || defined(OPENSSL_EXTRA)
21701+ if (ssl->hsInfoOn)
21702+ AddPacketName(ssl, "Alert");
21703+ if (ssl->toInfoOn) {
21704+ /* add record header back on to info + alert bytes level/code */
21705+ int ret = AddPacketInfo(ssl, "Alert", alert, input + *inOutIdx,
21706+ ALERT_SIZE, READ_PROTO, RECORD_HEADER_SZ, ssl->heap);
21707+ if (ret != 0)
21708+ return ret;
21709+ #ifdef WOLFSSL_CALLBACKS
21710+ AddLateRecordHeader(&ssl->curRL, &ssl->timeoutInfo);
21711+ #endif
21712+ }
21713+ #endif
2171421714
2171521715 if (IsEncryptionOn(ssl, 0))
2171621716 dataSz -= ssl->keys.padSz;
@@ -21725,11 +21725,18 @@ static int DoAlert(WOLFSSL* ssl, byte* input, word32* inOutIdx, int* type)
2172521725
2172621726 level = input[(*inOutIdx)++];
2172721727 code = input[(*inOutIdx)++];
21728- ssl->alert_history.last_rx.code = code;
21729- ssl->alert_history.last_rx.level = level;
2173021728 *type = code;
21731- if (level == alert_fatal) {
21732- ssl->options.isClosed = 1; /* Don't send close_notify */
21729+ #ifdef WOLFSSL_TLS13_IGNORE_PT_ALERT_ON_ENC
21730+ /* Don't process alert when TLS 1.3 and encrypting but plaintext alert. */
21731+ if (!IsAtLeastTLSv1_3(ssl->version) || !IsEncryptionOn(ssl, 0) ||
21732+ ssl->keys.decryptedCur)
21733+ #endif
21734+ {
21735+ ssl->alert_history.last_rx.code = code;
21736+ ssl->alert_history.last_rx.level = level;
21737+ if (level == alert_fatal) {
21738+ ssl->options.isClosed = 1; /* Don't send close_notify */
21739+ }
2173321740 }
2173421741
2173521742 if (++ssl->options.alertCount >= WOLFSSL_ALERT_COUNT_MAX) {
@@ -21743,20 +21750,35 @@ static int DoAlert(WOLFSSL* ssl, byte* input, word32* inOutIdx, int* type)
2174321750 }
2174421751
2174521752 LogAlert(*type);
21746- if (*type == close_notify) {
21747- ssl->options.closeNotify = 1;
21753+ if (IsAtLeastTLSv1_3(ssl->version) && IsEncryptionOn(ssl, 0) &&
21754+ !ssl->keys.decryptedCur)
21755+ {
21756+ #ifdef WOLFSSL_TLS13_IGNORE_PT_ALERT_ON_ENC
21757+ /* Ignore alert if TLS 1.3 and encrypting but was plaintext alert. */
21758+ *type = invalid_alert;
21759+ level = alert_none;
21760+
21761+ #else
21762+ /* Unexpected message when encryption is on and alert not encrypted. */
21763+ SendAlert(ssl, alert_fatal, unexpected_message);
21764+ WOLFSSL_ERROR_VERBOSE(PARSE_ERROR);
21765+ return PARSE_ERROR;
21766+ #endif
2174821767 }
2174921768 else {
21750- /*
21751- * A close_notify alert doesn't mean there's been an error, so we only
21752- * add other types of alerts to the error queue
21753- */
21754- WOLFSSL_ERROR(*type);
21769+ if (*type == close_notify) {
21770+ ssl->options.closeNotify = 1;
21771+ }
21772+ else {
21773+ /*
21774+ * A close_notify alert doesn't mean there's been an error, so we
21775+ * only add other types of alerts to the error queue
21776+ */
21777+ WOLFSSL_ERROR(*type);
21778+ }
2175521779 }
21756-
21757- if (IsEncryptionOn(ssl, 0)) {
21780+ if (IsEncryptionOn(ssl, 0))
2175821781 *inOutIdx += ssl->keys.padSz;
21759- }
2176021782
2176121783 return level;
2176221784}
@@ -22507,7 +22529,8 @@ static int DoProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2250722529#ifdef WOLFSSL_TLS13
2250822530 if (IsAtLeastTLSv1_3(ssl->version) && IsEncryptionOn(ssl, 0) &&
2250922531 ssl->curRL.type != application_data &&
22510- ssl->curRL.type != change_cipher_spec) {
22532+ ssl->curRL.type != change_cipher_spec &&
22533+ ssl->curRL.type != alert) {
2251122534 SendAlert(ssl, alert_fatal, unexpected_message);
2251222535 WOLFSSL_ERROR_VERBOSE(PARSE_ERROR);
2251322536 return PARSE_ERROR;
@@ -22615,9 +22638,9 @@ static int DoProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2261522638 case decryptMessage:
2261622639
2261722640 if (IsEncryptionOn(ssl, 0) && ssl->keys.decryptedCur == 0 &&
22618- (!IsAtLeastTLSv1_3(ssl->version) ||
22619- ssl->curRL.type != change_cipher_spec))
22620- {
22641+ (!IsAtLeastTLSv1_3(ssl->version) ||
22642+ ( ssl->curRL.type != change_cipher_spec &&
22643+ ssl->curRL.type != alert))) {
2262122644 ret = DoDecrypt(ssl);
2262222645 #ifdef WOLFSSL_ASYNC_CRYPT
2262322646 if (ret == WC_NO_ERR_TRACE(WC_PENDING_E))
@@ -22694,9 +22717,9 @@ static int DoProcessReplyEx(WOLFSSL* ssl, int allowSocketErr)
2269422717 case verifyMessage:
2269522718
2269622719 if (IsEncryptionOn(ssl, 0) && ssl->keys.decryptedCur == 0 &&
22697- (!IsAtLeastTLSv1_3(ssl->version) ||
22698- ssl->curRL.type != change_cipher_spec))
22699- {
22720+ (!IsAtLeastTLSv1_3(ssl->version) ||
22721+ ( ssl->curRL.type != change_cipher_spec &&
22722+ ssl->curRL.type != alert))) {
2270022723 if (!atomicUser
2270122724#if defined(HAVE_ENCRYPT_THEN_MAC) && !defined(WOLFSSL_AEAD_ONLY)
2270222725 && !ssl->options.startedETMRead
@@ -42234,11 +42257,11 @@ static int DisplaySecTrustError(CFErrorRef error, SecTrustRef trust)
4223442257 /* Description */
4223542258 desc = CFErrorCopyDescription(error);
4223642259 if (desc) {
42237- char buffer [256];
42238- if (CFStringGetCString(desc, buffer , sizeof(buffer ),
42260+ char buf [256];
42261+ if (CFStringGetCString(desc, buf , sizeof(buf ),
4223942262 kCFStringEncodingUTF8)) {
4224042263 WOLFSSL_MSG_EX("SecTrustEvaluateWithError Error description: %s\n",
42241- buffer );
42264+ buf );
4224242265 }
4224342266 CFRelease(desc);
4224442267 }
0 commit comments