mirror of
https://github.com/decke/smtprelay.git
synced 2026-05-10 01:14:23 -06:00
Compare commits
5 Commits
50b1fff623
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49c00bf7d8 | ||
|
|
8dcd6c8067 | ||
|
|
d634a89b14 | ||
|
|
85a9c49471 | ||
|
|
808b662e01 |
8
.github/workflows/codeql-analysis.yml
vendored
8
.github/workflows/codeql-analysis.yml
vendored
@@ -38,7 +38,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
|
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ jobs:
|
|||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
uses: github/codeql-action/init@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
|
uses: github/codeql-action/init@68bde559dea0fdcac2102bfdf6230c5f70eb485e # v4.35.4
|
||||||
with:
|
with:
|
||||||
languages: ${{ matrix.language }}
|
languages: ${{ matrix.language }}
|
||||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||||
@@ -58,7 +58,7 @@ jobs:
|
|||||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||||
# If this step fails, then you should remove it and run the build manually (see below)
|
# If this step fails, then you should remove it and run the build manually (see below)
|
||||||
- name: Autobuild
|
- name: Autobuild
|
||||||
uses: github/codeql-action/autobuild@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
|
uses: github/codeql-action/autobuild@68bde559dea0fdcac2102bfdf6230c5f70eb485e # v4.35.4
|
||||||
|
|
||||||
# ℹ️ Command-line programs to run using the OS shell.
|
# ℹ️ Command-line programs to run using the OS shell.
|
||||||
# 📚 https://git.io/JvXDl
|
# 📚 https://git.io/JvXDl
|
||||||
@@ -72,4 +72,4 @@ jobs:
|
|||||||
# make release
|
# make release
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Perform CodeQL Analysis
|
||||||
uses: github/codeql-action/analyze@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
|
uses: github/codeql-action/analyze@68bde559dea0fdcac2102bfdf6230c5f70eb485e # v4.35.4
|
||||||
|
|||||||
2
.github/workflows/dependency-review.yml
vendored
2
.github/workflows/dependency-review.yml
vendored
@@ -17,7 +17,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
|
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
2
.github/workflows/go.yml
vendored
2
.github/workflows/go.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
|
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
2
.github/workflows/release.yaml
vendored
2
.github/workflows/release.yaml
vendored
@@ -27,7 +27,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
|
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
|
|||||||
4
.github/workflows/scorecards.yml
vendored
4
.github/workflows/scorecards.yml
vendored
@@ -36,7 +36,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Harden Runner
|
- name: Harden Runner
|
||||||
uses: step-security/harden-runner@8d3c67de8e2fe68ef647c8db1e6a09f647780f40 # v2.19.0
|
uses: step-security/harden-runner@a5ad31d6a139d249332a2605b85202e8c0b78450 # v2.19.1
|
||||||
with:
|
with:
|
||||||
egress-policy: audit
|
egress-policy: audit
|
||||||
|
|
||||||
@@ -76,6 +76,6 @@ jobs:
|
|||||||
|
|
||||||
# Upload the results to GitHub's code scanning dashboard.
|
# Upload the results to GitHub's code scanning dashboard.
|
||||||
- name: "Upload to code-scanning"
|
- name: "Upload to code-scanning"
|
||||||
uses: github/codeql-action/upload-sarif@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
|
uses: github/codeql-action/upload-sarif@68bde559dea0fdcac2102bfdf6230c5f70eb485e # v4.35.4
|
||||||
with:
|
with:
|
||||||
sarif_file: results.sarif
|
sarif_file: results.sarif
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ var (
|
|||||||
listenStr = flagset.String("listen", "127.0.0.1:25 [::1]:25", "Address and port to listen for incoming SMTP")
|
listenStr = flagset.String("listen", "127.0.0.1:25 [::1]:25", "Address and port to listen for incoming SMTP")
|
||||||
localCert = flagset.String("local_cert", "", "SSL certificate for STARTTLS/TLS")
|
localCert = flagset.String("local_cert", "", "SSL certificate for STARTTLS/TLS")
|
||||||
localKey = flagset.String("local_key", "", "SSL private key for STARTTLS/TLS")
|
localKey = flagset.String("local_key", "", "SSL private key for STARTTLS/TLS")
|
||||||
|
tlsProfile = flagset.String("tls_profile", "default", "TLS profile: modern | intermediate | default | legacy")
|
||||||
localForceTLS = flagset.Bool("local_forcetls", false, "Force STARTTLS (needs local_cert and local_key)")
|
localForceTLS = flagset.Bool("local_forcetls", false, "Force STARTTLS (needs local_cert and local_key)")
|
||||||
readTimeoutStr = flagset.String("read_timeout", "60s", "Socket timeout for read operations")
|
readTimeoutStr = flagset.String("read_timeout", "60s", "Socket timeout for read operations")
|
||||||
writeTimeoutStr = flagset.String("write_timeout", "60s", "Socket timeout for write operations")
|
writeTimeoutStr = flagset.String("write_timeout", "60s", "Socket timeout for write operations")
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module github.com/decke/smtprelay
|
|||||||
require (
|
require (
|
||||||
github.com/DeRuina/timberjack v1.4.2
|
github.com/DeRuina/timberjack v1.4.2
|
||||||
github.com/chrj/smtpd v1.0.0
|
github.com/chrj/smtpd v1.0.0
|
||||||
github.com/fsnotify/fsnotify v1.10.0
|
github.com/fsnotify/fsnotify v1.10.1
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
github.com/peterbourgon/ff/v3 v3.4.0
|
github.com/peterbourgon/ff/v3 v3.4.0
|
||||||
github.com/rs/zerolog v1.35.1
|
github.com/rs/zerolog v1.35.1
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -6,8 +6,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
|
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
|
||||||
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
|
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
|
||||||
github.com/fsnotify/fsnotify v1.10.0 h1:Xx/5Ydg9CeBDX/wi4VJqStNtohYjitZhhlHt4h3St1M=
|
github.com/fsnotify/fsnotify v1.10.1 h1:b0/UzAf9yR5rhf3RPm9gf3ehBPpf0oZKIjtpKrx59Ho=
|
||||||
github.com/fsnotify/fsnotify v1.10.0/go.mod h1:TLheqan6HD6GBK6PrDWyDPBaEV8LspOxvPSjC+bVfgo=
|
github.com/fsnotify/fsnotify v1.10.1/go.mod h1:TLheqan6HD6GBK6PrDWyDPBaEV8LspOxvPSjC+bVfgo=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/klauspost/compress v1.18.4 h1:RPhnKRAQ4Fh8zU2FY/6ZFDwTVTxgJ/EMydqSTzE9a2c=
|
github.com/klauspost/compress v1.18.4 h1:RPhnKRAQ4Fh8zU2FY/6ZFDwTVTxgJ/EMydqSTzE9a2c=
|
||||||
|
|||||||
54
main.go
54
main.go
@@ -281,6 +281,7 @@ func generateUUID() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getTLSConfig() *tls.Config {
|
func getTLSConfig() *tls.Config {
|
||||||
|
// Certificate loading / validation
|
||||||
if *localCert == "" || *localKey == "" {
|
if *localCert == "" || *localKey == "" {
|
||||||
log.Fatal().
|
log.Fatal().
|
||||||
Str("cert_file", *localCert).
|
Str("cert_file", *localCert).
|
||||||
@@ -295,9 +296,60 @@ func getTLSConfig() *tls.Config {
|
|||||||
Msg("cannot load X509 keypair")
|
Msg("cannot load X509 keypair")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &tls.Config{
|
// TLS profile configuration
|
||||||
|
// tls.Config.CipherSuites only affects TLS 1.0–1.2.
|
||||||
|
|
||||||
|
// Base config: Go defaults unless overridden.
|
||||||
|
conf := &tls.Config{
|
||||||
Certificates: []tls.Certificate{cert},
|
Certificates: []tls.Certificate{cert},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
profile := strings.ToLower(strings.TrimSpace(*tlsProfile))
|
||||||
|
if profile == "" {
|
||||||
|
profile = "default"
|
||||||
|
}
|
||||||
|
|
||||||
|
switch profile {
|
||||||
|
case "default":
|
||||||
|
// Go defaults (leave MinVersion/MaxVersion/CipherSuites unset).
|
||||||
|
|
||||||
|
case "modern":
|
||||||
|
// TLS 1.3+.
|
||||||
|
conf.MinVersion = tls.VersionTLS13
|
||||||
|
|
||||||
|
case "intermediate":
|
||||||
|
// TLS 1.2+ with AEAD + ECDHE cipher suites only.
|
||||||
|
// Mozilla "intermediate" — AEAD + ECDHE only.
|
||||||
|
conf.MinVersion = tls.VersionTLS12
|
||||||
|
conf.CipherSuites = []uint16{
|
||||||
|
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
|
||||||
|
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
|
||||||
|
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
|
||||||
|
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
|
||||||
|
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256,
|
||||||
|
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
|
||||||
|
}
|
||||||
|
|
||||||
|
case "legacy":
|
||||||
|
// Last resort: TLS 1.0+ and everything Go exposes for TLS 1.0–1.2.
|
||||||
|
conf.MinVersion = tls.VersionTLS10
|
||||||
|
|
||||||
|
allSuites := []uint16{}
|
||||||
|
for _, cs := range tls.CipherSuites() {
|
||||||
|
allSuites = append(allSuites, cs.ID)
|
||||||
|
}
|
||||||
|
for _, cs := range tls.InsecureCipherSuites() {
|
||||||
|
allSuites = append(allSuites, cs.ID)
|
||||||
|
}
|
||||||
|
conf.CipherSuites = allSuites
|
||||||
|
|
||||||
|
default:
|
||||||
|
log.Warn().
|
||||||
|
Str("tls_profile", profile).
|
||||||
|
Msg("unknown tls_profile; using default")
|
||||||
|
}
|
||||||
|
|
||||||
|
return conf
|
||||||
}
|
}
|
||||||
|
|
||||||
func watchAliasFile() {
|
func watchAliasFile() {
|
||||||
|
|||||||
@@ -35,6 +35,33 @@
|
|||||||
;local_cert = smtpd.pem
|
;local_cert = smtpd.pem
|
||||||
;local_key = smtpd.key
|
;local_key = smtpd.key
|
||||||
|
|
||||||
|
; TLS PROFILE (STARTTLS / TLS listeners)
|
||||||
|
; Controls the minimum TLS version and allowed cipher suites for inbound
|
||||||
|
; connections when using listen protocols `starttls://` or `tls://`.
|
||||||
|
; Profiles follow the Mozilla SSL Configuration Generator guidelines.
|
||||||
|
;
|
||||||
|
; default
|
||||||
|
; Go standard library defaults. Tracks improvements as Go updates
|
||||||
|
; its TLS defaults. Recommended for most deployments.
|
||||||
|
;
|
||||||
|
; modern
|
||||||
|
; TLS 1.3+ only. Simplest and most secure, but rejects any client
|
||||||
|
; that cannot negotiate TLS 1.3.
|
||||||
|
; Matches Mozilla "modern" configuration.
|
||||||
|
;
|
||||||
|
; intermediate
|
||||||
|
; TLS 1.2+. For TLS 1.2 connections only AEAD ciphers (AES-GCM,
|
||||||
|
; ChaCha20-Poly1305) with ECDHE key exchange are allowed,
|
||||||
|
; providing forward secrecy. TLS 1.3 ciphers are always available.
|
||||||
|
; Matches Mozilla "intermediate" configuration.
|
||||||
|
;
|
||||||
|
; legacy
|
||||||
|
; TLS 1.0+ with all cipher suites the Go standard library supports,
|
||||||
|
; including insecure ones (RC4, 3DES). Use only when you must
|
||||||
|
; support very old clients that cannot negotiate TLS 1.2.
|
||||||
|
;
|
||||||
|
;tls_profile=default
|
||||||
|
|
||||||
; Enforce encrypted connection on STARTTLS ports before
|
; Enforce encrypted connection on STARTTLS ports before
|
||||||
; accepting mails from client.
|
; accepting mails from client.
|
||||||
;local_forcetls = false
|
;local_forcetls = false
|
||||||
|
|||||||
Reference in New Issue
Block a user