Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SSL流程和学员的一般用途_C#_Delegates_Sslstream - Fatal编程技术网

C# SSL流程和学员的一般用途

C# SSL流程和学员的一般用途,c#,delegates,sslstream,C#,Delegates,Sslstream,我以前从未使用过代理,但经过两个小时的努力,我理解了基本概念。我创建了一个简单的SSL客户机/服务器,具有相互身份验证。现在我的实际问题是: 在中,委托用于对服务器/客户端进行身份验证 SslStream sslStream = new SslStream( client.GetStream(), false, new RemoteCertificateValidationCallback (ValidateServer

我以前从未使用过代理,但经过两个小时的努力,我理解了基本概念。我创建了一个简单的SSL客户机/服务器,具有相互身份验证。现在我的实际问题是:

在中,委托用于对服务器/客户端进行身份验证

SslStream sslStream = new SslStream(
            client.GetStream(), 
            false, 
            new RemoteCertificateValidationCallback (ValidateServerCertificate), 
            null
            );
ValidateServerCertificate是调用委托时运行的方法

public static bool ValidateServerCertificate(
          object sender,
          X509Certificate certificate,
          X509Chain chain,
          SslPolicyErrors sslPolicyErrors)
    {
       if (sslPolicyErrors == SslPolicyErrors.None)
            return true;

        Console.WriteLine("Certificate error: {0}", sslPolicyErrors);

        // Do not allow this client to communicate with unauthenticated servers.
        return false;
    }
最让我困惑的是ValidateServerCertificate到底是如何获取参数的。也许这是一个愚蠢的问题,你现在正在笑,但请容忍我。在过去的几个小时里,我一直坐在教程和解释面前,但我没有发现任何对我有帮助的东西


提前感谢类将在某个时间点调用委托。当它调用委托时,它将被迫为委托所期望的参数提供值。然后使用这些参数调用委托表示的所有方法。

谢谢,我一直在想类似的事情一定会发生。可能是在客户在握手过程中提供了证书之后的某个地方。再次感谢您的澄清。