Подтвердить что ты не робот

Ошибка аутентификации, так как удаленная сторона закрыла транспортный поток

Я разрабатываю клиент TCP для подключения сервера OpenSSL с проверкой подлинности сертификата. Я использую файлы.crt и.key, используемые командой сервера. Эти сертификаты генерируются командами OpenSSL.

Я использую объект SslStream для аутентификации клиента Tcp, вызывая метод SslStream.AuthenticateAsClient, передавая IP сервера, SslProtocols.Ssl3 и X509CertificateCollection.

Я получаю следующую ошибку:

Ошибка аутентификации, потому что удаленная сторона закрыла транспортный поток

4b9b3361

Ответ 1

Я бы посоветовал не ограничивать SecurityProtocol TLS 1.1.

Рекомендуемое решение - использовать

System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls

Другой вариант - добавить следующий ключ реестра:

Key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319 
Value: SchUseStrongCrypto 

Стоит отметить, что .NET 4.6 будет использовать правильный протокол по умолчанию и не требует решения.

Ответ 2

Если вы хотите использовать более старую версию .net, создайте свой собственный флаг и произведите его.

    //
    // Summary:
    //     Specifies the security protocols that are supported by the Schannel security
    //     package.
    [Flags]
    private enum MySecurityProtocolType
    {
        //
        // Summary:
        //     Specifies the Secure Socket Layer (SSL) 3.0 security protocol.
        Ssl3 = 48,
        //
        // Summary:
        //     Specifies the Transport Layer Security (TLS) 1.0 security protocol.
        Tls = 192,
        //
        // Summary:
        //     Specifies the Transport Layer Security (TLS) 1.1 security protocol.
        Tls11 = 768,
        //
        // Summary:
        //     Specifies the Transport Layer Security (TLS) 1.2 security protocol.
        Tls12 = 3072
    }
    public Session()
    {
        System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)(MySecurityProtocolType.Tls12 | MySecurityProtocolType.Tls11 | MySecurityProtocolType.Tls);
    }

Ответ 3

Добавление приведенного ниже кода помогло мне преодолеть эту проблему.

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;

Ответ 4

Я столкнулся с тем же сообщением об ошибке при использовании файла ChargifyNET.dll для связи с API-интерфейсом Chargify. Добавление chargify.ProtocolType = SecurityProtocolType.Tls12; к конфигурации разрешило проблему для меня.

Вот полный фрагмент кода:

public ChargifyConnect GetChargifyConnect()
{
    var chargify = new ChargifyConnect();
    chargify.apiKey = ConfigurationManager.AppSettings["Chargify.apiKey"];
    chargify.Password = ConfigurationManager.AppSettings["Chargify.apiPassword"];
    chargify.URL = ConfigurationManager.AppSettings["Chargify.url"];

    // Without this an error will be thrown.
    chargify.ProtocolType = SecurityProtocolType.Tls12;

    return chargify;
}

Ответ 5

Для VB.NET вы можете поместить следующее перед веб-запросом:

Const _Tls12 As SslProtocols = DirectCast(&HC00, SslProtocols)
Const Tls12 As SecurityProtocolType = DirectCast(_Tls12, SecurityProtocolType)
ServicePointManager.SecurityProtocol = Tls12

Это решило мою проблему безопасности на .NET 3.5.

Ответ 6

using (var client = new HttpClient(handler))
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
                var response = await client.SendAsync(new HttpRequestMessage(HttpMethod.Get, apiEndPoint)).ConfigureAwait(false);
                await response.Content.ReadAsStringAsync().ConfigureAwait(false);
            }

Это сработало для меня