Merge pull request #2171 from lambdageek/dev/fix-marshal
[mono.git] / mcs / class / System / System.Net / FtpWebRequest.cs
index a45dcc99990d48585bd09b1fd9e69be16bc3b5a1..bb900979a48ff614732e30717f06f15925b1981f 100644 (file)
@@ -7,6 +7,15 @@
 // (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
 //
 
+#if SECURITY_DEP
+#if MONO_SECURITY_ALIAS
+extern alias MonoSecurity;
+using MSI = MonoSecurity::Mono.Security.Interface;
+#else
+using MSI = Mono.Security.Interface;
+#endif
+#endif
+
 using System;
 using System.IO;
 using System.Net.Sockets;
@@ -17,6 +26,7 @@ using System.Security.Cryptography.X509Certificates;
 using System.Net;
 using System.Net.Security;
 using System.Security.Authentication;
+using Mono.Net.Security;
 
 namespace System.Net
 {
@@ -1155,28 +1165,14 @@ namespace System.Net
                        ChangeToSSLSocket (ref stream);
                }
 
-#if SECURITY_DEP
-               RemoteCertificateValidationCallback callback = delegate (object sender,
-                                                                        X509Certificate certificate,
-                                                                        X509Chain chain,
-                                                                        SslPolicyErrors sslPolicyErrors) {
-                       // honor any exciting callback defined on ServicePointManager
-                       if (ServicePointManager.ServerCertificateValidationCallback != null)
-                               return ServicePointManager.ServerCertificateValidationCallback (sender, certificate, chain, sslPolicyErrors);
-                       // otherwise provide our own
-                       if (sslPolicyErrors != SslPolicyErrors.None)
-                               throw new InvalidOperationException ("SSL authentication error: " + sslPolicyErrors);
-                       return true;
-                       };
-#endif
-
                internal bool ChangeToSSLSocket (ref Stream stream) {
-#if   SECURITY_DEP
-                       SslStream sslStream = new SslStream (stream, true, callback, null);
-                       //sslStream.AuthenticateAsClient (Host, this.ClientCertificates, SslProtocols.Default, false);
-                       //TODO: client certificates
+#if SECURITY_DEP
+                       var provider = MonoTlsProviderFactory.GetProviderInternal ();
+                       var settings = new MSI.MonoTlsSettings ();
+                       settings.UseServicePointManagerCallback = true;
+                       var sslStream = provider.CreateSslStream (stream, true, settings);
                        sslStream.AuthenticateAsClient (requestUri.Host, null, SslProtocols.Default, false);
-                       stream = sslStream;
+                       stream = sslStream.AuthenticatedStream;
                        return true;
 #else
                        throw new NotImplementedException ();