Uh oh!
There was an error while loading. Please reload this page.
[Android] Fix app crash when using non-native HttpClientHandler - #69565
Conversation
ghost
commented
May 19, 2022
Tagging subscribers to 'arch-android': @steveisok, @akoeplinger Issue DetailsHTTP requests done with System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.---> System.NullReferenceException: Object reference not set to an instance of an object
at System.Net.CertificateValidationPal.GetRemoteCertificate(SafeDeleteContextsecurityContext,BooleanretrieveChainCertificates,X509Chain&chain)
at System.Net.CertificateValidationPal.GetRemoteCertificate(SafeDeleteContextsecurityContext)
at System.Net.Security.SslStream.SelectClientCertificate(Boolean&sessionRestartAttempt)
at System.Net.Security.SslStream.AcquireClientCredentials(Byte[]&thumbPrint)
at System.Net.Security.SslStream.GenerateToken(ReadOnlySpan`1inputBuffer,Byte[]&output)
at System.Net.Security.SslStream.NextMessage(ReadOnlySpan`1incomingBuffer)
at System.Net.Security.SslStream.<ForceAuthenticationAsync>d__144`1[[System.Net.Security.AsyncReadWriteAdapter,System.Net.Security,Version=7.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a]].MoveNext()
at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptionssslOptions,HttpRequestMessagerequest,Booleanasync,Streamstream,CancellationTokencancellationToken)---End of inner exception stack trace ---at System.Net.Http.ConnectHelper.EstablishSslConnectionAsync(SslClientAuthenticationOptionssslOptions,HttpRequestMessagerequest,Booleanasync,Streamstream,CancellationTokencancellationToken)
at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessagerequest,Booleanasync,CancellationTokencancellationToken)
at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessagerequest,Booleanasync,CancellationTokencancellationToken)
at System.Net.Http.HttpConnectionPool.AddHttp11ConnectionAsync(QueueItemqueueItem)
at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.<WaitWithCancellationAsync>d__1[[System.Net.Http.HttpConnection,System.Net.Http,Version=7.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a]].MoveNext()
at System.Net.Http.HttpConnectionPool.GetHttp11ConnectionAsync(HttpRequestMessagerequest,Booleanasync,CancellationTokencancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessagerequest,Booleanasync,BooleandoRequestAuth,CancellationTokencancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessagerequest,Booleanasync,CancellationTokencancellationToken)
at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessagerequest,HttpCompletionOptioncompletionOption,CancellationTokenSourcects,BooleandisposeCts,CancellationTokenSourcependingRequestsCts,CancellationTokenoriginalCancellationToken)
at Program.<Main>$(String[]args)in/home/simon/dotnet/runtime/src/mono/sample/Android/Program.cs:line 12There is a missing null check in Possibly also related to #69557
|
simonrozsival
commented
May 19, 2022
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
| ref X509Chain? chain) | ||
| { | ||
| SafeSslHandle sslContext = ((SafeDeleteSslContext)securityContext).SslContext; | ||
| SafeSslHandle? sslContext = ((SafeDeleteSslContext)securityContext)?.SslContext; |
There was a problem hiding this comment.
this shouldn't happen given that securityContext isn't marked as nullable, which suggests to me something higher up the call chain is doing something unexpected.
There was a problem hiding this comment.
The underlaying handle is nullable.
private SafeFreeCredentials? _credentialsHandle;
private SafeDeleteSslContext? _securityContext;
But is seems like it is like this for long time
Making the parameter nullable make sense to me. I think it will be null when we try to select client certificate before the handshake. cc: @rzikm
There was a problem hiding this comment.
The nullability annotations seem to be inconsistent across platforms:
- in the OSX version there's no
?but there's a null check: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Net.Security/src/System/Net/CertificateValidationPal.OSX.cs#L55 - in the Unix version there's a
?and there's a null check: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Net.Security/src/System/Net/CertificateValidationPal.Unix.cs#L31 - in the Windows version there's a
?and there's a null check: https://github.com/dotnet/runtime/blob/main/src/libraries/System.Net.Security/src/System/Net/CertificateValidationPal.Windows.cs#L34
There was a problem hiding this comment.
Ok thanks, that sounds like indeed we're expecting a null securityContext here and should make it consistent across platforms.
wfurt
commented
May 19, 2022
On a side note, #69527 removes the dual SafeHandle wrapping for Linux. We could do something similar for Android in future. |
simonrozsival
commented
May 20, 2022
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
simonrozsival
commented
May 20, 2022
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
…roid-certificate-validation-pal-null-reference-exception
simonrozsival
commented
May 26, 2022
/azp run outerloop-mono |
|
No pipelines are associated with this pull request. |
simonrozsival
commented
May 26, 2022
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
simonrozsival
commented
May 26, 2022
/azp run runtime-libraries-mono outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
simonrozsival
commented
May 26, 2022
I re-enabled the functional tests for |
Uh oh!
There was an error while loading. Please reload this page.
simonrozsival
commented
May 27, 2022
/azp run runtime-libraries-mono outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
simonrozsival
commented
May 30, 2022
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
simonrozsival
commented
May 31, 2022
I think this PR is now ready:
|
HTTP requests done with
HttpClient+HttpClientHandlercaused Android apps to crash.For example, a simple HTTP request using the default
HttpClientwill throw an exception with the following stack trace:There is a missing null check in
CertificateValidationpal.Android.cswhich was removed recently (https://github.com/dotnet/runtime/pull/68188/files#diff-5f4278661dbb1331a13f14f1bf94b3a67e7474e8e4c32a21a99860f966ab02aeL66-L68).Possibly also related to #69557