1
votes

I'm trying to connect to an Irc server which gave me error:

Authentication failed because the remote party has closed the transport stream.

The C# code:

_client = new StandardIrcClient();
_ircUrl = "irc.blabla.com";
_nick = "MyNick";
_port = 7021;
_useSsl = true;
_channels = new[] { "#test" };

IrcUserRegistrationInfo info = new IrcUserRegistrationInfo
{
    NickName = _nick,
    Password = "",
    RealName = _nick,
    UserName = _nick
};

_client.RawMessageReceived += (s, ev) =>
{
    write(ev.RawContent);
    _execute(ev.RawContent);
};

_client.Connected += (s, ev) =>
{
    write("Connected");
};

_client.Registered += (s, ev) =>
{
    _log.Debug("registered");

    if (!string.IsNullOrWhiteSpace(_inviteCommand))
    {
        if (_inviteCommand.IndexOf(":invite", StringComparison.OrdinalIgnoreCase) > -1)
        {
            _client.SendRawMessage($"PRIVMSG {_inviteCommand.Replace("invite", ":invite")}");
        }
    }

    _client.Channels.Join(_channels);
};

_client.ConnectFailed += (s, ev) =>
{
    write(ev.Error.Message);
    _client.Disconnect();
};

_client.Disconnected += (s, ev) =>
{
    _log.Debug("disconnected");
    write("Disconnected");
};

_client.Error += (s, ev) =>
{
    _log.Error(ev.Error);
};

_client.ErrorMessageReceived += (s, ev) =>
{
    _log.Error(ev.Message);
};

bool useSsl = _port > 0 && _useSsl;
if (useSsl)
{
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
}

_client.Connect(_ircUrl, _port == 0 ? 6667 : _port, useSsl, info);

EDIT

I'm using Net Standard library so I cannot add SSL3 since it says is not supported protocol.

1
Can you supply with an actual IRC server, so i can test with ?Orel Eraki
Can test on any irc with port >= 6697 and put true for useSSL flag in Connect methodSnake Eyes

1 Answers

0
votes

You didn't add Ssl3 SecurityProtocolType.Ssl3 to your SecurityProtocol. You need to enable Ssl3 security protocol also in your application.

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

Update: This issue occurs because the default set of SSL/TLS protocols that is used by ServicePointManager and SslStream was changed.

Old value: Ssl 3.0 | Tls 1.0 | Tls 1.1

New value: Tls 1.0 | Tls 1.1 | Tls 1.2

To work around this issue, update the server to Tls 1.0, Tls 1.1, or Tls 1.2 because SSL 3.0 has been shown to be unsecure and vulnerable to attacks such as POODLE.

Note If you cannot update the server, use AppContext class to opt out of this feature. To do this, use one of the following methods:

Programmatically: Must be the very first thing the application does because ServicePointManager will initialize only once.

Use the following code example in your application:

private const string DisableCachingName = @"TestSwitch.LocalAppContext.DisableCaching";
        private const string DontEnableSchUseStrongCryptoName = @"Switch.System.Net.DontEnableSchUseStrongCrypto";
        AppContext.SetSwitch(DisableCachingName, true);
        AppContext.SetSwitch(DontEnableSchUseStrongCryptoName, true);

For more information : Cannot connect to a server by using the ServicePointManager or SslStream APIs