Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 162 additions & 14 deletions patches/0010-Align-TLS-settings-with-Microsoft-policies.patch
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ Subject: [PATCH] Align TLS settings with Microsoft policies
---
doc/godebug.md | 9 +
src/crypto/tls/common.go | 9 +-
src/crypto/tls/defaults.go | 34 +-
src/crypto/tls/defaults_microsoft.go | 157 ++++++
src/crypto/tls/defaults.go | 40 +-
src/crypto/tls/defaults_microsoft.go | 182 +++++
src/crypto/tls/handshake_client.go | 21 +-
src/crypto/tls/handshake_client_test.go | 17 +-
src/crypto/tls/handshake_server_tls13.go | 22 +-
src/crypto/tls/handshake_test.go | 3 +
src/crypto/tls/microsoft_test.go | 528 ++++++++++++++++++
src/crypto/tls/microsoft_test.go | 635 ++++++++++++++++++
src/crypto/tls/schannel_windows.go | 7 +
src/internal/godebugs/table.go | 2 +
src/net/http/internal/http2/transport_test.go | 2 +
12 files changed, 788 insertions(+), 23 deletions(-)
12 files changed, 925 insertions(+), 24 deletions(-)
create mode 100644 src/crypto/tls/defaults_microsoft.go
create mode 100644 src/crypto/tls/microsoft_test.go

Expand Down Expand Up @@ -61,7 +61,7 @@ index dd4aaf546c6208e559018a083026c12a2880298d..1b701b257dc01e7a42c644538bca1318
}
return cipherSuites
diff --git a/src/crypto/tls/defaults.go b/src/crypto/tls/defaults.go
index c89036047ad5a385d3a84d07aba359fb1d618d78..cb71e22a4380e8566ec897f739d873a0b4c884be 100644
index c89036047ad5a385d3a84d07aba359fb1d618d78..4fdb4cfbd25d2b9cb01dea8d4585010a461ce67e 100644
--- a/src/crypto/tls/defaults.go
+++ b/src/crypto/tls/defaults.go
@@ -18,14 +18,17 @@ var tlsmlkem = godebug.New("tlsmlkem")
Expand Down Expand Up @@ -94,7 +94,23 @@ index c89036047ad5a385d3a84d07aba359fb1d618d78..cb71e22a4380e8566ec897f739d873a0
return []CurveID{
X25519MLKEM768, SecP256r1MLKEM768, SecP384r1MLKEM1024, MLKEM1024,
X25519, CurveP256, CurveP384, CurveP521,
@@ -67,17 +73,31 @@ func defaultSupportedSignatureAlgorithms() []SignatureScheme {
@@ -47,7 +53,7 @@ func curvePreferenceOrder() []CurveID {
// CertificateRequest. The two fields are merged to match with TLS 1.3.
// Note that in TLS 1.2, the ECDSA algorithms are not constrained to P-256, etc.
func defaultSupportedSignatureAlgorithms() []SignatureScheme {
- return []SignatureScheme{
+ sigAlgs := []SignatureScheme{
MLDSA44,
MLDSA65,
MLDSA87,
@@ -64,20 +70,38 @@ func defaultSupportedSignatureAlgorithms() []SignatureScheme {
PKCS1WithSHA1,
ECDSAWithSHA1,
}
+ if ms_tlsprofile.Value() != "off" {
+ preferSupported(sigAlgs, supportedSignatures)
+ }
+ return sigAlgs
}

func supportedCipherSuites(aesGCMPreferred bool) []uint16 {
Expand Down Expand Up @@ -133,10 +149,10 @@ index c89036047ad5a385d3a84d07aba359fb1d618d78..cb71e22a4380e8566ec897f739d873a0

diff --git a/src/crypto/tls/defaults_microsoft.go b/src/crypto/tls/defaults_microsoft.go
new file mode 100644
index 0000000000000000000000000000000000000000..b0238641e0e3be88d6a661ad5c5be17ba889cb28
index 0000000000000000000000000000000000000000..bedf8bbdd35b1ef792b4133db6e2314a6ab88f28
--- /dev/null
+++ b/src/crypto/tls/defaults_microsoft.go
@@ -0,0 +1,157 @@
@@ -0,0 +1,182 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
Expand All @@ -149,6 +165,8 @@ index 0000000000000000000000000000000000000000..b0238641e0e3be88d6a661ad5c5be17b
+
+ boring "github.com/microsoft/go/cryptobackend"
+ becdh "github.com/microsoft/go/cryptobackend/ecdh"
+ bed25519 "github.com/microsoft/go/cryptobackend/ed25519"
+ bmldsa "github.com/microsoft/go/cryptobackend/mldsa"
+ bmlkem "github.com/microsoft/go/cryptobackend/mlkem"
+)
+
Expand All @@ -166,6 +184,24 @@ index 0000000000000000000000000000000000000000..b0238641e0e3be88d6a661ad5c5be17b
+ MLKEM1024: !boring.Enabled || bmlkem.Supports1024(),
+}
+
+var supportedSignatures = map[SignatureScheme]bool{
+ MLDSA44: !boring.Enabled || bmldsa.Supports(bmldsa.MLDSA44()),
+ MLDSA65: !boring.Enabled || bmldsa.Supports(bmldsa.MLDSA65()),
+ MLDSA87: !boring.Enabled || bmldsa.Supports(bmldsa.MLDSA87()),
+ PSSWithSHA256: true,
+ ECDSAWithP256AndSHA256: true,
+ Ed25519: !boring.Enabled || bed25519.Supports(),
+ PSSWithSHA384: true,
+ PSSWithSHA512: true,
+ PKCS1WithSHA256: true,
+ PKCS1WithSHA384: true,
+ PKCS1WithSHA512: true,
+ ECDSAWithP384AndSHA384: true,
+ ECDSAWithP521AndSHA512: true,
+ PKCS1WithSHA1: true,
+ ECDSAWithSHA1: true,
+}
+
+func init() {
+ switch ms_tlsprofile.Value() {
+ case "default", "":
Expand All @@ -182,9 +218,15 @@ index 0000000000000000000000000000000000000000..b0238641e0e3be88d6a661ad5c5be17b
+ X25519MLKEM768, SecP384r1MLKEM1024, SecP256r1MLKEM768, MLKEM1024,
+ CurveP384, CurveP256, CurveP521, X25519,
+ }
+ // Move unsupported groups to the end while preserving order for supported groups.
+ slices.SortStableFunc(groups, func(a, b CurveID) int {
+ supportedA, supportedB := supportedGroups[a], supportedGroups[b]
+ preferSupported(groups, supportedGroups)
+ return groups
+}
+
+// preferSupported moves algorithms without backend support to the end,
+// preserving the relative order within both groups.
+func preferSupported[T comparable](algorithms []T, supported map[T]bool) {
+ slices.SortStableFunc(algorithms, func(a, b T) int {
+ supportedA, supportedB := supported[a], supported[b]
+ if supportedA && !supportedB {
+ return -1
+ }
Expand All @@ -193,7 +235,6 @@ index 0000000000000000000000000000000000000000..b0238641e0e3be88d6a661ad5c5be17b
+ }
+ return 0
+ })
+ return groups
+}
+
+// msDefaultCipherSuitesTLS13 is like [defaultCipherSuitesTLS13] with
Expand Down Expand Up @@ -403,10 +444,10 @@ index d9424c374eab88a7b581a44e88688f7abc7063ff..d56331d626832147c55268988f6dd93e
if err != nil {
diff --git a/src/crypto/tls/microsoft_test.go b/src/crypto/tls/microsoft_test.go
new file mode 100644
index 0000000000000000000000000000000000000000..7803472159d8ec7fc6a3c51eed0b40f9b045433a
index 0000000000000000000000000000000000000000..e152464feb908a39f95f5fa6b53352be72f20a54
--- /dev/null
+++ b/src/crypto/tls/microsoft_test.go
@@ -0,0 +1,528 @@
@@ -0,0 +1,635 @@
+// Copyright 2025 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
Expand All @@ -426,6 +467,8 @@ index 0000000000000000000000000000000000000000..7803472159d8ec7fc6a3c51eed0b40f9
+
+ boring "github.com/microsoft/go/cryptobackend"
+ becdh "github.com/microsoft/go/cryptobackend/ecdh"
+ bed25519 "github.com/microsoft/go/cryptobackend/ed25519"
+ bmldsa "github.com/microsoft/go/cryptobackend/mldsa"
+ bmlkem "github.com/microsoft/go/cryptobackend/mlkem"
+)
+
Expand Down Expand Up @@ -496,6 +539,111 @@ index 0000000000000000000000000000000000000000..7803472159d8ec7fc6a3c51eed0b40f9
+ }
+}
+
+func TestMicrosoftSignatureSupport(t *testing.T) {
+ testenv.SetGODEBUG(t, "ms_tlsprofile=off")
+ sigAlgs := defaultSupportedSignatureAlgorithms()
+ if len(supportedSignatures) != len(sigAlgs) {
+ t.Errorf("support map has %d entries, want %d", len(supportedSignatures), len(sigAlgs))
+ }
+ for _, sigAlg := range sigAlgs {
+ t.Run(sigAlg.String(), func(t *testing.T) {
+ got, ok := supportedSignatures[sigAlg]
+ if !ok {
+ t.Fatal("missing signature scheme in support map")
+ }
+ want := true
+ if boring.Enabled {
+ switch sigAlg {
+ case MLDSA44:
+ want = bmldsa.Supports(bmldsa.MLDSA44())
+ case MLDSA65:
+ want = bmldsa.Supports(bmldsa.MLDSA65())
+ case MLDSA87:
+ want = bmldsa.Supports(bmldsa.MLDSA87())
+ case Ed25519:
+ want = bed25519.Supports()
+ }
+ }
+ if got != want {
+ t.Errorf("backend support = %v, want %v", got, want)
+ }
+ })
+ }
+}
+
+func TestMicrosoftSignatureAlgorithmPreferences(t *testing.T) {
+ allSupported := make(map[SignatureScheme]bool)
+ for sigAlg := range supportedSignatures {
+ allSupported[sigAlg] = true
+ }
+ tests := []struct {
+ name string
+ supported map[SignatureScheme]bool
+ }{
+ {"Backend", supportedSignatures},
+ {"All", allSupported},
+ {"None", map[SignatureScheme]bool{}},
+ {"Partial", map[SignatureScheme]bool{
+ MLDSA65: true,
+ PSSWithSHA256: true,
+ Ed25519: true,
+ ECDSAWithP384AndSHA384: true,
+ }},
+ }
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ original := supportedSignatures
+ supportedSignatures = test.supported
+ t.Cleanup(func() { supportedSignatures = original })
+
+ for _, versions := range []struct {
+ name string
+ min, max uint16
+ }{
+ {"TLS12", VersionTLS12, VersionTLS12},
+ {"TLS13", VersionTLS13, VersionTLS13},
+ {"TLS12And13", VersionTLS12, VersionTLS13},
+ } {
+ for _, algorithms := range []struct {
+ name string
+ get func(uint16, uint16) []SignatureScheme
+ }{
+ {"Defaults", func(_, _ uint16) []SignatureScheme {
+ return defaultSupportedSignatureAlgorithms()
+ }},
+ {"signature_algorithms", supportedSignatureAlgorithms},
+ {"signature_algorithms_cert", supportedSignatureAlgorithmsCert},
+ } {
+ t.Run(versions.name+"/"+algorithms.name, func(t *testing.T) {
+ testenv.SetGODEBUG(t, "ms_tlsprofile=off")
+ upstream := algorithms.get(versions.min, versions.max)
+ for _, profile := range []string{"off", "default", ""} {
+ t.Run("ms_tlsprofile="+profile, func(t *testing.T) {
+ testenv.SetGODEBUG(t, "ms_tlsprofile="+profile)
+ want := upstream
+ if profile != "off" {
+ want = nil
+ for _, supported := range []bool{true, false} {
+ for _, sigAlg := range upstream {
+ if test.supported[sigAlg] == supported {
+ want = append(want, sigAlg)
+ }
+ }
+ }
+ }
+ got := algorithms.get(versions.min, versions.max)
+ if !slices.Equal(got, want) {
+ t.Errorf("signature algorithms = %v, want %v", got, want)
+ }
+ })
+ }
+ })
+ }
+ }
+ })
+ }
+}
+
+func TestMicrosoftHandshakeGroups(t *testing.T) {
+ // This test is designed to verify the default Microsoft TLS profile's group preferences
+ // and behavior during the handshake. It is based on TestHandshakeMLKEM.
Expand Down
17 changes: 10 additions & 7 deletions patches/0013-Add-ms_tlsmldsacert-GODEBUG-setting.patch
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ and Microsoft profiles. Document the setting's introduction in v1.27.2-2.
---
doc/godebug.md | 8 ++
src/crypto/tls/common.go | 4 +
src/crypto/tls/microsoft_test.go | 121 +++++++++++++++++++++++++++++++
src/crypto/tls/microsoft_test.go | 124 +++++++++++++++++++++++++++++++
src/internal/godebugs/table.go | 1 +
4 files changed, 134 insertions(+)
4 files changed, 137 insertions(+)

diff --git a/doc/godebug.md b/doc/godebug.md
index 6426e90c3509b00ca5e1296b401d873de30a96b8..27ed4ed5f972596f852a4004019d316af78ab0cd 100644
Expand Down Expand Up @@ -63,7 +63,7 @@ index 1b701b257dc01e7a42c644538bca131895ab0c2d..465b7ef7205dd1bc33e94d54c2da489a
if fips140.Version() == "v1.0.0" {
return true
diff --git a/src/crypto/tls/microsoft_test.go b/src/crypto/tls/microsoft_test.go
index 7803472159d8ec7fc6a3c51eed0b40f9b045433a..cd0d2d715afd2771c47597b489d70b6075d52f30 100644
index e152464feb908a39f95f5fa6b53352be72f20a54..b0430f65e4b21bf5abfe3732298500dd535612f2 100644
--- a/src/crypto/tls/microsoft_test.go
+++ b/src/crypto/tls/microsoft_test.go
@@ -5,6 +5,7 @@
Expand All @@ -74,15 +74,15 @@ index 7803472159d8ec7fc6a3c51eed0b40f9b045433a..cd0d2d715afd2771c47597b489d70b60
"crypto/tls/internal/fips140tls"
"internal/goexperiment"
"internal/testenv"
@@ -18,6 +19,7 @@ import (
boring "github.com/microsoft/go/cryptobackend"
becdh "github.com/microsoft/go/cryptobackend/ecdh"
@@ -20,6 +21,7 @@ import (
bed25519 "github.com/microsoft/go/cryptobackend/ed25519"
bmldsa "github.com/microsoft/go/cryptobackend/mldsa"
bmlkem "github.com/microsoft/go/cryptobackend/mlkem"
+ "golang.org/x/crypto/cryptobyte"
)

func TestMicrosoftDefaultCipherSuites(t *testing.T) {
@@ -523,6 +525,125 @@ func testCipherSuitePreferenceOrder(t *testing.T, maxVersion uint16, expected ui
@@ -630,6 +632,128 @@ func testCipherSuitePreferenceOrder(t *testing.T, maxVersion uint16, expected ui
}
}

Expand Down Expand Up @@ -120,6 +120,9 @@ index 7803472159d8ec7fc6a3c51eed0b40f9b045433a..cd0d2d715afd2771c47597b489d70b60
+ }
+ }
+ wantCertSigAlgs = append(wantCertSigAlgs, classicalCertSigAlgs...)
+ if ms_tlsprofile.Value() != "off" {
+ preferSupported(wantCertSigAlgs, supportedSignatures)
+ }
+ if !slices.Equal(certSigAlgs, wantCertSigAlgs) {
+ t.Errorf("signature_algorithms_cert = %v, want %v", certSigAlgs, wantCertSigAlgs)
+ }
Expand Down
28 changes: 14 additions & 14 deletions patches/index.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading