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.
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
* 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.
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.
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.
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.
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-07-21 Sebastien Pouliot <[email protected]>
* Makefile: Ensure SECURITY_DEP gets defined in our moonlight
raw profile
In System.Net:
2010-07-21 Sebastien Pouliot <[email protected]>
* ServicePointManager.cs: Add special validation for Moonlight
* WebConnection.cs: Change a define to NET_2_1
In System.Net.Security:
2010-07-21 Sebastien Pouliot <[email protected]>
* LocalCertificateSelectionCallback.cs:
* SslStream.cs:
Don't use alias in moonlight build (not needed and breaks
compilation otherwise)
svn path=/trunk/mcs/; revision=160675
* ServicePointManager.cs: errors parsing the certificate don't prevent
calling the callback now. Exceptions thrown parsing the certificate
are printed to stderr in case they are library errors.
svn path=/trunk/mcs/; revision=154316
2010-03-19 Sebastien Pouliot <[email protected]>
* Timer.cs: Removed old NET_2_0 defines and added some new
MOONLIGHT defines (needed for the client stack)
In System.Net:
2010-03-19 Sebastien Pouliot <[email protected]>
* AuthenticationManager.cs: Internal type for Moonlight.
Add BasicClient, DigestClient, NtlmClient for NET_2_1 since
this applies to both monotouch and moonlight (client stack).
Removed unneeded NET_2_0 defines
* CookieContainer.cs: For Moonlight it needs to be internal in
System.dll and public in System.Net.dll. Removed unneeded NET_2_0
defines
* HttpContinueDelegate.cs: Internal type for Moonlight.
* HttpRequestCreator.cs: Remove a MOONLIGHT define
* HttpStatusCode.cs: For Moonlight it needs to be internal in
System.dll and public in System.Net.dll
* HttpWebRequest.cs: Internal type for Moonlight. Change S.Config
to NET_2_1 defines (applies to both monotouch and moonlight).
Removed unneeded NET_2_0 and NET_1_1 defines
* HttpWebResponse.cs: Internal type for Moonlight. Removed
unneeded NET_2_0 defines
* IAuthenticationModule.cs: Internal type for Moonlight.
* ICertificatePolicy.cs: Internal type for Moonlight.
* ICredentialPolicy.cs: Internal type for Moonlight. Removed
unneeded NET_2_0 defines
* IWebRequestCreate.cs: For Moonlight it needs to be internal in
System.dll and public in System.Net.dll
* ServicePoint.cs: Internal type for Moonlight. Change S.Config
to NET_2_1 defines (applies to both monotouch and moonlight)
* ServicePointManager.cs: Remove a MOONLIGHT define
* WebException.cs: For Moonlight it needs to be internal in
System.dll and public in System.Net.dll. Removed unneeded NET_2_0
defines
* WebHeaderCollection.cs: Internal type for Moonlight. Removed
unneeded NET_2_0 defines
* WebRequest.cs: Internal type for Moonlight. Change S.Config
to NET_2_1 defines (applies to both monotouch and moonlight)
* WebResponse.cs: Internal type for Moonlight. Removed unneeded
NET_2_0 defines
In System.Net.Sockets:
2010-03-19 Sebastien Pouliot <[email protected]>
* Socket.cs: Remove some NET_2_0 defines (using) and add a few
MOONLIGHT defines needed to reuse Socket in the client http stack
* Socket_2_1.cs: Remove some MOONLIGHT defines
* SocketAsyncEventArgs.cs: For Moonlight check policy if outside
System.dll (the client stack use sockets with it's own web
xdomain policy)
In System:
2010-03-19 Sebastien Pouliot <[email protected]>
* Uri.cs: Remove some MOONLIGHT defines
In .:
2010-03-19 Sebastien Pouliot <[email protected]>
* moonlight_*_System.dll.sources: Bring extra types so we can
build a full, managed, internal HTTP stack to be reused for SL3+
* Makefile: Add a INSIDE_SYSTEM define when compiling System.dll
to makes it possible to rebuild the same types in System.Net.dll
svn path=/trunk/mcs/; revision=153916
* System.Net/WebConnection.cs: attach a validation callback to the new
event in Mono.Security.
* System.Net/ServicePointManager.cs: added a new ValidationHelper
class that takes care of building the certificate chain and perform
all the check that were done in Mono.Security before. This way the 2.0
server certificate validation callback can get all the data it needs.
* System.Net.Security/SslStream.cs: don't do anything if a chain
element has no error.
Fixes bug #584050.
svn path=/trunk/mcs/; revision=152654
* ServicePointManager.cs: implement ServerCertificateValidationCallback.
* DefaultCertificatePolicy.cs: if there's a SCVC registered, don't do
normal error checking.a
svn path=/trunk/mcs/; revision=137253
* ServicePointManager.cs: set the default limit of connections from
the configuration file(s) on startup.
Bug #339422 fixed.
svn path=/trunk/mcs/; revision=117126