From 15ac366bf979a5e7cc48697483b53710afccec50 Mon Sep 17 00:00:00 2001 From: gasbytes Date: Sat, 1 Jun 2024 17:46:17 +0200 Subject: [PATCH] added missing wrappers for sni setup & frees --- wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs | 47 ++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs b/wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs index b756934c2..3e78da76e 100644 --- a/wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs +++ b/wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs @@ -147,6 +147,10 @@ namespace wolfSSL.CSharp { { this.psk_cb.Free(); } + if (!Object.Equals(this.sni_cb, default(GCHandle))) + { + this.sni_cb.Free(); + } if (!Object.Equals(this.vrf_cb, default(GCHandle))) { this.vrf_cb.Free(); @@ -217,6 +221,10 @@ namespace wolfSSL.CSharp { { this.psk_cb.Free(); } + if (!Object.Equals(this.sni_cb, default(GCHandle))) + { + this.sni_cb.Free(); + } if (!Object.Equals(this.vrf_cb, default(GCHandle))) { this.vrf_cb.Free(); @@ -320,6 +328,10 @@ namespace wolfSSL.CSharp { private extern static int wolfSSL_CTX_set_tlsext_servername_callback(IntPtr ctx, sni_delegate sni_cb); [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] private extern static int wolfSSL_CTX_set_servername_arg(IntPtr ctx, IntPtr arg); + [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] + private extern static int wolfSSL_CTX_UseSNI(IntPtr ctx, byte type, IntPtr data, ushort size); + [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] + private extern static int wolfSSL_UseSNI(IntPtr ssl, byte type, IntPtr data, ushort size); /******************************** * SSL Structure @@ -1114,7 +1126,8 @@ namespace wolfSSL.CSharp { } } - public static void CTX_set_servername_callback(IntPtr ctx, sni_delegate sni_cb) { + public static void CTX_set_servername_callback(IntPtr ctx, sni_delegate sni_cb) + { try { GCHandle gch = GCHandle.FromIntPtr(ctx); ctx_handle handles = (ctx_handle)gch.Target; @@ -1127,7 +1140,8 @@ namespace wolfSSL.CSharp { } } - public static int CTX_set_tlsext_servername_callback(IntPtr ctx, sni_delegate sni_cb) { + public static int CTX_set_tlsext_servername_callback(IntPtr ctx, sni_delegate sni_cb) + { try { GCHandle gch = GCHandle.FromIntPtr(ctx); ctx_handle handles = (ctx_handle)gch.Target; @@ -1141,7 +1155,8 @@ namespace wolfSSL.CSharp { } } - public static int CTX_set_servername_arg(IntPtr ctx, IntPtr arg) { + public static int CTX_set_servername_arg(IntPtr ctx, IntPtr arg) + { try { GCHandle gch = GCHandle.FromIntPtr(ctx); ctx_handle handles = (ctx_handle)gch.Target; @@ -1155,6 +1170,32 @@ namespace wolfSSL.CSharp { } } + public static int CTX_UseSNI(IntPtr ctx, byte type, IntPtr data, ushort size) + { + try { + GCHandle gch = GCHandle.FromIntPtr(ctx); + ctx_handle handles = (ctx_handle)gch.Target; + + return wolfSSL_CTX_UseSNI(handles.get_ctx(), type, data, size); + } catch (Exception e) { + log(ERROR_LOG, "wolfssl ctx use sni error: " + e.ToString()); + return FAILURE; + } + } + + public static int UseSNI(IntPtr ssl, byte type, IntPtr data, ushort size) + { + try { + GCHandle gch = GCHandle.FromIntPtr(ssl); + ssl_handle handles = (ssl_handle)gch.Target; + + return wolfSSL_UseSNI(handles.get_ssl(), type, data, size); + } catch (Exception e) { + log(ERROR_LOG, "wolfssl use sni error: " + e.ToString()); + return FAILURE; + } + } + /// /// Set identity hint to use ///