Skip to content

Commit

Permalink
Merge pull request #50 from tierpod/security_config
Browse files Browse the repository at this point in the history
Security config
  • Loading branch information
tierpod authored Apr 13, 2024
2 parents 41d9a4e + 258378e commit e47ca16
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
8 changes: 8 additions & 0 deletions cmd/dmarc-report-converter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ func loadConfig(path string) (*config, error) {
return nil, fmt.Errorf("input.dir is not configured")
}

if c.Input.IMAP.Security == "" {
c.Input.IMAP.Security = "tls"
}

if c.Input.IMAP.Security != "tls" && c.Input.IMAP.Security != "starttls" && c.Input.IMAP.Security != "plaintext" {
return nil, fmt.Errorf("'input.imap.security' must be one of: tls, starttls, plaintext")
}

// Determine which template is used based upon Output.Format.
t := txtTmpl
switch c.Output.Format {
Expand Down
46 changes: 23 additions & 23 deletions cmd/dmarc-report-converter/imap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,31 @@ func fetchIMAPAttachments(cfg *config) error {

// connect to server
var c *client.Client
var err error
if cfg.Input.IMAP.Security == "plaintext" {
var err error
if cfg.Input.IMAP.Security == "plaintext" {
log.Printf("[WARN] Without encryption your credentials may be stolen. Be careful!")
c, err = client.Dial(cfg.Input.IMAP.Server)
} else if cfg.Input.IMAP.Security == "starttls" {
// go-imap v2 will replace all the following lines with
// c, err = client.DialStartTLS(cfg.Input.IMAP.Server, nil)
c, err = client.Dial(cfg.Input.IMAP.Server)
} else if cfg.Input.IMAP.Security == "starttls" {
// go-imap v2 will replace all the following lines with
// c, err = client.DialStartTLS(cfg.Input.IMAP.Server, nil)
// and there will be no need to import "errors"
c, err = client.Dial(cfg.Input.IMAP.Server)
if err == nil {
sstRet, sstErr := c.SupportStartTLS();
if sstErr != nil {
err = sstErr
} else if !sstRet {
err = errors.New("server doesn't support starttls")
} else {
err = c.StartTLS(nil);
}
}
if err != nil {
c.Logout()
}
} else {
c, err = client.DialTLS(cfg.Input.IMAP.Server, nil)
}
c, err = client.Dial(cfg.Input.IMAP.Server)
if err == nil {
sstRet, sstErr := c.SupportStartTLS()
if sstErr != nil {
err = sstErr
} else if !sstRet {
err = errors.New("server doesn't support starttls")
} else {
err = c.StartTLS(nil)
}
}
if err != nil {
c.Logout()
}
} else {
c, err = client.DialTLS(cfg.Input.IMAP.Server, nil)
}
if err != nil {
return err
}
Expand Down

0 comments on commit e47ca16

Please sign in to comment.