Actual AUTH and also enforce EHLO/HELO first
This commit is contained in:
parent
f656866e7d
commit
5ce65e6be9
5 changed files with 133 additions and 26 deletions
|
@ -26,14 +26,24 @@ import (
|
|||
type Config struct {
|
||||
LogLevel string
|
||||
Host string
|
||||
PasswordHash string
|
||||
Plain string
|
||||
TLS string
|
||||
CertPath string
|
||||
PrivateKeyPath string
|
||||
Ports PortConfig
|
||||
Certificate CertConfig
|
||||
Auth AuthConfig
|
||||
}
|
||||
|
||||
type GeneralConfig struct {
|
||||
type PortConfig struct {
|
||||
Plain string
|
||||
TLS string
|
||||
}
|
||||
|
||||
type CertConfig struct {
|
||||
CertFile string
|
||||
KeyFile string
|
||||
}
|
||||
|
||||
type AuthConfig struct {
|
||||
Enabled bool
|
||||
PasswordHash string
|
||||
}
|
||||
|
||||
func LoadConfig(path string) (*Config, error) {
|
||||
|
@ -42,8 +52,9 @@ func LoadConfig(path string) (*Config, error) {
|
|||
return nil, err
|
||||
}
|
||||
var config Config
|
||||
config.Plain = "disabled"
|
||||
config.TLS = "disabled"
|
||||
config.Ports.Plain = "disabled"
|
||||
config.Ports.TLS = "disabled"
|
||||
config.Auth.Enabled = true
|
||||
err = json.Unmarshal(contents, &config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -83,28 +83,33 @@ func main() {
|
|||
log.Info().Msgf("Starting diodemail v%v", Version)
|
||||
log.Info().Msgf("Loaded config from: %v", config_path)
|
||||
|
||||
if config.CertPath == "" || config.PrivateKeyPath == "" {
|
||||
if config.Certificate.CertFile == "" || config.Certificate.KeyFile == "" {
|
||||
log.Fatal().Msgf(
|
||||
"Must provide CertPath (got '%v') and PrivateKeyPath (got '%v')",
|
||||
config.CertPath,
|
||||
config.PrivateKeyPath,
|
||||
"Must provide CertFile (got '%v') and KeyFile (got '%v')",
|
||||
config.Certificate.CertFile,
|
||||
config.Certificate.KeyFile,
|
||||
)
|
||||
}
|
||||
|
||||
certificate, err := tls.LoadX509KeyPair(
|
||||
config.CertPath,
|
||||
config.PrivateKeyPath,
|
||||
config.Certificate.CertFile,
|
||||
config.Certificate.KeyFile,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal().Msgf("Failed to load TLS config: %v", err)
|
||||
}
|
||||
|
||||
if config.Auth.Enabled && config.Auth.PasswordHash == "" {
|
||||
log.Fatal().Msgf("Authentication is enabled but no password hash was supplied")
|
||||
}
|
||||
|
||||
err = smtp.Run(
|
||||
config.Host,
|
||||
config.PasswordHash,
|
||||
config.Plain,
|
||||
config.TLS,
|
||||
config.Ports.Plain,
|
||||
config.Ports.TLS,
|
||||
tls.Config{Certificates: []tls.Certificate{certificate}},
|
||||
config.Auth.Enabled,
|
||||
config.Auth.PasswordHash,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal().Msgf("%v", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue