Skip to content

Commit 867bf63

Browse files
KoodtMaineK00n
andauthored
TLS insecure option adding (#1220)
* TLS InsecureSkipVerify option added to sendMail * refactor(reporter/email): remove redundant if statement --------- Co-authored-by: MaineK00n <[email protected]>
1 parent 5d5dcd5 commit 867bf63

File tree

3 files changed

+22
-31
lines changed

3 files changed

+22
-31
lines changed

config/smtpconf.go

+10-9
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ import (
77

88
// SMTPConf is smtp config
99
type SMTPConf struct {
10-
SMTPAddr string `toml:"smtpAddr,omitempty" json:"-"`
11-
SMTPPort string `toml:"smtpPort,omitempty" valid:"port" json:"-"`
12-
User string `toml:"user,omitempty" json:"-"`
13-
Password string `toml:"password,omitempty" json:"-"`
14-
From string `toml:"from,omitempty" json:"-"`
15-
To []string `toml:"to,omitempty" json:"-"`
16-
Cc []string `toml:"cc,omitempty" json:"-"`
17-
SubjectPrefix string `toml:"subjectPrefix,omitempty" json:"-"`
18-
Enabled bool `toml:"-" json:"-"`
10+
SMTPAddr string `toml:"smtpAddr,omitempty" json:"-"`
11+
SMTPPort string `toml:"smtpPort,omitempty" valid:"port" json:"-"`
12+
TLSInsecureSkipVerify bool `toml:"tlsInsecureSkipVerify,omitempty" json:"-"`
13+
User string `toml:"user,omitempty" json:"-"`
14+
Password string `toml:"password,omitempty" json:"-"`
15+
From string `toml:"from,omitempty" json:"-"`
16+
To []string `toml:"to,omitempty" json:"-"`
17+
Cc []string `toml:"cc,omitempty" json:"-"`
18+
SubjectPrefix string `toml:"subjectPrefix,omitempty" json:"-"`
19+
Enabled bool `toml:"-" json:"-"`
1920
}
2021

2122
func checkEmails(emails []string) (errs []error) {

reporter/email.go

+3-14
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ func (e *emailSender) sendMail(smtpServerAddr, message string) (err error) {
9494
emailConf := e.conf
9595
//TLS Config
9696
tlsConfig := &tls.Config{
97-
ServerName: emailConf.SMTPAddr,
97+
ServerName: emailConf.SMTPAddr,
98+
InsecureSkipVerify: emailConf.TLSInsecureSkipVerify,
9899
}
99100
switch emailConf.SMTPPort {
100101
case "465":
@@ -178,19 +179,7 @@ func (e *emailSender) Send(subject, body string) (err error) {
178179
for k, v := range headers {
179180
header += fmt.Sprintf("%s: %s\r\n", k, v)
180181
}
181-
message := fmt.Sprintf("%s\r\n%s", header, body)
182-
183-
smtpServer := net.JoinHostPort(emailConf.SMTPAddr, emailConf.SMTPPort)
184-
185-
if emailConf.User != "" && emailConf.Password != "" {
186-
err = e.sendMail(smtpServer, message)
187-
if err != nil {
188-
return xerrors.Errorf("Failed to send emails: %w", err)
189-
}
190-
return nil
191-
}
192-
err = e.sendMail(smtpServer, message)
193-
if err != nil {
182+
if err := e.sendMail(net.JoinHostPort(emailConf.SMTPAddr, emailConf.SMTPPort), fmt.Sprintf("%s\r\n%s", header, body)); err != nil {
194183
return xerrors.Errorf("Failed to send emails: %w", err)
195184
}
196185
return nil

subcmds/discover.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,15 @@ func printConfigToml(ips []string) (err error) {
125125
126126
# https://vuls.io/docs/en/config.toml.html#email-section
127127
#[email]
128-
#smtpAddr = "smtp.example.com"
129-
#smtpPort = "587"
130-
#user = "username"
131-
#password = "password"
132-
133-
134-
135-
#subjectPrefix = "[vuls]"
128+
#smtpAddr = "smtp.example.com"
129+
#smtpPort = "587"
130+
#tlsInsecureSkipVerify = false
131+
#user = "username"
132+
#password = "password"
133+
134+
135+
136+
#subjectPrefix = "[vuls]"
136137
137138
# https://vuls.io/docs/en/config.toml.html#http-section
138139
#[http]

0 commit comments

Comments
 (0)