Validation fixes

This commit is contained in:
Neil Alexander
2021-07-08 22:38:18 +01:00
parent 73ec35d5fa
commit f9ae101d38
4 changed files with 15 additions and 4 deletions

View File

@@ -63,11 +63,12 @@ func (b *Backend) AnonymousLogin(state *smtp.ConnectionState) (smtp.Session, err
if err != nil {
return nil, fmt.Errorf("hex.DecodeString: %w", err)
}
if state.Hostname != base62.EncodeToString(pks) {
remote := base62.EncodeToString(pks)
if state.Hostname != remote {
return nil, fmt.Errorf("You are not who you claim to be")
}
b.Log.Println("Incoming SMTP session from", state.RemoteAddr.String())
b.Log.Println("Incoming SMTP session from", remote)
return &SessionRemote{
backend: b,
state: state,

View File

@@ -3,6 +3,7 @@ package smtpserver
import (
"bytes"
"crypto/ed25519"
"encoding/hex"
"fmt"
"io"
"time"
@@ -26,7 +27,13 @@ func (s *SessionRemote) Mail(from string, opts smtp.MailOptions) error {
return fmt.Errorf("mail.ParseAddress: %w", err)
}
if local := s.state.RemoteAddr.String(); local != host {
pks, err := hex.DecodeString(host)
if err != nil {
return fmt.Errorf("hex.DecodeString: %w", err)
}
remote := base62.EncodeToString(pks)
if local := s.state.RemoteAddr.String(); local != remote {
return fmt.Errorf("not allowed to send incoming mail as %s", from)
}