forked from wolfSSL/wolfssl
Merge pull request #3494 from JacobBarthelmeh/CSharp
pin the C# verify callback
This commit is contained in:
@ -58,6 +58,7 @@ namespace wolfSSL.CSharp {
|
|||||||
private GCHandle rec_cb;
|
private GCHandle rec_cb;
|
||||||
private GCHandle snd_cb;
|
private GCHandle snd_cb;
|
||||||
private GCHandle psk_cb;
|
private GCHandle psk_cb;
|
||||||
|
private GCHandle vrf_cb;
|
||||||
private IntPtr ctx;
|
private IntPtr ctx;
|
||||||
|
|
||||||
public void set_receive(GCHandle input)
|
public void set_receive(GCHandle input)
|
||||||
@ -87,6 +88,19 @@ namespace wolfSSL.CSharp {
|
|||||||
return this.psk_cb;
|
return this.psk_cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void set_vrf(GCHandle input)
|
||||||
|
{
|
||||||
|
if (!Object.Equals(this.vrf_cb, default(GCHandle)))
|
||||||
|
{
|
||||||
|
this.vrf_cb.Free();
|
||||||
|
}
|
||||||
|
this.vrf_cb = input;
|
||||||
|
}
|
||||||
|
public GCHandle get_vrf()
|
||||||
|
{
|
||||||
|
return this.vrf_cb;
|
||||||
|
}
|
||||||
|
|
||||||
public void set_ctx(IntPtr input)
|
public void set_ctx(IntPtr input)
|
||||||
{
|
{
|
||||||
this.ctx = input;
|
this.ctx = input;
|
||||||
@ -114,6 +128,10 @@ namespace wolfSSL.CSharp {
|
|||||||
{
|
{
|
||||||
this.psk_cb.Free();
|
this.psk_cb.Free();
|
||||||
}
|
}
|
||||||
|
if (!Object.Equals(this.vrf_cb, default(GCHandle)))
|
||||||
|
{
|
||||||
|
this.vrf_cb.Free();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,6 +143,7 @@ namespace wolfSSL.CSharp {
|
|||||||
{
|
{
|
||||||
private GCHandle fd_pin;
|
private GCHandle fd_pin;
|
||||||
private GCHandle psk_cb;
|
private GCHandle psk_cb;
|
||||||
|
private GCHandle vrf_cb;
|
||||||
private IntPtr ssl;
|
private IntPtr ssl;
|
||||||
|
|
||||||
public void set_fd(GCHandle input)
|
public void set_fd(GCHandle input)
|
||||||
@ -145,6 +164,19 @@ namespace wolfSSL.CSharp {
|
|||||||
return this.psk_cb;
|
return this.psk_cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void set_vrf(GCHandle input)
|
||||||
|
{
|
||||||
|
if (!Object.Equals(this.vrf_cb, default(GCHandle)))
|
||||||
|
{
|
||||||
|
this.vrf_cb.Free();
|
||||||
|
}
|
||||||
|
this.vrf_cb = input;
|
||||||
|
}
|
||||||
|
public GCHandle get_vrf()
|
||||||
|
{
|
||||||
|
return this.vrf_cb;
|
||||||
|
}
|
||||||
|
|
||||||
public void set_ssl(IntPtr input)
|
public void set_ssl(IntPtr input)
|
||||||
{
|
{
|
||||||
this.ssl = input;
|
this.ssl = input;
|
||||||
@ -165,6 +197,10 @@ namespace wolfSSL.CSharp {
|
|||||||
{
|
{
|
||||||
this.psk_cb.Free();
|
this.psk_cb.Free();
|
||||||
}
|
}
|
||||||
|
if (!Object.Equals(this.vrf_cb, default(GCHandle)))
|
||||||
|
{
|
||||||
|
this.vrf_cb.Free();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1837,13 +1873,22 @@ namespace wolfSSL.CSharp {
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IntPtr local_ctx = unwrap_ctx(ctx);
|
GCHandle gch;
|
||||||
|
ctx_handle handles;
|
||||||
|
IntPtr local_ctx = unwrap_ctx(ctx);
|
||||||
if (local_ctx == IntPtr.Zero)
|
if (local_ctx == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
log(ERROR_LOG, "CTX set_verify error");
|
log(ERROR_LOG, "CTX set_verify error");
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* pin the verify callback to protect from garbage collection */
|
||||||
|
if (!vc.Equals(null)) {
|
||||||
|
gch = GCHandle.FromIntPtr(ctx);
|
||||||
|
handles = (ctx_handle)gch.Target;
|
||||||
|
handles.set_vrf(GCHandle.Alloc(vc));
|
||||||
|
}
|
||||||
|
|
||||||
wolfSSL_CTX_set_verify(local_ctx, mode, vc);
|
wolfSSL_CTX_set_verify(local_ctx, mode, vc);
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
@ -1864,13 +1909,22 @@ namespace wolfSSL.CSharp {
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IntPtr local_ssl = unwrap_ssl(ssl);
|
GCHandle gch;
|
||||||
|
ssl_handle handles;
|
||||||
|
IntPtr local_ssl = unwrap_ssl(ssl);
|
||||||
if (local_ssl == IntPtr.Zero)
|
if (local_ssl == IntPtr.Zero)
|
||||||
{
|
{
|
||||||
log(ERROR_LOG, "set_verify error");
|
log(ERROR_LOG, "set_verify error");
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* pin the verify callback to protect from garbage collection */
|
||||||
|
if (!vc.Equals(null)) {
|
||||||
|
gch = GCHandle.FromIntPtr(ssl);
|
||||||
|
handles = (ssl_handle)gch.Target;
|
||||||
|
handles.set_vrf(GCHandle.Alloc(vc));
|
||||||
|
}
|
||||||
|
|
||||||
wolfSSL_set_verify(local_ssl, mode, vc);
|
wolfSSL_set_verify(local_ssl, mode, vc);
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user