簡體   English   中英

在 C# 中,在服務器端使用 SslStream.AuthenticateAsServer() 有什么意義?

[英]In C# what is the point of using SslStream.AuthenticateAsServer() on the server side?

我正在嘗試偵聽端口上的安全 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);

我的疑問是為什么服務器要對自己進行身份驗證? 或者我在這里錯過了什么。

也許你錯過了“作為”。 該調用告訴 SslStream 它應該為 TLS 握手(身份驗證發生的地方)做准備,並且它在握手中扮演服務器角色。

所以它真的是“開始身份驗證階段,作為服務器”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM