Skip to content

[Android] SSLStream throws 'Handshake has already been started' on API level 26 #78716

Closed

Description

@steveisok

The following block will throw an exception with Handshake has already been started on API level 26. Appears to be specific to our SSLEngine usage.

using var client = new TcpClient("login.sequrix.com", 443);
            using var stream = new SslStream(client.GetStream(), false);
            stream.AuthenticateAsClient(new SslClientAuthenticationOptions()
            {
                TargetHost = "login.sequrix.com"
            });
            stream.Read(new byte[100], 0, 100);

Exception:

Time	Device Name	Type	PID	Tag	Message
11-22 16:06:53.606	pixel_5_-_api_26	Warning	8609	System.err	java.lang.IllegalStateException: Handshake has already been started
	at com.android.org.conscrypt.OpenSSLEngineImpl.beginHandshakeInternal(OpenSSLEngineImpl.java:335)
	at com.android.org.conscrypt.OpenSSLEngineImpl.beginHandshake(OpenSSLEngineImpl.java:325)
11-22 16:06:53.607	pixel_5_-_api_26	Verbose	8609	SequriX	Push error: System.Security.Authentication.AuthenticationException: net_auth_SSPI
 ---> Interop+AndroidCrypto+SslException: Exception_WasThrown, Interop+AndroidCrypto+SslException
   Exception_EndOfInnerExceptionStack
   at System.Net.Security.SslStream.<ForceAuthenticationAsync>d__175`1[[System.Net.Security.AsyncReadWriteAdapter, System.Net.Security, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a]].MoveNext()
   at SuperSocket.ClientEngine.SslStreamTcpSession.AuthenticateAsClientAsync(SslStream sslStream, SecurityOption securityOption)

Activity

  1. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Nov 22, 2022
  2. added and removed
    untriagedNew issue has not been triaged by the area owner
    on Nov 22, 2022
  3. added this to the 8.0.0 milestone on Nov 22, 2022
  4. rgroenewoudt commented on Nov 23, 2022

    @rgroenewoudt

    This also effects SocketsHttpHandler and ClientWebSocket usage with HTTPS.

    For example:

    var client = new HttpClient(new SocketsHttpHandler());
    await client.GetStringAsync("https://google.com");
  5. simonrozsival commented on Nov 24, 2022

    @simonrozsival
    Member

    This is likely related to dotnet/SqlClient#1656

  6. simonrozsival commented on Nov 24, 2022

    @simonrozsival
    Member

    I reproduced the issue locally and it should be possible to fix it. I should have a fix ready soon.

  7. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Nov 25, 2022
  8. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Nov 30, 2022
  9. ghost locked as resolved and limited conversation to collaborators on Dec 30, 2022
  10. karelz commented on May 27, 2023

    @karelz
    Member

    Fixed in main (8.0) in PR #78849 and in 7.0.3 in PR #79280 and in 6.0.14 in PR #79277.

  11. modified the milestones: 8.0.0, 6.0.x on May 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions