Skip to content

Commit c56ea55

Browse files
committed
Fix TLS 1.3 cipher suite selection when TLS 1.2 ciphers precede TLS 1.3 ciphers
1 parent 7cfffd5 commit c56ea55

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

src/internal.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37166,6 +37166,30 @@ 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+
/* TLS 1.3 cipher suites use TLS13_BYTE (0x13) as first byte */
37176+
if (first == TLS13_BYTE)
37177+
return 1;
37178+
37179+
/* Special cases for integrity-only cipher suites */
37180+
if (first == ECC_BYTE && (second == TLS_SHA256_SHA256 ||
37181+
second == TLS_SHA384_SHA384))
37182+
return 1;
37183+
37184+
/* SM4 cipher suites for TLS 1.3 */
37185+
if (first == CIPHER_BYTE && (second == TLS_SM4_GCM_SM3 ||
37186+
second == TLS_SM4_CCM_SM3))
37187+
return 1;
37188+
37189+
return 0;
37190+
}
37191+
#endif /* WOLFSSL_TLS13 */
37192+
3716937193
/* Make sure server cert/key are valid for this suite, true on success
3717037194
* Returns 1 for valid server suite or 0 if not found
3717137195
* For asynchronous this can return WC_PENDING_E
@@ -37192,6 +37216,17 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
3719237216
first = suites->suites[idx];
3719337217
second = suites->suites[idx+1];
3719437218

37219+
#ifdef WOLFSSL_TLS13
37220+
/* When negotiating TLS 1.3, reject non-TLS 1.3 cipher suites */
37221+
if (IsAtLeastTLSv1_3(ssl->version) &&
37222+
ssl->options.side == WOLFSSL_SERVER_END) {
37223+
if (!IsTls13CipherSuite(first, second)) {
37224+
WOLFSSL_MSG("TLS 1.2 cipher suite not valid for TLS 1.3");
37225+
return 0;
37226+
}
37227+
}
37228+
#endif /* WOLFSSL_TLS13 */
37229+
3719537230
if (CipherRequires(first, second, REQUIRES_RSA)) {
3719637231
WOLFSSL_MSG("Requires RSA");
3719737232
if (ssl->options.haveRSA == 0) {

0 commit comments

Comments
 (0)