mirror of
https://github.com/decke/smtprelay.git
synced 2025-12-25 16:12:28 -07:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21b597f351 | ||
|
|
5f82b4736c | ||
|
|
de430286b3 | ||
|
|
769193ea4d | ||
|
|
0b65e904d8 | ||
|
|
2c9645ac68 | ||
|
|
770e819e2b | ||
|
|
d11f8d81ea | ||
|
|
6270d75571 |
8
.drone.yml
Normal file
8
.drone.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
kind: pipeline
|
||||
name: default
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: golang
|
||||
commands:
|
||||
- go build
|
||||
3
auth.go
3
auth.go
@@ -29,7 +29,7 @@ func AuthReady() bool {
|
||||
}
|
||||
|
||||
func AuthFetch(username string) (string, string, error) {
|
||||
if ! AuthReady() {
|
||||
if !AuthReady() {
|
||||
return "", "", errors.New("Authentication file not specified. Call LoadFile() first")
|
||||
}
|
||||
|
||||
@@ -65,4 +65,3 @@ func AuthCheckPassword(username string, secret string) error {
|
||||
}
|
||||
return errors.New("Password invalid")
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
VERSION = "1.2.0"
|
||||
VERSION = "1.3.0"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -25,7 +25,8 @@ var (
|
||||
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")
|
||||
remoteSender = flag.String("remote_sender", "", "Sender e-mail address on outgoing SMTP server")
|
||||
versionInfo = flag.Bool("version", false, "Show version information")
|
||||
)
|
||||
|
||||
func ConfigLoad() {
|
||||
|
||||
4
go.mod
4
go.mod
@@ -3,5 +3,7 @@ module code.bluelife.at/decke/smtprelay
|
||||
require (
|
||||
github.com/chrj/smtpd v0.1.2
|
||||
github.com/vharitonsky/iniflags v0.0.0-20180513140207-a33cd0b5f3de
|
||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9
|
||||
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472
|
||||
)
|
||||
|
||||
go 1.13
|
||||
|
||||
9
go.sum
9
go.sum
@@ -3,5 +3,10 @@ github.com/chrj/smtpd v0.1.2/go.mod h1:jt4ydELuZmqhn9hn3YpEPV1dY00aOB+Q1nWXnBDFK
|
||||
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/go.mod h1:irMhzlTz8+fVFj6CH2AN2i+WI5S6wWFtK3MBCIxIpyI=
|
||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9 h1:mKdxBk7AujPs8kU4m80U72y/zjbZ3UcXC7dClwKbUI0=
|
||||
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 h1:Gv7RPwsi3eZ2Fgewe3CBsuOebPwO27PoXzRpJPsvSSM=
|
||||
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
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=
|
||||
|
||||
80
main.go
80
main.go
@@ -25,7 +25,7 @@ func connectionChecker(peer smtpd.Peer) error {
|
||||
|
||||
nets := strings.Split(*allowedNets, " ")
|
||||
|
||||
for i := range(nets) {
|
||||
for i := range nets {
|
||||
_, allowedNet, _ := net.ParseCIDR(nets[i])
|
||||
|
||||
if allowedNet.Contains(peerIP) {
|
||||
@@ -117,15 +117,23 @@ func mailHandler(peer smtpd.Peer, env smtpd.Envelope) error {
|
||||
|
||||
log.Printf("delivering using smarthost %s\n", *remoteHost)
|
||||
|
||||
var sender string
|
||||
|
||||
if *remoteSender == "" {
|
||||
sender = env.Sender
|
||||
} else {
|
||||
sender = *remoteSender
|
||||
}
|
||||
|
||||
err := SendMail(
|
||||
*remoteHost,
|
||||
auth,
|
||||
env.Sender,
|
||||
sender,
|
||||
env.Recipients,
|
||||
env.Data,
|
||||
)
|
||||
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"}
|
||||
}
|
||||
|
||||
@@ -144,7 +152,7 @@ func main() {
|
||||
}
|
||||
|
||||
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 {
|
||||
log.Fatalf("Error opening logfile: %v", err)
|
||||
}
|
||||
@@ -155,7 +163,7 @@ func main() {
|
||||
|
||||
listeners := strings.Split(*listen, " ")
|
||||
|
||||
for i := range(listeners) {
|
||||
for i := range listeners {
|
||||
listener := listeners[i]
|
||||
|
||||
server := &smtpd.Server{
|
||||
@@ -191,13 +199,40 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
server.TLSConfig = &tls.Config {
|
||||
Certificates: [] tls.Certificate{cert},
|
||||
server.TLSConfig = &tls.Config{
|
||||
PreferServerCipherSuites: true,
|
||||
MinVersion: tls.VersionTLS11,
|
||||
|
||||
// Ciphersuites as defined in stock Go but without 3DES
|
||||
// https://golang.org/src/crypto/tls/cipher_suites.go
|
||||
CipherSuites: []uint16{
|
||||
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
|
||||
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
|
||||
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,
|
||||
},
|
||||
Certificates: []tls.Certificate{cert},
|
||||
}
|
||||
server.ForceTLS = *localForceTLS
|
||||
|
||||
log.Printf("Listen on %s (STARTSSL) ...\n", listener)
|
||||
lsnr, err := net.Listen("tcp", listener)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer lsnr.Close()
|
||||
|
||||
go server.Serve(lsnr)
|
||||
@@ -214,12 +249,39 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
server.TLSConfig = &tls.Config {
|
||||
Certificates: [] tls.Certificate{cert},
|
||||
server.TLSConfig = &tls.Config{
|
||||
PreferServerCipherSuites: true,
|
||||
MinVersion: tls.VersionTLS11,
|
||||
|
||||
// Ciphersuites as defined in stock Go but without 3DES
|
||||
// https://golang.org/src/crypto/tls/cipher_suites.go
|
||||
CipherSuites: []uint16{
|
||||
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
|
||||
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
|
||||
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,
|
||||
},
|
||||
Certificates: []tls.Certificate{cert},
|
||||
}
|
||||
|
||||
log.Printf("Listen on %s (TLS) ...\n", listener)
|
||||
lsnr, err := tls.Listen("tcp", listener, server.TLSConfig)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer lsnr.Close()
|
||||
|
||||
go server.Serve(lsnr)
|
||||
|
||||
@@ -54,3 +54,6 @@
|
||||
; Authentication credentials on outgoing SMTP server
|
||||
;remote_user =
|
||||
;remote_pass =
|
||||
|
||||
; Sender e-mail address on outgoing SMTP server
|
||||
;remote_sender =
|
||||
|
||||
Reference in New Issue
Block a user