35 lines
1.0 KiB
C#
35 lines
1.0 KiB
C#
namespace DearFTP.Connection.Commands
|
|
{
|
|
class AuthCommand : ICommand
|
|
{
|
|
public string[] Aliases { get; } = new string[]
|
|
{
|
|
"AUTH"
|
|
};
|
|
|
|
public void Execute(Session session, FtpStream stream, string alias, string argument)
|
|
{
|
|
string protocol = argument.ToUpper();
|
|
|
|
if (protocol != "TLS" && protocol != "TLS-C" && protocol != "SSL")
|
|
{
|
|
stream.Send(ResponseCode.ArgumentNotImplemented, "Invalid argument, expected 'TLS'");
|
|
return;
|
|
}
|
|
|
|
var tlsConfiguration = session.Configuration.Tls;
|
|
|
|
if (!tlsConfiguration.AllowTls)
|
|
{
|
|
session.LogError("Tls", "Client tried to use Tls but Tls is desactivated");
|
|
stream.Send(ResponseCode.NotImplemented, "Tls is not enabled on this server");
|
|
return;
|
|
}
|
|
|
|
stream.Send(ResponseCode.AcceptAuthenticationMechanism, "Tls activated.");
|
|
|
|
session.ActivateTls();
|
|
}
|
|
}
|
|
}
|