【问题标题】:In C# what is the point of using SslStream.AuthenticateAsServer() on the server side?在 C# 中,在服务器端使用 SslStream.AuthenticateAsServer() 有什么意义?
【发布时间】:2021-08-16 23:34:50
【问题描述】:

我正在尝试侦听端口上的安全 TCP 连接。我正在浏览微软文档上的服务器代码示例。我在这里粘贴以供快速参考:

static void ProcessClient (TcpClient client)
    {
        // A client has connected. Create the
        // SslStream using the client's network stream.
        SslStream sslStream = new SslStream(
            client.GetStream(), false);
        // Authenticate the server but don't require the client to authenticate.
        try
        {
            sslStream.AuthenticateAsServer(serverCertificate, clientCertificateRequired: false, checkCertificateRevocation: true);

            // Display the properties and settings for the authenticated stream.
            DisplaySecurityLevel(sslStream);
            DisplaySecurityServices(sslStream);
            DisplayCertificateInformation(sslStream);
            DisplayStreamProperties(sslStream);

我的疑问是为什么服务器要对自己进行身份验证?还是我在这里遗漏了什么。

【问题讨论】:

    标签: c# authentication server certificate sslstream


    【解决方案1】:

    也许您缺少“作为”。该调用告诉 SslStream 它应该为 TLS 握手(发生身份验证的地方)做准备,并且它在握手中扮演服务器角色。

    所以这真的是“开始身份验证阶段,作为服务器”。

    【讨论】:

    • 谢谢。我想你的回复对我来说完全有道理。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 2010-11-15
    • 2020-01-31
    • 2016-08-06
    • 1970-01-01
    相关资源
    最近更新 更多