Skip to content

Commit d18b251

Browse files
Merge pull request #9420 from wolfSSL/TLS13-cipher-suite-fix
Fix TLS 1.3 cipher suite when TLS 1.2 ciphers precede TLS 1.3 ciphers
2 parents 46a2234 + 0767cb8 commit d18b251

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/internal.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37166,6 +37166,37 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3716637166

3716737167
#endif /* !WOLFSSL_NO_TLS12 */
3716837168

37169+
#ifdef WOLFSSL_TLS13
37170+
/* Check if a cipher suite is a TLS 1.3 cipher suite
37171+
* Returns 1 if TLS 1.3 cipher suite, 0 otherwise
37172+
*/
37173+
static WC_INLINE int IsTls13CipherSuite(byte first, byte second)
37174+
{
37175+
(void)second; /* Suppress unused parameter warning */
37176+
37177+
/* TLS 1.3 cipher suites use TLS13_BYTE (0x13) as first byte */
37178+
if (first == TLS13_BYTE)
37179+
return 1;
37180+
37181+
#ifdef HAVE_NULL_CIPHER
37182+
/* Special cases for integrity-only cipher suites */
37183+
if (first == ECC_BYTE && (second == TLS_SHA256_SHA256 ||
37184+
second == TLS_SHA384_SHA384))
37185+
return 1;
37186+
#endif
37187+
37188+
#if (defined(WOLFSSL_SM4_GCM) || defined(WOLFSSL_SM4_CCM)) && \
37189+
defined(WOLFSSL_SM3)
37190+
/* SM4 cipher suites for TLS 1.3 */
37191+
if (first == CIPHER_BYTE && (second == TLS_SM4_GCM_SM3 ||
37192+
second == TLS_SM4_CCM_SM3))
37193+
return 1;
37194+
#endif
37195+
37196+
return 0;
37197+
}
37198+
#endif /* WOLFSSL_TLS13 */
37199+
3716937200
/* Make sure server cert/key are valid for this suite, true on success
3717037201
* Returns 1 for valid server suite or 0 if not found
3717137202
* For asynchronous this can return WC_PENDING_E
@@ -37192,6 +37223,17 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3719237223
first = suites->suites[idx];
3719337224
second = suites->suites[idx+1];
3719437225

37226+
#ifdef WOLFSSL_TLS13
37227+
/* When negotiating TLS 1.3, reject non-TLS 1.3 cipher suites */
37228+
if (IsAtLeastTLSv1_3(ssl->version) &&
37229+
ssl->options.side == WOLFSSL_SERVER_END) {
37230+
if (!IsTls13CipherSuite(first, second)) {
37231+
WOLFSSL_MSG("TLS 1.2 cipher suite not valid for TLS 1.3");
37232+
return 0;
37233+
}
37234+
}
37235+
#endif /* WOLFSSL_TLS13 */
37236+
3719537237
if (CipherRequires(first, second, REQUIRES_RSA)) {
3719637238
WOLFSSL_MSG("Requires RSA");
3719737239
if (ssl->options.haveRSA == 0) {

0 commit comments

Comments
 (0)