2019-03-24 00:08:41 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package post
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/smtp"
|
|
|
|
|
|
|
|
"github.com/zeebo/errs"
|
|
|
|
)
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// LoginAuth implements LOGIN authentication mechanism.
|
2019-03-24 00:08:41 +00:00
|
|
|
type LoginAuth struct {
|
|
|
|
Username string
|
|
|
|
Password string
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Start begins an authentication with a server.
|
2019-03-24 00:08:41 +00:00
|
|
|
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
|
2020-07-16 15:18:02 +01:00
|
|
|
// if server expects more data from client.
|
2019-03-24 00:08:41 +00:00
|
|
|
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
|
|
|
|
}
|