Skip to content

Commit

Permalink
Make server certificate validation optional
Browse files Browse the repository at this point in the history
  • Loading branch information
duduita committed Oct 31, 2023
1 parent 9a64b60 commit d86416b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
26 changes: 26 additions & 0 deletions source/implementations/f7/Meadow.F7/F7PlatformOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,30 @@ public int[] GetProcessorUtilization()
{
return new[] {100 - Core.Interop.Nuttx.meadow_idle_monitor_get_value()};
}

/// <inheritdoc/>
public void SetServerCertificateValidationMode(ServerCertificateValidationMode authmode)

Check failure on line 97 in source/implementations/f7/Meadow.F7/F7PlatformOS.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ServerCertificateValidationMode' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 97 in source/implementations/f7/Meadow.F7/F7PlatformOS.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ServerCertificateValidationMode' could not be found (are you missing a using directive or an assembly reference?)
{
Resolver.Log.Trace($"Attempting to set the server certificate validation mode to {authmode}");

int authModeInt = (int)authmode;
if (authModeInt < 0 || authModeInt > 2)
{
string errorMessage = $"Invalid validation mode: {authModeInt}";
Resolver.Log.Error($"Invalid validation mode: {authModeInt}");
throw new ArgumentException(errorMessage);
}

int ret = Core.Interop.Nuttx.mono_mbedtls_set_server_cert_authmode(authModeInt);
if (ret < 0)
{
string errorMessage = $"Error setting validation mode.";
Resolver.Log.Error(errorMessage);
throw new Exception(errorMessage);
}

Resolver.Log.Trace($"Server certificate validation mode set to {authmode} successfully!");

return;
}
}
1 change: 1 addition & 0 deletions source/implementations/f7/Meadow.F7/Interop/Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ internal static partial class Interop
public static partial class Nuttx
{
public const string LIBRARY_NAME = "nuttx";
public const string MBEDTLS_LIBRARY_NAME = "mbedtls";
}
}
}
12 changes: 12 additions & 0 deletions source/implementations/f7/Meadow.F7/Interop/Interop.mbedtls.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Runtime.InteropServices;
namespace Meadow.Core;

internal static partial class Interop
{
public static partial class Nuttx
{
[DllImport(MBEDTLS_LIBRARY_NAME, SetLastError = true)]
public static extern int mono_mbedtls_set_server_cert_authmode(int authmode);
}
}

0 comments on commit d86416b

Please sign in to comment.