【发布时间】:2021-03-31 10:00:17
【问题描述】:
无论是针对net5.0还是net6.0框架,在尝试创建sslstream时,在Ubuntu OS上运行时,在Windows上运行时反复抛出错误strong> 操作系统,处理此错误的正确方法是什么?
错误信息
System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
---> Interop+OpenSsl+SslException: SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.
---> Interop+Crypto+OpenSslCryptographicException: error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure
--- End of inner exception stack trace ---
at Interop.OpenSsl.DoSslHandshake(SafeSslHandle context, ReadOnlySpan`1 input, Byte[]& sendBuf, Int32& sendCount)
at System.Net.Security.SslStreamPal.HandshakeInternal(SafeFreeCredentials credential, SafeDeleteSslContext& context, ReadOnlySpan`1 inputBuffer, Byte[]& outputBuffer, SslAuthenticationOptions sslAuthenticationOptions)
--- End of inner exception stack trace ---
at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)
示例代码
public static SslStream CreateSslStream(this TcpClient client, bool leaveInnerStreamOpen = false)
{
var validationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
var selectionCallback = new LocalCertificateSelectionCallback(SelectLocalCertificate);
return new SslStream(client.GetStream(), leaveInnerStreamOpen, validationCallback, selectionCallback);
}
【问题讨论】:
标签: .net-core tcpclient sslstream