Skip to content

Commit 15ac366

Browse files
committed
added missing wrappers for sni setup & frees
1 parent 52f1caf commit 15ac366

1 file changed

Lines changed: 44 additions & 3 deletions

File tree

wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ public void free()
147147
{
148148
this.psk_cb.Free();
149149
}
150+
if (!Object.Equals(this.sni_cb, default(GCHandle)))
151+
{
152+
this.sni_cb.Free();
153+
}
150154
if (!Object.Equals(this.vrf_cb, default(GCHandle)))
151155
{
152156
this.vrf_cb.Free();
@@ -217,6 +221,10 @@ public void free()
217221
{
218222
this.psk_cb.Free();
219223
}
224+
if (!Object.Equals(this.sni_cb, default(GCHandle)))
225+
{
226+
this.sni_cb.Free();
227+
}
220228
if (!Object.Equals(this.vrf_cb, default(GCHandle)))
221229
{
222230
this.vrf_cb.Free();
@@ -320,6 +328,10 @@ public void free()
320328
private extern static int wolfSSL_CTX_set_tlsext_servername_callback(IntPtr ctx, sni_delegate sni_cb);
321329
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
322330
private extern static int wolfSSL_CTX_set_servername_arg(IntPtr ctx, IntPtr arg);
331+
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
332+
private extern static int wolfSSL_CTX_UseSNI(IntPtr ctx, byte type, IntPtr data, ushort size);
333+
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
334+
private extern static int wolfSSL_UseSNI(IntPtr ssl, byte type, IntPtr data, ushort size);
323335

324336
/********************************
325337
* SSL Structure
@@ -1114,7 +1126,8 @@ public static void CTX_free(IntPtr ctx)
11141126
}
11151127
}
11161128

1117-
public static void CTX_set_servername_callback(IntPtr ctx, sni_delegate sni_cb) {
1129+
public static void CTX_set_servername_callback(IntPtr ctx, sni_delegate sni_cb)
1130+
{
11181131
try {
11191132
GCHandle gch = GCHandle.FromIntPtr(ctx);
11201133
ctx_handle handles = (ctx_handle)gch.Target;
@@ -1127,7 +1140,8 @@ public static void CTX_set_servername_callback(IntPtr ctx, sni_delegate sni_cb)
11271140
}
11281141
}
11291142

1130-
public static int CTX_set_tlsext_servername_callback(IntPtr ctx, sni_delegate sni_cb) {
1143+
public static int CTX_set_tlsext_servername_callback(IntPtr ctx, sni_delegate sni_cb)
1144+
{
11311145
try {
11321146
GCHandle gch = GCHandle.FromIntPtr(ctx);
11331147
ctx_handle handles = (ctx_handle)gch.Target;
@@ -1141,7 +1155,8 @@ public static int CTX_set_tlsext_servername_callback(IntPtr ctx, sni_delegate sn
11411155
}
11421156
}
11431157

1144-
public static int CTX_set_servername_arg(IntPtr ctx, IntPtr arg) {
1158+
public static int CTX_set_servername_arg(IntPtr ctx, IntPtr arg)
1159+
{
11451160
try {
11461161
GCHandle gch = GCHandle.FromIntPtr(ctx);
11471162
ctx_handle handles = (ctx_handle)gch.Target;
@@ -1155,6 +1170,32 @@ public static int CTX_set_servername_arg(IntPtr ctx, IntPtr arg) {
11551170
}
11561171
}
11571172

1173+
public static int CTX_UseSNI(IntPtr ctx, byte type, IntPtr data, ushort size)
1174+
{
1175+
try {
1176+
GCHandle gch = GCHandle.FromIntPtr(ctx);
1177+
ctx_handle handles = (ctx_handle)gch.Target;
1178+
1179+
return wolfSSL_CTX_UseSNI(handles.get_ctx(), type, data, size);
1180+
} catch (Exception e) {
1181+
log(ERROR_LOG, "wolfssl ctx use sni error: " + e.ToString());
1182+
return FAILURE;
1183+
}
1184+
}
1185+
1186+
public static int UseSNI(IntPtr ssl, byte type, IntPtr data, ushort size)
1187+
{
1188+
try {
1189+
GCHandle gch = GCHandle.FromIntPtr(ssl);
1190+
ssl_handle handles = (ssl_handle)gch.Target;
1191+
1192+
return wolfSSL_UseSNI(handles.get_ssl(), type, data, size);
1193+
} catch (Exception e) {
1194+
log(ERROR_LOG, "wolfssl use sni error: " + e.ToString());
1195+
return FAILURE;
1196+
}
1197+
}
1198+
11581199
/// <summary>
11591200
/// Set identity hint to use
11601201
/// </summary>

0 commit comments

Comments
 (0)