From a28fc5e70bd8ed21cb8ef297fc269d6a14f0f0f9 Mon Sep 17 00:00:00 2001 From: David Garske Date: Wed, 18 Mar 2020 13:33:15 -0700 Subject: [PATCH] Peer review feedback. Handle socket.Connect() failures. --- .../wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs | 36 ++++++++++++++----- .../wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs | 2 +- 2 files changed, 28 insertions(+), 10 deletions(-) mode change 100644 => 100755 wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs diff --git a/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs b/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs index ca4b5f803..c2e3321df 100755 --- a/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs +++ b/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs @@ -107,13 +107,16 @@ public class wolfSSL_TLS_CSHarp wolfssl.get_ciphers(ciphers, 4096); Console.WriteLine("Ciphers : " + ciphers.ToString()); - //ciphers = new StringBuilder("ECDHE-ECDSA-AES128-GCM-SHA256"); - //if (wolfssl.CTX_set_cipher_list(ctx, ciphers) != wolfssl.SUCCESS) - //{ - // Console.WriteLine("ERROR CTX_set_cipher_list()"); - // wolfssl.CTX_free(ctx); - // return; - //} + /* Uncomment Section to enable specific cipher suite */ +#if false + ciphers = new StringBuilder("ECDHE-ECDSA-AES128-GCM-SHA256"); + if (wolfssl.CTX_set_cipher_list(ctx, ciphers) != wolfssl.SUCCESS) + { + Console.WriteLine("ERROR CTX_set_cipher_list()"); + wolfssl.CTX_free(ctx); + return; + } +#endif short minDhKey = 128; wolfssl.CTX_SetMinDhKey_Sz(ctx, minDhKey); @@ -129,8 +132,23 @@ public class wolfSSL_TLS_CSHarp /* set up TCP socket */ tcp = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - tcp.Connect("127.0.0.1", 11111); - Console.WriteLine("Connection established"); + try + { + tcp.Connect("localhost", 11111); + } + catch (Exception e) + { + Console.WriteLine("tcp.Connect() error " + e.ToString()); + wolfssl.CTX_free(ctx); + return; + } + if (!tcp.Connected) + { + Console.WriteLine("tcp.Connect() failed!"); + tcp.Close(); + wolfssl.CTX_free(ctx); + return; + } Console.WriteLine("Connected TCP"); ssl = wolfssl.new_ssl(ctx); diff --git a/wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs b/wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs old mode 100644 new mode 100755 index 4cc828465..feef463d0 --- a/wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs +++ b/wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ - + using System; using System.Runtime.InteropServices;