Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
3577fb2
Seal AndroidClientHandler
simonrozsival Dec 2, 2021
f3e240e
Update comments of AndroidClientHandler and AndroidMessageHandler
simonrozsival Dec 2, 2021
fc29fe6
Change all internal virtual methods of AndroidMessageHandler to prote…
simonrozsival Dec 2, 2021
1b93b20
Update comments
simonrozsival Dec 3, 2021
ab27212
Fix AndroidClientHandler's access to protected methods of AndroidMess…
simonrozsival Dec 3, 2021
b25426d
Deprecate AndroidClientHandler
simonrozsival Dec 3, 2021
49551cc
Fix references in comments
simonrozsival Dec 3, 2021
d1506bd
Remove unnecessary string interpolation
simonrozsival Dec 3, 2021
a898314
Do not make legacy android client handler obsolete
simonrozsival Dec 6, 2021
3018cf3
Revert change to the sample app
simonrozsival Dec 6, 2021
2186995
Use different comments for .NET6 and for Xamarin.Android
simonrozsival Dec 7, 2021
860ab9a
Fix visibility of internal handler
simonrozsival Dec 7, 2021
e0c3026
Remove broken private proxy class and add replace it with internal me…
simonrozsival Dec 7, 2021
03e74e6
Unseal the AndroidClientHandler class and revert method signatures to…
simonrozsival Dec 7, 2021
8e70504
Revert "Unseal the AndroidClientHandler class and revert method signa…
simonrozsival Dec 8, 2021
960f76d
Add breaking changes in AndroidClientHandler to the acceptable breaka…
simonrozsival Dec 8, 2021
2529f0a
Merge branch 'main' of git://github.com/xamarin/xamarin-android into …
simonrozsival Dec 8, 2021
bb4d8ad
Minor code style modification
simonrozsival Dec 8, 2021
2580f53
Unseal the AndroidClientHandler class and revert method signatures to…
simonrozsival Dec 8, 2021
3a08356
Revert "Add breaking changes in AndroidClientHandler to the acceptabl…
simonrozsival Dec 8, 2021
107ee70
WIP Fix test errors
simonrozsival Dec 9, 2021
207c3a2
Fix syntax errors in tests
simonrozsival Dec 9, 2021
91ea475
Change redirect
simonrozsival Dec 12, 2021
45c1ca7
Try disabling integration tests to find the cause for failing tests
simonrozsival Dec 17, 2021
c3989c7
Revert "Try disabling integration tests to find the cause for failing…
simonrozsival Dec 17, 2021
22ef294
Try disabling different integration tests to find the cause for faili…
simonrozsival Dec 17, 2021
36d06fd
Revert "Try disabling different integration tests to find the cause f…
simonrozsival Dec 20, 2021
a7d56bd
Merge branch 'main' of git://github.com/xamarin/xamarin-android into …
simonrozsival Dec 20, 2021
f6d7934
Fix typo
simonrozsival Dec 21, 2021
271907c
Disable all tests related to AndroidClientHandler and AndroidMessageH…
simonrozsival Dec 21, 2021
bd70107
Searching failing test: some tests
simonrozsival Dec 21, 2021
4a16874
Searching failing test: enable some integration tests
simonrozsival Dec 21, 2021
5a0fc0a
Revert "Fix typo"
simonrozsival Dec 21, 2021
06e9f15
Enable more tests
simonrozsival Dec 21, 2021
012f067
Disable some android client handler tests
simonrozsival Dec 22, 2021
730d15b
Disable some tests
simonrozsival Dec 22, 2021
4c8bfe3
Another iteration of enabling and disabling tests
simonrozsival Dec 22, 2021
67f702f
Disable some tests
simonrozsival Dec 22, 2021
b49fd00
Revert all recent changes to tests
simonrozsival Dec 23, 2021
5bebb83
Disable fix for GetUnderlyingHandler in an attempt to find the root c…
simonrozsival Jan 5, 2022
b66688a
Update fix for GetUnderlyingHandler
simonrozsival Jan 6, 2022
e18bfcc
Remove unnecessary change
simonrozsival Jan 6, 2022
cbbafc3
Fix error message
simonrozsival Jan 6, 2022
3ff3d4f
Ignore most AndroidClientHandlerTests
simonrozsival Jan 6, 2022
39b4731
Disable more AndroidClientHandlerTests
simonrozsival Jan 6, 2022
a7dd119
Disable test in AndroidClientHandlerTests
simonrozsival Jan 7, 2022
142a0d5
Enable AndroidClientHandler tests without casts
simonrozsival Jan 7, 2022
9e39110
Add using
simonrozsival Jan 7, 2022
a06991f
Re-enable remaining tests
simonrozsival Jan 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions src/Mono.Android/Xamarin.Android.Net/AndroidClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ namespace Xamarin.Android.Net
/// by AndroidClientHandler is requested by the server, the application can provide its own authentication module (<see cref="AuthenticationData"/>,
/// <see cref="PreAuthenticationData"/>) to handle the protocol authorization.</para>
/// <para>AndroidClientHandler also supports requests to servers with "invalid" (e.g. self-signed) SSL certificates. Since this process is a bit convoluted using
/// the Java APIs, AndroidClientHandler defines two ways to handle the situation. First, easier, is to store the necessary certificates (either CA or server certificates)
/// in the <see cref="TrustedCerts"/> collection or, after deriving a custom class from AndroidClientHandler, by overriding one or more methods provided for this purpose
/// (<see cref="ConfigureTrustManagerFactory"/>, <see cref="ConfigureKeyManagerFactory"/> and <see cref="ConfigureKeyStore"/>). The former method should be sufficient
/// for most use cases, the latter allows the application to provide fully customized key store, trust manager and key manager, if needed. Note that the instance of
/// AndroidClientHandler configured to accept an "invalid" certificate from the particular server will most likely fail to validate certificates from other servers (even
/// if they use a certificate with a fully validated trust chain) unless you store the CA certificates from your Android system in <see cref="TrustedCerts"/> along with
/// the self-signed certificate(s).</para>
/// the Java APIs, AndroidClientHandler defines a way to handle the situation. It can store the necessary certificates (either CA or server certificates)
/// in the <see cref="TrustedCerts"/> collection. If, however, the application requires finer control over the SSL configuration (e.g. it implements its own
/// TrustManager) then it should derive a custom class from <see cref="Xamarin.Android.Net.AndroidMessageHandler"/> instead of using AndroidClientHandler.
/// Note that the instance of AndroidClientHandler configured to accept an "invalid" certificate from the particular server will most likely fail to validate
/// certificates from other servers (even if they use a certificate with a fully validated trust chain) unless you store the CA certificates from your Android
/// system in <see cref="TrustedCerts"/> along with the self-signed certificate(s).</para>
/// </remarks>
[Obsolete("AndroidClientHandler has been deprecated. Use AndroidMessageHandler instead.")]
public class AndroidClientHandler : HttpClientHandler
{
internal const string LOG_APP = "monodroid-net";
Expand Down Expand Up @@ -132,9 +132,7 @@ public bool RequestNeedsAuthorization
/// in this property in order for AndroidClientHandler to configure the request to accept the server certificate.</para>
/// <para>AndroidClientHandler uses a custom <see cref="KeyStore"/> and <see cref="TrustManagerFactory"/> to configure the connection.
/// If, however, the application requires finer control over the SSL configuration (e.g. it implements its own TrustManager) then
/// it should leave this property empty and instead derive a custom class from AndroidClientHandler and override, as needed, the
/// <see cref="ConfigureTrustManagerFactory"/>, <see cref="ConfigureKeyManagerFactory"/> and <see cref="ConfigureKeyStore"/> methods
/// instead</para>
/// it should derive a custom class from <see cref="Xamarin.Android.Net.AndroidMessageHandler"/> instead of using AndroidClientHandler.</para>
/// </summary>
/// <value>The trusted certs.</value>
public IList <Certificate>? TrustedCerts
Expand Down Expand Up @@ -210,7 +208,7 @@ protected void AssertSelf ()
/// <param name="connection">HTTPS connection object.</param>
protected virtual IHostnameVerifier? GetSSLHostnameVerifier (HttpsURLConnection connection)
{
return null;
return _underlyingHander.GetSSLHostnameVerifierInternal (connection);
}

/// <summary>
Expand All @@ -227,12 +225,12 @@ protected void AssertSelf ()

protected virtual async Task <Java.Net.Proxy?> GetJavaProxy (Uri destination, CancellationToken cancellationToken)
{
return await _underlyingHander.GetJavaProxy (destination, cancellationToken);
return await _underlyingHander.GetJavaProxyInternal (destination, cancellationToken);
}

protected virtual async Task WriteRequestContentToOutput (HttpRequestMessage request, HttpURLConnection httpConnection, CancellationToken cancellationToken)
{
await _underlyingHander.WriteRequestContentToOutput (request, httpConnection, cancellationToken);
await _underlyingHander.WriteRequestContentToOutputInternal (request, httpConnection, cancellationToken);
}

/// <summary>
Expand All @@ -245,7 +243,7 @@ protected virtual async Task WriteRequestContentToOutput (HttpRequestMessage req
/// <param name="conn">Pre-configured connection instance</param>
protected virtual Task SetupRequest (HttpRequestMessage request, HttpURLConnection conn)
{
return _underlyingHander.SetupRequest (request, conn);
return _underlyingHander.SetupRequestInternal (request, conn);
}

/// <summary>
Expand All @@ -259,7 +257,7 @@ protected virtual Task SetupRequest (HttpRequestMessage request, HttpURLConnecti
{
AssertSelf ();

return _underlyingHander.ConfigureKeyStore (keyStore);
return _underlyingHander.ConfigureKeyStoreInternal (keyStore);
}

/// <summary>
Expand All @@ -275,7 +273,7 @@ protected virtual Task SetupRequest (HttpRequestMessage request, HttpURLConnecti
{
AssertSelf ();

return _underlyingHander.ConfigureKeyManagerFactory (keyStore);
return _underlyingHander.ConfigureKeyManagerFactoryInternal (keyStore);
}

/// <summary>
Expand All @@ -292,7 +290,7 @@ protected virtual Task SetupRequest (HttpRequestMessage request, HttpURLConnecti
{
AssertSelf ();

return _underlyingHander.ConfigureTrustManagerFactory (keyStore);
return _underlyingHander.ConfigureTrustManagerFactoryInternal (keyStore);
}

/// <summary>
Expand All @@ -308,18 +306,25 @@ protected virtual Task SetupRequest (HttpRequestMessage request, HttpURLConnecti
/// <param name="connection">HTTPS connection to return socket factory for</param>
protected virtual SSLSocketFactory? ConfigureCustomSSLSocketFactory (HttpsURLConnection connection)
{
return _underlyingHander.ConfigureCustomSSLSocketFactory (connection);
return _underlyingHander.ConfigureCustomSSLSocketFactoryInternal (connection);
}

[DynamicDependency (DynamicallyAccessedMemberTypes.PublicParameterlessConstructor, typeof (AndroidMessageHandler))]
object GetUnderlyingHandler ()
{
var fieldName = "_nativeHandler";
var baseType = GetType ().BaseType;
var field = baseType.GetField (fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
FieldInfo? field = null;

for (var type = GetType (); type != null; type = type.BaseType) {
field = type.GetField (fieldName, BindingFlags.Instance | BindingFlags.NonPublic);
if (field != null)
break;
}

if (field == null) {
throw new InvalidOperationException ($"Field '{fieldName}' is missing from type '{baseType}'.");
throw new InvalidOperationException ($"Field '{fieldName}' is missing from type '{GetType ()}'.");
}

return field.GetValue (this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,35 @@
namespace Xamarin.Android.Net
{
/// <summary>
#if MONOANDROID1_0
/// A convenience wrapper around <see cref="System.Net.Http.HttpResponseMessage"/> returned by <see cref="AndroidClientHandler.SendAsync"/>
/// that allows easy access to authentication data as returned by the server, if any.
#else
/// A convenience wrapper around <see cref="System.Net.Http.HttpResponseMessage"/> returned by <see cref="AndroidMessageHandler.SendAsync"/>
/// that allows easy access to authentication data as returned by the server, if any.
#endif
/// </summary>
public class AndroidHttpResponseMessage : HttpResponseMessage
{
URL? javaUrl;
HttpURLConnection? httpConnection;

/// <summary>
#if MONOANDROID1_0
/// Set to the same value as <see cref="AndroidClientHandler.RequestedAuthentication"/>.
#else
/// Set to the same value as <see cref="AndroidMessageHandler.RequestedAuthentication"/>.
#endif
/// </summary>
/// <value>The requested authentication.</value>
public IList <AuthenticationData>? RequestedAuthentication { get; internal set; }

/// <summary>
#if MONOANDROID1_0
/// Set to the same value as <see cref="AndroidClientHandler.RequestNeedsAuthorization"/>
#else
/// Set to the same value as <see cref="AndroidMessageHandler.RequestNeedsAuthorization"/>
#endif
/// </summary>
/// <value>The request needs authorization.</value>
public bool RequestNeedsAuthorization {
Expand Down
Loading