Esempio n. 1
0
        protected async Task EvaluateMxRecordProfile(MxRecordTlsProfile mxRecordTlsProfile)
        {
            if (mxRecordTlsProfile.MxHostname == null)
            {
                await _tlsRecordDao.SaveTlsEvaluatorResults(mxRecordTlsProfile, EvaluatorResults.EmptyResults);

                _log.Debug(
                    $"MX record with ID {mxRecordTlsProfile.MxRecordId} has no hostname, saving null results.");
            }
            else
            {
                string failedConnectionErrors = mxRecordTlsProfile.ConnectionResults.GetFailedConnectionErrors();

                if (string.IsNullOrWhiteSpace(failedConnectionErrors))
                {
                    var tlsEvaluatorResults = _mxSecurityEvaluator.Evaluate(mxRecordTlsProfile.ConnectionResults);

                    await _tlsRecordDao.SaveTlsEvaluatorResults(mxRecordTlsProfile, tlsEvaluatorResults);

                    _log.Debug(
                        $"Evaluated TLS connection results for MX record with ID {mxRecordTlsProfile.MxRecordId}.");
                }
                else
                {
                    await _tlsRecordDao.SaveTlsEvaluatorResults(mxRecordTlsProfile,
                                                                EvaluatorResults.GetConnectionFailedResults(failedConnectionErrors));

                    _log.Debug(
                        $"MX record with ID {mxRecordTlsProfile.MxRecordId} TLS connection failed, saving single inconclusive result.");
                }
            }
        }
Esempio n. 2
0
        protected Task EvaluateMxRecordProfile(MxRecordTlsProfile mxRecordTlsProfile)
        {
            if (mxRecordTlsProfile.MxHostname == null)
            {
                _log.Debug($"No hostname for MX record with ID {mxRecordTlsProfile.MxRecordId}.");

                return(_tlsRecordDao.SaveTlsEvaluatorResults(mxRecordTlsProfile, EvaluatorResults.EmptyResults));
            }

            if (mxRecordTlsProfile.ConnectionResults.HasFailedConnection())
            {
                _log.Debug($"TLS connection failed for host {mxRecordTlsProfile.MxHostname}");

                string failedConnectionErrors = mxRecordTlsProfile.ConnectionResults.GetFailedConnectionErrors();

                return(_tlsRecordDao.SaveTlsEvaluatorResults(mxRecordTlsProfile,
                                                             EvaluatorResults.GetConnectionFailedResults(failedConnectionErrors)));
            }

            if (mxRecordTlsProfile.ConnectionResults.HostNotFound())
            {
                _log.Debug($"Host not found for {mxRecordTlsProfile.MxHostname}");

                return(_tlsRecordDao.SaveTlsEvaluatorResults(mxRecordTlsProfile,
                                                             EvaluatorResults.GetHostNotFoundResults(mxRecordTlsProfile.MxHostname)));
            }

            _log.Debug($"Evaluating TLS connection results for {mxRecordTlsProfile.MxHostname}.");

            return(_tlsRecordDao.SaveTlsEvaluatorResults(mxRecordTlsProfile,
                                                         _mxSecurityEvaluator.Evaluate(mxRecordTlsProfile.ConnectionResults)));
        }
Esempio n. 3
0
        public async Task SaveTlsEvaluatorResults(MxRecordTlsProfile tlsProfile, EvaluatorResults tlsEvaluatorResults)
        {
            string connectionString = await _connectionInfoAsync.GetConnectionStringAsync();

            using (MySqlConnection connection = new MySqlConnection(connectionString))
            {
                await connection.OpenAsync().ConfigureAwait(false);

                MySqlCommand command = BuildTlsEvaluatorResultsCommand(connection, tlsProfile, tlsEvaluatorResults);

                await command.ExecuteNonQueryAsync();
            }
        }
Esempio n. 4
0
        private MySqlCommand BuildTlsEvaluatorResultsCommand(
            MySqlConnection connection,
            MxRecordTlsProfile tlsProfile,
            EvaluatorResults tlsEvaluatorResults)
        {
            MySqlCommand command = new MySqlCommand(TlsRecordDaoResources.InsertTlsEvaluatorResults, connection);

            command.Parameters.AddWithValue("mx_record_id", tlsProfile.MxRecordId);
            command.Parameters.AddWithValue("last_checked", tlsProfile.LastChecked);
            command.Parameters.AddWithValue("data",
                                            JsonConvert.SerializeObject(tlsEvaluatorResults, _serializerSettings));

            return(command);
        }