mirror of
https://github.com/decke/smtprelay.git
synced 2025-12-25 16:52:29 -07:00
Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed1c3a9888 | ||
|
|
6f3bd16988 | ||
|
|
4e0bf0908d | ||
|
|
6662fb7155 | ||
|
|
076fd65dea | ||
|
|
880c3c365c | ||
|
|
36673ae3f0 | ||
|
|
b42ad6ddc9 | ||
|
|
999ccab778 | ||
|
|
53c2c27647 | ||
|
|
2afbe67407 | ||
|
|
00b96161b3 | ||
|
|
e10cbcdbb0 | ||
|
|
0e643f7230 | ||
|
|
324585c63c | ||
|
|
92cb02e46b | ||
|
|
62fcc11f61 | ||
|
|
bfe8d39bb3 | ||
|
|
cbb6f523c5 | ||
|
|
eb4a6b9eb6 | ||
|
|
45db4ef786 | ||
|
|
946effcbcf | ||
|
|
118d1b88c2 | ||
|
|
5fd6aad9b1 | ||
|
|
21b597f351 | ||
|
|
5f82b4736c | ||
|
|
de430286b3 | ||
|
|
769193ea4d | ||
|
|
0b65e904d8 | ||
|
|
2c9645ac68 | ||
|
|
770e819e2b | ||
|
|
d11f8d81ea | ||
|
|
6270d75571 | ||
|
|
92be537b25 | ||
|
|
b9d1663a18 | ||
|
|
3a96014c70 | ||
|
|
ade7cbca36 | ||
|
|
ab341c697d | ||
|
|
ab850e8765 | ||
|
|
a82b0faf96 | ||
|
|
76a04a2001 | ||
|
|
0df376e54a |
24
.github/workflows/go.yml
vendored
Normal file
24
.github/workflows/go.yml
vendored
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
name: Go
|
||||||
|
on: [push]
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Set up Go 1.14
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: 1.14
|
||||||
|
id: go
|
||||||
|
|
||||||
|
- name: Check out code into the Go module directory
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- name: Get dependencies
|
||||||
|
run: |
|
||||||
|
go get -v -t -d ./...
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: go build -v .
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
# smtp-proxy
|
# smtprelay
|
||||||
|
|
||||||
|
[](https://goreportcard.com/report/github.com/decke/smtprelay)
|
||||||
|
|
||||||
Simple Golang based SMTP relay/proxy server that accepts mail via SMTP
|
Simple Golang based SMTP relay/proxy server that accepts mail via SMTP
|
||||||
and forwards it directly to another SMTP server.
|
and forwards it directly to another SMTP server.
|
||||||
@@ -25,5 +27,5 @@ produces mail.
|
|||||||
* Authentication support with file (LOGIN, PLAIN)
|
* Authentication support with file (LOGIN, PLAIN)
|
||||||
* Enforce encryption for authentication
|
* Enforce encryption for authentication
|
||||||
* Forwards all mail to a smarthost (GMail, MailGun or any other SMTP server)
|
* Forwards all mail to a smarthost (GMail, MailGun or any other SMTP server)
|
||||||
* Small codebase (smtp-proxy ~250 LoC, chrj/smtpd ~1200 LoC)
|
* Small codebase
|
||||||
* IPv6 support
|
* IPv6 support
|
||||||
|
|||||||
67
auth.go
Normal file
67
auth.go
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"errors"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
filename string
|
||||||
|
)
|
||||||
|
|
||||||
|
func AuthLoadFile(file string) error {
|
||||||
|
f, err := os.Open(file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
|
||||||
|
filename = file
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func AuthReady() bool {
|
||||||
|
return (filename != "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func AuthFetch(username string) (string, string, error) {
|
||||||
|
if !AuthReady() {
|
||||||
|
return "", "", errors.New("Authentication file not specified. Call LoadFile() first")
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := os.Open(filename)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(file)
|
||||||
|
for scanner.Scan() {
|
||||||
|
parts := strings.Fields(scanner.Text())
|
||||||
|
|
||||||
|
if len(parts) != 3 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.ToLower(username) == strings.ToLower(parts[0]) {
|
||||||
|
return parts[1], parts[2], nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", "", errors.New("User not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
func AuthCheckPassword(username string, secret string) error {
|
||||||
|
hash, _, err := AuthFetch(username)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if bcrypt.CompareHashAndPassword([]byte(hash), []byte(secret)) == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return errors.New("Password invalid")
|
||||||
|
}
|
||||||
6
cmd/README.md
Normal file
6
cmd/README.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
To run the hasher, do like this
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ go run hasher.go hunter2
|
||||||
|
```
|
||||||
18
cmd/hasher.go
Normal file
18
cmd/hasher.go
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
password := os.Args[1]
|
||||||
|
|
||||||
|
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error generating hash: %s", err)
|
||||||
|
}
|
||||||
|
fmt.Println(string(hash))
|
||||||
|
}
|
||||||
35
config.go
Normal file
35
config.go
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
|
||||||
|
"github.com/vharitonsky/iniflags"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
VERSION = "1.3.0"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
logFile = flag.String("logfile", "/var/log/smtprelay.log", "Path to logfile")
|
||||||
|
hostName = flag.String("hostname", "localhost.localdomain", "Server hostname")
|
||||||
|
welcomeMsg = flag.String("welcome_msg", "", "Welcome message for SMTP session")
|
||||||
|
listen = flag.String("listen", "127.0.0.1:25 [::1]:25", "Address and port to listen for incoming SMTP")
|
||||||
|
localCert = flag.String("local_cert", "", "SSL certificate for STARTTLS/TLS")
|
||||||
|
localKey = flag.String("local_key", "", "SSL private key for STARTTLS/TLS")
|
||||||
|
localForceTLS = flag.Bool("local_forcetls", false, "Force STARTTLS (needs local_cert and local_key)")
|
||||||
|
allowedNets = flag.String("allowed_nets", "127.0.0.1/8 ::1/128", "Networks allowed to send mails")
|
||||||
|
allowedSender = flag.String("allowed_sender", "", "Regular expression for valid FROM EMail adresses")
|
||||||
|
allowedRecipients = flag.String("allowed_recipients", "", "Regular expression for valid TO EMail adresses")
|
||||||
|
allowedUsers = flag.String("allowed_users", "", "Path to file with valid users/passwords")
|
||||||
|
remoteHost = flag.String("remote_host", "smtp.gmail.com:587", "Outgoing SMTP server")
|
||||||
|
remoteUser = flag.String("remote_user", "", "Username for authentication on outgoing SMTP server")
|
||||||
|
remotePass = flag.String("remote_pass", "", "Password for authentication on outgoing SMTP server")
|
||||||
|
remoteAuth = flag.String("remote_auth", "plain", "Auth method on outgoing SMTP server (plain, login)")
|
||||||
|
remoteSender = flag.String("remote_sender", "", "Sender e-mail address on outgoing SMTP server")
|
||||||
|
versionInfo = flag.Bool("version", false, "Show version information")
|
||||||
|
)
|
||||||
|
|
||||||
|
func ConfigLoad() {
|
||||||
|
iniflags.Parse()
|
||||||
|
}
|
||||||
7
go.mod
7
go.mod
@@ -1,6 +1,9 @@
|
|||||||
module code.bluelife.at/decke/smtp-proxy
|
module github.com/decke/smtprelay
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/chrj/smtpd v0.1.2
|
github.com/chrj/smtpd v0.2.0
|
||||||
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de
|
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de
|
||||||
|
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9
|
||||||
)
|
)
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|||||||
11
go.sum
11
go.sum
@@ -1,5 +1,12 @@
|
|||||||
github.com/chrj/smtpd v0.1.2 h1:yWaMOCmnPlcNgJzkak1TBhhkObAfomd+NmZG5epdO88=
|
github.com/chrj/smtpd v0.2.0 h1:QGbE4UQz7sKjvXpRgNLuiBOjcWTzBKu/dj0hyDLpD14=
|
||||||
github.com/chrj/smtpd v0.1.2/go.mod h1:jt4ydELuZmqhn9hn3YpEPV1dY00aOB+Q1nWXnBDFKeY=
|
github.com/chrj/smtpd v0.2.0/go.mod h1:1hmG9KbrE10JG1SmvG79Krh4F6713oUrw2+gRp1oSYk=
|
||||||
github.com/eaigner/dkim v0.0.0-20150301120808-6fe4a7ee9cfb/go.mod h1:FSCIHbrqk7D01Mj8y/jW+NS1uoCerr+ad+IckTHTFf4=
|
github.com/eaigner/dkim v0.0.0-20150301120808-6fe4a7ee9cfb/go.mod h1:FSCIHbrqk7D01Mj8y/jW+NS1uoCerr+ad+IckTHTFf4=
|
||||||
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de h1:fkw+7JkxF3U1GzQoX9h69Wvtvxajo5Rbzy6+YMMzPIg=
|
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de h1:fkw+7JkxF3U1GzQoX9h69Wvtvxajo5Rbzy6+YMMzPIg=
|
||||||
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de/go.mod h1:irMhzlTz8+fVFj6CH2AN2i+WI5S6wWFtK3MBCIxIpyI=
|
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de/go.mod h1:irMhzlTz8+fVFj6CH2AN2i+WI5S6wWFtK3MBCIxIpyI=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM=
|
||||||
|
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
|||||||
138
main.go
138
main.go
@@ -1,9 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
@@ -15,29 +13,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/chrj/smtpd"
|
"github.com/chrj/smtpd"
|
||||||
"github.com/vharitonsky/iniflags"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
VERSION = "1.1.0"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
logFile = flag.String("logfile", "/var/log/smtpd-proxy.log", "Path to logfile")
|
|
||||||
hostName = flag.String("hostname", "localhost.localdomain", "Server hostname")
|
|
||||||
welcomeMsg = flag.String("welcome_msg", "", "Welcome message for SMTP session")
|
|
||||||
listen = flag.String("listen", "127.0.0.1:25 [::1]:25", "Address and port to listen for incoming SMTP")
|
|
||||||
localCert = flag.String("local_cert", "", "SSL certificate for STARTTLS/TLS")
|
|
||||||
localKey = flag.String("local_key", "", "SSL private key for STARTTLS/TLS")
|
|
||||||
localForceTLS = flag.Bool("local_forcetls", false, "Force STARTTLS (needs local_cert and local_key)")
|
|
||||||
allowedNets = flag.String("allowed_nets", "127.0.0.1/8 ::1/128", "Networks allowed to send mails")
|
|
||||||
allowedSender = flag.String("allowed_sender", "", "Regular expression for valid FROM EMail adresses")
|
|
||||||
allowedRecipients = flag.String("allowed_recipients", "", "Regular expression for valid TO EMail adresses")
|
|
||||||
allowedUsers = flag.String("allowed_users", "", "Path to file with valid users/passwords")
|
|
||||||
remoteHost = flag.String("remote_host", "smtp.gmail.com:587", "Outgoing SMTP server")
|
|
||||||
remoteUser = flag.String("remote_user", "", "Username for authentication on outgoing SMTP server")
|
|
||||||
remotePass = flag.String("remote_pass", "", "Password for authentication on outgoing SMTP server")
|
|
||||||
versionInfo= flag.Bool("version", false, "Show version information")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func connectionChecker(peer smtpd.Peer) error {
|
func connectionChecker(peer smtpd.Peer) error {
|
||||||
@@ -50,7 +25,7 @@ func connectionChecker(peer smtpd.Peer) error {
|
|||||||
|
|
||||||
nets := strings.Split(*allowedNets, " ")
|
nets := strings.Split(*allowedNets, " ")
|
||||||
|
|
||||||
for i := range(nets) {
|
for i := range nets {
|
||||||
_, allowedNet, _ := net.ParseCIDR(nets[i])
|
_, allowedNet, _ := net.ParseCIDR(nets[i])
|
||||||
|
|
||||||
if allowedNet.Contains(peerIP) {
|
if allowedNet.Contains(peerIP) {
|
||||||
@@ -62,6 +37,18 @@ func connectionChecker(peer smtpd.Peer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func senderChecker(peer smtpd.Peer, addr string) error {
|
func senderChecker(peer smtpd.Peer, addr string) error {
|
||||||
|
// check sender address from auth file if user is authenticated
|
||||||
|
if *allowedUsers != "" && peer.Username != "" {
|
||||||
|
_, email, err := AuthFetch(peer.Username)
|
||||||
|
if err != nil {
|
||||||
|
return smtpd.Error{Code: 451, Message: "Bad sender address"}
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.ToLower(addr) != strings.ToLower(email) {
|
||||||
|
return smtpd.Error{Code: 451, Message: "Bad sender address"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if *allowedSender == "" {
|
if *allowedSender == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -98,34 +85,15 @@ func recipientChecker(peer smtpd.Peer, addr string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func authChecker(peer smtpd.Peer, username string, password string) error {
|
func authChecker(peer smtpd.Peer, username string, password string) error {
|
||||||
file, err := os.Open(*allowedUsers)
|
err := AuthCheckPassword(username, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("User file not found %v", err)
|
log.Printf("Auth error: %v\n", err)
|
||||||
return smtpd.Error{Code: 535, Message: "Authentication credentials invalid"}
|
return smtpd.Error{Code: 535, Message: "Authentication credentials invalid"}
|
||||||
}
|
}
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
scanner := bufio.NewScanner(file)
|
|
||||||
for scanner.Scan() {
|
|
||||||
parts := strings.Fields(scanner.Text())
|
|
||||||
|
|
||||||
if len(parts) != 2 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if username == parts[0] && password == parts[1] {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return smtpd.Error{Code: 535, Message: "Authentication credentials invalid"}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func mailHandler(peer smtpd.Peer, env smtpd.Envelope) error {
|
func mailHandler(peer smtpd.Peer, env smtpd.Envelope) error {
|
||||||
if *allowedUsers != "" && peer.Username == "" {
|
|
||||||
return smtpd.Error{Code: 530, Message: "Authentication Required"}
|
|
||||||
}
|
|
||||||
|
|
||||||
peerIP := ""
|
peerIP := ""
|
||||||
if addr, ok := peer.Addr.(*net.TCPAddr); ok {
|
if addr, ok := peer.Addr.(*net.TCPAddr); ok {
|
||||||
peerIP = addr.IP.String()
|
peerIP = addr.IP.String()
|
||||||
@@ -138,22 +106,37 @@ func mailHandler(peer smtpd.Peer, env smtpd.Envelope) error {
|
|||||||
host, _, _ := net.SplitHostPort(*remoteHost)
|
host, _, _ := net.SplitHostPort(*remoteHost)
|
||||||
|
|
||||||
if *remoteUser != "" && *remotePass != "" {
|
if *remoteUser != "" && *remotePass != "" {
|
||||||
|
switch *remoteAuth {
|
||||||
|
case "plain":
|
||||||
auth = smtp.PlainAuth("", *remoteUser, *remotePass, host)
|
auth = smtp.PlainAuth("", *remoteUser, *remotePass, host)
|
||||||
|
case "login":
|
||||||
|
auth = LoginAuth(*remoteUser, *remotePass)
|
||||||
|
default:
|
||||||
|
return smtpd.Error{Code: 530, Message: "Authentication method not supported"}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
env.AddReceivedLine(peer)
|
env.AddReceivedLine(peer)
|
||||||
|
|
||||||
log.Printf("delivering using smarthost %s\n", *remoteHost)
|
log.Printf("delivering using smarthost %s\n", *remoteHost)
|
||||||
|
|
||||||
|
var sender string
|
||||||
|
|
||||||
|
if *remoteSender == "" {
|
||||||
|
sender = env.Sender
|
||||||
|
} else {
|
||||||
|
sender = *remoteSender
|
||||||
|
}
|
||||||
|
|
||||||
err := SendMail(
|
err := SendMail(
|
||||||
*remoteHost,
|
*remoteHost,
|
||||||
auth,
|
auth,
|
||||||
env.Sender,
|
sender,
|
||||||
env.Recipients,
|
env.Recipients,
|
||||||
env.Data,
|
env.Data,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("delivery failed: %v\n", err);
|
log.Printf("delivery failed: %v\n", err)
|
||||||
return smtpd.Error{Code: 554, Message: "Forwarding failed"}
|
return smtpd.Error{Code: 554, Message: "Forwarding failed"}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,16 +146,40 @@ func mailHandler(peer smtpd.Peer, env smtpd.Envelope) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// Ciphersuites as defined in stock Go but without 3DES and RC4
|
||||||
|
// https://golang.org/src/crypto/tls/cipher_suites.go
|
||||||
|
var tlsCipherSuites = []uint16{
|
||||||
|
tls.TLS_AES_128_GCM_SHA256,
|
||||||
|
tls.TLS_AES_256_GCM_SHA384,
|
||||||
|
tls.TLS_CHACHA20_POLY1305_SHA256,
|
||||||
|
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
|
||||||
|
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
|
||||||
|
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
||||||
|
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
||||||
|
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
|
||||||
|
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
||||||
|
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
|
||||||
|
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
|
||||||
|
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
|
||||||
|
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
|
||||||
|
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
|
||||||
|
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
|
||||||
|
tls.TLS_RSA_WITH_AES_128_GCM_SHA256, // does not provide PFS
|
||||||
|
tls.TLS_RSA_WITH_AES_256_GCM_SHA384, // does not provide PFS
|
||||||
|
tls.TLS_RSA_WITH_AES_128_CBC_SHA256,
|
||||||
|
tls.TLS_RSA_WITH_AES_128_CBC_SHA,
|
||||||
|
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
|
||||||
|
}
|
||||||
|
|
||||||
iniflags.Parse()
|
ConfigLoad()
|
||||||
|
|
||||||
if *versionInfo {
|
if *versionInfo {
|
||||||
fmt.Printf("smtpd-proxy/%s\n", VERSION)
|
fmt.Printf("smtprelay/%s\n", VERSION)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
if *logFile != "" {
|
if *logFile != "" {
|
||||||
f, err := os.OpenFile(*logFile, os.O_WRONLY | os.O_CREATE | os.O_APPEND, 0600)
|
f, err := os.OpenFile(*logFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error opening logfile: %v", err)
|
log.Fatalf("Error opening logfile: %v", err)
|
||||||
}
|
}
|
||||||
@@ -183,7 +190,7 @@ func main() {
|
|||||||
|
|
||||||
listeners := strings.Split(*listen, " ")
|
listeners := strings.Split(*listen, " ")
|
||||||
|
|
||||||
for i := range(listeners) {
|
for i := range listeners {
|
||||||
listener := listeners[i]
|
listener := listeners[i]
|
||||||
|
|
||||||
server := &smtpd.Server{
|
server := &smtpd.Server{
|
||||||
@@ -196,6 +203,11 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if *allowedUsers != "" {
|
if *allowedUsers != "" {
|
||||||
|
err := AuthLoadFile(*allowedUsers)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Authentication file: %s\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
server.Authenticator = authChecker
|
server.Authenticator = authChecker
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,13 +226,19 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
server.TLSConfig = &tls.Config {
|
server.TLSConfig = &tls.Config{
|
||||||
Certificates: [] tls.Certificate{cert},
|
PreferServerCipherSuites: true,
|
||||||
|
MinVersion: tls.VersionTLS11,
|
||||||
|
CipherSuites: tlsCipherSuites,
|
||||||
|
Certificates: []tls.Certificate{cert},
|
||||||
}
|
}
|
||||||
server.ForceTLS = *localForceTLS
|
server.ForceTLS = *localForceTLS
|
||||||
|
|
||||||
log.Printf("Listen on %s (STARTSSL) ...\n", listener)
|
log.Printf("Listen on %s (STARTSSL) ...\n", listener)
|
||||||
lsnr, err := net.Listen("tcp", listener)
|
lsnr, err := net.Listen("tcp", listener)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
defer lsnr.Close()
|
defer lsnr.Close()
|
||||||
|
|
||||||
go server.Serve(lsnr)
|
go server.Serve(lsnr)
|
||||||
@@ -237,12 +255,18 @@ func main() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
server.TLSConfig = &tls.Config {
|
server.TLSConfig = &tls.Config{
|
||||||
Certificates: [] tls.Certificate{cert},
|
PreferServerCipherSuites: true,
|
||||||
|
MinVersion: tls.VersionTLS11,
|
||||||
|
CipherSuites: tlsCipherSuites,
|
||||||
|
Certificates: []tls.Certificate{cert},
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("Listen on %s (TLS) ...\n", listener)
|
log.Printf("Listen on %s (TLS) ...\n", listener)
|
||||||
lsnr, err := tls.Listen("tcp", listener, server.TLSConfig)
|
lsnr, err := tls.Listen("tcp", listener, server.TLSConfig)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
defer lsnr.Close()
|
defer lsnr.Close()
|
||||||
|
|
||||||
go server.Serve(lsnr)
|
go server.Serve(lsnr)
|
||||||
|
|||||||
34
scripts/release.sh
Executable file
34
scripts/release.sh
Executable file
@@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
PROJECT=smtprelay
|
||||||
|
VERSION=1.3.0
|
||||||
|
|
||||||
|
for goos in freebsd linux windows
|
||||||
|
do
|
||||||
|
for goarch in 386 amd64
|
||||||
|
do
|
||||||
|
export GOOS=${goos}
|
||||||
|
export GOARCH=${goarch}
|
||||||
|
|
||||||
|
RELDIR=${PROJECT}-${VERSION}-${GOOS}-${GOARCH}
|
||||||
|
|
||||||
|
rm -rf ${RELDIR}
|
||||||
|
mkdir ${RELDIR} || exit 1
|
||||||
|
cp -p README.md LICENSE ${PROJECT}.ini ${RELDIR}/ || exit 1
|
||||||
|
|
||||||
|
if [ ${GOOS} = "windows" ]; then
|
||||||
|
BINARY=${PROJECT}.exe
|
||||||
|
sed -I '' -e 's/;logfile =.*/logfile =/g' ${RELDIR}/${PROJECT}.ini
|
||||||
|
sed -I '' -e 's/$/^M/' ${RELDIR}/${PROJECT}.ini
|
||||||
|
else
|
||||||
|
BINARY=${PROJECT}
|
||||||
|
fi
|
||||||
|
|
||||||
|
go build -ldflags="-s -w" -o ${RELDIR}/${BINARY} || exit 1
|
||||||
|
|
||||||
|
chown -R root:wheel ${RELDIR} || exit 1
|
||||||
|
tar cvfJ ${RELDIR}.tar.xz ${RELDIR} || exit 1
|
||||||
|
rm -rf ${RELDIR}
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
29
smtp.go
29
smtp.go
@@ -67,7 +67,7 @@ func NewClient(conn net.Conn, host string) (*Client, error) {
|
|||||||
text.Close()
|
text.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c := &Client{Text: text, conn: conn, serverName: host, localName: "localhost"}
|
c := &Client{Text: text, conn: conn, serverName: host, localName: *hostName}
|
||||||
_, c.tls = conn.(*tls.Conn)
|
_, c.tls = conn.(*tls.Conn)
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
@@ -451,3 +451,30 @@ func validateLine(line string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LOGIN authentication
|
||||||
|
type loginAuth struct {
|
||||||
|
username, password string
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoginAuth(username, password string) smtp.Auth {
|
||||||
|
return &loginAuth{username, password}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *loginAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {
|
||||||
|
return "LOGIN", []byte{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *loginAuth) Next(fromServer []byte, more bool) ([]byte, error) {
|
||||||
|
if more {
|
||||||
|
switch string(fromServer) {
|
||||||
|
case "Username:":
|
||||||
|
return []byte(a.username), nil
|
||||||
|
case "Password:":
|
||||||
|
return []byte(a.password), nil
|
||||||
|
default:
|
||||||
|
return nil, errors.New("Unknown fromServer")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
; smtp-proxy configuration
|
; smtprelay configuration
|
||||||
|
|
||||||
; Logfile
|
; Logfile
|
||||||
;logfile = /var/log/smtpd-proxy.log
|
;logfile = /var/log/smtprelay.log
|
||||||
|
|
||||||
; Hostname for this SMTP server
|
; Hostname for this SMTP server
|
||||||
;hostname = "localhost.localdomain"
|
;hostname = "localhost.localdomain"
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
; File which contains username and password used for
|
; File which contains username and password used for
|
||||||
; authentication before they can send mail.
|
; authentication before they can send mail.
|
||||||
; File format: username password
|
; File format: username bcrypt-hash email
|
||||||
;allowed_users =
|
;allowed_users =
|
||||||
|
|
||||||
; Relay all mails to this SMTP server
|
; Relay all mails to this SMTP server
|
||||||
@@ -54,3 +54,10 @@
|
|||||||
; Authentication credentials on outgoing SMTP server
|
; Authentication credentials on outgoing SMTP server
|
||||||
;remote_user =
|
;remote_user =
|
||||||
;remote_pass =
|
;remote_pass =
|
||||||
|
|
||||||
|
; Authentication method on outgoing SMTP server
|
||||||
|
; (plain, login)
|
||||||
|
;remote_auth = plain
|
||||||
|
|
||||||
|
; Sender e-mail address on outgoing SMTP server
|
||||||
|
;remote_sender =
|
||||||
Reference in New Issue
Block a user