mirror of https://github.com/wolfSSL/wolfssl.git
- Platform specific function to correctly set the path for the certificates;
- Updated all the examples with it;pull/7610/head
parent
6cb97a7262
commit
2ab709c89a
|
@ -78,9 +78,14 @@ public class wolfSSL_DTLS_PSK_Server
|
|||
IntPtr ssl;
|
||||
|
||||
/* These paths should be changed according to use */
|
||||
string fileCert = @"server-cert.pem";
|
||||
string fileKey = @"server-key.pem";
|
||||
StringBuilder dhparam = new StringBuilder("dh2048.pem");
|
||||
string fileCert = wolfssl.setPath("server-cert.pem");
|
||||
string fileKey = wolfssl.setPath("server-key.pem");
|
||||
StringBuilder dhparam = new StringBuilder(wolfssl.setPath("dh2048.pem"));
|
||||
|
||||
if (fileCert == "" || fileKey == "" || dhparam.Length == 0) {
|
||||
Console.WriteLine("Platform not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
wolfssl.psk_delegate psk_cb = new wolfssl.psk_delegate(my_psk_server_cb);
|
||||
|
||||
|
@ -106,6 +111,12 @@ public class wolfSSL_DTLS_PSK_Server
|
|||
return;
|
||||
}
|
||||
|
||||
if (!File.Exists(dhparam.ToString())) {
|
||||
Console.WriteLine("Could not find dh file");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (wolfssl.CTX_use_certificate_file(ctx, fileCert, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
|
||||
{
|
||||
|
|
|
@ -58,9 +58,14 @@ public class wolfSSL_DTLS_Server
|
|||
IntPtr ssl;
|
||||
|
||||
/* These paths should be changed for use */
|
||||
string fileCert = @"server-cert.pem";
|
||||
string fileKey = @"server-key.pem";
|
||||
StringBuilder dhparam = new StringBuilder("dh2048.pem");
|
||||
string fileCert = wolfssl.setPath("server-cert.pem");
|
||||
string fileKey = wolfssl.setPath(@"server-key.pem");
|
||||
StringBuilder dhparam = new StringBuilder(wolfssl.setPath("dh2048.pem"));
|
||||
|
||||
if (fileCert == "" || fileKey == "" || dhparam.Length == 0) {
|
||||
Console.WriteLine("Platform not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder buff = new StringBuilder(1024);
|
||||
StringBuilder reply = new StringBuilder("Hello, this is the wolfSSL C# wrapper");
|
||||
|
@ -87,6 +92,12 @@ public class wolfSSL_DTLS_Server
|
|||
return;
|
||||
}
|
||||
|
||||
if (!File.Exists(dhparam.ToString())) {
|
||||
Console.WriteLine("Could not find dh file");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (wolfssl.CTX_use_certificate_file(ctx, fileCert, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
|
||||
{
|
||||
|
|
|
@ -214,12 +214,17 @@ class wolfSSL_Example_IOCallbacks
|
|||
IntPtr ssl;
|
||||
Socket fd;
|
||||
|
||||
wolfssl.psk_delegate psk_cb = new wolfssl.psk_delegate(my_psk_server_cb);
|
||||
wolfssl.CallbackVerify_delegate verify_cb = new wolfssl.CallbackVerify_delegate(my_verify_cb);
|
||||
|
||||
/* These paths should be changed according to use */
|
||||
string fileCert = @"server-cert.pem";
|
||||
string fileKey = @"server-key.pem";
|
||||
string fileCert = wolfssl.setPath("server-cert.pem");
|
||||
string fileKey = wolfssl.setPath("server-key.pem");
|
||||
StringBuilder dhparam = new StringBuilder(wolfssl.setPath("dh2048.pem"));
|
||||
|
||||
if (fileCert == "" || fileKey == "" || dhparam.Length == 0) {
|
||||
Console.WriteLine("Platform not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder buff = new StringBuilder(1024);
|
||||
StringBuilder reply = new StringBuilder("Hello, this is the wolfSSL C# wrapper");
|
||||
|
@ -242,6 +247,12 @@ class wolfSSL_Example_IOCallbacks
|
|||
return;
|
||||
}
|
||||
|
||||
if (!File.Exists(dhparam.ToString())) {
|
||||
Console.WriteLine("Could not find dh file");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wolfssl.CTX_use_certificate_file(ctx, fileCert, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
|
||||
{
|
||||
Console.WriteLine("Error in setting cert file");
|
||||
|
|
|
@ -77,19 +77,6 @@ public class wolfSSL_TLS_Client
|
|||
return -1;
|
||||
}
|
||||
|
||||
public static string setPath() {
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
return @"../../certs/ca-cert.pem";
|
||||
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
return @"../../../../certs/ca-cert.pem";
|
||||
} else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
IntPtr ctx;
|
||||
|
@ -98,14 +85,14 @@ public class wolfSSL_TLS_Client
|
|||
IntPtr sniHostName;
|
||||
|
||||
/* These paths should be changed for use */
|
||||
string caCert = setPath();
|
||||
if (caCert == "") {
|
||||
string caCert = wolfssl.setPath("ca-cert.pem");
|
||||
StringBuilder dhparam = new StringBuilder(wolfssl.setPath("dh2048.pem"));
|
||||
|
||||
if (caCert == "" || dhparam.Length == 0) {
|
||||
Console.WriteLine("Platform not supported.");
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder dhparam = new StringBuilder("dh2048.pem");
|
||||
|
||||
StringBuilder buff = new StringBuilder(1024);
|
||||
StringBuilder reply = new StringBuilder("Hello, this is the wolfSSL C# wrapper");
|
||||
|
||||
|
@ -131,6 +118,12 @@ public class wolfSSL_TLS_Client
|
|||
return;
|
||||
}
|
||||
|
||||
if (!File.Exists(dhparam.ToString())) {
|
||||
Console.WriteLine("Could not find dh file");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wolfssl.CTX_load_verify_locations(ctx, caCert, null)
|
||||
!= wolfssl.SUCCESS)
|
||||
{
|
||||
|
|
|
@ -82,7 +82,11 @@ public class wolfSSL_TLS_PSK_Client
|
|||
|
||||
wolfssl.psk_client_delegate psk_cb = new wolfssl.psk_client_delegate(my_psk_client_cb);
|
||||
|
||||
StringBuilder dhparam = new StringBuilder("dh2048.pem");
|
||||
StringBuilder dhparam = new StringBuilder(wolfssl.setPath("dh2048.pem"));
|
||||
if (dhparam.Length == 0) {
|
||||
Console.WriteLine("Platform not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder buff = new StringBuilder(1024);
|
||||
StringBuilder reply = new StringBuilder("Hello, this is the wolfSSL C# client psk wrapper");
|
||||
|
@ -157,6 +161,12 @@ public class wolfSSL_TLS_PSK_Client
|
|||
return;
|
||||
}
|
||||
|
||||
if (!File.Exists(dhparam.ToString())) {
|
||||
Console.WriteLine("Could not find dh file");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
wolfssl.SetTmpDH_file(ssl, dhparam, wolfssl.SSL_FILETYPE_PEM);
|
||||
|
||||
if (wolfssl.connect(ssl) != wolfssl.SUCCESS)
|
||||
|
|
|
@ -80,9 +80,14 @@ public class wolfSSL_TLS_PSK_Server
|
|||
wolfssl.psk_delegate psk_cb = new wolfssl.psk_delegate(my_psk_server_cb);
|
||||
|
||||
/* These paths should be changed according to use */
|
||||
string fileCert = @"server-cert.pem";
|
||||
string fileKey = @"server-key.pem";
|
||||
StringBuilder dhparam = new StringBuilder("dh2048.pem");
|
||||
string fileCert = wolfssl.setPath("server-cert.pem");
|
||||
string fileKey = wolfssl.setPath("server-key.pem");
|
||||
StringBuilder dhparam = new StringBuilder(wolfssl.setPath("dh2048.pem"));
|
||||
|
||||
if (fileCert == "" || fileKey == "" || dhparam.Length == 0) {
|
||||
Console.WriteLine("Platform not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder buff = new StringBuilder(1024);
|
||||
StringBuilder reply = new StringBuilder("Hello, this is the wolfSSL C# wrapper");
|
||||
|
@ -105,6 +110,12 @@ public class wolfSSL_TLS_PSK_Server
|
|||
return;
|
||||
}
|
||||
|
||||
if (!File.Exists(dhparam.ToString())) {
|
||||
Console.WriteLine("Could not find dh file");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wolfssl.CTX_use_certificate_file(ctx, fileCert, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
|
||||
{
|
||||
Console.WriteLine("Error in setting cert file");
|
||||
|
|
|
@ -80,19 +80,6 @@ public class wolfSSL_TLS_CSHarp
|
|||
return 0;
|
||||
}
|
||||
|
||||
public static string setPath(string file) {
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
return @"../../certs/" + file;
|
||||
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
return @"../../../../certs/" + file;
|
||||
} else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
IntPtr ctx;
|
||||
|
@ -101,15 +88,15 @@ public class wolfSSL_TLS_CSHarp
|
|||
IntPtr arg_sni;
|
||||
|
||||
/* These paths should be changed for use */
|
||||
string fileCert = setPath("server-cert.pem");
|
||||
string fileKey = setPath("server-key.pem");
|
||||
if (fileCert == "" || fileKey == "") {
|
||||
string fileCert = wolfssl.setPath("server-cert.pem");
|
||||
string fileKey = wolfssl.setPath("server-key.pem");
|
||||
StringBuilder dh2048Pem = new StringBuilder(wolfssl.setPath("dh2048.pem"));
|
||||
|
||||
if (fileCert == "" || fileKey == "" || dh2048Pem.Length == 0) {
|
||||
Console.WriteLine("Platform not supported.");
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder dhparam = new StringBuilder("dh2048.pem");
|
||||
|
||||
StringBuilder buff = new StringBuilder(1024);
|
||||
StringBuilder reply = new StringBuilder("Hello, this is the wolfSSL C# wrapper");
|
||||
|
||||
|
@ -134,6 +121,12 @@ public class wolfSSL_TLS_CSHarp
|
|||
return;
|
||||
}
|
||||
|
||||
if (!File.Exists(dhparam.ToString())) {
|
||||
Console.WriteLine("Could not find dh file");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wolfssl.CTX_use_certificate_file(ctx, fileCert, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
|
||||
{
|
||||
Console.WriteLine("Error in setting cert file");
|
||||
|
@ -197,7 +190,14 @@ public class wolfSSL_TLS_CSHarp
|
|||
return;
|
||||
}
|
||||
|
||||
wolfssl.SetTmpDH_file(ssl, dhparam, wolfssl.SSL_FILETYPE_PEM);
|
||||
if (wolfssl.SetTmpDH_file(ssl, dh2048Pem, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
|
||||
{
|
||||
Console.WriteLine("Error in setting dh2048Pem");
|
||||
Console.WriteLine(wolfssl.get_error(ssl));
|
||||
tcp.Stop();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wolfssl.accept(ssl) != wolfssl.SUCCESS)
|
||||
{
|
||||
|
|
|
@ -116,9 +116,14 @@ public class wolfSSL_TLS_ServerThreaded
|
|||
IntPtr ctx;
|
||||
|
||||
/* These paths should be changed for use */
|
||||
string fileCert = @"server-cert.pem";
|
||||
string fileKey = @"server-key.pem";
|
||||
StringBuilder dhparam = new StringBuilder("dh2048.pem");
|
||||
string fileCert = wolfssl.setPath("server-cert.pem");
|
||||
string fileKey = wolfssl.setPath("server-key.pem");
|
||||
StringBuilder dhparam = new StringBuilder(wolfssl.setPath("dh2048.pem"));
|
||||
|
||||
if (fileCert == "" || fileKey == "" || dhparam.Length == 0) {
|
||||
Console.WriteLine("Platform not supported");
|
||||
return;
|
||||
}
|
||||
|
||||
/* example of function used for setting logging */
|
||||
wolfssl.SetLogging(standard_log);
|
||||
|
@ -140,6 +145,12 @@ public class wolfSSL_TLS_ServerThreaded
|
|||
return;
|
||||
}
|
||||
|
||||
if (!File.Exists(dhparam.ToString())) {
|
||||
Console.WriteLine("Could not find dh file");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wolfssl.CTX_use_certificate_file(ctx, fileCert, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
|
||||
{
|
||||
Console.WriteLine("Error in setting cert file");
|
||||
|
|
|
@ -485,6 +485,26 @@ namespace wolfSSL.CSharp {
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Utility function used to access the certificates
|
||||
/// based on the platform.
|
||||
/// <returns>return the platform specific path to the certificate</returns>
|
||||
/// </summary>
|
||||
public static string setPath(string file) {
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
Console.WriteLine("Linux - " + file);
|
||||
return @"../../certs/" + file;
|
||||
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
Console.WriteLine("Windows - " + file);
|
||||
return @"../../../../certs/" + file;
|
||||
} else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Call back to allow receiving TLS information
|
||||
|
|
Loading…
Reference in New Issue