Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Lukas123798 opened this issue Aug 13, 2022 · 11 comments
Labels
area-System.Net needs-author-action An issue or pull request that requires more info or actions from the author. os-android
Milestone

Comments

@Lukas123798
Copy link

Lukas123798 commented Aug 13, 2022

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)
@janseris
Copy link

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

@Lukas123798
Copy link
Author

Is there some solution or conclusion ?

@akravch
Copy link

akravch commented Sep 15, 2022

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.

@ghost
Copy link

ghost commented Mar 8, 2023

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

Issue Details

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)
Author: Lukas123798
Assignees: -
Labels:

area-System.Net

Milestone: -

@ghost
Copy link

ghost commented Mar 8, 2023

Tagging subscribers to 'arch-android': @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

Issue Details

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)
Author: Lukas123798
Assignees: -
Labels:

area-System.Net, os-android, untriaged

Milestone: -

@wfurt
Copy link
Member

wfurt commented Mar 8, 2023

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

@steveisok
Copy link
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.

@steveisok steveisok added needs-author-action An issue or pull request that requires more info or actions from the author. and removed untriaged New issue has not been triaged by the area owner labels Mar 8, 2023
@ghost
Copy link

ghost commented Mar 8, 2023

This issue has been marked needs-author-action and may be missing some important information.

@simonrozsival
Copy link
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.

@ghost ghost added the no-recent-activity label Mar 22, 2023
@ghost
Copy link

ghost commented Mar 22, 2023

This issue has been automatically marked no-recent-activity because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will remove no-recent-activity.

@ghost
Copy link

ghost commented Apr 5, 2023

This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

@ghost ghost closed this as completed Apr 5, 2023
@ghost ghost locked as resolved and limited conversation to collaborators May 5, 2023
@karelz karelz added this to the 8.0.0 milestone May 27, 2023
@ghost ghost removed the no-recent-activity label May 27, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net needs-author-action An issue or pull request that requires more info or actions from the author. os-android
Projects
None yet
Development

No branches or pull requests

7 participants