From: Matthew Endsley Date: Wed, 3 Feb 2021 21:23:33 +0000 (-0800) Subject: Do not compute HMAC for zero-length cookies X-Git-Tag: 1.0.0~20^2~4^2~1 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=4b223b14cd5d719e9378d89710ffa7e6ee11bfea;p=rhonda%2Fimpostor.hazel.git Do not compute HMAC for zero-length cookies This is a common case since all clients send a non-signed ClientHello message to initiate a new session. There is no need to perform the hash+hmac for signatures that will always fail verification due to a mismatched size. --- diff --git a/Hazel/Dtls/Handshake.cs b/Hazel/Dtls/Handshake.cs index a70af4e..880311b 100644 --- a/Hazel/Dtls/Handshake.cs +++ b/Hazel/Dtls/Handshake.cs @@ -452,6 +452,11 @@ namespace Hazel.Dtls /// True if the cookie is valid. Otherwise false public static bool VerifyCookie(ByteSpan cookie, EndPoint peerAddress, HMAC hmac) { + if (cookie.Length != CookieSize) + { + return false; + } + ByteSpan expectedHash = ComputeAddressMac(peerAddress, hmac); if (expectedHash.Length != cookie.Length) {