mirror of
https://github.com/neilalexander/yggmail.git
synced 2026-05-21 02:26:29 +03:00
Back to hex keys after all
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
package imapserver
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/emersion/go-imap"
|
||||
"github.com/emersion/go-imap/backend"
|
||||
"github.com/jxskiss/base62"
|
||||
"github.com/neilalexander/yggmail/internal/config"
|
||||
"github.com/neilalexander/yggmail/internal/storage"
|
||||
"github.com/neilalexander/yggmail/internal/utils"
|
||||
@@ -26,7 +26,7 @@ func (b *Backend) Login(_ *imap.ConnInfo, username, password string) (backend.Us
|
||||
return nil, fmt.Errorf("failed to authenticate: wrong domain in username")
|
||||
}
|
||||
}
|
||||
username = base62.EncodeToString(b.Config.PublicKey)
|
||||
username = hex.EncodeToString(b.Config.PublicKey)
|
||||
if authed, err := b.Storage.ConfigTryPassword(password); err != nil {
|
||||
b.Log.Printf("Failed to authenticate IMAP user %q due to error: %s", username, err)
|
||||
return nil, fmt.Errorf("failed to authenticate: %w", err)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package imapserver
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/emersion/go-imap/backend"
|
||||
"github.com/jxskiss/base62"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
@@ -14,7 +14,7 @@ type User struct {
|
||||
}
|
||||
|
||||
func (u *User) Username() string {
|
||||
return base62.EncodeToString(u.backend.Config.PublicKey)
|
||||
return hex.EncodeToString(u.backend.Config.PublicKey)
|
||||
}
|
||||
|
||||
func (u *User) ListMailboxes(subscribed bool) (mailboxes []backend.Mailbox, err error) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package smtpsender
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
@@ -8,7 +9,6 @@ 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(base62.EncodeToString(q.queues.Config.PublicKey)); err != nil {
|
||||
if err := client.Hello(hex.EncodeToString(q.queues.Config.PublicKey)); err != nil {
|
||||
q.queues.Log.Println("Remote server", q.destination, "did not accept HELLO:", err)
|
||||
return fmt.Errorf("client.Hello: %w", err)
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -9,7 +9,6 @@ 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"
|
||||
@@ -64,7 +63,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 := base62.DecodeString(host)
|
||||
k, err := hex.DecodeString(host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -2,10 +2,9 @@ package utils
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/jxskiss/base62"
|
||||
)
|
||||
|
||||
const Domain = "yggmail"
|
||||
@@ -25,9 +24,9 @@ func ParseAddress(email string) (ed25519.PublicKey, error) {
|
||||
if email[at+1:] != Domain {
|
||||
return nil, fmt.Errorf("invalid email domain")
|
||||
}
|
||||
pk, err := base62.DecodeString(email[:at])
|
||||
pk, err := hex.DecodeString(email[:at])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("base62.DecodeString: %w", err)
|
||||
return nil, fmt.Errorf("hex.DecodeString: %w", err)
|
||||
}
|
||||
ed := make(ed25519.PublicKey, ed25519.PublicKeySize)
|
||||
copy(ed, pk)
|
||||
|
||||
Reference in New Issue
Block a user