added LOGIN auth scheme to satellite mail service (#1552)

This commit is contained in:
Yaroslav Vorobiov 2019-03-24 02:08:41 +02:00 committed by GitHub
parent b9bb986b8a
commit cce6fa8fd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 58 additions and 5 deletions

40
internal/post/login.go Normal file
View File

@ -0,0 +1,40 @@
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package post
import (
"net/smtp"
"github.com/zeebo/errs"
)
// LoginAuth implements LOGIN authentication mechanism
type LoginAuth struct {
Username string
Password string
}
// Start begins an authentication with a server
func (auth LoginAuth) Start(server *smtp.ServerInfo) (proto string, toServer []byte, err error) {
if !server.TLS {
return "", nil, errs.New("unencrypted connection")
}
return "LOGIN", nil, nil
}
// Next continues the authentication with server response and flag representing
// if server expects more data from client
func (auth LoginAuth) Next(fromServer []byte, more bool) (toServer []byte, err error) {
if more {
switch string(fromServer) {
case "Username:":
return []byte(auth.Username), nil
case "Password:":
return []byte(auth.Password), nil
default:
return nil, errs.New("unknown question")
}
}
return nil, nil
}

View File

@ -25,6 +25,10 @@ type Auth struct {
// Start returns proto and auth credentials for first auth msg
func (auth *Auth) Start(server *smtp.ServerInfo) (proto string, toServer []byte, err error) {
if !server.TLS {
return "", nil, errs.New("unencrypted connection")
}
token, err := auth.Storage.Token()
if err != nil {
return "", nil, err

View File

@ -448,8 +448,8 @@ func (planet *Planet) newSatellites(count int) ([]*satellite.Peer, error) {
Interval: 120 * time.Second,
},
Mail: mailservice.Config{
SMTPServerAddress: "smtp.gmail.com:587",
From: "Labs <yaroslav-satellite-test@storj.io>",
SMTPServerAddress: "smtp.mail.example.com:587",
From: "Labs <storj@example.com>",
AuthType: "simulate",
},
Console: consoleweb.Config{

View File

@ -21,8 +21,8 @@ type Config struct {
TemplatePath string `help:"path to email templates source" default:""`
From string `help:"sender email address" default:""`
AuthType string `help:"smtp authentication type" default:"simulate"`
PlainLogin string `help:"plain auth user login" default:""`
PlainPassword string `help:"plain auth user password" default:""`
Login string `help:"plain/login auth user login" default:""`
Password string `help:"plain/login auth user password" default:""`
RefreshToken string `help:"refresh token used to retrieve new access token" default:""`
ClientID string `help:"oauth2 app's client id" default:""`
ClientSecret string `help:"oauth2 app's client secret" default:""`

View File

@ -421,7 +421,16 @@ func New(log *zap.Logger, full *identity.FullIdentity, db DB, config *Config) (*
case "plain":
sender = &post.SMTPSender{
From: *from,
Auth: smtp.PlainAuth("", mailConfig.PlainLogin, mailConfig.PlainPassword, host),
Auth: smtp.PlainAuth("", mailConfig.Login, mailConfig.Password, host),
ServerAddress: mailConfig.SMTPServerAddress,
}
case "login":
sender = &post.SMTPSender{
From: *from,
Auth: post.LoginAuth{
Username: mailConfig.Login,
Password: mailConfig.Password,
},
ServerAddress: mailConfig.SMTPServerAddress,
}
default: