@@ -7248,55 +7248,6 @@ static int TLSX_Cookie_Write(Cookie* cookie, byte* output, byte msgType,
72487248 return 0;
72497249}
72507250
7251- #if defined(WOLFSSL_DTLS13) && defined (WOLFSSL_SEND_HRR_COOKIE)
7252- /* Extract the key share group from the cookie and store it in the
7253- * ssl session for later checks.
7254- *
7255- * ssl The SSL/TLS object.
7256- * returns 0 on success and other values indicate failure.
7257- */
7258- static int TLSX_Cookie_RestoreHrrGroup(WOLFSSL* ssl)
7259- {
7260- TLSX* extension;
7261- Cookie* cookie;
7262- #ifndef NO_SHA256
7263- byte macSz = WC_SHA256_DIGEST_SIZE;
7264- #elif defined(WOLFSSL_SHA384)
7265- byte macSz = WC_SHA384_DIGEST_SIZE;
7266- #elif defined(WOLFSSL_TLS13_SHA512)
7267- byte macSz = WC_SHA512_DIGEST_SIZE;
7268- #elif defined(WOLFSSL_SM3)
7269- byte macSz = WC_SM3_DIGEST_SIZE;
7270- #else
7271- #error "No digest available to use with HMAC for cookies."
7272- #endif /* NO_SHA */
7273-
7274- extension = TLSX_Find(ssl->extensions, TLSX_COOKIE);
7275- if (extension == NULL)
7276- return 0;
7277-
7278- cookie = (Cookie*)extension->data;
7279- if (cookie == NULL)
7280- return 0;
7281-
7282- /* Cookie Data = Hash Len | Hash | CS | KeyShare Group (optional) | MAC */
7283-
7284- /* Check if the cookie has a key share group */
7285- if (cookie->data[0] + 4 + macSz < cookie->len) {
7286- word16 keyShareGroup = 0;
7287- ato16(cookie->data + 3 + cookie->data[0], &keyShareGroup);
7288-
7289- /* The key share group in the cookie is the group selected by the
7290- * server in the HelloRetryRequest. Hence, the client must use this
7291- * group in the second ClientHello.
7292- */
7293- ssl->hrr_keyshare_group = keyShareGroup;
7294- }
7295-
7296- return 0;
7297- }
7298- #endif /* WOLFSSL_DTLS13 && WOLFSSL_SEND_HRR_COOKIE */
7299-
73007251/* Parse the Cookie extension.
73017252 * In messages: ClientHello and HelloRetryRequest.
73027253 *
@@ -7340,19 +7291,11 @@ static int TLSX_Cookie_Parse(WOLFSSL* ssl, const byte* input, word16 length,
73407291 if (extension == NULL) {
73417292#ifdef WOLFSSL_DTLS13
73427293 if (ssl->options.dtls && IsAtLeastTLSv1_3(ssl->version)) {
7343- int ret = 0;
73447294 /* Allow a cookie extension with DTLS 1.3 because it is possible
73457295 * that a different SSL instance sent the cookie but we are now
73467296 * receiving it. */
7347- ret = TLSX_Cookie_Use(ssl, input + idx, len, NULL, 0, 0,
7348- &ssl->extensions);
7349- #if defined(WOLFSSL_SEND_HRR_COOKIE)
7350- if (ret == 0 && ssl->options.dtlsStateful) {
7351- /* Try to extract a HRR key share group from the cookie */
7352- ret = TLSX_Cookie_RestoreHrrGroup(ssl);
7353- }
7354- #endif
7355- return ret;
7297+ return TLSX_Cookie_Use(ssl, input + idx, len, NULL, 0, 0,
7298+ &ssl->extensions);
73567299 }
73577300 else
73587301#endif
@@ -10274,20 +10217,6 @@ int TLSX_KeyShare_Parse_ClientHello(const WOLFSSL* ssl,
1027410217 offset += ret;
1027510218 }
1027610219
10277- if (ssl->hrr_keyshare_group != 0) {
10278- /*
10279- * https://datatracker.ietf.org/doc/html/rfc8446#section-4.2.8
10280- * when sending the new ClientHello, the client MUST
10281- * replace the original "key_share" extension with one containing only a
10282- * new KeyShareEntry for the group indicated in the selected_group field
10283- * of the triggering HelloRetryRequest
10284- */
10285- if (seenGroupsCnt != 1 || seenGroups[0] != ssl->hrr_keyshare_group) {
10286- WOLFSSL_ERROR_VERBOSE(BAD_KEY_SHARE_DATA);
10287- return BAD_KEY_SHARE_DATA;
10288- }
10289- }
10290-
1029110220 return 0;
1029210221}
1029310222
0 commit comments