// (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;
using System.Net;
using System.Net.Security;
using System.Security.Authentication;
+using Mono.Net.Security;
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 ();