标签: sslstream

为什么跨越AppDomains从SslStream读取成功但返回空缓冲区?

SslStream使用该Read(byte[] buffer, int offset, int count)方法正常阅读时,我得到了预期的结果.

但是,如果我将SslStream对象移动到一个新对象AppDomain,则读取仍然可以正常工作(即返回正确读取的字节数),但该buffer数组为空.

为什么是这样?

c# attributes appdomain marshalling sslstream

2
推荐指数
1
解决办法
441
查看次数

SSLStream:"调用SSPI失败"异常


我有一个奇怪的问题:我在c#中编写了一个基于.net2的服务器和客户端,它们通过.net 2 SslStream聊天.Cl和S之间有1个用于发送命令的连接,还有一个用于在cl和s之间发送文件的连接.
在我的Windows机器上本地一切正常.但是,如果我在我的Linux服务器上运行服务器(使用单声道),共享文件在某些​​情况下不起作用.我有不同的文件类别,在其中有两个工作,第三个,服务器挂起,SSLStream.AuthenticateAsServer(....);客户端抛出一个异常,消息"调用SSPI失败,请参阅内部异常".Innerexception是一个System.ComponentModel.Win32Exception,消息"收到的消息是意外的或格式错误的".

我认为我在linux上运行它的方式可能是错误的.实际上我使用VS2012进行本地开发,当我想把它放在服务器上时,我上传VS编译的exe和Im mono server.exe用来启动它.但我也尝试在Windows上使用monodevelop来编译它(monodevelop中编译的东西也在本地工作)并在linux服务器上使用它,但结果却相同.

任何帮助将不胜感激.



继承了我缩短的代码:

客户:

//gets auth guid before, then it does
Thread Thre = new Thread(sendfile);
Thre.Start(authguid);


private void sendfile(string guid){
TcpClient cl = new TcpClient();
cl.Connect(hostname, 8789);
SslStream Stream = new SslStream(cl.GetStream(), true, new RemoteCertificateValidationCallback(ServerConnector.ValidateServerCertificate));
Stream.AuthenticateAsClient(hostname);//throws the exception
//sends auth guid and file

}
Run Code Online (Sandbox Code Playgroud)

服务器:

 public class FServer
    {

        protected static bool halt = false;
        protected List<FConnection> connections;
        private TcpListener tcpServer;
        private IPEndPoint ipEnde = new IPEndPoint(IPAddress.Any, 8789);
        private delegate …
Run Code Online (Sandbox Code Playgroud)

c# mono sspi sslstream .net-2.0

2
推荐指数
1
解决办法
3万
查看次数

带有可选 ClientCertificate 的 SslStream AuthenticateAsServer

考虑到SslStream.AuthenticateAsServer方法,第二个参数clientCertificateRequired

如果设置为 true,则需要客户端证书。否则会抛出异常。客户端证书将在属性RemoteCertificate 中可用。

当设置为 false 时,不需要客户端证书,属性RemoteCertificate应始终为 null。即使是客户提供的。

我喜欢完成的是让客户决定是否提供证书。但是,如果他们确实提供了一个,我想在服务器上知道它。

我试图首先将变量设置为 true,如果失败,则回退到不需要证书。但是,这会导致“已验证异常”。

try{
        sslStream.AuthenticateAsServer(x509certificate, true, SslProtocols.Tls, true);
}catch(Exception ex){
        sslStream.AuthenticateAsServer(x509certificate, false, SslProtocols.Tls, true);
}
Run Code Online (Sandbox Code Playgroud)

c# ssl sslstream x509certificate

2
推荐指数
1
解决办法
2515
查看次数

Interop Crypto OpenSslCryptographicException:错误:14094410:SSL 例程:ssl3_read_bytes:sslv3 警报握手失败

无论目标net5.0net6.0框架,当尝试创建一个时,它在Ubuntu操作系统sslstream上运行时反复抛出错误,而在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) …
Run Code Online (Sandbox Code Playgroud)

tcpclient sslstream .net-core

2
推荐指数
1
解决办法
8287
查看次数

将SslStream与IOCP一起使用

我使用Socket类的异步/ IOCP方法,BeginSend()/ BeginRead()/ etc编写了一个TCP服务器.我想使用SslStream添加SSL功能,但是从界面看起来Socket和SslStream并不打算一起工作,特别是因为我根本不使用Streams而且SslStream似乎依赖于使用Stream来处理.

这是可能的,还是我在错误的地方?我是否需要设计自己的Stream子类,该子类将提供给我的Socket实例并指向SslStream?由于扩展问题,我的服务器使用IOCP对我很重要.

.net c# sockets sslstream iocp

1
推荐指数
1
解决办法
1572
查看次数