반응형
원격지가 전송 스트림을 닫았 기 때문에 인증에 실패했습니다.
인증서 인증으로 OpenSSL 서버를 연결하는 TCP 클라이언트를 개발 중입니다. 서버 팀에서 공유하는 .crt 및 .key 파일을 사용하고 있습니다. 이러한 인증서는 OpenSSL 명령에 의해 생성됩니다.
내가 사용하고 호출하여 TCP 클라이언트를 인증하는 개체를 서버에 전달하여 방법을 , 하고 .SslStream
SslStream.AuthenticateAsClient
IP
SslProtocols.Ssl3
X509CertificateCollection
다음과 같은 오류가 발생합니다.
원격지가 전송 스트림을 닫았 기 때문에 인증에 실패했습니다.
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은 기본적으로 올바른 프로토콜을 사용하며 두 솔루션 모두 필요하지 않습니다.
이전 버전의 .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);
}
아래 코드를 추가하면 문제를 해결하는 데 도움이됩니다.
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
ChargifyNET.dll을 사용하여 Chargify API와 통신하는 동안 동일한 오류 메시지가 표시되었습니다. 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;
}
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);
}
이것은 나를 위해 일했습니다.
VB.NET의 경우 웹 요청 전에 다음을 배치 할 수 있습니다.
Const _Tls12 As SslProtocols = DirectCast(&HC00, SslProtocols)
Const Tls12 As SecurityProtocolType = DirectCast(_Tls12, SecurityProtocolType)
ServicePointManager.SecurityProtocol = Tls12
이 .NET 3.5에서 내 보안 문제를 해결했습니다.
반응형
'ProgramingTip' 카테고리의 다른 글
배치 파일에서 어디에서 길이를 어떻게 얻습니까? (0) | 2020.11.26 |
---|---|
모든 항목을 바꿉니다. (0) | 2020.11.26 |
VS Code 통합 터미널의 색상 테마 (0) | 2020.11.26 |
DeprecationWarning : 펼쳐보기를 다른 서버로 실행할 때 보안 및 사용성 문제로 인해 Buffer ()가 더 이상 사용되지 않습니다. (0) | 2020.11.26 |
WebClient.DownloadString ()은 고유 한 문자가있는 곳을 반환합니다. (0) | 2020.11.26 |