代码之家  ›  专栏  ›  技术社区  ›  Snake Eyes

IrcDotNet连接错误身份验证失败,因为远程方在使用SSL时已关闭传输流

  •  0
  • Snake Eyes  · 技术社区  · 7 年前

    我正在尝试连接到Irc服务器,该服务器给了我错误:

    身份验证失败,因为远程方已关闭 传输流。

    C#代码:

    _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);
    

    编辑

    净标准 图书馆所以我 不能 添加SSL3,因为它表示不支持该协议。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Rahul Nikate    7 年前

    您没有添加Ssl3 SecurityProtocolType.Ssl3 给你 SecurityProtocol Ssl3 安全协议也在您的应用程序中。

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

    出现此问题是因为默认的 SSL/TLS ServicePointManager 和 SslStream 改变了。

    旧值:

    新值: Tls 1.0 | Tls 1.1 | Tls 1.2

    要解决此问题,请将服务器更新为 Tls 1.0, Tls 1.1, or Tls 1.2 SSL 3.0 已被证明是不安全的,容易受到狮子狗之类的攻击。

    注意:如果无法更新服务器,请使用 AppContext 类以选择退出此功能。为此,请使用以下方法之一:

    必须是应用程序要做的第一件事,因为 服务点管理器 将只初始化一次。

    在应用程序中使用以下代码示例:

    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