Exemple #1
0
        public void Publish(SpfRecordsEvaluated message)
        {
            List <Message>        rootMessages           = message.Messages;
            List <Message>        recordsMessages        = message.Records?.Messages;
            IEnumerable <Message> recordsRecordsMessages = message.Records?.Records?.SelectMany(x => x.Messages);
            List <SpfRecord>      recordsRecords         = message.Records?.Records;
            List <Message>        recursiveMessages      = new List <Message>();

            if (recordsRecords != null && recordsRecords.Count > 0)
            {
                foreach (SpfRecord record in recordsRecords)
                {
                    IEnumerable <Message> recordMessages = GetMessages(record);
                    recursiveMessages.AddRange(recordMessages);
                }
            }

            IEnumerable <Message> messages = (rootMessages ?? new List <Message>())
                                             .Concat(recordsMessages ?? new List <Message>())
                                             .Concat(recordsRecordsMessages ?? new List <Message>())
                                             .Concat(recursiveMessages ?? new List <Message>());

            Status status = _domainStatusEvaluator.GetStatus(messages.ToList());

            DomainStatusEvaluation domainStatusEvaluation = new DomainStatusEvaluation(message.Id, "SPF", status);

            _log.LogInformation($"Publishing SPF domain status for {message.Id} of {status}");

            _dispatcher.Dispatch(domainStatusEvaluation, _spfEntityConfig.SnsTopicArn);
        }
        public async Task Publish(TlsResultsEvaluated message)
        {
            List <TlsEvaluatedResult> evaluatedResults =
                message.TlsRecords?.Records?.Select(x => x.TlsEvaluatedResult).ToList();
            List <Error> evaluatedCertificates = message.Certificates?.Errors;

            Dictionary <string, List <TlsEntityState> > domainsContainingHost = await _dao.GetDomains(message.Id);

            foreach (string domain in domainsContainingHost.Keys)
            {
                List <TlsEntityState>     existingHostStates = domainsContainingHost[domain];
                List <TlsEvaluatedResult> existingResults    = existingHostStates
                                                               .Where(x => x.TlsRecords?.Records != null)
                                                               .SelectMany(x => x.TlsRecords?.Records?.Select(y => y.TlsEvaluatedResult)).ToList();

                List <Error> existingCertificates = existingHostStates
                                                    .Where(x => x.CertificateResults?.Errors != null)
                                                    .SelectMany(x => x.CertificateResults?.Errors).ToList();

                existingResults.AddRange(evaluatedResults ?? new List <TlsEvaluatedResult>());

                existingCertificates.AddRange(evaluatedCertificates ?? new List <Error>());

                Status status = _domainStatusEvaluator.GetStatus(existingResults, existingCertificates);

                DomainStatusEvaluation domainStatusEvaluation = new DomainStatusEvaluation(domain, "TLS", status);

                _log.LogInformation(
                    $"Publishing TLS domain status for domain {domain} because it contains mx host {message.Id} which was evaluated");
                _dispatcher.Dispatch(domainStatusEvaluation, _tlsEntityConfig.SnsTopicArn);
            }
        }
        public void Publish(DkimRecordEvaluationResult message)
        {
            if (message.SelectorResults is null || message.SelectorResults.Count == 0)
            {
                return;
            }

            List <Contracts.SharedDomain.DkimSelector> selectors = message.SelectorResults?.Select(x => x.Selector).ToList();

            IEnumerable <SharedDomainMessage> pollErrors = selectors
                                                           .Where(x => x.PollError != null)
                                                           .Select(x => x.PollError);

            IEnumerable <SharedDomainMessage> selectorMessages = selectors
                                                                 .Where(x => x.Records != null)
                                                                 .SelectMany(x => x.Records)
                                                                 .Where(x => x.Messages != null)
                                                                 .SelectMany(x => x.Messages);

            IEnumerable <SharedDomainMessage> messages = pollErrors.Concat(selectorMessages);

            List <DkimEvaluatorMessage> recordResults = message.SelectorResults.SelectMany(x => x.RecordsResults)
                                                        .SelectMany(x => x.Messages).ToList();

            Status status = _domainStatusEvaluator.GetStatus(recordResults.ToList(), messages.ToList());

            DomainStatusEvaluation domainStatusEvaluation = new DomainStatusEvaluation(message.Id, "DKIM", status);

            _log.LogInformation($"Publishing DKIM domain status for {message.Id}.");

            _dispatcher.Dispatch(domainStatusEvaluation, _spfEntityConfig.SnsTopicArn);
        }