public ScanTestScenarioResult GetScenarioResult(ScanTestScenario scenario)
 {
     if (_ScenarioResults.TryGetValue(scenario, out var scenarioResult))
     {
         return(scenarioResult);
     }
     return(ScanTestScenarioResult.Unknown(scenario));
 }
        public void SetScenarioResult(ScanTestScenario scenario, ScanTestScenarioResult scenarioResult)
        {
            _ScenarioResults[scenario] = scenarioResult;

            if (scenarioResult.State == ScanTestState.Fail)
            {
                State  = ScanTestState.Fail;
                Reason = $"{FailedResults.Length} scenario(s) failed.";
            }
        }
Ejemplo n.º 3
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);
                                }
                            }