Skip to content

Commit

Permalink
dtls.c: minor cleanup of cookie check.
Browse files Browse the repository at this point in the history
Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
  • Loading branch information
boaks committed Jan 21, 2023
1 parent 4cb6adc commit c58f484
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1967,20 +1967,17 @@ dtls_0_verify_peer(dtls_context_t *ctx,
return len;
}

dtls_debug_dump("compare with cookie", cookie, len);

/* check if cookies match */
if (len == DTLS_COOKIE_LENGTH && memcmp(cookie, mycookie, len) == 0) {
if (len == 0) {
dtls_debug("cookie len is 0!\n");
} else if (len != DTLS_COOKIE_LENGTH) {
dtls_debug("cookie len mismatch recv. %u != %u!\n", len, DTLS_COOKIE_LENGTH);
} else if (memcmp(cookie, mycookie, len)) {
dtls_debug("not matching cookie!\n");
} else {
dtls_debug("found matching cookie\n");
return 0;
}

if (len > 0) {
dtls_debug_dump("invalid cookie", cookie, len);
} else {
dtls_debug("cookie len is 0!\n");
}

/* ClientHello did not contain any valid cookie, hence we send a
* HelloVerifyRequest. */

Expand Down

0 comments on commit c58f484

Please sign in to comment.