mirror of
https://github.com/neilalexander/yggmail.git
synced 2026-05-21 18:46:28 +03:00
Back to hex keys after all
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/emersion/go-smtp"
|
||||
"github.com/jxskiss/base62"
|
||||
"github.com/neilalexander/yggmail/internal/config"
|
||||
"github.com/neilalexander/yggmail/internal/smtpsender"
|
||||
"github.com/neilalexander/yggmail/internal/storage"
|
||||
@@ -37,7 +36,7 @@ func (b *Backend) Login(state *smtp.ConnectionState, username, password string)
|
||||
return nil, fmt.Errorf("failed to authenticate: wrong domain in username")
|
||||
}
|
||||
}
|
||||
username = base62.EncodeToString(b.Config.PublicKey)
|
||||
username = hex.EncodeToString(b.Config.PublicKey)
|
||||
// The connection came from our local listener
|
||||
if authed, err := b.Storage.ConfigTryPassword(password); err != nil {
|
||||
b.Log.Printf("Failed to authenticate SMTP user %q due to error: %s", username, err)
|
||||
@@ -71,7 +70,7 @@ func (b *Backend) AnonymousLogin(state *smtp.ConnectionState) (smtp.Session, err
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("hex.DecodeString: %w", err)
|
||||
}
|
||||
remote := base62.EncodeToString(pks)
|
||||
remote := hex.EncodeToString(pks)
|
||||
if state.Hostname != remote {
|
||||
return nil, fmt.Errorf("You are not who you claim to be")
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@ package smtpserver
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/emersion/go-message"
|
||||
"github.com/emersion/go-smtp"
|
||||
"github.com/jxskiss/base62"
|
||||
"github.com/neilalexander/yggmail/internal/smtpsender"
|
||||
"github.com/neilalexander/yggmail/internal/utils"
|
||||
)
|
||||
@@ -48,7 +48,7 @@ func (s *SessionLocal) Data(r io.Reader) error {
|
||||
m.Header.Add(
|
||||
"Received", fmt.Sprintf("from %s by Yggmail %s; %s",
|
||||
s.state.RemoteAddr.String(),
|
||||
base62.EncodeToString(s.backend.Config.PublicKey),
|
||||
hex.EncodeToString(s.backend.Config.PublicKey),
|
||||
time.Now().String(),
|
||||
),
|
||||
)
|
||||
@@ -60,7 +60,7 @@ func (s *SessionLocal) Data(r io.Reader) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("parseAddress: %w", err)
|
||||
}
|
||||
host := base62.EncodeToString(pk)
|
||||
host := hex.EncodeToString(pk)
|
||||
|
||||
if _, ok := servers[host]; ok {
|
||||
continue
|
||||
|
||||
@@ -10,16 +10,14 @@ import (
|
||||
|
||||
"github.com/emersion/go-message"
|
||||
"github.com/emersion/go-smtp"
|
||||
"github.com/jxskiss/base62"
|
||||
"github.com/neilalexander/yggmail/internal/utils"
|
||||
)
|
||||
|
||||
type SessionRemote struct {
|
||||
backend *Backend
|
||||
state *smtp.ConnectionState
|
||||
public ed25519.PublicKey
|
||||
from string
|
||||
localparts []string
|
||||
backend *Backend
|
||||
state *smtp.ConnectionState
|
||||
public ed25519.PublicKey
|
||||
from string
|
||||
}
|
||||
|
||||
func (s *SessionRemote) Mail(from string, opts smtp.MailOptions) error {
|
||||
@@ -28,12 +26,7 @@ func (s *SessionRemote) Mail(from string, opts smtp.MailOptions) error {
|
||||
return fmt.Errorf("mail.ParseAddress: %w", err)
|
||||
}
|
||||
|
||||
pks, err := hex.DecodeString(s.state.RemoteAddr.String())
|
||||
if err != nil {
|
||||
return fmt.Errorf("hex.DecodeString: %w", err)
|
||||
}
|
||||
|
||||
if remote := base62.EncodeToString(pks); base62.EncodeToString(pk) != remote {
|
||||
if remote := s.state.RemoteAddr.String(); hex.EncodeToString(pk) != remote {
|
||||
return fmt.Errorf("not allowed to send incoming mail as %s", from)
|
||||
}
|
||||
|
||||
@@ -62,7 +55,7 @@ func (s *SessionRemote) Data(r io.Reader) error {
|
||||
|
||||
m.Header.Add(
|
||||
"Received", fmt.Sprintf("from Yggmail %s; %s",
|
||||
base62.EncodeToString(s.public),
|
||||
hex.EncodeToString(s.public),
|
||||
time.Now().String(),
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user