]> git.deb.at Git - rhonda/impostor.hazel.git/commitdiff
Add stub DTLS client connection
authorMatthew Endsley <mendsley@gmail.com>
Mon, 1 Feb 2021 21:53:52 +0000 (13:53 -0800)
committerMatthew Endsley <mendsley@gmail.com>
Tue, 2 Feb 2021 17:30:36 +0000 (09:30 -0800)
Hazel/Dtls/DtlsConnectionListener.cs
Hazel/Dtls/DtlsUnityConnection.cs [new file with mode: 0644]
Hazel/Hazel.csproj
Hazel/Udp/UdpConnection.cs
Hazel/Udp/UnityUdpClientConnection.cs

index 72eabc8f2a2143331e1a2f7a2004f38a25212c53..600b0fa645b83636679a5b9da9c05a80da66256a 100644 (file)
@@ -108,7 +108,6 @@ namespace Hazel.Dtls
                 this.CanHandleApplicationData = false;
                 this.QueuedApplicationDataMessage.Clear();
 
-                this.CurrentEpoch = new CurrentEpoch();
                 this.CurrentEpoch.NextOutgoingSequence = 2; // Account for our ClientHelloVerify
                 this.CurrentEpoch.NextExpectedSequence = nextExpectedSequenceNumber;
                 this.CurrentEpoch.PreviousSequenceWindowBitmask = 0;
@@ -116,7 +115,6 @@ namespace Hazel.Dtls
                 this.CurrentEpoch.ServerFinishedVerification.SecureClear();
                 this.CurrentEpoch.ExpectedClientFinishedVerification.SecureClear();
 
-                this.NextEpoch = new NextEpoch();
                 this.NextEpoch.State = HandshakeState.ExpectingHello;
                 this.NextEpoch.RecordProtection = null;
                 this.NextEpoch.ClientRandom = new byte[Random.Size];
diff --git a/Hazel/Dtls/DtlsUnityConnection.cs b/Hazel/Dtls/DtlsUnityConnection.cs
new file mode 100644 (file)
index 0000000..b4a71e9
--- /dev/null
@@ -0,0 +1,70 @@
+using Hazel.Udp;
+using System.Net;
+using System.Security.Cryptography;
+
+namespace Hazel.Dtls
+{
+    /// <summary>
+    /// Connects to a UDP-DTLS server
+    /// </summary>
+    /// <inheritdoc />
+    public abstract class DtlsUnityConnection : UnityUdpClientConnection
+    {
+        private RSA[] serverPublicKeys;
+
+        /// <summary>
+        /// Create a new instance of the DTLS connection
+        /// </summary>
+        /// <inheritdoc />
+        public DtlsUnityConnection(IPEndPoint remoteEndPoint, IPMode ipMode = IPMode.IPv4)
+            : base(remoteEndPoint, ipMode)
+        {
+        }
+
+        /// <inheritdoc />
+        protected override void Dispose(bool disposing)
+        {
+            base.Dispose(disposing);
+        }
+
+        /// <summary>
+        /// Set the list of server public keys
+        /// </summary>
+        /// <param name="serverPublicKeys">
+        /// List of public keys of authentic servers
+        /// </param>
+        public void SetPublicKeys(RSA[] serverPublicKeys)
+        {
+            if (this.serverPublicKeys != null)
+            {
+                foreach (RSA publicKey in this.serverPublicKeys)
+                {
+                    publicKey?.Dispose();
+                }
+            }
+
+            this.serverPublicKeys = serverPublicKeys;
+        }
+
+        /// <summary>
+        /// Abort the existing connection and restart the process
+        /// </summary>
+        protected override void RestartConnection()
+        {
+            throw new System.NotImplementedException();
+            base.RestartConnection();
+        }
+
+        /// <inheritdoc />
+        protected override void WriteBytesToConnection(byte[] bytes, int length)
+        {
+            throw new System.NotImplementedException();
+        }
+
+        /// <inheritdoc />
+        protected internal override void HandleReceive(MessageReader message, int bytesReceived)
+        {
+            throw new System.NotImplementedException();
+        }
+    }
+}
index e091addffb377f7221e496bf47112b5893f31bd6..9b15a5a4795f3eecf3e031561b7242d245184248 100644 (file)
@@ -80,6 +80,7 @@
     <Compile Include="DataReceivedEventArgs.cs" />
     <Compile Include="DisconnectedEventArgs.cs" />
     <Compile Include="Dtls\AesGcmRecordProtection.cs" />
+    <Compile Include="Dtls\DtlsUnityConnection.cs" />
     <Compile Include="Dtls\DtlsConnectionListener.cs" />
     <Compile Include="Dtls\Handshake.cs" />
     <Compile Include="Dtls\IHandshakeCipherSuite.cs" />
index e28118a38526e541c4707fd3cb0441008f184e97..b57b3a404501b8e2833df05a70442bfc2b6146c5 100644 (file)
@@ -1,4 +1,4 @@
-using System;
+using System;
 using System.Net.Sockets;
 
 namespace Hazel.Udp
@@ -122,7 +122,7 @@ namespace Hazel.Udp
         ///     Handles the receiving of data.
         /// </summary>
         /// <param name="message">The buffer containing the bytes received.</param>
-        protected internal void HandleReceive(MessageReader message, int bytesReceived)
+        protected internal virtual void HandleReceive(MessageReader message, int bytesReceived)
         {
             ushort id;
             switch (message.Buffer[0])
index 2a088594f505d9d806f4105bad54a4d11f94de94..c5fdcec6752b1d77ce8f7634d63fe23133063f5c 100644 (file)
@@ -1,4 +1,4 @@
-using System;
+using System;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
@@ -32,6 +32,15 @@ namespace Hazel.Udp
         }
 
         public void FixedUpdate()
+        {
+            this.ResendPacketsIfNeeded();
+        }
+
+        protected virtual void RestartConnection()
+        {
+        }
+
+        protected virtual void ResendPacketsIfNeeded()
         {
             base.ManageReliablePackets();
         }
@@ -106,6 +115,8 @@ namespace Hazel.Udp
                 throw new HazelException("A SocketException occurred while binding to the port.", e);
             }
 
+            this.RestartConnection();
+
             try
             {
                 StartListeningForData();
@@ -252,4 +263,4 @@ namespace Hazel.Udp
             base.Dispose(disposing);
         }
     }
-}
\ No newline at end of file
+}