Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TLS InsecureSkipVerify option #187

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,19 @@ The provider acts like any other, i.e. will be registered as `/auth/email/login`

For email notify provider, please use `github.com/go-pkgz/auth/provider/sender` package:
```go
sndr := sender.NewEmailClient(sender.EmailParams{
Host: "email.hostname",
Port: 567,
SMTPUserName: "username",
SMTPPassword: "pass",
StartTLS: true,
From: "[email protected]",
Subject: "subject",
ContentType: "text/html",
Charset: "UTF-8",
}, log.Default())
authenticator.AddVerifProvider("email", "template goes here", sndr)
sndr := sender.NewEmailClient(sender.EmailParams{
Host: "email.hostname",
Port: 567,
SMTPUserName: "username",
SMTPPassword: "pass",
StartTLS: true,
InsecureSkipVerify: false,
From: "[email protected]",
Subject: "subject",
ContentType: "text/html",
Charset: "UTF-8",
}, log.Default())
authenticator.AddVerifProvider("email", "template goes here", sndr)
```

See [that documentation](https://github.com/go-pkgz/email#options) for full options list.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
require (
github.com/dghubble/oauth1 v0.7.2
github.com/go-oauth2/oauth2/v4 v4.5.2
github.com/go-pkgz/email v0.4.1
github.com/go-pkgz/email v0.4.2-0.20231201080243-58c9950a4232
github.com/go-pkgz/repeater v1.1.3
github.com/go-pkgz/rest v1.17.0
github.com/golang-jwt/jwt v3.2.2+incompatible
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ github.com/go-oauth2/oauth2/v4 v4.5.2 h1:CuZhD3lhGuI6aNLyUbRHXsgG2RwGRBOuCBfd4WQ
github.com/go-oauth2/oauth2/v4 v4.5.2/go.mod h1:wk/2uLImWIa9VVQDgxz99H2GDbhmfi/9/Xr+GvkSUSQ=
github.com/go-pkgz/email v0.4.1 h1:2vtP2gibsSzqhz6eD5DklSp11m657XEVf17fuXaxMvk=
github.com/go-pkgz/email v0.4.1/go.mod h1:BdxglsQnymzhfdbnncEE72a6DrucZHy6I+42LK2jLEc=
github.com/go-pkgz/email v0.4.2-0.20231201080243-58c9950a4232 h1:yfe3v+ai3DYyHl39xCQRB8+uJa1AbaVd1+2m51ZDq6s=
github.com/go-pkgz/email v0.4.2-0.20231201080243-58c9950a4232/go.mod h1:BdxglsQnymzhfdbnncEE72a6DrucZHy6I+42LK2jLEc=
github.com/go-pkgz/repeater v1.1.3 h1:q6+JQF14ESSy28Dd7F+wRelY4F+41HJ0LEy/szNnMiE=
github.com/go-pkgz/repeater v1.1.3/go.mod h1:hVTavuO5x3Gxnu8zW7d6sQBfAneKV8X2FjU48kGfpKw=
github.com/go-pkgz/rest v1.17.0 h1:LoBI/lDBMuqwWhOOkc6thM9NnwJO+K9nWvCOjZ7BAgE=
Expand Down
20 changes: 12 additions & 8 deletions provider/sender/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sender

import (
"time"

vladimirdulov marked this conversation as resolved.
Show resolved Hide resolved
"github.com/go-pkgz/auth/logger"
"github.com/go-pkgz/email"
)
Expand All @@ -24,13 +23,14 @@ type EmailParams struct {
Subject string // Email subject
ContentType string // Content type

TLS bool // TLS auth
StartTLS bool // StartTLS auth
Charset string // Character set
LoginAuth bool // LOGIN auth method instead of default PLAIN, needed for Office 365 and outlook.com
SMTPUserName string // username
SMTPPassword string // password
TimeOut time.Duration // TCP connection timeout
TLS bool // TLS auth
StartTLS bool // StartTLS auth
InsecureSkipVerify bool // Skip certificate verification
Charset string // Character set
LoginAuth bool // LOGIN auth method instead of default PLAIN, needed for Office 365 and outlook.com
SMTPUserName string // username
SMTPPassword string // password
TimeOut time.Duration // TCP connection timeout
}

// NewEmailClient creates email client
Expand Down Expand Up @@ -69,6 +69,10 @@ func NewEmailClient(emailParams EmailParams, l logger.L) *Email {
opts = append(opts, email.STARTTLS(true))
}

if emailParams.InsecureSkipVerify {
opts = append(opts, email.InsecureSkipVerify(true))
}

sender := email.NewSender(emailParams.Host, opts...)

return &Email{EmailParams: emailParams, L: l, sender: sender}
Expand Down
23 changes: 12 additions & 11 deletions provider/sender/email_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ func TestEmailSend(t *testing.T) {

func TestEmail_New(t *testing.T) {
p := EmailParams{
Host: "127.0.0.2",
From: "[email protected]",
SMTPUserName: "user",
SMTPPassword: "pass",
Subject: "subj",
ContentType: "text/html",
Charset: "UTF-8",
LoginAuth: true,
StartTLS: true,
TLS: true,
Host: "127.0.0.2",
From: "[email protected]",
SMTPUserName: "user",
SMTPPassword: "pass",
Subject: "subj",
ContentType: "text/html",
Charset: "UTF-8",
LoginAuth: true,
StartTLS: true,
TLS: true,
InsecureSkipVerify: true,
}
e := NewEmailClient(p, logger.Std)
assert.Equal(t, p, e.EmailParams)
Expand All @@ -62,7 +63,7 @@ func TestEmail_SendFailed(t *testing.T) {
require.NotNil(t, err, "failed to make smtp client")

p = EmailParams{Host: "127.0.0.1", Port: 225, From: "[email protected]", Subject: "subj", ContentType: "text/html",
TLS: true}
TLS: true, InsecureSkipVerify: true}
vladimirdulov marked this conversation as resolved.
Show resolved Hide resolved
e = NewEmailClient(p, logger.Std)
err = e.Send("[email protected]", "some text")
require.NotNil(t, err)
Expand Down
Loading