@@ -1038,22 +1038,6 @@ int DoClientHelloStateless(WOLFSSL* ssl, const byte* input, word32 helloSz,
10381038
10391039#if defined(WOLFSSL_DTLS_CID )
10401040
1041- typedef struct ConnectionID {
1042- byte length ;
1043- /* Ignore "nonstandard extension used : zero-sized array in struct/union"
1044- * MSVC warning */
1045- #ifdef _MSC_VER
1046- #pragma warning(disable: 4200)
1047- #endif
1048- byte id [];
1049- } ConnectionID ;
1050-
1051- typedef struct CIDInfo {
1052- ConnectionID * tx ;
1053- ConnectionID * rx ;
1054- byte negotiated : 1 ;
1055- } CIDInfo ;
1056-
10571041static ConnectionID * DtlsCidNew (const byte * cid , byte size , void * heap )
10581042{
10591043 ConnectionID * ret ;
@@ -1231,9 +1215,8 @@ int TLSX_ConnectionID_Use(WOLFSSL* ssl)
12311215int TLSX_ConnectionID_Parse (WOLFSSL * ssl , const byte * input , word16 length ,
12321216 byte isRequest )
12331217{
1234- ConnectionID * id ;
12351218 CIDInfo * info ;
1236- byte cidSize ;
1219+ byte cidSz ;
12371220 TLSX * ext ;
12381221
12391222 ext = TLSX_Find (ssl -> extensions , TLSX_CONNECTION_ID );
@@ -1249,35 +1232,41 @@ int TLSX_ConnectionID_Parse(WOLFSSL* ssl, const byte* input, word16 length,
12491232 }
12501233 }
12511234
1235+ if (length < OPAQUE8_LEN )
1236+ return BUFFER_ERROR ;
1237+
1238+ cidSz = * input ;
1239+ if (cidSz + OPAQUE8_LEN > length )
1240+ return BUFFER_ERROR ;
1241+
12521242 info = DtlsCidGetInfo (ssl );
12531243 if (info == NULL )
12541244 return BAD_STATE_E ;
12551245
12561246 /* it may happen if we process two ClientHello because the server sent an
1257- * HRR request */
1258- if (info -> tx != NULL ) {
1247+ * HRR/HVR request */
1248+ if (info -> tx != NULL || info -> negotiated ) {
12591249 if (ssl -> options .side != WOLFSSL_SERVER_END &&
1260- ssl -> options .serverState != SERVER_HELLO_RETRY_REQUEST_COMPLETE )
1250+ ssl -> options .serverState != SERVER_HELLO_RETRY_REQUEST_COMPLETE &&
1251+ !IsSCR (ssl ))
12611252 return BAD_STATE_E ;
12621253
1263- XFREE (info -> tx , ssl -> heap , DYNAMIC_TYPE_TLSX );
1264- info -> tx = NULL ;
1265- }
1266-
1267- if (length < OPAQUE8_LEN )
1268- return BUFFER_ERROR ;
1269-
1270- cidSize = * input ;
1271- if (cidSize + OPAQUE8_LEN > length )
1272- return BUFFER_ERROR ;
1254+ /* Should not be null if negotiated */
1255+ if (info -> tx == NULL )
1256+ return BAD_STATE_E ;
12731257
1274- if (cidSize > 0 ) {
1275- id = (ConnectionID * )XMALLOC (sizeof (* id ) + cidSize , ssl -> heap ,
1276- DYNAMIC_TYPE_TLSX );
1258+ /* For now we don't support changing the CID on a rehandshake */
1259+ if (cidSz != info -> tx -> length ||
1260+ XMEMCMP (info -> tx -> id , input + OPAQUE8_LEN , cidSz ) != 0 )
1261+ return DTLS_CID_ERROR ;
1262+ }
1263+ else if (cidSz > 0 ) {
1264+ ConnectionID * id = (ConnectionID * )XMALLOC (sizeof (* id ) + cidSz ,
1265+ ssl -> heap , DYNAMIC_TYPE_TLSX );
12771266 if (id == NULL )
12781267 return MEMORY_ERROR ;
1279- XMEMCPY (id -> id , input + OPAQUE8_LEN , cidSize );
1280- id -> length = cidSize ;
1268+ XMEMCPY (id -> id , input + OPAQUE8_LEN , cidSz );
1269+ id -> length = cidSz ;
12811270 info -> tx = id ;
12821271 }
12831272
@@ -1317,10 +1306,6 @@ int wolfSSL_dtls_cid_use(WOLFSSL* ssl)
13171306{
13181307 int ret ;
13191308
1320- /* CID is supported on DTLSv1.3 only */
1321- if (!IsAtLeastTLSv1_3 (ssl -> version ))
1322- return WOLFSSL_FAILURE ;
1323-
13241309 ssl -> options .useDtlsCID = 1 ;
13251310 ret = TLSX_ConnectionID_Use (ssl );
13261311 if (ret != 0 )
@@ -1345,8 +1330,11 @@ int wolfSSL_dtls_cid_set(WOLFSSL* ssl, unsigned char* cid, unsigned int size)
13451330 if (cidInfo == NULL )
13461331 return WOLFSSL_FAILURE ;
13471332
1348- XFREE (cidInfo -> rx , ssl -> heap , DYNAMIC_TYPE_TLSX );
1349- cidInfo -> rx = NULL ;
1333+ if (cidInfo -> rx != NULL ) {
1334+ WOLFSSL_MSG ("wolfSSL doesn't support changing the CID during a "
1335+ "connection" );
1336+ return WOLFSSL_FAILURE ;
1337+ }
13501338
13511339 /* empty CID */
13521340 if (size == 0 )
@@ -1384,7 +1372,42 @@ int wolfSSL_dtls_cid_get_tx(WOLFSSL* ssl, unsigned char* buf,
13841372 return DtlsCidGet (ssl , buf , bufferSz , 0 );
13851373}
13861374
1375+ int wolfSSL_dtls_cid_max_size (void )
1376+ {
1377+ return DTLS_CID_MAX_SIZE ;
1378+ }
13871379#endif /* WOLFSSL_DTLS_CID */
1380+
1381+ byte DtlsGetCidTxSize (WOLFSSL * ssl )
1382+ {
1383+ #ifdef WOLFSSL_DTLS_CID
1384+ unsigned int cidSz ;
1385+ int ret ;
1386+ ret = wolfSSL_dtls_cid_get_tx_size (ssl , & cidSz );
1387+ if (ret != WOLFSSL_SUCCESS )
1388+ return 0 ;
1389+ return (byte )cidSz ;
1390+ #else
1391+ (void )ssl ;
1392+ return 0 ;
1393+ #endif
1394+ }
1395+
1396+ byte DtlsGetCidRxSize (WOLFSSL * ssl )
1397+ {
1398+ #ifdef WOLFSSL_DTLS_CID
1399+ unsigned int cidSz ;
1400+ int ret ;
1401+ ret = wolfSSL_dtls_cid_get_rx_size (ssl , & cidSz );
1402+ if (ret != WOLFSSL_SUCCESS )
1403+ return 0 ;
1404+ return (byte )cidSz ;
1405+ #else
1406+ (void )ssl ;
1407+ return 0 ;
1408+ #endif
1409+ }
1410+
13881411#endif /* WOLFSSL_DTLS */
13891412
13901413#endif /* WOLFCRYPT_ONLY */
0 commit comments