Skip to content

Authentication failed when trying to connect to secure websocket with android 8 #83118

Closed

Description

@Lukas123798

Description

I cant connect to secure websocket(wss), it just writing Unable to connect to the remote server and error Authentication failed, full log is down there, and to unsecure websocket i can connect easily on any android.
When i used android 11 phone it works fine.
I am using library 'WebSocket4Net' which working perfectly in xamarin with all androids.

Steps to Reproduce

Connect to a secure websocket with .NET MAUI APP on android phone with android version 8, tested on both physical phone and emulator.
Or there is my repo where you can test it Repo

Version with bug

6.0.400

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 8, but most likely its all older android versions

Did you find any workaround?

In xamarin, there is SSL/TLS implementation and HttpClient implementation option in project settings, but in .NET MAUI its not or i didnt found it
I tryed copied this from Xamarin project where this websocket works fine on every platform, but its still not working.

<PropertyGroup Condition="$(TargetFramework.Contains('-android'))">
            <AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
            <AndroidTlsProvider></AndroidTlsProvider>
      </PropertyGroup>

Also i tryed this, but also not helpful

<AndroidHttpClientHandlerType>System.Net.Http.HttpClientHandler</AndroidHttpClientHandlerType>
<AndroidTlsProvider>legacy</AndroidTlsProvider>
<AndroidTlsProvider>btls</AndroidTlsProvider>

I tryed some settings in Websocket object with EnabledProtocols, but also nothing.

Relevant log output

Authentication failed, see inner exception. at System.Net.Security.SsiStream<ForceAuthenticationAsy nc>d_175' 1 [(System.NetSecurity.AsyncReadWriteAdapter, System.Net.Security, Version=6.0.0.0, Culture-neutral, PublicKeyToken=b03f5f7111d50a3aMMoveNext0 at SuperSocketClientEngine.SsIStreamTcpSessio n.AuthenticateAsClientAsync(SslStream ssIStream, Security0ption securityOption)

Activity

  1. janseris commented on Aug 14, 2022

    @janseris

    Might be the same issue as connecting to Sql Server where SSL fails (used on log in even when not encrypting)

  2. Lukas123798 commented on Aug 20, 2022

    @Lukas123798
    Author

    Is there some solution or conclusion ?

  3. akravch commented on Sep 15, 2022

    @akravch

    Facing the same issue on a non-MAUI Android .NET 6 app with errors like this:

    System.Net.WebSockets.WebSocketException (0x80004005): Unable to connect to the remote server
    ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
    ---> Interop+AndroidCrypto+SslException: Exception of type 'Interop+AndroidCrypto+SslException' was thrown.
    --- End of inner exception stack trace ---
    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()
    

    Also, in logcat I see the following right before the .NET exception:

    W System.err: java.lang.IllegalStateException: Handshake has already been started
    W System.err: 	at com.android.org.conscrypt.OpenSSLEngineImpl.beginHandshakeInternal(OpenSSLEngineImpl.java:335)
    W System.err: 	at com.android.org.conscrypt.OpenSSLEngineImpl.beginHandshake(OpenSSLEngineImpl.java:325)
    

    Switching to the legacy HTTP handler didn't help as well.

  4. ghost added
    untriagedNew issue has not been triaged by the area owner
    on Mar 8, 2023
  5. transferred this issue fromdotnet/mauion Mar 8, 2023
  6. wfurt commented on Mar 8, 2023

    @wfurt
    Member

    do you see that with .NET 7 as well? AFAIK there were many improvements. cc @simonrozsival

  7. steveisok commented on Mar 8, 2023

    @steveisok
    Member

    We addressed a bunch of these issues in the 6 and 7 servicing releases around the Dec / Jan timeframe. @Lukas123798, I'd grab the latest and try again.

  8. added
    needs-author-actionAn issue or pull request that requires more info or actions from the author.
    and removed
    untriagedNew issue has not been triaged by the area owner
    on Mar 8, 2023
  9. simonrozsival commented on Mar 8, 2023

    @simonrozsival
    Member

    The error "Handshake has already been started" used to occur on Android API 21-26 and it was fixed in #78849. That fix was shipped in one of the recent servicing releases as @steveisok said.

  10. ghost closed this as completedon Apr 5, 2023
  11. ghost locked as resolved and limited conversation to collaborators on May 5, 2023
  12. added this to the 8.0.0 milestone 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

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions