因为远程方已关闭在WPF传输流异常

因为远程方已关闭在WPF传输流异常

本文介绍了Socket和身份验证失败,因为远程方已关闭在WPF传输流异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Java的网状基于服务器,为自己(和服务器的家伙告诉我,那是接受来自客户端的任何证书现在),它自动生成证书连接。

I am trying to connect with Java netty based server, which auto generates certificates for itself (and server guys told me, that is accepting any certificate from client side for now).

我的任务是迁移的TCPSocket连接到TLS加密连接。

My task was to migrate TcpSocket connection into Tls encrypted connection.

首先,我转换的TCPSocket到的NetworkStream:

First of all, I converted TcpSocket into NetworkStream:

using (var client = new NetworkStream(connection.TcpSocket))
{
    if (client.CanRead)
    {
        client.BeginRead(recvState.DataBuffer, 0, recvState.DataBuffer.Length, ReceiveCallback,
        recvState);
    }
}

和正在工作的完美。于是,我决定建立SslAuthentication - 喜欢这里:

and that is working perfectly. So then, I decided to build SslAuthentication - like here:

using (var client = new NetworkStream(connection.TcpSocket))
using (var sslStream = new SslStream(client, false, App_CertificateValidation))
{
    var clientCertificate = new X509Certificate2("client.pfx");
    var clientCertificateCollection = new X509Certificate2Collection(new[] { clientCertificate });
    sslStream.AuthenticateAsClient("MyServer", clientCertificateCollection, SslProtocols.Tls, false);

    if (sslStream.CanRead)
    {
        sslStream.BeginRead(recvState.DataBuffer, 0, recvState.DataBuffer.Length, ReceiveCallback,
        recvState);
    }
}



其中, client.pfx 是一个没有密码随机证书,如在项目中的文件,并导入到当前用户认证>个人>证书 certmgr.msc

Where client.pfx is random certificate with no password, as a file in project and also imported into Current User Certificates > Personal > Certificates in certmgr.msc.

问题是AuthenticateAsClient抛出

The problem is AuthenticateAsClient throws an

System.IO.IOException:身份验证失败,因为远程方
已关闭传输流异常

此外,如果在AuthenticateAsCtlient方法主机名意味着什么,如果服务器接受每个证书? ?我应该把有什么显著

Also, if the hostname in AuthenticateAsCtlient method means anything, if server accepts every certificate? Should I put there something significant?

我仍然可以与服务器人员联系,这样我就可以问他们的一切 - 我们需要的任何其他信息

I still can contact with the server guys, so I can ask them about everything - do we need any additional information?

推荐答案

得到它的工作。

谁主持socket服务器的服务器必须已安装在其证书存储证书的用私钥 。如果你安装它,没有它(只是证书或只公钥),你会得到验证失败的那些错误。

The server who is hosting the socket server MUST have installed on its Certification Storage the certificate WITH the Private Key. If you install it without it (just the certificate or just the public key) you will get those errors of authentication failure.

我希望它帮助。

这篇关于Socket和身份验证失败,因为远程方已关闭在WPF传输流异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 17:59