@@ -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 ;
@@ -1079,20 +1063,22 @@ static int DtlsCidGetSize(WOLFSSL* ssl, unsigned int* size, int rx)
10791063 ConnectionID * id ;
10801064 CIDInfo * info ;
10811065
1082- if (ssl == NULL || size == NULL )
1066+ if (ssl == NULL )
10831067 return BAD_FUNC_ARG ;
10841068
10851069 info = DtlsCidGetInfo (ssl );
10861070 if (info == NULL )
10871071 return WOLFSSL_FAILURE ;
10881072
10891073 id = rx ? info -> rx : info -> tx ;
1090- if (id == NULL ) {
1091- * size = 0 ;
1092- return WOLFSSL_SUCCESS ;
1074+ if (id == NULL || id -> length == 0 ) {
1075+ if (size != NULL )
1076+ * size = 0 ;
1077+ return WOLFSSL_FAILURE ;
10931078 }
10941079
1095- * size = id -> length ;
1080+ if (size != NULL )
1081+ * size = id -> length ;
10961082 return WOLFSSL_SUCCESS ;
10971083}
10981084
@@ -1231,9 +1217,8 @@ int TLSX_ConnectionID_Use(WOLFSSL* ssl)
12311217int TLSX_ConnectionID_Parse (WOLFSSL * ssl , const byte * input , word16 length ,
12321218 byte isRequest )
12331219{
1234- ConnectionID * id ;
12351220 CIDInfo * info ;
1236- byte cidSize ;
1221+ byte cidSz ;
12371222 TLSX * ext ;
12381223
12391224 ext = TLSX_Find (ssl -> extensions , TLSX_CONNECTION_ID );
@@ -1254,31 +1239,41 @@ int TLSX_ConnectionID_Parse(WOLFSSL* ssl, const byte* input, word16 length,
12541239 return BAD_STATE_E ;
12551240
12561241 /* it may happen if we process two ClientHello because the server sent an
1257- * HRR request */
1242+ * HRR/HVR request */
12581243 if (info -> tx != NULL ) {
12591244 if (ssl -> options .side != WOLFSSL_SERVER_END &&
1260- ssl -> options .serverState != SERVER_HELLO_RETRY_REQUEST_COMPLETE )
1245+ ssl -> options .serverState != SERVER_HELLO_RETRY_REQUEST_COMPLETE &&
1246+ !IsSCR (ssl ))
12611247 return BAD_STATE_E ;
12621248
1263- XFREE (info -> tx , ssl -> heap , DYNAMIC_TYPE_TLSX );
1264- info -> tx = NULL ;
1249+ if (!info -> negotiated ) {
1250+ XFREE (info -> tx , ssl -> heap , DYNAMIC_TYPE_TLSX );
1251+ info -> tx = NULL ;
1252+ }
12651253 }
12661254
12671255 if (length < OPAQUE8_LEN )
12681256 return BUFFER_ERROR ;
12691257
1270- cidSize = * input ;
1271- if (cidSize + OPAQUE8_LEN > length )
1258+ cidSz = * input ;
1259+ if (cidSz + OPAQUE8_LEN > length )
12721260 return BUFFER_ERROR ;
12731261
1274- if (cidSize > 0 ) {
1275- id = (ConnectionID * )XMALLOC (sizeof (* id ) + cidSize , ssl -> heap ,
1276- DYNAMIC_TYPE_TLSX );
1277- if (id == NULL )
1278- return MEMORY_ERROR ;
1279- XMEMCPY (id -> id , input + OPAQUE8_LEN , cidSize );
1280- id -> length = cidSize ;
1281- info -> tx = id ;
1262+ if (cidSz > 0 ) {
1263+ if (!info -> negotiated ) {
1264+ ConnectionID * id = (ConnectionID * )XMALLOC (sizeof (* id ) + cidSz ,
1265+ ssl -> heap , DYNAMIC_TYPE_TLSX );
1266+ if (id == NULL )
1267+ return MEMORY_ERROR ;
1268+ XMEMCPY (id -> id , input + OPAQUE8_LEN , cidSz );
1269+ id -> length = cidSz ;
1270+ info -> tx = id ;
1271+ }
1272+ else {
1273+ /* For now we don't support changing the CID on a rehandshake */
1274+ if (XMEMCMP (info -> tx -> id , input + OPAQUE8_LEN , cidSz ) != 0 )
1275+ return DTLS_CID_ERROR ;
1276+ }
12821277 }
12831278
12841279 info -> negotiated = 1 ;
@@ -1317,10 +1312,6 @@ int wolfSSL_dtls_cid_use(WOLFSSL* ssl)
13171312{
13181313 int ret ;
13191314
1320- /* CID is supported on DTLSv1.3 only */
1321- if (!IsAtLeastTLSv1_3 (ssl -> version ))
1322- return WOLFSSL_FAILURE ;
1323-
13241315 ssl -> options .useDtlsCID = 1 ;
13251316 ret = TLSX_ConnectionID_Use (ssl );
13261317 if (ret != 0 )
@@ -1345,8 +1336,11 @@ int wolfSSL_dtls_cid_set(WOLFSSL* ssl, unsigned char* cid, unsigned int size)
13451336 if (cidInfo == NULL )
13461337 return WOLFSSL_FAILURE ;
13471338
1348- XFREE (cidInfo -> rx , ssl -> heap , DYNAMIC_TYPE_TLSX );
1349- cidInfo -> rx = NULL ;
1339+ if (cidInfo -> rx != NULL ) {
1340+ WOLFSSL_MSG ("wolfSSL doesn't support changing the CID during a "
1341+ "connection" );
1342+ return WOLFSSL_FAILURE ;
1343+ }
13501344
13511345 /* empty CID */
13521346 if (size == 0 )
@@ -1384,6 +1378,11 @@ int wolfSSL_dtls_cid_get_tx(WOLFSSL* ssl, unsigned char* buf,
13841378 return DtlsCidGet (ssl , buf , bufferSz , 0 );
13851379}
13861380
1381+ int wolfSSL_dtls_cid_max_size (void )
1382+ {
1383+ return DTLS_CID_MAX_SIZE ;
1384+ }
1385+
13871386#endif /* WOLFSSL_DTLS_CID */
13881387#endif /* WOLFSSL_DTLS */
13891388
0 commit comments