Skip to content

Add SslStream legacy path compatibility switch - #132210

Open
rzikm wants to merge 3 commits into
dotnet:mainfrom
rzikm:rzikm/sslstream-legacy-appctx-switch
Open

Add SslStream legacy path compatibility switch#132210
rzikm wants to merge 3 commits into
dotnet:mainfrom
rzikm:rzikm/sslstream-legacy-appctx-switch

Conversation

@rzikm

@rzikm rzikm commented Aug 12, 2026

Copy link
Copy Markdown
Member

Summary

Adds a compatibility switch that allows applications to temporarily restore the legacy SslStream handshake implementation instead of routing through the TlsSession wedge introduced by #130366.

The new switch is disabled by default, so existing behavior remains unchanged:

  • AppContext: System.Net.Security.UseLegacySslStreamHandshake
  • Environment variable: DOTNET_SYSTEM_NET_SECURITY_USELEGACYSSLSTREAMHANDSHAKE

When enabled, SslStream skips TryNextMessageViaTlsSession and uses its legacy GenerateToken path. This provides an operational rollback mechanism while the remaining work tracked by #131315 is completed.

Tests cover the default, explicit AppContext values, the environment variable, AppContext precedence in both directions, deterministic inherited-environment handling, both client and server path selection, and post-handshake data transfer.

Testing

  • Built System.Net.Security successfully with zero warnings.
  • SslStreamRemoteExecutorTests.UseLegacySslStreamHandshake_SelectsExpectedHandshakePath: 7 passed.

Related to #131315.

Note

This pull request description was created with GitHub Copilot.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 60eb7c64-0be6-41c5-ae15-18ea56a74e07
Copilot AI lite review requested due to automatic review settings August 12, 2026 13:54
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@rzikm
rzikm requested a review from a team August 12, 2026 13:56
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-in compatibility switch for SslStream to bypass the TlsSession wedge handshake path and fall back to the legacy GenerateToken handshake implementation, providing an operational rollback while the wedge integration work is completed.

Changes:

  • Introduces System.Net.Security.UseLegacySslStream / DOTNET_SYSTEM_NET_SECURITY_USELEGACYSSLSTREAM via LocalAppContextSwitches.
  • Gates SslStream’s NextMessage handshake flow to skip TryNextMessageViaTlsSession when the switch is enabled.
  • Adds functional coverage (via RemoteExecutor) to validate handshake path selection and post-handshake data transfer.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamRemoteExecutorTests.cs Adds a RemoteExecutor-based test that toggles AppContext/env var and asserts legacy vs wedge handshake selection.
src/libraries/System.Net.Security/src/System/Net/Security/SslStream.Protocol.cs Adds the switch gate to control whether the wedge handshake path is used.
src/libraries/System.Net.Security/src/System/Net/Security/LocalAppContextSwitches.cs Adds a cached compatibility switch with an AppContext key and environment variable override.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 60eb7c64-0be6-41c5-ae15-18ea56a74e07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (2)

src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamRemoteExecutorTests.cs:43

  • Using ProcessStartInfo.Environment.Add can throw if the variable is already present in the inherited environment, and when environmentValue is null the test does not clear the variable. That can make this test fail or become environment-dependent if DOTNET_SYSTEM_NET_SECURITY_USELEGACYSSLSTREAMHANDSHAKE is set externally.
            var psi = new ProcessStartInfo();
            if (environmentValue.HasValue)
            {
                psi.Environment.Add("DOTNET_SYSTEM_NET_SECURITY_USELEGACYSSLSTREAMHANDSHAKE", environmentValue.Value ? "1" : "0");
            }

src/libraries/System.Net.Security/tests/FunctionalTests/SslStreamRemoteExecutorTests.cs:36

  • The precedence case where AppContext=true and environment=false isn't covered. Adding it helps ensure AppContext always wins over the environment variable in both directions.
        [InlineData(null, false, false)]
        [InlineData(null, true, true)]
        [InlineData(false, true, false)]

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 60eb7c64-0be6-41c5-ae15-18ea56a74e07
Copilot AI review requested due to automatic review settings August 12, 2026 19:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants