//
// (c) Copyright 2006 Novell, Inc. (http://www.novell.com)
//
-#if NET_2_0
+
+#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;
using System.Net.Security;
using System.Security.Authentication;
+using Mono.Net.Security;
namespace System.Net
{
Uri requestUri;
string file_name; // By now, used for upload
ServicePoint servicePoint;
+ Stream origDataStream;
Stream dataStream;
Stream controlStream;
StreamReader controlReader;
WebRequestMethods.Ftp.UploadFileWithUniqueName // STUR
};
+ Encoding dataEncoding = Encoding.UTF8;
+
internal FtpWebRequest (Uri uri)
{
this.requestUri = uri;
}
}
+#if !NET_2_1
[MonoTODO]
public static new RequestCachePolicy DefaultCachePolicy
{
throw GetMustImplement ();
}
}
+#endif
public bool EnableSsl {
get {
}
set {
CheckRequestStarted ();
- if (value == null)
- throw new ArgumentNullException ();
-
proxy = value;
}
}
asyncResult.SetCompleted (false, ftpResponse);
}
catch (Exception e) {
- State = RequestState.Error;
+ if (!GetServicePoint ().UsesProxy)
+ State = RequestState.Error;
SetCompleteWithError (e);
}
}
if (local_path [0] == '/')
local_path = local_path.Substring (1);
- Uri initial = new Uri ("ftp://dummy-host" + initial_path);
+ UriBuilder initialBuilder = new UriBuilder () {
+ Scheme = "ftp",
+ Host = "dummy-host",
+ Path = initial_path,
+ };
+ Uri initial = initialBuilder.Uri;
result = new Uri (initial, local_path).LocalPath;
}
void ProcessMethod ()
{
+ ServicePoint sp = GetServicePoint ();
+ if (sp.UsesProxy) {
+ if (method != WebRequestMethods.Ftp.DownloadFile)
+ throw new NotSupportedException ("FTP+proxy only supports RETR");
+
+ HttpWebRequest req = (HttpWebRequest) WebRequest.Create (proxy.GetProxy (requestUri));
+ req.Address = requestUri;
+ requestState = RequestState.Finished;
+ WebResponse response = req.GetResponse ();
+ ftpResponse.Stream = new FtpDataStream (this, response.GetResponseStream (), true);
+ ftpResponse.StatusCode = FtpStatusCode.CommandOK;
+ return;
+ }
State = RequestState.Connecting;
ResolveHost ();
}
}
- private void CloseDataConnection () {
- if(dataStream != null) {
- dataStream.Close ();
- dataStream = null;
+ internal void CloseDataConnection () {
+ if(origDataStream != null) {
+ origDataStream.Close ();
+ origDataStream = null;
}
}
Authenticate ();
FtpStatus status = SendCommand ("OPTS", "utf8", "on");
- // ignore status for OPTS
+ if ((int)status.StatusCode < 200 || (int)status.StatusCode > 300)
+ dataEncoding = Encoding.Default;
+ else
+ dataEncoding = Encoding.UTF8;
+
status = SendCommand (WebRequestMethods.Ftp.PrintWorkingDirectory);
initial_path = GetInitialPath (status);
}
throw CreateExceptionFromResponse (status);
if (usePassive) {
- dataStream = new NetworkStream (s, false);
+ origDataStream = new NetworkStream (s, true);
+ dataStream = origDataStream;
if (EnableSsl)
ChangeToSSLSocket (ref dataStream);
}
}
s.Close ();
- dataStream = new NetworkStream (incoming, false);
+ origDataStream = new NetworkStream (incoming, true);
+ dataStream = origDataStream;
if (EnableSsl)
ChangeToSSLSocket (ref dataStream);
}
commandString += " " + String.Join (" ", parameters);
commandString += EOL;
- cmd = Encoding.ASCII.GetBytes (commandString);
+ cmd = dataEncoding.GetBytes (commandString);
try {
controlStream.Write (cmd, 0, cmd.Length);
} catch (IOException) {
string line = null;
string find = code.ToString() + ' ';
while (true){
+ line = null;
try {
line = controlReader.ReadLine();
} catch (IOException) {
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 TARGET_JVM
- stream.ChangeToSSLSocket ();
- return true;
-#elif 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 ();
}
}
-#endif