Skip to content

Commit

Permalink
Fix DKIM scans for email submissions
Browse files Browse the repository at this point in the history
  • Loading branch information
wolveix committed Apr 8, 2024
1 parent 310818d commit 5ff2225
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/dss/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
Use: "dss",
Short: "Scan a domain's DNS records.",
Long: "Scan a domain's DNS records.\nhttps://github.com/GlobalCyberAlliance/domain-security-scanner",
Version: "3.0.7",
Version: "3.0.8",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
var logWriter io.Writer

Expand Down
3 changes: 2 additions & 1 deletion cmd/dss/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package main

import (
"bufio"
"os"

"github.com/GlobalCyberAlliance/domain-security-scanner/pkg/advisor"
"github.com/GlobalCyberAlliance/domain-security-scanner/pkg/model"
"github.com/GlobalCyberAlliance/domain-security-scanner/pkg/scanner"
"github.com/spf13/cobra"
"os"
)

func init() {
Expand Down
3 changes: 2 additions & 1 deletion pkg/http/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package http
import (
"context"
"fmt"
"net/http"

"github.com/GlobalCyberAlliance/domain-security-scanner/pkg/model"
"github.com/GlobalCyberAlliance/domain-security-scanner/pkg/scanner"
"github.com/danielgtaylor/huma/v2"
"net/http"
)

func (s *Server) registerScanRoutes() {
Expand Down
18 changes: 14 additions & 4 deletions pkg/mail/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type (
}

FoundMail struct {
Address string
DKIM string
Address string
DKIMSelector string
}
)

Expand Down Expand Up @@ -98,9 +98,19 @@ func (s *Server) GetMail() (map[string]FoundMail, error) {
continue
}

if dkim != "" {
dkimHeaders := strings.Split(dkim, ";")
for _, dkimHeader := range dkimHeaders {
if strings.HasPrefix(dkimHeader, " s=") {
dkim = strings.TrimPrefix(dkimHeader, " s=")
break
}
}
}

addresses[msg.Envelope.From[0].HostName] = FoundMail{
Address: msg.Envelope.From[0].Address(),
DKIM: dkim,
Address: msg.Envelope.From[0].Address(),
DKIMSelector: dkim,
}
emailsToBeDeleted = append(emailsToBeDeleted, msg.SeqNum)
}
Expand Down
16 changes: 11 additions & 5 deletions pkg/mail/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (s *Server) handler() error {
s.logger.Error().Err(err).Msg("could not obtain the latest mail from mail server")
}

var domainList []string
var dkimSelectors, domainList []string
for domain := range addresses {
cooldownDomain := s.cooldown.Get(domain)
if cooldownDomain != nil {
Expand All @@ -83,13 +83,23 @@ func (s *Server) handler() error {

s.cooldown.Set(domain, &domain)

if addresses[domain].DKIMSelector != "" {
dkimSelectors = append(dkimSelectors, addresses[domain].DKIMSelector)
}

domainList = append(domainList, domain)
}

if len(domainList) == 0 {
continue
}

if len(dkimSelectors) > 0 {
if err = s.Scanner.OverwriteOption(scanner.WithDKIMSelectors(dkimSelectors...)); err != nil {
s.logger.Error().Err(err).Msg("failed to override DKIM selectors for mail")
}
}

results, err := s.Scanner.Scan(domainList...)
if err != nil {
s.logger.Error().Err(err).Msg("An error occurred while scanning domains")
Expand All @@ -99,10 +109,6 @@ func (s *Server) handler() error {
for _, result := range results {
sender := addresses[result.Domain].Address

if addresses[result.Domain].DKIM != "" {
result.DKIM = addresses[result.Domain].DKIM
}

resultWithAdvice := model.ScanResultWithAdvice{
ScanResult: result,
}
Expand Down

0 comments on commit 5ff2225

Please sign in to comment.