Base62 mail domains

This commit is contained in:
Neil Alexander
2021-07-08 22:25:52 +01:00
parent 48354a98ec
commit ea3a94a1ce
8 changed files with 19 additions and 115 deletions

View File

@@ -1,7 +1,6 @@
package smtpsender
import (
"encoding/hex"
"fmt"
"log"
"math"
@@ -9,6 +8,7 @@ import (
"time"
"github.com/emersion/go-smtp"
"github.com/jxskiss/base62"
"github.com/neilalexander/yggmail/internal/config"
"github.com/neilalexander/yggmail/internal/transport"
"go.uber.org/atomic"
@@ -93,7 +93,7 @@ func (q *Queue) run() {
}
defer client.Close()
if err := client.Hello(hex.EncodeToString(q.queues.Config.PublicKey)); err != nil {
if err := client.Hello(base62.EncodeToString(q.queues.Config.PublicKey)); err != nil {
return fmt.Errorf("client.Hello: %w", err)
}

View File

@@ -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"
)
@@ -25,7 +25,7 @@ func (s *SessionLocal) Mail(from string, opts smtp.MailOptions) error {
return fmt.Errorf("parseAddress: %w", err)
}
if host != hex.EncodeToString(s.backend.Config.PublicKey) {
if host != base62.EncodeToString(s.backend.Config.PublicKey) {
return fmt.Errorf("not allowed to send outgoing mail as %s", from)
}
@@ -47,7 +47,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(),
hex.EncodeToString(s.backend.Config.PublicKey),
base62.EncodeToString(s.backend.Config.PublicKey),
time.Now().String(),
),
)
@@ -65,7 +65,7 @@ func (s *SessionLocal) Data(r io.Reader) error {
}
servers[host] = struct{}{}
if host == hex.EncodeToString(s.backend.Config.PublicKey) {
if host == base62.EncodeToString(s.backend.Config.PublicKey) {
var b bytes.Buffer
if err := m.WriteTo(&b); err != nil {
return fmt.Errorf("m.WriteTo: %w", err)

View File

@@ -3,13 +3,13 @@ package smtpserver
import (
"bytes"
"crypto/ed25519"
"encoding/hex"
"fmt"
"io"
"time"
"github.com/emersion/go-message"
"github.com/emersion/go-smtp"
"github.com/jxskiss/base62"
)
type SessionRemote struct {
@@ -40,7 +40,7 @@ func (s *SessionRemote) Rcpt(to string) error {
return fmt.Errorf("mail.ParseAddress: %w", err)
}
if local := hex.EncodeToString(s.backend.Config.PublicKey); host != local {
if local := base62.EncodeToString(s.backend.Config.PublicKey); host != local {
return fmt.Errorf("not allowed to send mail to %q", host)
}
@@ -56,7 +56,7 @@ func (s *SessionRemote) Data(r io.Reader) error {
m.Header.Add(
"Received", fmt.Sprintf("from Yggmail %s; %s",
hex.EncodeToString(s.public),
base62.EncodeToString(s.public),
time.Now().String(),
),
)

View File

@@ -9,6 +9,7 @@ import (
iwt "github.com/Arceliar/ironwood/types"
gologme "github.com/gologme/log"
"github.com/jxskiss/base62"
"github.com/neilalexander/utp"
"github.com/yggdrasil-network/yggdrasil-go/src/config"
"github.com/yggdrasil-network/yggdrasil-go/src/core"
@@ -63,7 +64,7 @@ func NewYggdrasilTransport(log *log.Logger, sk ed25519.PrivateKey, pk ed25519.Pu
func (t *YggdrasilTransport) Dial(host string) (net.Conn, error) {
addr := make(iwt.Addr, ed25519.PublicKeySize)
k, err := hex.DecodeString(host)
k, err := base62.DecodeString(host)
if err != nil {
return nil, err
}