public static ScanTestMediaServerResult Pass(MediaServerInfo mediaServer)
 {
     return(new ScanTestMediaServerResult(mediaServer)
     {
         State = ScanTestState.Pass
     });
 }
 public static ScanTestMediaServerResult Unknown(MediaServerInfo mediaServer)
 {
     return(new ScanTestMediaServerResult(mediaServer)
     {
         State = ScanTestState.Unknown
     });
 }
 public static ScanTestMediaServerResult Skip(MediaServerInfo mediaServer, string reason)
 {
     return(new ScanTestMediaServerResult(mediaServer)
     {
         State = ScanTestState.Skip,
         Reason = reason
     });
 }
 public static ScanTestMediaServerResult Fail(MediaServerInfo mediaServer, Exception exception)
 {
     return(new ScanTestMediaServerResult(mediaServer)
     {
         State = ScanTestState.Fail,
         Exception = exception
     });
 }
예제 #5
0
 private Task <ScanTestMediaServerResult> DoScan(MediaServerInfo mediaServer, CancellationToken cancellationToken)
 {
     try
     {
         return(new ScanTestMediaServer(Options).Run(mediaServer, cancellationToken));
     }
     catch (Exception ex)
     {
         return(Task.FromResult(ScanTestMediaServerResult.Fail(mediaServer, ex)));
     }
 }
        private ScanTestMediaServerResult(MediaServerInfo mediaServer)
        {
            MediaServer = mediaServer;

            _ScenarioResults = new Dictionary <ScanTestScenario, ScanTestScenarioResult>();
        }
예제 #7
0
        public async Task <ScanTestMediaServerResult> Run(MediaServerInfo mediaServer, CancellationToken cancellationToken)
        {
            var result = ScanTestMediaServerResult.Pass(mediaServer);

            try
            {
                await RegisterClient(cancellationToken).ConfigureAwait(false);

                try
                {
                    await JoinChannel(cancellationToken).ConfigureAwait(false);

                    // test a variety of scenarios
                    foreach (var scenario in new[]
                    {
                        ScanTestScenario.Host,
                        ScanTestScenario.Stun,
                        ScanTestScenario.TurnUdp,
                        ScanTestScenario.TurnTcp,
                        ScanTestScenario.Turns
                    })
                    {
                        if (Options.ShouldTest(scenario))
                        {
                            try
                            {
                                TimeSpan?certificateValidFor = null;

                                if (scenario.RequiresTls())
                                {
                                    // set certificate check
                                    TcpSocket.ClientSslAuthenticate = (sslStream, targetHost, enabledSslProtocols) =>
                                    {
                                        sslStream.AuthenticateAsClient(targetHost, null, enabledSslProtocols, false);

                                        if (sslStream.RemoteCertificate is X509Certificate2 remoteCertificate)
                                        {
                                            certificateValidFor = remoteCertificate.NotAfter - DateTime.UtcNow;

                                            if (ServerCertificates.TryAdd(targetHost, remoteCertificate))
                                            {
                                                var daysRemaining = Math.Max(0, certificateValidFor.Value.TotalDays);

                                                Console.Error.WriteLine(string.Join(Environment.NewLine, new[]
                                                {
                                                    $"TLS certificate subject: {remoteCertificate.Subject}",
                                                    $"TLS certificate issuer: {remoteCertificate.Issuer}",
                                                    $"TLS certificate issued: {remoteCertificate.NotBefore:yyyy-MM-ddTHH\\:mm\\:ss}",
                                                    $"TLS certificate expiry: {remoteCertificate.NotAfter:yyyy-MM-ddTHH\\:mm\\:ss} ({(int)daysRemaining} day(s) remaining)",
                                                    $"TLS certificate thumbprint: {remoteCertificate.Thumbprint}"
                                                }));
                                            }
                                        }
                                    };
                                }
                                try
                                {
                                    await OpenConnection(mediaServer.Id, scenario, cancellationToken).ConfigureAwait(false);

                                    // pass
                                    result.SetScenarioResult(scenario, ScanTestScenarioResult.Pass(scenario, certificateValidFor));
                                }
                                catch (Exception ex)
                                {
                                    // fail
                                    result.SetScenarioResult(scenario, ScanTestScenarioResult.Fail(scenario, ex));
                                }
                                finally
                                {
                                    await CloseConnection().ConfigureAwait(false);
                                }
                            }