public void IPv4TlsLoopbackSendReceiveTest() { CancellationTokenSource cancelServer = new CancellationTokenSource(); TaskCompletionSource <bool> testComplete = new TaskCompletionSource <bool>(); Assert.True(File.Exists(@"certs\localhost.pfx"), "The TLS transport channel test was missing the localhost.pfx certificate file."); var serverCertificate = new X509Certificate2(@"certs\localhost.pfx", ""); var verifyCert = serverCertificate.Verify(); logger.LogDebug("Server Certificate loaded from file, Subject=" + serverCertificate.Subject + ", valid=" + verifyCert + "."); var serverChannel = new SIPTLSChannel(serverCertificate, IPAddress.Loopback, 8060); serverChannel.DisableLocalTCPSocketsCheck = true; var clientChannel = new SIPTLSChannel(serverCertificate, IPAddress.Loopback, 8061); clientChannel.DisableLocalTCPSocketsCheck = true; var serverTask = Task.Run(() => { RunServer(serverChannel, cancelServer); }); var clientTask = Task.Run(async() => { await RunClient(clientChannel, serverChannel.GetContactURI(SIPSchemesEnum.sips, IPAddress.Loopback), testComplete); }); Task.WhenAny(new Task[] { serverTask, clientTask, Task.Delay(TRANSPORT_TEST_TIMEOUT) }).Wait(); if (testComplete.Task.IsCompleted == false) { // The client did not set the completed signal. This means the delay task must have completed and hence the test failed. testComplete.SetResult(false); } Assert.True(testComplete.Task.Result); cancelServer.Cancel(); }
public void IPv6TlsLoopbackSendReceiveTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); if (!Socket.OSSupportsIPv6) { logger.LogDebug("Test skipped as OS does not support IPv6."); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { logger.LogDebug("Test skipped as MacOS is not able to load certificates from a .pfx file pre .NET Core 5.0."); } else { ManualResetEventSlim serverReadyEvent = new ManualResetEventSlim(false); CancellationTokenSource cancelServer = new CancellationTokenSource(); TaskCompletionSource <bool> testComplete = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); Assert.True(File.Exists(@"certs/localhost.pfx"), "The TLS transport channel test was missing the localhost.pfx certificate file."); var serverCertificate = new X509Certificate2(@"certs/localhost.pfx", ""); var verifyCert = serverCertificate.Verify(); logger.LogDebug("Server Certificate loaded from file, Subject=" + serverCertificate.Subject + ", valid=" + verifyCert + "."); var serverChannel = new SIPTLSChannel(serverCertificate, IPAddress.IPv6Loopback, 0); serverChannel.DisableLocalTCPSocketsCheck = true; var clientChannel = new SIPTLSChannel(new IPEndPoint(IPAddress.IPv6Loopback, 0)); clientChannel.DisableLocalTCPSocketsCheck = true; var serverTask = Task.Run(() => { RunServer(serverChannel, cancelServer, serverReadyEvent); }); var clientTask = Task.Run(async() => { #pragma warning disable RCS1090 // Add call to 'ConfigureAwait' (or vice versa). await RunClient( clientChannel, serverChannel.GetContactURI(SIPSchemesEnum.sips, new SIPEndPoint(SIPProtocolsEnum.tls, new IPEndPoint(IPAddress.IPv6Loopback, 0))), testComplete, cancelServer, serverReadyEvent); #pragma warning restore RCS1090 // Add call to 'ConfigureAwait' (or vice versa). }); if (!Task.WhenAny(new Task[] { serverTask, clientTask }).Wait(TRANSPORT_TEST_TIMEOUT)) { logger.LogWarning($"Tasks timed out"); } if (testComplete.Task.IsCompleted == false) { // The client did not set the completed signal. This means the delay task must have completed and hence the test failed. testComplete.SetResult(false); } Assert.True(testComplete.Task.Result); cancelServer.Cancel(); } }
public void IPv4TlsLoopbackSendReceiveTest() { logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name); logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name); ManualResetEventSlim serverReadyEvent = new ManualResetEventSlim(false); CancellationTokenSource cancelServer = new CancellationTokenSource(); TaskCompletionSource <bool> testComplete = new TaskCompletionSource <bool>(); Assert.True(File.Exists(@"certs/localhost.pfx"), "The TLS transport channel test was missing the localhost.pfx certificate file."); var serverCertificate = new X509Certificate2(@"certs/localhost.pfx", ""); var verifyCert = serverCertificate.Verify(); logger.LogDebug("Server Certificate loaded from file, Subject=" + serverCertificate.Subject + ", valid=" + verifyCert + "."); var serverChannel = new SIPTLSChannel(serverCertificate, IPAddress.Loopback, 0); serverChannel.DisableLocalTCPSocketsCheck = true; var clientChannel = new SIPTLSChannel(serverCertificate, IPAddress.Loopback, 0); clientChannel.DisableLocalTCPSocketsCheck = true; var serverTask = Task.Run(() => { RunServer(serverChannel, cancelServer, serverReadyEvent); }); var clientTask = Task.Run(async() => { await RunClient( clientChannel, serverChannel.GetContactURI(SIPSchemesEnum.sips, new SIPEndPoint(SIPProtocolsEnum.tls, new IPEndPoint(IPAddress.Loopback, 0))), testComplete, cancelServer, serverReadyEvent); }); serverReadyEvent.Wait(); if (!Task.WhenAny(new Task[] { serverTask, clientTask }).Wait(TRANSPORT_TEST_TIMEOUT)) { logger.LogWarning($"Tasks timed out"); } if (testComplete.Task.IsCompleted == false) { // The client did not set the completed signal. This means the delay task must have completed and hence the test failed. testComplete.SetResult(false); } Assert.True(testComplete.Task.Result); cancelServer.Cancel(); }