Hi,
I made a simple ftp client in C# which does what I need (connect to a ftp, optionally using a proxy), but I want to be able to use AUTH SSL also.
So instead of NetworkStream I looked at SslStream and hoped it would be a fairly easy substitute.
However I seem to have a lot of problems when handshaking with my (glftpd, selfsigned openssl cert) ftp. Here's a code snippit:
TcpClient client = new TcpClient("192.168.0.2", 1337);
SslStream sslStream = new SslStream(
client.GetStream(),
false,
new RemoteCertificateValidationCallback(ValidateServerCertificate),
null
);
try
{
sslStream.AuthenticateAsClient("192.168.0.2"); // or "glftpd", neither worked.
}
catch (AuthenticationException e)
{
Console.WriteLine("Exception: {0}", e.Message);
if (e.InnerException != null)
{
Console.WriteLine("Inner exception: {0}", e.InnerException.Message);
}
Console.WriteLine("Authentication failed - closing the connection.");
client.Close();
return;
}
I break on AuthenticateAsClient with IOException: "The handshake failed due to an unexpected packet format.". I don't break in ValidateServerCertificate (never reached).
I find it hard to debug this error as I can set the TcpClient port to 1208219421 and still recieve the same error (so I don't even know if it fails to talk to a ssl port).
The code (among 3-4 different C# ssl guides I looked at) above is modified from link text
I've tried both sslStream.AuthenticateAsClient(..., ..., SslProtocols.Tls, false) and sslStream.AuthenticateAsClient(..., ..., SslProtocols.Ssl3, false) Ssl2 and Default, and I know for a fact that TLS works with my glftpd install.
If I had to guess I'd think it has something to do with machinename/certname, but I've tried the certname (which is "glftpd"), so right now I'm clueless as to why I get failed handshake.
Also it should be noted that the cert is self-signed.
Any help is greatly appreciated!
- Chuck