Skip to content

Commit

Permalink
TLS insecure option adding (#1220)
Browse files Browse the repository at this point in the history
* TLS InsecureSkipVerify option added to sendMail

* refactor(reporter/email): remove redundant if statement

---------

Co-authored-by: MaineK00n <mainek00n.1229@gmail.com>
  • Loading branch information
Koodt and MaineK00n authored Apr 5, 2024
1 parent 5d5dcd5 commit 867bf63
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 31 deletions.
19 changes: 10 additions & 9 deletions config/smtpconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import (

// SMTPConf is smtp config
type SMTPConf struct {
SMTPAddr string `toml:"smtpAddr,omitempty" json:"-"`
SMTPPort string `toml:"smtpPort,omitempty" valid:"port" json:"-"`
User string `toml:"user,omitempty" json:"-"`
Password string `toml:"password,omitempty" json:"-"`
From string `toml:"from,omitempty" json:"-"`
To []string `toml:"to,omitempty" json:"-"`
Cc []string `toml:"cc,omitempty" json:"-"`
SubjectPrefix string `toml:"subjectPrefix,omitempty" json:"-"`
Enabled bool `toml:"-" json:"-"`
SMTPAddr string `toml:"smtpAddr,omitempty" json:"-"`
SMTPPort string `toml:"smtpPort,omitempty" valid:"port" json:"-"`
TLSInsecureSkipVerify bool `toml:"tlsInsecureSkipVerify,omitempty" json:"-"`
User string `toml:"user,omitempty" json:"-"`
Password string `toml:"password,omitempty" json:"-"`
From string `toml:"from,omitempty" json:"-"`
To []string `toml:"to,omitempty" json:"-"`
Cc []string `toml:"cc,omitempty" json:"-"`
SubjectPrefix string `toml:"subjectPrefix,omitempty" json:"-"`
Enabled bool `toml:"-" json:"-"`
}

func checkEmails(emails []string) (errs []error) {
Expand Down
17 changes: 3 additions & 14 deletions reporter/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ func (e *emailSender) sendMail(smtpServerAddr, message string) (err error) {
emailConf := e.conf
//TLS Config
tlsConfig := &tls.Config{
ServerName: emailConf.SMTPAddr,
ServerName: emailConf.SMTPAddr,
InsecureSkipVerify: emailConf.TLSInsecureSkipVerify,
}
switch emailConf.SMTPPort {
case "465":
Expand Down Expand Up @@ -178,19 +179,7 @@ func (e *emailSender) Send(subject, body string) (err error) {
for k, v := range headers {
header += fmt.Sprintf("%s: %s\r\n", k, v)
}
message := fmt.Sprintf("%s\r\n%s", header, body)

smtpServer := net.JoinHostPort(emailConf.SMTPAddr, emailConf.SMTPPort)

if emailConf.User != "" && emailConf.Password != "" {
err = e.sendMail(smtpServer, message)
if err != nil {
return xerrors.Errorf("Failed to send emails: %w", err)
}
return nil
}
err = e.sendMail(smtpServer, message)
if err != nil {
if err := e.sendMail(net.JoinHostPort(emailConf.SMTPAddr, emailConf.SMTPPort), fmt.Sprintf("%s\r\n%s", header, body)); err != nil {
return xerrors.Errorf("Failed to send emails: %w", err)
}
return nil
Expand Down
17 changes: 9 additions & 8 deletions subcmds/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,15 @@ func printConfigToml(ips []string) (err error) {
# https://vuls.io/docs/en/config.toml.html#email-section
#[email]
#smtpAddr = "smtp.example.com"
#smtpPort = "587"
#user = "username"
#password = "password"
#from = "from@example.com"
#to = ["to@example.com"]
#cc = ["cc@example.com"]
#subjectPrefix = "[vuls]"
#smtpAddr = "smtp.example.com"
#smtpPort = "587"
#tlsInsecureSkipVerify = false
#user = "username"
#password = "password"
#from = "from@example.com"
#to = ["to@example.com"]
#cc = ["cc@example.com"]
#subjectPrefix = "[vuls]"
# https://vuls.io/docs/en/config.toml.html#http-section
#[http]
Expand Down

0 comments on commit 867bf63

Please sign in to comment.