90 Commits
Author SHA1 Message Date
Martin Baulig 89427f4938 [System]: Free ServicePoint instances when they're no longer used. (#8562)
* [System]: Free ServicePoints when they're no longer used.

* Cleanup.

* Don't crash when ServicePoint.CloseConnectionGroup() is called after the ServicePoint has been freed.

* Remove the CloseConnectionGroupConcurrency() test.

This test was for a regression in a piece of code that no longer exist
and the test is poorly designed as it depends on precise timings.
It also attempts to make a web request to a non-exisiting server and
just ignores the error - it is unclear whether that is intentional or not.
2018-05-08 23:21:46 +01:00
Martin Baulig 86981b96a5 [System]: Allow SecurityProtocolType.SystemDefault.
In CoreFX, `ServicePointManager.SecurityProtocol` defaults to
`SecurityProtocolType.SystemDefault` (which is zero).

We now allow this value to mean "whatever the system default is"
in both AppleTls and BTLS.

The default value of `ServicePointManager.SecurityProtocol` has also
been changed to be consistent with CoreFX.
2018-05-08 23:17:55 +01:00
Marek Safar 95b0698304 [System] Clean up some warnings 2016-10-25 14:28:35 +02:00
Alexander Köplinger 112631f5c6 [bcl] Add missing APIs for netstandard parity and expose a few APIs on mobile
This ensures we're compliant with the upcoming netstandard2.0 API surface area.
2016-09-23 17:50:06 +02:00
Marek Habersack d063541740 Set DefaultPersistentConnectionLimit to 10 for Xamarin.Android
This is to make it the same as the Xamarin.iOS setting and
fixes https://bugzilla.xamarin.com/show_bug.cgi?id=7467
2016-09-14 11:18:13 +02:00
Ludovic Henry 249daf43de [mcs] Replace NET_2_1 by MOBILE
NET_2_1 is also defined whenever we define MOBILE, so they have the same effect. Silverlight was 2.1 but it's been dead for a while now, and we do not even support it.
2016-08-18 16:34:36 +02:00
Marek Safar b6a30059db [bcl] Update Reference Source to .NET Framework 4.6.2 2016-08-09 18:07:14 +02:00
Marek Safar a2147aa78a [System] WebProxy from referencesource 2016-05-31 09:58:26 +02:00
Martin Baulig 80741c16fd [System]: 'ServicePointManager.CertificatePolicy': lazily initialize.
The internal GetLegacyCertificatePolicy() now returns null unless this
property has explicitly been assigned to, so the legacy handler will not
be used in ChainValidationHelper.

(cherry picked from commit e69e878405)
2016-02-17 20:40:59 -05:00
Martin Baulig a429d91690 [System]: Disallow "https" proxies in ServicePointManager.FindServicePoint().
(cherry picked from commit e734cd8b59)
2016-02-17 20:40:09 -05:00
Martin Baulig c56f5c199c [System]: Use correct default value for ServicePointManager.SecurityProtocol.
(cherry picked from commit ddf47829d9)
2016-02-17 20:39:58 -05:00
Martin Baulig 25a206c6da [System/TLS]: Switch to the new ChainValidationHelper.
* Removed Mono.Security.Protocol.Tls.ValidationResult, use
  Mono.Security.Interface instead.  This is an API breaking
  change, but you can fix your application by simply adding
  the new using directive.

  The rationale behind this is to avoid a dependency on the
  Mono.Security.Protocol.Tls namespace when building and
  related classes when building the new TLS stack.

* Enable ChainValidationHelper in WebConnection, LegacySslStream
  and SslStream.

  The custom conditionals that were previously required for the
  mobile profiles are now gone as ChainValidationHelper already
  handles that internally.

* This is an internal API, the public front-end is
  Mono.Security.Interface.CertificateValidationHelper.

  CertificateValidationHelper can be used to access the system
  certificate validator on OS X and iOS; we do not compute the
  X509Chain on these platforms as it's not supported by the OS.

(cherry picked from commit 9713f35878dd90fe87423b5052b4f82ddc0b87f0)
2015-10-14 19:26:06 -04:00
Martin Baulig 47efc2461e [System]: Use 'ServerCertValidationCallback' in ServicePointManager.
This is a new internal wrapper class defined in
external/referencesource/System/net/System/Net/ServicePointManager.cs

It wraps the RemoteCertificateValidationCallback, capturing the
current ExecutionContext.

(cherry picked from commit c1695a55dc9a55f6b344bfc4c91991bd1f04c046)
2015-10-13 16:25:41 -04:00
Martin Baulig f01a88837f [System] Add internal 'ServicePointManager.DisableStrongCrypto'.
It's an internal API that's used by the referencesource.

(cherry picked from commit 7fbd50ab52fc4cdf2fa9282ecd9d286ac48d9ba8)
(cherry picked from commit eb2f282d6f)
2015-10-12 17:19:15 -04:00
Simon Hartmann 932359f3d6 implemented DnsRefreshTimeout to ServicePointManager and adjusted behavior of ServicePoint.HostEntry property.
simplified some calls as requested
2015-09-08 11:08:50 +02:00
Marek Safar 92ff3c372d [system.net.http] Make SendAsync state free to handle recursive calls. Fixes #22724 2014-09-08 11:48:51 +02:00
Alexander Köplinger 48e112d652 [Cleanup] Removed TARGET_JVM
It was once part of a special Java target profile, but this is no longer used today.
2014-08-08 03:28:34 +02:00
Martin Baulig f462bcc944 [Http]: Only recycle ServicePoints from the idle timer (fixes #19823).
Thanks a lot for Martin Potter to find and report the race condition
which was causing the problem.

ServicePointManager.RecycleServicePoints() was a left-over from the
old times when we didn't have an idle-timer based approach.
2014-06-10 19:21:32 +02:00
Marek Habersack 34fb07d05f Include support for SSL/TLS right in System when building for the MONODROID profile
This patch builds upon commit 96a8500795 which placed parts of Mono.Security
responsible for dealing with SSL/TLS certificates for the purpose of certificate verification. The code enables
validation of the certifcates even if the user does not provide their own validation callback. The changes as related to
the original commit are few, basically consisting of enabling the same code used by MonoTouch in the MonoDroid context with
the only actual code change being the certificate validation bit mentioned above.

Since the change involves adding a subset of Mono.Security files to the monodroid version of System.dll, it is
also necessary to remove Mono.Android's dependence on Mono.Security.dll. The reason is that the code in AndroidPlatform
which looks up TLS support methods in Mono.Android.dll would use a type (X509CertificateCollection) that is now part of
System.dll but is *also* in Mono.Security.dll referenced by Mono.Android.dll and therefore the lookup would fail since
we'd have two distinct types from the reflection point of view.

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=18962
2014-04-25 21:39:53 +02:00
Sebastien Pouliot 43fcd744d0 [SSL/TLS] Expose Client/Server callbacks that can be used to select/reorder SSL/TLS cipher suites used (for client or server) and add unit tests for them [#16327] 2014-02-19 08:51:51 -05:00
Martin Baulig c6a70a9586 Rewrite and fix the web stack's connection reuse and idle logic.
* ServicePoint now uses an idle timer to close idle connections.

* WebConnectionGroup has been mostly rewritten to use a linked
  list of open connections and their idle times.

  This fixes both the problem that we were leaking sockets and
  that we were not reusing existing connections.

* ServicePoint now correctly keeps track of the number of open
  connections.

* ServicePointManager now uses the correct default idle time
  of 100 seconds (previously 15 minutes).

* WebConnection uses the new WebConnectionGroup's busy logic
  to correctly flag connections as busy / reusable.
2014-02-13 14:17:14 +01:00
Paolo Molaro cc7b7992ff Reduce contention and unnecessary checks at each lookup, part of xambug #14644. 2013-11-05 17:37:08 +01:00
Sebastien Pouliot 96a8500795 Allow the MONOTOUCH targetr to build its SSL/TLS support right inside System.dll and remove code duplication and non-required code paths. 2013-07-01 16:21:04 -04:00
Martin Baulig db06719d2a [System]: Make ServicePointManager hash on the proxy as well as uri and use_connect.
This fixes #12640.
2013-06-21 14:25:51 +02:00
Atsushi Eno 76af46a676 Fix monodroid build. 2013-02-27 17:51:56 +09:00
Marek Safar 93c35ffe14 Fix more compiler warnings 2013-02-26 10:37:02 +01:00
Marek Safar 5aeeb9cf7b Fix few warnings 2013-02-25 19:10:09 +01:00
Marek Safar 0647a5d16b Remove duplicated files from system.dll (saves about 100kb) 2013-02-25 19:10:09 +01:00
Rodrigo Kumpera 5007c14d62 Kill the MOONLIGHT define in System. 2013-02-11 13:01:11 -05:00
Atsushi Eno 740d826912 fix mobile build (from 6b4c3f0). 2013-02-08 17:05:31 +09:00
Marek Safar 6b4c3f0d72 Merge pull request #472 from MelanieT/spmanager_fix
Fix ServicePointManager.DefaultConnectionLimit to work as specified.
2013-02-07 07:05:41 -08:00
Martin Baulig db232608f4 [#7599][Web]: Use original uri to compute service point hash.
Use the original request Uri, not the proxy address, to compute
the service point hash.
2012-10-21 18:56:13 +02:00
Sebastien Pouliot 0c644b5fcc Provide a non-null X509Chain in the callback for MonoTouch (useful for custom validations) but we are not fully building it (since we do not use the output) and this can be done if customization is required 2012-10-09 19:43:52 -04:00
Melanie Thielker 9605c20c97 Fix ServicePointManager to accept the DefaultConnectionLimit property being
set as per the .NET spec.
2012-09-30 18:46:38 +02:00
Sebastien Pouliot 6fc934ea50 [OSX] Reset errors to 0 if the OS tells us that (1) the chain is ok, (2) the certificate usage is for SSL server and (3) the server identity is confirmed (2+3 were part of an earlier fix). Without this reset we depended on the mono certificate store as an extra condition (which would requires mozroots to be executed and we want to avoid this 'duplicated' requirement and trust OSX). This does not affect iOS where no mono stores exists. 2012-09-13 20:48:42 -04:00
Jonathan Pryor 1249082309 [M4A] Clear RemoteCertificateChainErrors if Android validates the chain.
The problem: Mono for Android 4.2.5 horribly broke SSL support:

	http://lists.ximian.com/pipermail/monodroid/2012-September/012213.html

Why? Because of ad89f72f (kinda): As Mono for Android doesn't provide
or use its own set of SSL root certificates (opting instead to just
let Android worry about it), the `chain.Build()` method will ALWAYS
result in SslPolicyErrors.RemoteCertificateChainErrors being returned
from GetErrorsFromChain().

The world before ad89f72f "masked" this because errors & status11 were
always cleared if Android accepted the chain; however, clearing these
out masked other bugs, such as #5706 (in which https://74.125.224.134
is accepted as valid when it can't be valid, by definition).

The fix is to clear out SslPolicyErrors.RemoteCertificateChainErrors
if Android accepts the certificate chain. Any other errors are left
unchanged, thus keeping #5706 fixed.
2012-09-13 14:46:59 -04:00
Sebastien Pouliot ad89f72f5b [M4A] Do not reset 'errors' and 'status11' when a certificate is trusted. Fix last part of #5706 2012-08-23 16:39:57 -04:00
Sebastien Pouliot 3a274aac77 [OSX|iOS] Do not reset 'errors' and 'status11' when a certificate is trusted. Use the OS to validate the certificate (as valid for SSL server usage) and for the host name checks. Fix parts of #5706 2012-08-23 16:37:23 -04:00
Jonathan Pryor 3363b136c6 Pass SSL certificate chain, not just collection, to Mono.Android.dll
Fixes BCL half of: https://bugzilla.xamarin.com/show_bug.cgi?id=6501

Today I learned that the SSL certificate collection (as held in
X509CertificateCollection) is a potentially unordered sequence of SSL
certificates, which not all versions of Android will validate.

The fix is to use the properly ordered SSL certificate chain (as held
in X509Chain), and have Android validate that.
2012-08-13 13:48:16 -04:00
Gonzalo Paniagua Javier 798784bac5 Backport from mobile 2012-07-11 18:17:36 -04:00
Marek Safar 5b82f0e08c Clean up some NET_2_0 2012-06-14 15:44:35 +01:00
Sebastien Pouliot 903ce57ce7 Propagate all errors to the (old) ICertificatePolicy or (newer) callback. Fix bug #5546 for iOS 2012-06-06 21:11:54 -04:00
Miguel de Icaza f48ceb9860 [System] Removal of the NET_2_0 in the source code
Modulo the GUID in the assembly and the GUID embedded in some
field initializers that use the assembly GUID for their name, the
assemblies are idential before and after the patch.
2012-06-02 13:16:40 -04:00
Miguel de Icaza ae0feab435 Removal of NET_1_1 defines and some NET_2_0; Both defines are true these days in Mono, no versions prior to 2.0 are supported 2012-06-01 18:04:24 -04:00
Gonzalo Paniagua Javier 9007f5e043 Avoid deadlocking when getting the ServicePoint
SSL connections were deadlocking when getting the service point for the
	connection in the last few releases of 2.10.x and in master.

	Fixes bug #4599.
2012-04-24 04:54:54 -04:00
Sebastien Pouliot e952c9a89b Do not build a managed X509Chain in MonoTouch and simply ask iOS about the chain. Other SSL related checks about the leaf certificate are still required/done. Avoid many internal exceptions since Mono's machine store does not exists inside iOS devices (note: already part of MonoTouch since 4.3) 2012-01-12 15:47:37 -05:00
Sebastien Pouliot 1db32e3410 avoid potential InvalidCastException when we already deal with bad/non-present extensions (reduce error message when -E:all is used) 2011-07-19 10:34:57 -04:00
Gonzalo Paniagua Javier 891af303aa [Socket] Implemented TCP keep alive support
Implemented SetTcpKeepAlive for ServicePoint*.
2011-01-13 18:28:16 -05:00
Gonzalo Paniagua Javier 604d5faa0b More StringComparison.Ordinal
Use StringComparison.Ordinal when calling IndexOf to find the index of
	an ASCII string.
2010-10-31 17:23:18 -04:00
Jonathan Pryor ac277b3917 Add preliminary HTTPS handling support for Android.
The problem is that Android only exposes Java APIs for ~everything of
consequence, including/especially X509 Certificate validation.  Since
we want Mono-based HTTPS support to use the underlying platform
certificates, this requires some amount of Java-using glue.  However,
we don't want to pull in a ton of Java glue into System.dll (bleh!),
so we'll instead place the glue into Mono.Android.dll's
Android.Runtime.AndroidEnvironment.TrustEvaluateSsl(), and instead
create a delegate which will invoke TrustEvaluateSsl() when needed.
2010-10-12 17:47:53 -04:00