mirror of
https://github.com/neilalexander/yggmail.git
synced 2026-05-08 04:46:28 +03:00
Back to hex keys after all
This commit is contained in:
@@ -14,7 +14,6 @@ import (
|
|||||||
"github.com/emersion/go-imap/server"
|
"github.com/emersion/go-imap/server"
|
||||||
"github.com/emersion/go-sasl"
|
"github.com/emersion/go-sasl"
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
"github.com/jxskiss/base62"
|
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
|
|
||||||
"github.com/neilalexander/yggmail/internal/config"
|
"github.com/neilalexander/yggmail/internal/config"
|
||||||
@@ -69,7 +68,7 @@ func main() {
|
|||||||
copy(sk, skBytes)
|
copy(sk, skBytes)
|
||||||
}
|
}
|
||||||
pk := sk.Public().(ed25519.PublicKey)
|
pk := sk.Public().(ed25519.PublicKey)
|
||||||
log.Printf("Mail address: %s@%s\n", base62.EncodeToString(pk), utils.Domain)
|
log.Printf("Mail address: %s@%s\n", hex.EncodeToString(pk), utils.Domain)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case password != nil && *password:
|
case password != nil && *password:
|
||||||
@@ -150,7 +149,7 @@ func main() {
|
|||||||
|
|
||||||
localServer := smtp.NewServer(localBackend)
|
localServer := smtp.NewServer(localBackend)
|
||||||
localServer.Addr = *smtpaddr
|
localServer.Addr = *smtpaddr
|
||||||
localServer.Domain = base62.EncodeToString(pk)
|
localServer.Domain = hex.EncodeToString(pk)
|
||||||
localServer.MaxMessageBytes = 1024 * 1024
|
localServer.MaxMessageBytes = 1024 * 1024
|
||||||
localServer.MaxRecipients = 50
|
localServer.MaxRecipients = 50
|
||||||
localServer.AllowInsecureAuth = true
|
localServer.AllowInsecureAuth = true
|
||||||
@@ -179,7 +178,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
overlayServer := smtp.NewServer(overlayBackend)
|
overlayServer := smtp.NewServer(overlayBackend)
|
||||||
overlayServer.Domain = base62.EncodeToString(pk)
|
overlayServer.Domain = hex.EncodeToString(pk)
|
||||||
overlayServer.MaxMessageBytes = 1024 * 1024
|
overlayServer.MaxMessageBytes = 1024 * 1024
|
||||||
overlayServer.MaxRecipients = 50
|
overlayServer.MaxRecipients = 50
|
||||||
overlayServer.AuthDisabled = true
|
overlayServer.AuthDisabled = true
|
||||||
|
|||||||
1
go.mod
1
go.mod
@@ -10,7 +10,6 @@ require (
|
|||||||
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21
|
github.com/emersion/go-sasl v0.0.0-20200509203442-7bfe0ed36a21
|
||||||
github.com/emersion/go-smtp v0.15.0
|
github.com/emersion/go-smtp v0.15.0
|
||||||
github.com/gologme/log v1.2.0
|
github.com/gologme/log v1.2.0
|
||||||
github.com/jxskiss/base62 v0.0.0-20191017122030-4f11678b909b // indirect
|
|
||||||
github.com/mattn/go-sqlite3 v1.14.7
|
github.com/mattn/go-sqlite3 v1.14.7
|
||||||
github.com/neilalexander/utp v0.1.1-0.20210705212447-691f29ad692b
|
github.com/neilalexander/utp v0.1.1-0.20210705212447-691f29ad692b
|
||||||
github.com/yggdrasil-network/yggdrasil-go v0.4.1-0.20210707004512-3704ebf4cbea
|
github.com/yggdrasil-network/yggdrasil-go v0.4.1-0.20210707004512-3704ebf4cbea
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -62,8 +62,6 @@ github.com/huandu/xstrings v1.0.0/go.mod h1:4qWG/gcEcfX4z/mBDHJ++3ReCw9ibxbsNJbc
|
|||||||
github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0=
|
github.com/huandu/xstrings v1.2.0 h1:yPeWdRnmynF7p+lLYz0H2tthW9lqhMJrQV/U7yy4wX0=
|
||||||
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=
|
github.com/huandu/xstrings v1.2.0/go.mod h1:DvyZB1rfVYsBIigL8HwpZgxHwXozlTgGqn63UyNX5k4=
|
||||||
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||||
github.com/jxskiss/base62 v0.0.0-20191017122030-4f11678b909b h1:XUr8tvMEILhphQPp3TFcIudb5KTOzFeD0pJyDn5+5QI=
|
|
||||||
github.com/jxskiss/base62 v0.0.0-20191017122030-4f11678b909b/go.mod h1:a5Mn24iYVJRUQSkFupGByqykzD+k+wFI8J91zGHuPf8=
|
|
||||||
github.com/kardianos/minwinsvc v1.0.0/go.mod h1:Bgd0oc+D0Qo3bBytmNtyRKVlp85dAloLKhfxanPFFRc=
|
github.com/kardianos/minwinsvc v1.0.0/go.mod h1:Bgd0oc+D0Qo3bBytmNtyRKVlp85dAloLKhfxanPFFRc=
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package imapserver
|
package imapserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/emersion/go-imap"
|
"github.com/emersion/go-imap"
|
||||||
"github.com/emersion/go-imap/backend"
|
"github.com/emersion/go-imap/backend"
|
||||||
"github.com/jxskiss/base62"
|
|
||||||
"github.com/neilalexander/yggmail/internal/config"
|
"github.com/neilalexander/yggmail/internal/config"
|
||||||
"github.com/neilalexander/yggmail/internal/storage"
|
"github.com/neilalexander/yggmail/internal/storage"
|
||||||
"github.com/neilalexander/yggmail/internal/utils"
|
"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")
|
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 {
|
if authed, err := b.Storage.ConfigTryPassword(password); err != nil {
|
||||||
b.Log.Printf("Failed to authenticate IMAP user %q due to error: %s", username, err)
|
b.Log.Printf("Failed to authenticate IMAP user %q due to error: %s", username, err)
|
||||||
return nil, fmt.Errorf("failed to authenticate: %w", err)
|
return nil, fmt.Errorf("failed to authenticate: %w", err)
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package imapserver
|
package imapserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/emersion/go-imap/backend"
|
"github.com/emersion/go-imap/backend"
|
||||||
"github.com/jxskiss/base62"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
@@ -14,7 +14,7 @@ type User struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) Username() string {
|
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) {
|
func (u *User) ListMailboxes(subscribed bool) (mailboxes []backend.Mailbox, err error) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package smtpsender
|
package smtpsender
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
@@ -8,7 +9,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
"github.com/jxskiss/base62"
|
|
||||||
"github.com/neilalexander/yggmail/internal/config"
|
"github.com/neilalexander/yggmail/internal/config"
|
||||||
"github.com/neilalexander/yggmail/internal/transport"
|
"github.com/neilalexander/yggmail/internal/transport"
|
||||||
"go.uber.org/atomic"
|
"go.uber.org/atomic"
|
||||||
@@ -93,7 +93,7 @@ func (q *Queue) run() {
|
|||||||
}
|
}
|
||||||
defer client.Close()
|
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)
|
q.queues.Log.Println("Remote server", q.destination, "did not accept HELLO:", err)
|
||||||
return fmt.Errorf("client.Hello: %w", err)
|
return fmt.Errorf("client.Hello: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
"github.com/jxskiss/base62"
|
|
||||||
"github.com/neilalexander/yggmail/internal/config"
|
"github.com/neilalexander/yggmail/internal/config"
|
||||||
"github.com/neilalexander/yggmail/internal/smtpsender"
|
"github.com/neilalexander/yggmail/internal/smtpsender"
|
||||||
"github.com/neilalexander/yggmail/internal/storage"
|
"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")
|
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
|
// The connection came from our local listener
|
||||||
if authed, err := b.Storage.ConfigTryPassword(password); err != nil {
|
if authed, err := b.Storage.ConfigTryPassword(password); err != nil {
|
||||||
b.Log.Printf("Failed to authenticate SMTP user %q due to error: %s", username, err)
|
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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("hex.DecodeString: %w", err)
|
return nil, fmt.Errorf("hex.DecodeString: %w", err)
|
||||||
}
|
}
|
||||||
remote := base62.EncodeToString(pks)
|
remote := hex.EncodeToString(pks)
|
||||||
if state.Hostname != remote {
|
if state.Hostname != remote {
|
||||||
return nil, fmt.Errorf("You are not who you claim to be")
|
return nil, fmt.Errorf("You are not who you claim to be")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ package smtpserver
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/emersion/go-message"
|
"github.com/emersion/go-message"
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
"github.com/jxskiss/base62"
|
|
||||||
"github.com/neilalexander/yggmail/internal/smtpsender"
|
"github.com/neilalexander/yggmail/internal/smtpsender"
|
||||||
"github.com/neilalexander/yggmail/internal/utils"
|
"github.com/neilalexander/yggmail/internal/utils"
|
||||||
)
|
)
|
||||||
@@ -48,7 +48,7 @@ func (s *SessionLocal) Data(r io.Reader) error {
|
|||||||
m.Header.Add(
|
m.Header.Add(
|
||||||
"Received", fmt.Sprintf("from %s by Yggmail %s; %s",
|
"Received", fmt.Sprintf("from %s by Yggmail %s; %s",
|
||||||
s.state.RemoteAddr.String(),
|
s.state.RemoteAddr.String(),
|
||||||
base62.EncodeToString(s.backend.Config.PublicKey),
|
hex.EncodeToString(s.backend.Config.PublicKey),
|
||||||
time.Now().String(),
|
time.Now().String(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@@ -60,7 +60,7 @@ func (s *SessionLocal) Data(r io.Reader) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("parseAddress: %w", err)
|
return fmt.Errorf("parseAddress: %w", err)
|
||||||
}
|
}
|
||||||
host := base62.EncodeToString(pk)
|
host := hex.EncodeToString(pk)
|
||||||
|
|
||||||
if _, ok := servers[host]; ok {
|
if _, ok := servers[host]; ok {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -10,16 +10,14 @@ import (
|
|||||||
|
|
||||||
"github.com/emersion/go-message"
|
"github.com/emersion/go-message"
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
"github.com/jxskiss/base62"
|
|
||||||
"github.com/neilalexander/yggmail/internal/utils"
|
"github.com/neilalexander/yggmail/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SessionRemote struct {
|
type SessionRemote struct {
|
||||||
backend *Backend
|
backend *Backend
|
||||||
state *smtp.ConnectionState
|
state *smtp.ConnectionState
|
||||||
public ed25519.PublicKey
|
public ed25519.PublicKey
|
||||||
from string
|
from string
|
||||||
localparts []string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SessionRemote) Mail(from string, opts smtp.MailOptions) error {
|
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)
|
return fmt.Errorf("mail.ParseAddress: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pks, err := hex.DecodeString(s.state.RemoteAddr.String())
|
if remote := s.state.RemoteAddr.String(); hex.EncodeToString(pk) != remote {
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("hex.DecodeString: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if remote := base62.EncodeToString(pks); base62.EncodeToString(pk) != remote {
|
|
||||||
return fmt.Errorf("not allowed to send incoming mail as %s", from)
|
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(
|
m.Header.Add(
|
||||||
"Received", fmt.Sprintf("from Yggmail %s; %s",
|
"Received", fmt.Sprintf("from Yggmail %s; %s",
|
||||||
base62.EncodeToString(s.public),
|
hex.EncodeToString(s.public),
|
||||||
time.Now().String(),
|
time.Now().String(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
iwt "github.com/Arceliar/ironwood/types"
|
iwt "github.com/Arceliar/ironwood/types"
|
||||||
gologme "github.com/gologme/log"
|
gologme "github.com/gologme/log"
|
||||||
"github.com/jxskiss/base62"
|
|
||||||
"github.com/neilalexander/utp"
|
"github.com/neilalexander/utp"
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/config"
|
"github.com/yggdrasil-network/yggdrasil-go/src/config"
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/core"
|
"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) {
|
func (t *YggdrasilTransport) Dial(host string) (net.Conn, error) {
|
||||||
addr := make(iwt.Addr, ed25519.PublicKeySize)
|
addr := make(iwt.Addr, ed25519.PublicKeySize)
|
||||||
k, err := base62.DecodeString(host)
|
k, err := hex.DecodeString(host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,9 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/jxskiss/base62"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const Domain = "yggmail"
|
const Domain = "yggmail"
|
||||||
@@ -25,9 +24,9 @@ func ParseAddress(email string) (ed25519.PublicKey, error) {
|
|||||||
if email[at+1:] != Domain {
|
if email[at+1:] != Domain {
|
||||||
return nil, fmt.Errorf("invalid email domain")
|
return nil, fmt.Errorf("invalid email domain")
|
||||||
}
|
}
|
||||||
pk, err := base62.DecodeString(email[:at])
|
pk, err := hex.DecodeString(email[:at])
|
||||||
if err != nil {
|
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)
|
ed := make(ed25519.PublicKey, ed25519.PublicKeySize)
|
||||||
copy(ed, pk)
|
copy(ed, pk)
|
||||||
|
|||||||
Reference in New Issue
Block a user