コード例 #1
0
 public static ScanTestMediaServerResult Pass(MediaServerInfo mediaServer)
 {
     return(new ScanTestMediaServerResult(mediaServer)
     {
         State = ScanTestState.Pass
     });
 }
コード例 #2
0
 public static ScanTestMediaServerResult Unknown(MediaServerInfo mediaServer)
 {
     return(new ScanTestMediaServerResult(mediaServer)
     {
         State = ScanTestState.Unknown
     });
 }
コード例 #3
0
 public static ScanTestMediaServerResult Skip(MediaServerInfo mediaServer, string reason)
 {
     return(new ScanTestMediaServerResult(mediaServer)
     {
         State = ScanTestState.Skip,
         Reason = reason
     });
 }
コード例 #4
0
 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)));
     }
 }
コード例 #6
0
        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);
                                }
                            }