]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Encode each certificate size in Certficate message
authorMatthew Endsley <mendsley@gmail.com>
Wed, 3 Feb 2021 22:49:12 +0000 (14:49 -0800)
committerMatthew Endsley <mendsley@gmail.com>
Wed, 3 Feb 2021 22:51:17 +0000 (14:51 -0800)
Hazel/Dtls/Handshake.cs

index 649e716a428a18c2711021d07743088cdc695fce..d8bde25097a7ef2892b1f81fe4bdd4342e55be9e 100644 (file)
@@ -589,11 +589,13 @@ namespace Hazel.Dtls
         public static ByteSpan Encode(X509Certificate2 certificate)
         {
             ByteSpan certData = certificate.GetRawCertData();
-            int totalSize = certData.Length + 3;
+            int totalSize = certData.Length + 3 + 3;
 
             ByteSpan result = new byte[totalSize];
 
             ByteSpan writer = result;
+            writer.WriteBigEndian24((uint)certData.Length + 3);
+            writer = writer.Slice(3);
             writer.WriteBigEndian24((uint)certData.Length);
             writer = writer.Slice(3);
 
@@ -608,7 +610,7 @@ namespace Hazel.Dtls
         public static bool Parse(out X509Certificate2 certificate, ByteSpan span)
         {
             certificate = null;
-            if (span.Length < 3)
+            if (span.Length < 6)
             {
                 return false;
             }
@@ -621,7 +623,14 @@ namespace Hazel.Dtls
                 return false;
             }
 
-            byte[] rawData = new byte[totalSize];
+            uint certificateSize = span.ReadBigEndian24();
+            span = span.Slice(3);
+            if (span.Length < certificateSize)
+            {
+                return false;
+            }
+
+            byte[] rawData = new byte[certificateSize];
             span.CopyTo(rawData, 0);
             try
             {