Skip to content

Commit cb81cc8

Browse files
Merge remote-tracking branch 'upstream/master' into gh7197
2 parents 3e59b83 + d36bfab commit cb81cc8

34 files changed

Lines changed: 7655 additions & 470 deletions

.github/workflows/os-check.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ jobs:
6363
'--enable-coding=no',
6464
'--enable-dtls --enable-dtls13 --enable-ocspstapling --enable-ocspstapling2
6565
--enable-cert-setup-cb --enable-sessioncerts',
66+
'--enable-dtls --enable-dtls13 --enable-tls13
67+
CPPFLAGS=-DWOLFSSL_TLS13_IGNORE_PT_ALERT_ON_ENC',
6668
'--disable-sni --disable-ecc --disable-tls13 --disable-secure-renegotiation-info',
6769
'CPPFLAGS=-DWOLFSSL_BLIND_PRIVATE_KEY',
6870
'--enable-all --enable-certgencache',

.github/workflows/rng-tools.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ jobs:
101101
# Retry up to five times
102102
for i in {1..5}; do
103103
TEST_RES=0
104-
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/build-dir/lib make check || TEST_RES=$?
104+
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$GITHUB_WORKSPACE/build-dir/lib RNGD_JITTER_TIMEOUT=100 make check || TEST_RES=$?
105105
if [ "$TEST_RES" -eq "0" ]; then
106106
break
107107
fi

.wolfssl_known_macro_extras

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ WOLFSSL_AESNI_BY6
653653
WOLFSSL_AES_CTR_EXAMPLE
654654
WOLFSSL_AFTER_DATE_CLOCK_SKEW
655655
WOLFSSL_ALGO_HW_MUTEX
656+
WOLFSSL_ALLOW_AKID_SKID_MATCH
656657
WOLFSSL_ALLOW_BAD_TLS_LEGACY_VERSION
657658
WOLFSSL_ALLOW_CRIT_AIA
658659
WOLFSSL_ALLOW_CRIT_AKID
@@ -902,6 +903,7 @@ WOLFSSL_TICKET_ENC_HMAC_SHA512
902903
WOLFSSL_TI_CURRTIME
903904
WOLFSSL_TLS13_DRAFT
904905
WOLFSSL_TLS13_IGNORE_AEAD_LIMITS
906+
WOLFSSL_TLS13_IGNORE_PT_ALERT_ON_ENC
905907
WOLFSSL_TLS13_SHA512
906908
WOLFSSL_TLS13_TICKET_BEFORE_FINISHED
907909
WOLFSSL_TLSX_PQC_MLKEM_STORE_PRIV_KEY
@@ -1028,6 +1030,7 @@ __MWERKS__
10281030
__NT__
10291031
__OS2__
10301032
__OpenBSD__
1033+
__PIC__
10311034
__PIE__
10321035
__POWERPC__
10331036
__PPC__

configure.ac

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10111,10 +10111,7 @@ fi
1011110111
1011210112
if test "x$ENABLED_SYS_CA_CERTS" = "xyes"
1011310113
then
10114-
if test "x$ENABLED_FILESYSTEM" = "xno"
10115-
then
10116-
ENABLED_SYS_CA_CERTS="no"
10117-
elif test "x$ENABLED_CERTS" = "xno"
10114+
if test "x$ENABLED_CERTS" = "xno"
1011810115
then
1011910116
ENABLED_SYS_CA_CERTS="no"
1012010117
fi
@@ -10146,6 +10143,16 @@ then
1014610143
AC_MSG_ERROR([Unable to find Apple Security.framework headers])
1014710144
])
1014810145
;;
10146+
mingw*)
10147+
;;
10148+
*)
10149+
# Only disable on no filesystem non Mac/Windows, as Mac and Windows
10150+
# depend on APIs which don't need filesystem support enabled in wolfSSL.
10151+
if test "x$ENABLED_FILESYSTEM" = "xno"
10152+
then
10153+
ENABLED_SYS_CA_CERTS="no"
10154+
fi
10155+
;;
1014910156
esac
1015010157
fi
1015110158

doc/dox_comments/header_files/ssl.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14418,8 +14418,7 @@ int wolfSSL_set_max_early_data(WOLFSSL* ssl, unsigned int sz);
1441814418
\ingroup IO
1441914419
1442014420
\brief This function writes early data to the server on resumption.
14421-
Call this function instead of wolfSSL_connect() or wolfSSL_connect_TLSv13()
14422-
to connect to the server and send the data in the handshake.
14421+
Call this function before wolfSSL_connect() or wolfSSL_connect_TLSv13().
1442314422
This function is only used with clients.
1442414423
1442514424
\param [in,out] ssl a pointer to a WOLFSSL structure, created using wolfSSL_new().
@@ -14431,7 +14430,7 @@ int wolfSSL_set_max_early_data(WOLFSSL* ssl, unsigned int sz);
1443114430
not using TLSv1.3.
1443214431
\return SIDE_ERROR if called with a server.
1443314432
\return WOLFSSL_FATAL_ERROR if the connection is not made.
14434-
\return WOLFSSL_SUCCESS if successful.
14433+
\return the amount of early data written in bytes if successful.
1443514434
1443614435
_Example_
1443714436
\code
@@ -14444,7 +14443,7 @@ int wolfSSL_set_max_early_data(WOLFSSL* ssl, unsigned int sz);
1444414443
...
1444514444
1444614445
ret = wolfSSL_write_early_data(ssl, earlyData, sizeof(earlyData), &outSz);
14447-
if (ret != WOLFSSL_SUCCESS) {
14446+
if (ret < 0) {
1444814447
err = wolfSSL_get_error(ssl, ret);
1444914448
printf(“error = %d, %s\n”, err, wolfSSL_ERR_error_string(err, buffer));
1445014449
goto err_label;

src/internal.c

Lines changed: 62 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/sniffer.c

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4847,32 +4847,45 @@ static int DecryptDo(WOLFSSL* ssl, byte* plain, const byte* input,
48474847
XMEMCPY(ssl->decrypt.nonce, ssl->keys.aead_dec_imp_IV, AESGCM_IMP_IV_SZ);
48484848
XMEMCPY(ssl->decrypt.nonce + AESGCM_IMP_IV_SZ, input, AESGCM_EXP_IV_SZ);
48494849

4850-
if ((ret = aes_auth_fn(ssl->decrypt.aes,
4851-
plain,
4852-
input + AESGCM_EXP_IV_SZ,
4853-
sz - AESGCM_EXP_IV_SZ - ssl->specs.aead_mac_size,
4854-
ssl->decrypt.nonce, AESGCM_NONCE_SZ,
4855-
ssl->decrypt.additional, AEAD_AUTH_DATA_SZ,
4856-
NULL, 0)) < 0) {
4857-
#ifdef WOLFSSL_ASYNC_CRYPT
4858-
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
4859-
ret = wolfSSL_AsyncPush(ssl, &ssl->decrypt.aes->asyncDev);
4850+
if (sz < AESGCM_EXP_IV_SZ + ssl->specs.aead_mac_size) {
4851+
ret = BUFFER_ERROR;
4852+
}
4853+
4854+
if (ret == 0) {
4855+
ret = aes_auth_fn(ssl->decrypt.aes,
4856+
plain,
4857+
input + AESGCM_EXP_IV_SZ,
4858+
sz - AESGCM_EXP_IV_SZ - ssl->specs.aead_mac_size,
4859+
ssl->decrypt.nonce, AESGCM_NONCE_SZ,
4860+
ssl->decrypt.additional, AEAD_AUTH_DATA_SZ,
4861+
NULL, 0);
4862+
if (ret < 0) {
4863+
#ifdef WOLFSSL_ASYNC_CRYPT
4864+
if (ret == WC_NO_ERR_TRACE(WC_PENDING_E)) {
4865+
ret = wolfSSL_AsyncPush(ssl, &ssl->decrypt.aes->asyncDev);
4866+
}
4867+
#endif
48604868
}
4861-
#endif
48624869
}
48634870
}
48644871
break;
48654872
#endif /* HAVE_AESGCM || HAVE_AESCCM */
48664873

48674874
#ifdef HAVE_ARIA
48684875
case wolfssl_aria_gcm:
4869-
ret = wc_AriaDecrypt(ssl->decrypt.aria,
4870-
plain,
4871-
(byte *)input + AESGCM_EXP_IV_SZ,
4872-
sz - AESGCM_EXP_IV_SZ - ssl->specs.aead_mac_size,
4873-
ssl->decrypt.nonce, AESGCM_NONCE_SZ,
4874-
ssl->decrypt.additional, ssl->specs.aead_mac_size,
4875-
NULL, 0);
4876+
if (sz < AESGCM_EXP_IV_SZ + ssl->specs.aead_mac_size) {
4877+
ret = BUFFER_ERROR;
4878+
}
4879+
4880+
if (ret == 0) {
4881+
ret = wc_AriaDecrypt(ssl->decrypt.aria,
4882+
plain,
4883+
(byte *)input + AESGCM_EXP_IV_SZ,
4884+
sz - AESGCM_EXP_IV_SZ - ssl->specs.aead_mac_size,
4885+
ssl->decrypt.nonce, AESGCM_NONCE_SZ,
4886+
ssl->decrypt.additional, ssl->specs.aead_mac_size,
4887+
NULL, 0);
4888+
}
48764889
break;
48774890
#endif
48784891

0 commit comments

Comments
 (0)