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

SSLStream fails #7577

Closed
rgroenewoudt opened this issue Nov 22, 2022 · 3 comments
Closed

SSLStream fails #7577

rgroenewoudt opened this issue Nov 22, 2022 · 3 comments
Assignees
Labels
Area: Mono Runtime Mono-related issues: BCL bugs, AOT issues, etc.

Comments

@rgroenewoudt
Copy link

Android application type

Android for .NET (net6.0-android, etc.)

Affected platform version

VS2022 17.4.1

Description

On Android 9+ it works fine.

Using SSLStream on an Android 8 device fails with:

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

On Android 6 this fails with:

System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
[mono-rt]  ---> System.PlatformNotSupportedException: Setting an SNI hostname is not supported on this API level.
[mono-rt]    at Interop.AndroidCrypto.SSLStreamSetTargetHost(SafeSslHandle sslHandle, String targetHost)

Documentation doesn't indicate this as an known issue.

Steps to Reproduce

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);

AndroidApp4.zip

Did you find any workaround?

No response

Relevant log output

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)
@rgroenewoudt rgroenewoudt added Area: App Runtime Issues in `libmonodroid.so`. needs-triage Issues that need to be assigned. labels Nov 22, 2022
@rgroenewoudt
Copy link
Author

rgroenewoudt commented Nov 22, 2022

System.Net.WebSockets.ClientWebsocket also uses SSLStream so this breaks using TLS websocket entirely on devices using Android <9.

@grendello grendello assigned steveisok and unassigned grendello Nov 22, 2022
@grendello grendello added Area: Mono Runtime Mono-related issues: BCL bugs, AOT issues, etc. and removed Area: App Runtime Issues in `libmonodroid.so`. needs-triage Issues that need to be assigned. labels Nov 22, 2022
@michaldobrodenka
Copy link

My workaround is to use Xamarin.Android for now

@steveisok
Copy link
Member

Closing in favor of dotnet/runtime#78716 and dotnet/runtime#78715

@ghost ghost locked as resolved and limited conversation to collaborators Dec 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: Mono Runtime Mono-related issues: BCL bugs, AOT issues, etc.
Projects
None yet
Development

No branches or pull requests

4 participants