The following code is able to connect to a FTP server using TLS:
private FtpClient getFtpsClient(System.Uri uri) {
if (uri.Scheme != "ftps") {
throw new NotImplementedException("Only ftps is implementent");
}
var userInfo = uri.UserInfo.Split(":");
FtpClient client = new FtpClient(uri.Host, userInfo[0], userInfo[1]);
client.EncryptionMode = FtpEncryptionMode.Explicit;
client.SslProtocols = SslProtocols.Tls;
client.ValidateCertificate += new FtpSslValidation(OnValidateCertificate);
client.Connect();
void OnValidateCertificate(FtpClient control, FtpSslValidationEventArgs e) {
var cert2 = new X509Certificate2(e.Certificate);
e.Accept = cert2.Verify();
}
return client;
}
As library I use FluentFTP. I wonder, if the method X509Certificate2.Verify()
is enough to prevent security issues.
What exactly does X509Certificate2.Verify()
do? The referenced documentation is very short on information.
Would it fail on a man-in-the-middle attack?