互操作加密 OpenSslCryptographicException:错误:14094410:SSL 例程:ssl3_read_bytes:sslv3 警报握手失败

问题描述

无论目标是 net5.0 还是 net6.0 框架,在尝试创建 sslstream 时,它在运行时反复抛出在 Ubuntu 操作系统上运行的错误Windows 操作系统,处理此错误的正确方法是什么?

错误信息

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)