]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Do not compute HMAC for zero-length cookies
authorMatthew Endsley <mendsley@gmail.com>
Wed, 3 Feb 2021 21:23:33 +0000 (13:23 -0800)
committerMatthew Endsley <mendsley@gmail.com>
Wed, 3 Feb 2021 22:40:59 +0000 (14:40 -0800)
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.

Hazel/Dtls/Handshake.cs

index a70af4e3b6c33ec208d10117b8a6df53cb73c28d..880311b587dd26686eb0f4b2fc3703ebef7cde09 100644 (file)
@@ -452,6 +452,11 @@ namespace Hazel.Dtls
         /// <returns>True if the cookie is valid. Otherwise false</returns>
         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)
             {