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."); } } }
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))); }
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(); } }
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); }
public void WhenAllTestAreTcpConnectionFailedShouldReturnOneError() { var results = new ConnectionResults(new TlsConnectionResult(Error.TCP_CONNECTION_FAILED, "", null), new TlsConnectionResult(Error.TCP_CONNECTION_FAILED, "", null), new TlsConnectionResult(Error.TCP_CONNECTION_FAILED, "", null), new TlsConnectionResult(Error.TCP_CONNECTION_FAILED, "", null), new TlsConnectionResult(Error.TCP_CONNECTION_FAILED, "", null), new TlsConnectionResult(Error.TCP_CONNECTION_FAILED, "", null), new TlsConnectionResult(Error.TCP_CONNECTION_FAILED, "", null), new TlsConnectionResult(Error.TCP_CONNECTION_FAILED, "", null), new TlsConnectionResult(Error.TCP_CONNECTION_FAILED, "", null), new TlsConnectionResult(Error.TCP_CONNECTION_FAILED, "", null), new TlsConnectionResult(Error.TCP_CONNECTION_FAILED, "", null), new TlsConnectionResult(Error.TCP_CONNECTION_FAILED, "", null)); MxRecordTlsProfile profile = new MxRecordTlsProfile(1, "abc.com", DateTime.UtcNow, results); string failedConnectionErrors = profile.ConnectionResults.GetFailedConnectionErrors(); Assert.IsTrue(string.IsNullOrWhiteSpace(failedConnectionErrors)); }
public async Task <List <MxRecordTlsProfile> > GetDomainTlsConnectionResults(int domainId) { string connectionString = await _connectionInfoAsync.GetConnectionStringAsync(); using (MySqlConnection connection = new MySqlConnection(connectionString)) { await connection.OpenAsync().ConfigureAwait(false); MySqlCommand command = new MySqlCommand(TlsRecordDaoResources.GetDomainTlsConnectionResults, connection); command.Parameters.AddWithValue("domain_id", domainId); using (DbDataReader reader = await command.ExecuteReaderAsync()) { List <MxRecordTlsProfile> results = new List <MxRecordTlsProfile>(); while (await reader.ReadAsync()) { int mxRecordId = reader.GetInt32("mx_record_id"); string mxHostname = reader.GetString("hostname"); DateTime lastChecked = reader.GetDateTime("last_checked"); MxRecordTlsProfile tlsProfile = new MxRecordTlsProfile( mxRecordId, mxHostname, lastChecked, GetTlsConnectionResults(reader)); results.Add(tlsProfile); } return(results); } } }