From fab4cfc2a4e12c15e5bf8feaa89a9b219c220b05 Mon Sep 17 00:00:00 2001 From: reservoir-cmyk Date: Tue, 1 Dec 2026 07:20:16 +0900 Subject: [PATCH 1/3] config/tls: add X25519MLKEM768 to curves directive --- framework/config/tls/general.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/framework/config/tls/general.go b/framework/config/tls/general.go index a3fd95368..bc044ecf6 100644 --- a/framework/config/tls/general.go +++ b/framework/config/tls/general.go @@ -60,10 +60,11 @@ var strCiphersMap = map[string]uint16{ } var strCurvesMap = map[string]tls.CurveID{ - "p256": tls.CurveP256, - "p384": tls.CurveP384, - "p521": tls.CurveP521, - "X25519": tls.X25519, + "p256": tls.CurveP256, + "p384": tls.CurveP384, + "p521": tls.CurveP521, + "X25519": tls.X25519, + "X25519MLKEM768": tls.X25519MLKEM768, } // TLSversionsDirective parses directive with arguments that specify From 11e92a5165b33658a53b982cf5cb6544bc52a89f Mon Sep 17 00:00:00 2001 From: reservoir-cmyk Date: Tue, 1 Dec 2026 07:21:58 +0900 Subject: [PATCH 2/3] config/tls: add tests for TLSCurvesDirective --- framework/config/tls/general_test.go | 109 +++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 framework/config/tls/general_test.go diff --git a/framework/config/tls/general_test.go b/framework/config/tls/general_test.go new file mode 100644 index 000000000..dcbd17d70 --- /dev/null +++ b/framework/config/tls/general_test.go @@ -0,0 +1,109 @@ +/* +Maddy Mail Server - Composable all-in-one email server. +Copyright © 2019-2020 Max Mazurov , Maddy Mail Server contributors + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +package tls + +import ( + "crypto/tls" + "reflect" + "strings" + "testing" + + "github.com/foxcpp/maddy/framework/config" +) + +func parseCurves(t *testing.T, args ...string) []tls.CurveID { + t.Helper() + + v, err := TLSCurvesDirective(nil, config.Node{Name: "curves", Args: args}) + if err != nil { + t.Fatalf("TLSCurvesDirective(%v) failed: %v", args, err) + } + curves, ok := v.([]tls.CurveID) + if !ok { + t.Fatalf("TLSCurvesDirective(%v) returned %T, want []tls.CurveID", args, v) + } + return curves +} + +func TestTLSCurvesDirectiveNames(t *testing.T) { + cases := []struct { + name string + want tls.CurveID + }{ + {"p256", tls.CurveP256}, + {"p384", tls.CurveP384}, + {"p521", tls.CurveP521}, + {"X25519", tls.X25519}, + {"X25519MLKEM768", tls.X25519MLKEM768}, + } + for _, tc := range cases { + got := parseCurves(t, tc.name) + if !reflect.DeepEqual(got, []tls.CurveID{tc.want}) { + t.Errorf("curves %s: got %v, want [%v]", tc.name, got, tc.want) + } + } +} + +func TestTLSCurvesDirectiveMLKEMHybrid(t *testing.T) { + // A user who pins curves explicitly replaces whatever CurvePreferences + // crypto/tls would have used by default. Where those defaults include + // the X25519MLKEM768 hybrid group — as the standard library defaults + // do on Go 1.24 and later, subject to GODEBUG settings — a pinned list + // without the hybrid silently drops it. The directive must offer a way + // to keep the hybrid in the pinned list, in the specified order. + got := parseCurves(t, "X25519MLKEM768", "X25519") + want := []tls.CurveID{tls.X25519MLKEM768, tls.X25519} + if !reflect.DeepEqual(got, want) { + t.Errorf("got %v, want %v", got, want) + } +} + +func TestTLSCurvesDirectiveDuplicates(t *testing.T) { + // Duplicate names are kept as specified: the directive does not + // deduplicate, so the resulting list mirrors the configuration. + got := parseCurves(t, "X25519", "X25519") + want := []tls.CurveID{tls.X25519, tls.X25519} + if !reflect.DeepEqual(got, want) { + t.Errorf("got %v, want %v", got, want) + } +} + +func TestTLSCurvesDirectiveUnknown(t *testing.T) { + for _, args := range [][]string{ + {"p999"}, + {"X25519", "bogus"}, + {"x25519mlkem768"}, // names are matched exactly, as with X25519 + {""}, // an empty name is not a curve either + } { + _, err := TLSCurvesDirective(nil, config.Node{Name: "curves", Args: args}) + if err == nil { + t.Errorf("curves %v: expected error, got none", args) + continue + } + if !strings.Contains(err.Error(), "unknown curve") { + t.Errorf("curves %v: error %q does not mention %q", args, err, "unknown curve") + } + } +} + +func TestTLSCurvesDirectiveNoArgs(t *testing.T) { + if _, err := TLSCurvesDirective(nil, config.Node{Name: "curves"}); err == nil { + t.Error("expected error for curves directive without arguments, got none") + } +} From eaf8afa96cdf63b4f351a4fb5218338ba1878b48 Mon Sep 17 00:00:00 2001 From: reservoir-cmyk Date: Tue, 1 Dec 2026 07:24:00 +0900 Subject: [PATCH 3/3] docs: list X25519MLKEM768 in tls curves --- docs/reference/tls.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/reference/tls.md b/docs/reference/tls.md index 0da6aebb2..a5fba0df1 100644 --- a/docs/reference/tls.md +++ b/docs/reference/tls.md @@ -103,7 +103,7 @@ Default: defined by Go version The elliptic curves that will be used in an ECDHE handshake, in preference order. -Valid values: `p256`, `p384`, `p521`, `X25519`. +Valid values: `p256`, `p384`, `p521`, `X25519`, `X25519MLKEM768`. ## Client @@ -151,7 +151,7 @@ Default: defined by Go version The elliptic curves that will be used in an ECDHE handshake, in preference order. -Valid values: `p256`, `p384`, `p521`, `X25519`. +Valid values: `p256`, `p384`, `p521`, `X25519`, `X25519MLKEM768`. ---